예제 #1
0
        public bool DoSyncChannelSummaryPerDay(UnitParameter up, DateTime start, DateTime end, ref string msg)
        {
            //清除旧汇总资料
            (from t in DB.LamdaTable(up, "ChannelSummaryPerDay")
             where t.log_date >= start.ToString("yyyy-MM-dd HH:mm:ss") && t.log_date <= end.ToString("yyyy-MM-dd HH:mm:ss")
             select t).Delete(up);
            //从分销商报表中统计数据
            var channelSummaryList = (from t in DB.LamdaTable(up, "RetailSummaryPerDay", "a")
                                      join t2 in DB.LamdaTable(up, "Retail", "b") on t.retail_uid equals t2.uid
                                      join t3 in DB.LamdaTable(up, "ChannelBusiness", "c") on t2.belong_channel_uid equals t3.uid
                                      where t.log_time >= start.ToString("yyyy-MM-dd HH:mm:ss") && t.log_time <= end.ToString("yyyy-MM-dd HH:mm:ss")
                                      group new { t, t2, t3 } by new { t.retail_uid, t2.royalty_category, t3.uid, t3.rebate_cps, t3.rebate_cpa } into g
                                      select new
            {
                channel_uid = g.t3.uid,
                retail_uid = g.t.retail_uid,
                log_date = end.ToString("yyyy-MM-dd HH:mm:ss"),
                hits = g.t.hits.sum(),
                volume_count = g.t.volume_count.sum(),
                volume_rate = 0,
                register_count = g.t.register_count.sum(),
                perfection_count = g.t.perfection_count.sum(),
                perfection_rate = 0,
                unit_price_cps = g.t3.rebate_cps,
                unit_price_cpa = g.t3.rebate_cpa,
                g.t2.royalty_category,
                income = 0
            }).GetQueryList(up);

            foreach (dynamic item in channelSummaryList)
            {
                if (DoubleStd.IsNotDoubleThen(item.register_count) != 0)
                {
                    item.perfection_rate = DoubleStd.IsNotDoubleThen(item.perfection_count) / DoubleStd.IsNotDoubleThen(item.register_count);
                    item.volume_rate     = DoubleStd.IsNotDoubleThen(item.volume_count) / DoubleStd.IsNotDoubleThen(item.register_count);
                }

                switch (ComFunc.nvl(item.royalty_category))
                {
                case "cps":
                    item.income = DoubleStd.IsNotDoubleThen(item.volume_count) * DoubleStd.IsNotDoubleThen(item.unit_price_cps);
                    break;

                case "cpa":
                    item.income = DoubleStd.IsNotDoubleThen(item.register_count) * DoubleStd.IsNotDoubleThen(item.unit_price_cpa);
                    break;

                default:
                    item.income = 0;
                    break;
                }

                DB.QuickInsert(up, "ChannelSummaryPerDay", new
                {
                    uid = Guid.NewGuid().ToString(),
                    item.channel_uid,
                    item.retail_uid,
                    item.log_date,
                    item.hits,
                    item.volume_count,
                    item.volume_rate,
                    item.register_count,
                    item.perfection_count,
                    item.perfection_rate,
                    item.unit_price_cps,
                    item.unit_price_cpa,
                    item.income,
                    add_id   = "admin",
                    add_ip   = "",
                    add_name = "admin",
                    add_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                });
            }

            return(true);
        }
예제 #2
0
        public bool DoSyncPlatSummaryPerDay(UnitParameter up, DateTime start, DateTime end, ref string msg)
        {
            //清除旧汇总资料
            (from t in DB.LamdaTable(up, "PlatSummaryPerDay")
             where t.log_date >= start.ToString("yyyy-MM-dd HH:mm:ss") && t.log_date <= end.ToString("yyyy-MM-dd HH:mm:ss")
             select t).Delete(up);

            var platSummaryList = (from t in DB.LamdaTable(up, "APPSummaryPerDay", "a")
                                   where t.log_time >= start.ToString("yyyy-MM-dd HH:mm:ss") && t.log_time <= end.ToString("yyyy-MM-dd HH:mm:ss")
                                   select new
            {
                log_date = end.ToString("yyyy-MM-dd HH:mm:ss"),
                hits = t.hits.sum(),
                register_count = t.register_count.sum(),
                perfection_count = t.perfection_count.sum(),
                volume_count = t.volume_count.sum(),
                consume_amount = t.consume.sum(),
                recharge_amount = t.recharge.sum(),
                consume_sum = t.consume_sum.sum(),
                recharge_sum = t.recharge_sum.sum()
            }).GetQueryList(up);
            var withdrewChannelSummaryTodayList = (from t in DB.LamdaTable(up, "ChannelWithDraw", "a")
                                                   where t.status == "audit" && t.submit_time >= start.ToString("yyyy-MM-dd HH:mm:ss") && t.submit_time <= end.ToString("yyyy-MM-dd HH:mm:ss")
                                                   select new
            {
                withdrew_sum = t.amount.sum()
            }).GetQueryList(up);
            var withdrewChannelSummaryList = (from t in DB.LamdaTable(up, "ChannelWithDraw", "a")
                                              where t.status == "audit"
                                              select new
            {
                withdrew_sum = t.amount.sum()
            }).GetQueryList(up);
            var withdrewRetailSummaryTodayList = (from t in DB.LamdaTable(up, "RetailWithDraw", "a")
                                                  where t.status == "audit" && t.submit_time >= start.ToString("yyyy-MM-dd HH:mm:ss") && t.submit_time <= end.ToString("yyyy-MM-dd HH:mm:ss")
                                                  select new
            {
                withdrew_sum = t.amount.sum()
            }).GetQueryList(up);
            var withdrewRetailSummaryList = (from t in DB.LamdaTable(up, "RetailWithDraw", "a")
                                             where t.status == "audit"
                                             select new
            {
                withdrew_sum = t.amount.sum()
            }).GetQueryList(up);
            var withdrew_today = 0.0;

            if (withdrewChannelSummaryTodayList.Count > 0)
            {
                withdrew_today = DoubleStd.IsNotDoubleThen(withdrewChannelSummaryTodayList.First().GetValue("withdrew_sum")) + withdrew_today;
            }
            if (withdrewRetailSummaryTodayList.Count > 0)
            {
                withdrew_today = DoubleStd.IsNotDoubleThen(withdrewRetailSummaryTodayList.First().GetValue("withdrew_sum")) + withdrew_today;
            }
            var withdrew_sum = 0.0;

            if (withdrewChannelSummaryList.Count > 0)
            {
                withdrew_sum = DoubleStd.IsNotDoubleThen(withdrewChannelSummaryList.First().GetValue("withdrew_sum")) + withdrew_today;
            }
            if (withdrewRetailSummaryList.Count > 0)
            {
                withdrew_sum = DoubleStd.IsNotDoubleThen(withdrewRetailSummaryList.First().GetValue("withdrew_sum")) + withdrew_today;
            }

            foreach (dynamic item in platSummaryList)
            {
                item.uid = Guid.NewGuid().ToString();
                if (DoubleStd.IsNotDoubleThen(item.register_count) != 0)
                {
                    item.perfection_rate = DoubleStd.IsNotDoubleThen(item.perfection_count) / DoubleStd.IsNotDoubleThen(item.register_count);
                    item.volume_rate     = DoubleStd.IsNotDoubleThen(item.volume_count) / DoubleStd.IsNotDoubleThen(item.register_count);
                }
                item.withdrew_amount = withdrew_today;
                item.withdrew_sum    = withdrew_sum;

                DB.QuickInsert(up, "PlatSummaryPerDay", new
                {
                    item.uid,
                    item.log_date,
                    item.hits,
                    item.register_count,
                    item.perfection_count,
                    item.perfection_rate,
                    item.volume_count,
                    item.volume_rate,
                    item.consume_amount,
                    item.recharge_amount,
                    item.consume_sum,
                    item.recharge_sum,
                    item.withdrew_amount,
                    item.withdrew_sum,
                    add_id   = "admin",
                    add_ip   = "",
                    add_name = "admin",
                    add_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                });
            }
            return(true);
        }
예제 #3
0
        public bool DoSyncRetailSummaryPerDay(UnitParameter up, DateTime start, DateTime end, ref string msg)
        {
            //清除旧汇总资料
            (from t in DB.LamdaTable(up, "RetailSummaryPerDay")
             where t.log_time >= start.ToString("yyyy-MM-dd HH:mm:ss") && t.log_time <= end.ToString("yyyy-MM-dd HH:mm:ss")
             select t).Delete(up);
            //获取前一日的汇入资料
            var limit         = 10000;
            var is_end        = false;
            var to            = 1;
            var retailSummary = new Dictionary <string, dynamic>();

            do
            {
                up.ToPage           = to;
                up.Count_Of_OnePage = limit;
                var exchangeresult = (from t in DB.LamdaTable(up, "APPExchange", "a")
                                      join t2 in DB.LamdaTable(up, "APPInfo", "b") on t.app_uid equals t2.uid
                                      join t3 in DB.LamdaTable(up, "UserInfo", "c") on t.mobile equals t3.mobile
                                      join t4 in DB.LamdaTable(up, "Retail", "d") on t3.recommend_uid equals t4.uid
                                      where t.log_time >= start.ToString("yyyy-MM-dd HH:mm:ss") && t.log_time <= end.ToString("yyyy-MM-dd HH:mm:ss")
                                      select new
                {
                    t.app_uid,
                    t.log_time,
                    t.mobile,
                    t.is_deal,
                    t.is_register,
                    t.is_perfection,
                    retail_uid = t3.recommend_uid
                }).QueryByPage(up);
                var list = exchangeresult.QueryData <FrameDLRObject>();
                //计算app
                var hit_group = from t in list
                                group t by new { app_uid = t.GetValue("app_uid"), retail_uid = t.GetValue("retail_uid") } into g
                    select new
                {
                    app_uid       = g.First().GetValue("app_uid"),
                    retail_uid    = g.First().GetValue("retail_uid"),
                    require_count = g.First().GetValue("require_count"),
                    hits          = g.Count()
                };
                var register_group = from t in list
                                     where t.is_register == 1
                                     group t by new { app_uid = t.GetValue("app_uid"), retail_uid = t.GetValue("retail_uid") } into g
                    select new
                {
                    app_uid        = g.First().GetValue("app_uid"),
                    retail_uid     = g.First().GetValue("retail_uid"),
                    register_count = g.Count()
                };
                var volume_group = from t in list
                                   where t.is_deal == 1
                                   group t by new { app_uid = t.GetValue("app_uid"), retail_uid = t.GetValue("retail_uid") } into g
                    select new
                {
                    app_uid      = g.First().GetValue("app_uid"),
                    retail_uid   = g.First().GetValue("retail_uid"),
                    volume_count = g.Count()
                };
                var perfection_group = from t in list
                                       where t.is_perfection == 1
                                       group t by new { app_uid = t.GetValue("app_uid"), retail_uid = t.GetValue("retail_uid") } into g
                    select new
                {
                    app_uid          = g.First().GetValue("app_uid"),
                    retail_uid       = g.First().GetValue("retail_uid"),
                    perfection_count = g.Count()
                };
                //点击量
                foreach (var item in hit_group)
                {
                    var key = ComFunc.nvl(item.app_uid) + ComFunc.nvl(item.retail_uid);
                    if (!retailSummary.ContainsKey(key))
                    {
                        var dobj = FrameDLRObject.CreateInstance();
                        dobj.uid        = Guid.NewGuid().ToString();
                        dobj.retail_uid = item.retail_uid;
                        dobj.app_uid    = item.app_uid;
                        dobj.log_time   = end.ToString("yyyy-MM-dd");
                        dobj.add_id     = "admin";
                        dobj.add_ip     = "";
                        dobj.add_name   = "admin";
                        dobj.add_time   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                        retailSummary.Add(key, dobj);
                    }
                    retailSummary[key].hits = IntStd.IsNotIntThen(retailSummary[key].hits) + IntStd.IsNotIntThen(item.hits);
                }
                //注册量
                foreach (var item in register_group)
                {
                    var key = ComFunc.nvl(item.app_uid) + ComFunc.nvl(item.retail_uid);
                    retailSummary[key].register_count = IntStd.IsNotIntThen(retailSummary[key].register_count) + IntStd.IsNotIntThen(item.register_count);
                }
                //成单量
                foreach (var item in volume_group)
                {
                    var key = ComFunc.nvl(item.app_uid) + ComFunc.nvl(item.retail_uid);
                    retailSummary[key].volume_count = IntStd.IsNotIntThen(retailSummary[key].volume_count) + IntStd.IsNotIntThen(item.volume_count);
                }
                //完善量
                foreach (var item in perfection_group)
                {
                    var key = ComFunc.nvl(item.app_uid) + ComFunc.nvl(item.retail_uid);
                    retailSummary[key].perfection_count = IntStd.IsNotIntThen(retailSummary[key].perfection_count) + IntStd.IsNotIntThen(item.perfection_count);
                }

                to++;
                is_end = exchangeresult.CurrentPage >= exchangeresult.TotalPage;
            } while (!is_end);
            //抓取分销商的提现记录
            var withdrew_dic = (from t in DB.LamdaTable(up, "RetailAccountLog", "a")
                                join t2 in DB.LamdaTable(up, "Retail", "b") on t.retail_uid equals t2.uid
                                where t.action == "提现" && t.log_time >= start.ToString("yyyy-MM-dd HH:mm:ss") && t.log_time <= end.ToString("yyyy-MM-dd HH:mm:ss")
                                group new { t, t2 } by new { t.retail_uid, t2.rebate, t2.royalty_category } into g
                                select new
            {
                g.t.retail_uid,
                g.t2.rebate,
                g.t2.royalty_category,
                withdrew_sum = g.t.amount.sum()
            }).GetQueryList(up).ToDictionary(k => ComFunc.nvl(k.GetValue("retail_uid")), v => (dynamic)v);

            foreach (var item in retailSummary.Values)
            {
                if (DoubleStd.IsNotDoubleThen(item.register_count) != 0)
                {
                    item.perfection_rate = DoubleStd.IsNotDoubleThen(item.perfection_count) / DoubleStd.IsNotDoubleThen(item.register_count);
                    item.volume_rate     = DoubleStd.IsNotDoubleThen(item.volume_count) / DoubleStd.IsNotDoubleThen(item.register_count);
                }
                else
                {
                    item.perfection_rate = 0;
                    item.volume_rate     = 0;
                }

                item.withdrew_sum = withdrew_dic.ContainsKey(ComFunc.nvl(item.retail_uid)) ? DoubleStd.IsNotDoubleThen(withdrew_dic[ComFunc.nvl(item.retail_uid)].withdrew_sum) : 0;
                item.income       = 0;
                if (withdrew_dic.ContainsKey(ComFunc.nvl(item.retail_uid)))
                {
                    var dobj = withdrew_dic[ComFunc.nvl(item.retail_uid)];
                    switch (ComFunc.nvl(dobj.royalty_category))
                    {
                    case "cps":
                        item.income = DoubleStd.IsNotDoubleThen(item.volume_count) * DoubleStd.IsNotDoubleThen(dobj.rebate);
                        break;

                    case "cpa":
                        item.income = DoubleStd.IsNotDoubleThen(item.register_count) * DoubleStd.IsNotDoubleThen(dobj.rebate);
                        break;

                    default:
                        item.income = 0;
                        break;
                    }
                }

                DB.QuickInsert(up, "RetailSummaryPerDay", item);
            }

            return(true);
        }
예제 #4
0
        /// <summary>
        /// 汇总APP的每日汇总报表,指定时间段
        /// </summary>
        /// <param name="up"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool DoSyncAPPSummaryPerDay(UnitParameter up, DateTime start, DateTime end, ref string msg)
        {
            //清除旧汇总资料
            (from t in DB.LamdaTable(up, "APPSummaryPerDay")
             where t.log_time >= start.ToString("yyyy-MM-dd HH:mm:ss") && t.log_time <= end.ToString("yyyy-MM-dd HH:mm:ss")
             select t).Delete(up);
            //获取前一日的汇入资料
            var limit  = 10000;
            var is_end = false;
            var to     = 1;

            var app_summarylist = (from t in DB.LamdaTable(up, "APPInfo", "a")
                                   select new
            {
                uid = "",
                app_uid = t.uid,
                log_time = end.ToString("yyyy-MM-dd HH:mm:ss"),
                hits = 0,
                register_count = 0,
                register_rate = 0,
                perfection_count = 0,
                perfection_rate = 0,
                volume_count = 0,
                volume_rate = 0,
                consume = 0,
                recharge = 0,
                consume_sum = 0,
                recharge_sum = 0,
                remain_amount = t.available_amount,
                reqirement_count = t.require_count,
                t.rebate_to_us_cps
            }).GetQueryList(up);
            //获取当日充值数据
            var s = from t in DB.LamdaTable(up, "APPCharge", "a")
                    where t.is_success == 1 && t.submit_time >= start.ToString("yyyy-MM-dd HH:mm:ss") && t.submit_time <= end.ToString("yyyy-MM-dd HH:mm:ss")
                    group new { t } by t.app_uid into g
                select new
            {
                g.t.app_uid,
                recharge_amount = g.t.amount.sum()
            };
            var rechargeSumToday = s.GetQueryList(up);
            var rechargeSum      = (from t in DB.LamdaTable(up, "APPCharge", "a")
                                    where t.is_success == 1
                                    group new { t } by t.app_uid into g
                                    select new
            {
                g.t.app_uid,
                recharge_amount = g.t.amount.sum()
            }).GetQueryList(up);

            foreach (dynamic item in app_summarylist)
            {
                item.uid = Guid.NewGuid().ToString();
                dynamic rech = rechargeSumToday.Where(w => w.app_uid == item.app_uid).FirstOrDefault();
                if (rech != null)
                {
                    item.recharge = DoubleStd.IsNotDoubleThen(rech.recharge_amount);
                }
                dynamic rechsum = rechargeSum.Where(w => w.app_uid == item.app_uid).FirstOrDefault();
                if (rech != null)
                {
                    item.recharge_sum = DoubleStd.IsNotDoubleThen(rech.recharge_amount);
                }
            }
            var app_summary = app_summarylist.ToDictionary(k => ComFunc.nvl(k.GetValue("app_uid")), v => (dynamic)v);

            do
            {
                up.ToPage           = to;
                up.Count_Of_OnePage = limit;
                var exchangeresult = (from t in DB.LamdaTable(up, "APPExchange", "a")
                                      join t2 in DB.LamdaTable(up, "APPInfo", "b").LeftJoin() on t.app_uid equals t2.uid
                                      where t.log_time >= start.ToString("yyyy-MM-dd HH:mm:ss") && t.log_time <= end.ToString("yyyy-MM-dd HH:mm:ss")
                                      select new
                {
                    t.app_uid,
                    t.log_time,
                    t.mobile,
                    t.is_deal,
                    t.is_register,
                    t.is_perfection,
                    t2.require_count
                }).QueryByPage(up);
                var list = exchangeresult.QueryData <FrameDLRObject>();
                //计算app
                var hit_group = from t in list
                                group t by t.GetValue("app_uid") into g
                                select new
                {
                    app_uid       = g.First().GetValue("app_uid"),
                    require_count = g.First().GetValue("require_count"),
                    hits          = g.Count()
                };
                var register_group = from t in list
                                     where t.is_register == 1
                                     group t by t.GetValue("app_uid") into g
                                     select new
                {
                    app_uid        = g.First().GetValue("app_uid"),
                    register_count = g.Count()
                };
                var volume_group = from t in list
                                   where t.is_deal == 1
                                   group t by t.GetValue("app_uid") into g
                                   select new
                {
                    app_uid      = g.First().GetValue("app_uid"),
                    volume_count = g.Count()
                };
                var perfection_group = from t in list
                                       where t.is_perfection == 1
                                       group t by t.GetValue("app_uid") into g
                                       select new
                {
                    app_uid          = g.First().GetValue("app_uid"),
                    perfection_count = g.Count()
                };
                //点击量
                foreach (var item in hit_group)
                {
                    var key = ComFunc.nvl(item.app_uid);
                    if (!app_summary.ContainsKey(key))
                    {
                        GlobalCommon.Logger.WriteLog(LoggerLevel.DEBUG, $"DoSyncSummaryPerDay:同步数据时发现未记录的APP_UID-{key}");
                        continue;
                    }
                    app_summary[key].hits = IntStd.IsNotIntThen(app_summary[key].hits) + IntStd.IsNotIntThen(item.hits);
                }
                //注册量
                foreach (var item in register_group)
                {
                    var key = ComFunc.nvl(item.app_uid);
                    if (!app_summary.ContainsKey(key))
                    {
                        continue;
                    }
                    app_summary[key].register_count = IntStd.IsNotIntThen(app_summary[key].register_count) + IntStd.IsNotIntThen(item.register_count);
                }
                //成单量
                foreach (var item in volume_group)
                {
                    var key = ComFunc.nvl(item.app_uid);
                    if (!app_summary.ContainsKey(key))
                    {
                        continue;
                    }
                    app_summary[key].volume_count = IntStd.IsNotIntThen(app_summary[key].volume_count) + IntStd.IsNotIntThen(item.volume_count);
                }
                //完善量
                foreach (var item in perfection_group)
                {
                    var key = ComFunc.nvl(item.app_uid);
                    if (!app_summary.ContainsKey(key))
                    {
                        continue;
                    }
                    app_summary[key].volume_count = IntStd.IsNotIntThen(app_summary[key].perfection_count) + IntStd.IsNotIntThen(item.perfection_count);
                }

                to++;
                is_end = exchangeresult.CurrentPage == exchangeresult.TotalPage;
            } while (!is_end);

            foreach (var item in app_summary.Values)
            {
                //计算完善率,成单率
                if (DoubleStd.IsNotDoubleThen(item.register_count) != 0)
                {
                    item.perfection_rate = DoubleStd.IsNotDoubleThen(item.perfection_count) / DoubleStd.IsNotDoubleThen(item.register_count);
                    item.volume_rate     = DoubleStd.IsNotDoubleThen(item.volume_count) / DoubleStd.IsNotDoubleThen(item.register_count);
                    item.consume         = IntStd.IsNotIntThen(item.volume_count) * DoubleStd.IsNotDoubleThen(item.rebate_to_us_cps);
                }
                DB.QuickInsert(up, "APPSummaryPerDay", new
                {
                    item.uid,
                    item.app_uid,
                    item.log_time,
                    item.hits,
                    item.register_count,
                    item.perfection_count,
                    item.perfection_rate,
                    item.volume_count,
                    item.volume_rate,
                    item.consume,
                    item.recharge,
                    item.consume_sum,
                    item.recharge_sum,
                    item.reqirement_count,
                    add_id   = "admin",
                    add_ip   = "",
                    add_name = "admin",
                    add_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                });
            }
            return(true);
        }
예제 #5
0
        object Charge(string id)
        {
            if (ComFunc.nvl(id) == "")
            {
                return new { code = "failed", msg = "账号无效" }
            }
            ;

            double amount = PostDataD.amount;
            var    memo   = ComFunc.nvl(PostDataD.memo);
            var    wd_no  = ComFunc.nvl(PostDataD.wd_no);
            var    ou_id  = ComFunc.nvl(PostDataD.ou_id);
            var    up     = DB.NewDBUnitParameter();

            BeginTrans();

            dynamic useritem = null;
            var     s        = from t in DB.LamdaTable("ecs_users", "a")
                               where t.user_id == id && t.is_validated == 1
                               select t;
            var userresult = DB.ExcuteLamda(up, s);

            if (userresult.QueryTable.RowLength <= 0)
            {
                return(new { code = "failed", msg = "账号无效" });
            }
            else
            {
                useritem = userresult.QueryData <FrameDLRObject>()[0];
            }

            var result = DB.ExcuteLamda(up, from t in DB.LamdaTable("ecs_user_wallet", "a")
                                        where t.user_id == id
                                        select t);

            if (amount <= 0)
            {
                return(new { code = "failed", msg = "金额不合法" });
            }
            if (DB.IsExists(up, from t in DB.LamdaTable("ecs_user_wallet_line", "a")
                            where t.ebs_wd_no == wd_no
                            select t))
            {
                return(new { code = "failed", msg = "WD编号重复" });
            }



            if (result.QueryTable.RowLength <= 0)
            {
                DB.QuickInsert(up, "ecs_user_wallet", new
                {
                    user_id      = id,
                    user_name    = useritem.user_name,
                    total_amount = amount,
                    memo         = memo,
                    add_time     = DateTime.Now,
                    add_id       = "WalletAPI",
                    last_time    = DateTime.Now,
                    last_id      = "WalletAPI"
                });
            }
            else
            {
                dynamic item = result.QueryData <FrameDLRObject>()[0];
                DB.QuickUpdate(up, "ecs_user_wallet", new
                {
                    total_amount = DoubleStd.IsNotDoubleThen(item.total_amount) + amount
                }, new
                {
                    user_id = id
                });
            }
            //写入line
            var newlineno = IntStd.IsNotIntThen(DB.Max(up, from t in DB.LamdaTable("ecs_user_wallet_line", "a")
                                                       where t.user_id == id
                                                       select t, "line_no")) + 1;

            DB.QuickInsert(up, "ecs_user_wallet_line", new
            {
                user_id      = id,
                line_no      = newlineno,
                ebs_wd_no    = wd_no,
                ebs_ou_id    = ou_id,
                total_amount = amount,
                memo         = memo,
                add_time     = DateTime.Now,
                add_id       = "WalletAPI",
                last_time    = DateTime.Now,
                last_id      = "WalletAPI"
            });

            dynamic data = DB.ExcuteLamda(up, from t in DB.LamdaTable("ecs_user_wallet", "a")
                                          where t.user_id == id
                                          select t).QueryData <FrameDLRObject>()[0];

            var newseq = GetNewSeq(ComFunc.nvl(DB.Max(up, from t in DB.LamdaTable("ecs_user_wallet_log", "a")
                                                      where t.user_id == id
                                                      select t, "seq")));

            //记录流水

            DB.QuickInsert(up, "ecs_user_wallet_log", new
            {
                user_id               = id,
                uid                   = Guid.NewGuid().ToString(),
                amount                = amount,
                events                = "打款",
                memo                  = memo,
                ebs_wd_no             = wd_no,
                ebs_ou_id             = ou_id,
                last_time             = DateTime.Now,
                last_id               = "WalletAPI",
                seq                   = newseq,
                line_total_amount     = amount,
                line_freeze_amount    = 0,
                line_used_amount      = 0,
                line_available_amount = amount,
                total_amount          = data.total_amount,
                freeze_amount         = DecimalStd.IsNotDecimalThen(data.freeze_amount),
                used_amount           = DecimalStd.IsNotDecimalThen(data.used_amount),
                available_amount      = DecimalStd.IsNotDecimalThen(data.total_amount) - DecimalStd.IsNotDecimalThen(data.freeze_amount) - DecimalStd.IsNotDecimalThen(data.used_amount)
            });

            CommitTrans();
            return(new
            {
                code = "success",
                wallet = new
                {
                    user_id = data.user_id,
                    total_amount = data.total_amount,
                    freeze_amount = DecimalStd.IsNotDecimalThen(data.freeze_amount),
                    used_amount = DecimalStd.IsNotDecimalThen(data.used_amount),
                    available_amount = DecimalStd.IsNotDecimalThen(data.total_amount) - DecimalStd.IsNotDecimalThen(data.freeze_amount) - DecimalStd.IsNotDecimalThen(data.used_amount)
                }
            });
        }
예제 #6
0
        object Use(string id)
        {
            lock (lockobj)
            {
                double amount    = PostDataD.amount;
                var    memo      = ComFunc.nvl(PostDataD.memo);
                var    ou_id     = ComFunc.nvl(PostDataD.ou_id);
                var    ebs_wd_no = ComFunc.nvl(PostDataD.ebs_wd_no);
                var    up        = DB.NewDBUnitParameter();
                BeginTrans();

                var s = from t in DB.LamdaTable("ecs_user_wallet", "a")
                        where t.user_id == id
                        select t;
                var result = DB.ExcuteLamda(up, s);
                if (result.QueryTable.RowLength <= 0)
                {
                    return(new { code = "failed", msg = "账号无效" });
                }

                dynamic item = result.QueryData <FrameDLRObject>()[0];
                if (amount > DoubleStd.IsNotDoubleThen(item.freeze_amount))
                {
                    return(new { code = "failed", msg = "金额溢出" });
                }
                //核销行资料
                var tmpamount = amount;
                //找出可用的行资料
                var availablelist = DB.ExcuteLamda(up, from t in DB.LamdaTable("ecs_user_wallet_line", "a")
                                                   orderby t.line_no ascending
                                                   where t.user_id == id && t.freeze_amount.isnull(0) > 0 && t.notnull(ou_id, t.ebs_ou_id == ou_id) && t.notnull(ebs_wd_no, t.ebs_wd_no.within($",{ebs_wd_no},"))
                                                   select t).QueryData <FrameDLRObject>();
                if (availablelist.Count <= 0)
                {
                    return(new { code = "failed", msg = "无可用额度" });
                }
                var total_freeze_amount = DoubleStd.IsNotDoubleThen(item.freeze_amount);
                var total_used_amount   = DoubleStd.IsNotDoubleThen(item.used_amount);
                var tmplist             = new List <object>();
                foreach (dynamic obj in availablelist)
                {
                    var freeze = DoubleStd.IsNotDoubleThen(obj.freeze_amount);
                    if (tmpamount > freeze)
                    {
                        obj.freeze_amount        = 0;
                        obj.used_amount          = DoubleStd.IsNotDoubleThen(obj.used_amount) + freeze;
                        obj.current_use_amount   = freeze;
                        obj.available_amount     = DoubleStd.IsNotDoubleThen(obj.total_amount) - DoubleStd.IsNotDoubleThen(obj.freeze_amount) - DoubleStd.IsNotDoubleThen(obj.used_amount);
                        obj.all_total_amount     = item.total_amount;
                        obj.all_freeze_amount    = total_freeze_amount = total_freeze_amount - freeze;
                        obj.all_used_amount      = total_used_amount = total_used_amount + freeze;
                        obj.all_available_amount = DoubleStd.IsNotDoubleThen(obj.all_total_amount) - DoubleStd.IsNotDoubleThen(obj.all_freeze_amount) - DoubleStd.IsNotDoubleThen(obj.all_used_amount);
                        tmplist.Add(obj);
                        tmpamount = tmpamount - freeze;
                    }
                    else
                    {
                        obj.freeze_amount        = DoubleStd.IsNotDoubleThen(obj.freeze_amount) - tmpamount;
                        obj.used_amount          = DoubleStd.IsNotDoubleThen(obj.used_amount) + tmpamount;
                        obj.current_use_amount   = tmpamount;
                        obj.available_amount     = DoubleStd.IsNotDoubleThen(obj.total_amount) - DoubleStd.IsNotDoubleThen(obj.freeze_amount) - DoubleStd.IsNotDoubleThen(obj.used_amount);
                        obj.all_total_amount     = item.total_amount;
                        obj.all_freeze_amount    = total_freeze_amount = total_freeze_amount - tmpamount;
                        obj.all_used_amount      = total_used_amount = total_used_amount + tmpamount;
                        obj.all_available_amount = DoubleStd.IsNotDoubleThen(obj.all_total_amount) - DoubleStd.IsNotDoubleThen(obj.all_freeze_amount) - DoubleStd.IsNotDoubleThen(obj.all_used_amount);
                        tmplist.Add(obj);
                        tmpamount = 0;
                        break;
                    }
                }
                if (tmpamount > 0)
                {
                    return(new { code = "failed", msg = "无可用额度" });
                }
                foreach (dynamic obj in tmplist)
                {
                    DB.QuickUpdate(up, "ecs_user_wallet_line", new
                    {
                        freeze_amount = obj.freeze_amount,
                        used_amount   = obj.used_amount,
                        memo          = memo,
                        last_time     = DateTime.Now,
                        last_id       = "WalletAPI"
                    }, new
                    {
                        user_id   = obj.user_id,
                        ebs_wd_no = obj.ebs_wd_no
                    });
                }

                DB.QuickUpdate(up, "ecs_user_wallet", new
                {
                    freeze_amount = DoubleStd.IsNotDoubleThen(item.freeze_amount) - amount,
                    used_amount   = DoubleStd.IsNotDoubleThen(item.used_amount) + amount
                }, new
                {
                    user_id = id
                });

                dynamic data = DB.ExcuteLamda(up, from t in DB.LamdaTable("ecs_user_wallet", "a")
                                              where t.user_id == id
                                              select t).QueryData <FrameDLRObject>()[0];
                var newseq = GetNewSeq(ComFunc.nvl(DB.Max(up, from t in DB.LamdaTable("ecs_user_wallet_log", "a")
                                                          where t.user_id == id
                                                          select t, "seq")));
                //记录流水
                foreach (dynamic obj in tmplist)
                {
                    DB.QuickInsert(up, "ecs_user_wallet_log", new
                    {
                        user_id               = id,
                        uid                   = Guid.NewGuid().ToString(),
                        amount                = obj.current_use_amount,
                        events                = "核销",
                        memo                  = memo,
                        ebs_wd_no             = obj.ebs_wd_no,
                        ebs_ou_id             = obj.ebs_ou_id,
                        last_time             = DateTime.Now,
                        last_id               = "WalletAPI",
                        seq                   = newseq,
                        line_total_amount     = obj.total_amount,
                        line_freeze_amount    = DecimalStd.IsNotDecimalThen(obj.freeze_amount),
                        line_used_amount      = DecimalStd.IsNotDecimalThen(obj.used_amount),
                        line_available_amount = obj.available_amount,
                        total_amount          = obj.all_total_amount,
                        freeze_amount         = DecimalStd.IsNotDecimalThen(obj.all_freeze_amount),
                        used_amount           = DecimalStd.IsNotDecimalThen(obj.all_used_amount),
                        available_amount      = DecimalStd.IsNotDecimalThen(obj.all_total_amount) - DecimalStd.IsNotDecimalThen(obj.all_freeze_amount) - DecimalStd.IsNotDecimalThen(obj.all_used_amount)
                    });
                    newseq = GetNewSeq(newseq);
                }

                CommitTrans();
                return(new
                {
                    code = "success",
                    wallet = new
                    {
                        user_id = data.user_id,
                        current_freeze_amount = amount,
                        total_amount = data.total_amount,
                        freeze_amount = DecimalStd.IsNotDecimalThen(data.freeze_amount),
                        used_amount = DecimalStd.IsNotDecimalThen(data.used_amount),
                        available_amount = data.total_amount - DecimalStd.IsNotDecimalThen(data.freeze_amount) - DecimalStd.IsNotDecimalThen(data.used_amount),
                        lines = from t in tmplist
                                select new
                        {
                            line_no = ((dynamic)t).line_no,
                            ebs_wd_no = ((dynamic)t).ebs_wd_no,
                            ebs_ou_id = ((dynamic)t).ebs_ou_id,
                            current_use_amount = ((dynamic)t).current_use_amount,
                            total_amount = ((dynamic)t).total_amount,
                            freeze_amount = ((dynamic)t).freeze_amount,
                            used_amount = ((dynamic)t).used_amount,
                            available_amount = DoubleStd.IsNotDoubleThen(((dynamic)t).total_amount) - DoubleStd.IsNotDoubleThen(((dynamic)t).freeze_amount) - DoubleStd.IsNotDoubleThen(((dynamic)t).used_amount)
                        }
                    }
                });
            }
        }
예제 #7
0
        object PreCancel(string id)
        {
            lock (lockobj)
            {
                double amount    = PostDataD.amount;
                var    memo      = ComFunc.nvl(PostDataD.memo);
                var    ou_id     = ComFunc.nvl(PostDataD.ou_id);
                var    ebs_wd_no = ComFunc.nvl(PostDataD.ebs_wd_no);
                var    up        = DB.NewDBUnitParameter();
                BeginTrans();

                var s = from t in DB.LamdaTable("ecs_user_wallet", "a")
                        where t.user_id == id
                        select t;
                var result = DB.ExcuteLamda(up, s);
                if (result.QueryTable.RowLength <= 0)
                {
                    return(new { code = "failed", msg = "账号无效" });
                }
                dynamic item = result.QueryData <FrameDLRObject>()[0];
                if (amount > DoubleStd.IsNotDoubleThen(item.freeze_amount))
                {
                    return(new { code = "failed", msg = "金额溢出" });
                }
                //找到行资料-倒叙搜索
                var tmpamount     = amount;
                var availablelist = DB.ExcuteLamda(up, from t in DB.LamdaTable("ecs_user_wallet_line", "a")
                                                   orderby t.line_no descending
                                                   where t.user_id == id && t.freeze_amount.isnull(0) > 0 && t.notnull(ou_id, t.ebs_ou_id == ou_id) && t.notnull(ebs_wd_no, t.ebs_wd_no.within($",{ebs_wd_no},"))
                                                   select t).QueryData <FrameDLRObject>();
                if (availablelist.Count <= 0)
                {
                    return(new { code = "failed", msg = "无可用额度" });
                }
                var total_freeze_amount = DoubleStd.IsNotDoubleThen(item.freeze_amount);
                var total_used_amount   = DoubleStd.IsNotDoubleThen(item.used_amount);
                var tmplist             = new List <object>();
                foreach (dynamic obj in availablelist)
                {
                    var freeze = DoubleStd.IsNotDoubleThen(obj.freeze_amount);
                    if (tmpamount > freeze)
                    {
                        obj.freeze_amount         = 0;
                        obj.current_cancel_amount = freeze;
                        obj.available_amount      = DoubleStd.IsNotDoubleThen(obj.total_amount) - DoubleStd.IsNotDoubleThen(obj.freeze_amount) - DoubleStd.IsNotDoubleThen(obj.used_amount);
                        obj.all_total_amount      = item.total_amount;
                        obj.all_freeze_amount     = total_freeze_amount = total_freeze_amount - freeze;
                        obj.all_used_amount       = total_used_amount;
                        obj.all_available_amount  = DoubleStd.IsNotDoubleThen(obj.all_total_amount) - DoubleStd.IsNotDoubleThen(obj.all_freeze_amount) - DoubleStd.IsNotDoubleThen(obj.all_used_amount);
                        tmplist.Add(obj);
                        tmpamount = tmpamount - freeze;
                    }
                    else
                    {
                        obj.freeze_amount         = DoubleStd.IsNotDoubleThen(obj.freeze_amount) - tmpamount;
                        obj.current_cancel_amount = tmpamount;
                        obj.available_amount      = DoubleStd.IsNotDoubleThen(obj.total_amount) - DoubleStd.IsNotDoubleThen(obj.freeze_amount) - DoubleStd.IsNotDoubleThen(obj.used_amount);
                        obj.all_total_amount      = item.total_amount;
                        obj.all_freeze_amount     = total_freeze_amount = total_freeze_amount - tmpamount;
                        obj.all_used_amount       = total_used_amount;
                        obj.all_available_amount  = DoubleStd.IsNotDoubleThen(obj.all_total_amount) - DoubleStd.IsNotDoubleThen(obj.all_freeze_amount) - DoubleStd.IsNotDoubleThen(obj.all_used_amount);
                        tmplist.Add(obj);
                        tmpamount = 0;
                        break;
                    }
                }
                if (tmpamount > 0)
                {
                    return(new { code = "failed", msg = "无可用额度" });
                }

                CommitTrans();

                return(new
                {
                    code = "success",
                    wallet = new
                    {
                        user_id = item.user_id,
                        current_cancel_amount = amount,
                        total_amount = item.total_amount,
                        freeze_amount = DecimalStd.IsNotDecimalThen(item.freeze_amount) - DecimalStd.IsNotDecimalThen(amount),
                        used_amount = DecimalStd.IsNotDecimalThen(item.used_amount),
                        available_amount = item.total_amount - DecimalStd.IsNotDecimalThen(item.freeze_amount) - DecimalStd.IsNotDecimalThen(item.used_amount) + DecimalStd.IsNotDecimalThen(amount),
                        lines = from t in tmplist
                                select new
                        {
                            line_no = ((dynamic)t).line_no,
                            ebs_wd_no = ((dynamic)t).ebs_wd_no,
                            ebs_ou_id = ((dynamic)t).ebs_ou_id,
                            current_cancel_amount = ((dynamic)t).current_cancel_amount,
                            total_amount = ((dynamic)t).total_amount,
                            freeze_amount = ((dynamic)t).freeze_amount,
                            used_amount = ((dynamic)t).used_amount,
                            available_amount = DoubleStd.IsNotDoubleThen(((dynamic)t).total_amount) - DoubleStd.IsNotDoubleThen(((dynamic)t).freeze_amount) - DoubleStd.IsNotDoubleThen(((dynamic)t).used_amount)
                        }
                    }
                });
            }
        }