using Api.Framework.Enums; using Api.Framework.Model; using Api.Framework.SDK; using Api.Framework.Utils; using CsharpHttpHelper; using SqlSugar; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using static Api.Framework.Cps.AlimamaApi; namespace Api.Framework.Tools { /// /// 变量替换 /// public class VariateReplace { private static List pddlist = new List() { "[拼多多待结算数量]", "[拼多多待结算金额]", "[拼多多冻结金额]", "[拼多多冻结订单数]", "[拼多多未收货金额]", "[拼多多未收货订单数]" }; private static List tblist = new List() { "[淘宝待结算数量]", "[淘宝待结算金额]", "[淘宝冻结金额]", "[淘宝冻结订单数]", "[淘宝未收货金额]", "[淘宝未收货订单数]" }; private static List jdlist = new List() { "[京东待结算数量]", "[京东待结算金额]", "[京东冻结金额]", "[京东冻结订单数]", "[京东未收货金额]", "[京东未收货订单数]" }; private static List wphlist = new List() { "[唯品会待结算数量]", "[唯品会待结算金额]", "[唯品会冻结金额]", "[唯品会冻结订单数]", "[唯品会未收货金额]", "[唯品会未收货订单数]" }; private static List dylist = new List() { "[抖音待结算数量]", "[抖音待结算金额]", "[抖音冻结金额]", "[抖音冻结订单数]", "[抖音未收货金额]", "[抖音未收货订单数]" }; private static List snlist = new List() { "[苏宁待结算数量]", "[苏宁待结算金额]", "[苏宁冻结金额]", "[苏宁冻结订单数]", "[苏宁未收货金额]", "[苏宁未收货订单数]" }; private static List kslist = new List() { "[快手待结算数量]", "[快手待结算金额]", "[快手冻结金额]", "[快手冻结订单数]", "[快手未收货金额]", "[快手未收货订单数]" }; private static List list = new List() { "[待结算总数数量]", "[待结算总数金额]", "[待收货积分]", "[未收货积分]", "[未收货总金额]", "[待结算积分]", "[冻结总金额]", "[待收货订单数]", "[未收货订单数]", "[待结算订单数]", "[冻结订单数]" }; StringBuilder mess = null; private object lock_replace = new object(); private void Replace(string key, string value) { if (mess != null) { lock (lock_replace) mess = mess.Replace(key, value); } } /// /// 通用替换变量 /// /// 替换的内容 /// 与变量有关联的对象 /// public string CommonReplace(string _mess, params object[] objs) { if (string.IsNullOrEmpty(_mess)) return string.Empty; mess = new StringBuilder(_mess); try { Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName); List actions = new List(); //List tasks = new List(); foreach (var item in objs) { var type = item.GetType(); if (type == typeof(fl_order_alimama)) { var order = item as fl_order_alimama; Replace("[订单号]", order.trade_parent_id); Replace("[商品标题]", order.item_title); Replace("[子订单号]", order.trade_id); Replace("[付款金额]", order.alipay_total_price.ToString()); Replace("[结算时间]", order.db_endtime.ToString("yyyy-MM-dd HH:mm:ss")); Replace("[下级订单状态]", order.db_status.ToString()); #region [原始返利积分] [维权金额] 淘宝变量 if (order != null) { var session = ApiClient.GetSession(); if (_mess.Contains("[维权金额]")) { var refund_alimama = session.Find("select * from fl_order_refund_alimama where tbtradeparentid = @tbtradeparentid and tbtradeid = @tbtradeid", new { tbtradeparentid = order.trade_parent_id, tbtradeid = order.trade_id }).FirstOrDefault(); if (refund_alimama != null) Replace("[维权金额]", refund_alimama.refundfee.ToString()); } if (_mess.Contains("[原始返利积分]")) { if (order.db_userid != 0) { var member = session.FindMemberInfoById(order.db_userid); if (member != null) { ////获取历史的增加积分 //var pointHists = session.Find("select * from fl_point_hist where uid = @uid and type = @pointType_name and message = @message", new { uid = order.db_userid, pointType_name = PointType.消费补贴, message = $"淘宝购买:{order.item_title} - ({order.trade_parent_id}) - ({order.trade_id})" }); //var histAddPoint = 0d; ////if (pointHists != null && pointHists.Count == 1) //if (pointHists != null && pointHists.Count != 0) //{ // pointHists = pointHists.OrderByDescending(f => f.crt_time).ToList(); // histAddPoint = pointHists[0].point; //} //if (histAddPoint != 0) //{ // Replace("[原始返利积分]", histAddPoint.ToString("0.00")); //} //else //{ // var itempoint = session.FindItemPoint(member, (double)(Math.Round((decimal)order.alipay_total_price * (decimal)order.income_rate, 2, MidpointRounding.AwayFromZero)), order.item_num, CpsType.阿里妈妈);//重新计算阿里妈妈给的佣金 // if (itempoint != null) // { // Replace("[原始返利积分]", itempoint.UserPoint.ToString()); // } //} var isReplace = false; var rhPoint = session.FindRefundHistPoint(order.trade_parent_id, order.trade_id, CpsType.阿里妈妈); if (rhPoint != null) { //获取积分信息 var point = HttpHelper.JsonToObject(rhPoint.db_point) as ItemPoint; if (point != null) { Replace("[原始返利积分]", point.UserPoint.ToString("0.00")); isReplace = true; } } if (!isReplace) { #region 其他方案 //获取历史的增加积分 var pointHists = session.Find("select * from fl_point_hist where uid = @uid and type = @pointType_name and message = @message", new { uid = order.db_userid, pointType_name = PointType.消费补贴.ToString(), message = $"淘宝购买:{order.item_title} - ({order.trade_parent_id}) - ({order.trade_id})" }); var histAddPoint = 0d; //if (pointHists != null && pointHists.Count == 1) if (pointHists != null && pointHists.Count != 0) { pointHists = pointHists.OrderByDescending(f => f.crt_time).ToList(); histAddPoint = pointHists[0].point; } if (histAddPoint != 0) { Replace("[原始返利积分]", histAddPoint.ToString("0.00")); } else { var itempoint = session.FindItemPoint(member, (double)(Math.Round((decimal)order.alipay_total_price * (decimal)order.income_rate, 2, MidpointRounding.AwayFromZero)), order.item_num, CpsType.阿里妈妈);//重新计算阿里妈妈给的佣金 if (itempoint != null) { Replace("[原始返利积分]", itempoint.UserPoint.ToString()); } } #endregion } } } Replace("[原始返利积分]", "0.00"); } } #endregion } if (type == typeof(fl_order_jingdong)) { var order = item as fl_order_jingdong; Replace("[订单号]", order.orderId.ToString()); Replace("[商品标题]", order.skuName); Replace("[付款金额]", order.estimateCosPrice.ToString()); Replace("[结算时间]", order.db_endtime.ToString("yyyy-MM-dd HH:mm:ss")); Replace("[下级订单状态]", order.db_status.ToString()); } if (type == typeof(fl_order_pinduoduo)) { var order = item as fl_order_pinduoduo; Replace("[订单号]", order.order_sn); Replace("[商品标题]", order.goods_name); Replace("[付款金额]", order.order_amount.ToString()); Replace("[结算时间]", order.db_endtime.ToString("yyyy-MM-dd HH:mm:ss")); Replace("[下级订单状态]", order.db_status.ToString()); } if (type == typeof(fl_order_douyin)) { var order = item as fl_order_douyin; Replace("[订单号]", order.order_id); Replace("[商品标题]", order.product_name); Replace("[付款金额]", Util.ConvertDouble_FenToYuan(order.total_pay_amount).ToString("0.00")); Replace("[结算时间]", order.db_endtime.ToString("yyyy-MM-dd HH:mm:ss")); Replace("[下级订单状态]", order.db_status.ToString()); } if (type == typeof(fl_order_weipinhui)) { var order = item as fl_order_weipinhui; Replace("[订单号]", order.orderSn); Replace("[商品标题]", order.goodsName); Replace("[付款金额]", order.goodsFinalPrice.ToString()); Replace("[结算时间]", order.db_endtime.ToString("yyyy-MM-dd HH:mm:ss")); Replace("[下级订单状态]", order.db_status.ToString()); } if (type == typeof(fl_order_douyin)) { var order = item as fl_order_douyin; Replace("[订单号]", order.order_id); Replace("[商品标题]", order.product_name); Replace("[付款金额]", Util.ConvertDouble_FenToYuan(order.total_pay_amount).ToString()); Replace("[结算时间]", order.db_endtime.ToString("yyyy-MM-dd HH:mm:ss")); Replace("[下级订单状态]", order.db_status.ToString()); } if (type == typeof(fl_order_suning)) { var order = item as fl_order_suning; Replace("[订单号]", order.orderCode); Replace("[商品标题]", order.productName); Replace("[付款金额]", Util.ConvertDouble_FenToYuan((int)(double.Parse(order.payAmount) * 100)).ToString("0.00")); Replace("[结算时间]", order.db_endtime.ToString("yyyy-MM-dd HH:mm:ss")); Replace("[下级订单状态]", order.db_status.ToString()); } if (type == typeof(fl_order_kuaishou)) { var order = item as fl_order_kuaishou; Replace("[订单号]", order.oid.ToString()); Replace("[商品标题]", order.itemTitle); Replace("[付款金额]", order.paymentFee.ToString("0.00")); Replace("[结算时间]", order.db_endtime.ToString("yyyy-MM-dd HH:mm:ss")); Replace("[下级订单状态]", order.db_status.ToString()); } else if (type == typeof(fl_robot_info)) { var robot = item as fl_robot_info; Replace("[机器人账号]", robot.name); Replace("[机器人昵称]", robot.nick); } else if (type == typeof(fl_member_info)) { var session = ApiClient.GetSession(); var member = item as fl_member_info; if (_mess.Contains("[上级昵称]")) { var m = session.FindMemberInfoById(member.inviter_id); if (m != null) Replace("[上级昵称]", m.realnick); else Replace("[上级昵称]", "无"); } Replace("[消费者昵称]", member.realnick); Replace("[限制兑换时间]", member.ban_exchange_time.ToString("yyyy-MM-dd HH:mm:ss")); Replace("[可兑换积分]", "[剩余积分]"); Replace("[剩余积分]", member.cur_point.ToString()); Replace("[账号]", member.username); Replace("[昵称]", member.realnick); Replace("[累计积分]", member.sum_point.ToString()); Replace("[提成积分]", member.ext_point.ToString()); Replace("[其他积分]", member.rew_point.ToString()); Replace("[消费积分]", member.buy_point.ToString()); Replace("[推广积分]", ((decimal)member.rew_point + (decimal)member.ext_point).ToString()); Replace("[支付宝账号]", member.alipay_num); Replace("[支付宝姓名]", member.alipay_name); Replace("[身份证号]", member.identity_card); Replace("[身份证号码]", member.identity_card); Replace("[姓名]", member.identity_name); Replace("[身份证姓名]", member.identity_name); Replace("[平台类型]", member.robot_type.ToString()); #region 今日订单信息/已退款订单数/今日总积分/已退款积分 if (_mess.Contains("[订单总数]")) { actions.Add(new Action(delegate { var timeNow = DateTime.Now; var session1 = ApiClient.GetSession(); var data = session1.FindRow($@"select COALESCE(SUM(num),0) as num from ( select count(*) as num from fl_order_alimama where db_userid = @userid UNION all select count(*) as num from fl_order_pinduoduo where db_userid = @userid UNION all select count(*) as num from fl_order_jingdong where db_userid = @userid UNION all select count(*) as num from fl_order_weipinhui where db_userid = @userid UNION all select count(*) as num from fl_order_suning where db_userid = @userid UNION all select count(*) as num from fl_order_douyin where db_userid = @userid UNION all select count(*) as num from fl_order_kuaishou where db_userid = @userid ) as temp", new { userid = member.id }); Replace("[订单总数]", data["num"].ToString()); LogHelper.GetSingleObj().Debug("", $"订单总数:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); })); } if (_mess.Contains("[今日总订单]")) { actions.Add(new Action(delegate { var timeNow = DateTime.Now; var session1 = ApiClient.GetSession(); var data = session1.FindRow($@"select COALESCE(SUM(num),0) as num from ( select count(*) as num from fl_order_alimama where @begin_time < create_time and create_time <= @end_time and db_userid = @userid UNION All select count(*) as num from fl_order_pinduoduo where @begin_time < order_create_time and order_create_time <= @end_time and db_userid = @userid UNION All select count(*) as num from fl_order_jingdong where @begin_time < orderTime and orderTime <= @end_time and db_userid = @userid UNION All select count(*) as num from fl_order_suning where @begin_time < orderSubmitTime and orderSubmitTime <= @end_time and db_userid = @userid UNION All select count(*) as num from fl_order_weipinhui where @begin_time1 < orderTime and orderTime <= @end_time1 and db_userid = @userid UNION All select count(*) as num from fl_order_douyin where @begin_time2 < pay_time and pay_time <= @end_time2 and db_userid = @userid UNION All select count(*) as num from fl_order_kuaishou where @begin_time < payTime and payTime <= @end_time and db_userid = @userid ) as temp", new { begin_time = DateTime.Today.AddSeconds(-1).ToString("yyyy-MM-dd HH:mm:ss"), end_time = DateTime.Today.AddDays(1).AddSeconds(-1).ToString("yyyy-MM-dd HH:mm:ss"), begin_time1 = Util.GetTimeSpan(DateTime.Today.AddSeconds(-1), true), end_time1 = Util.GetTimeSpan(DateTime.Today.AddDays(1).AddSeconds(-1), true), begin_time2 = Util.GetTimeSpan(DateTime.Today.AddSeconds(-1), false), end_time2 = Util.GetTimeSpan(DateTime.Today.AddDays(1).AddSeconds(-1), false), userid = member.id }); Replace("[今日总订单]", data["num"].ToString()); LogHelper.GetSingleObj().Debug("", $"今日总订单:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); })); } if (_mess.Contains("[已退款订单数]")) { Replace("[已退款订单数]", FindOrderInfoByState(999, member.id, OrderStateType.退款订单数)); } if (_mess.Contains("[今日总积分]")) { actions.Add(new Action(delegate { var timeNow = DateTime.Now; var session1 = ApiClient.GetSession(); var result = session1.FindRow($@"select COALESCE(SUM(num),0) as num from ( select COALESCE(SUM(db_userpoint),0) as num from fl_order_alimama where @begin_time < create_time and create_time <= @end_time and db_userid = @userid UNION all select COALESCE(SUM(db_userpoint),0) as num from fl_order_pinduoduo where @begin_time < order_create_time and order_create_time <= @end_time and db_userid = @userid UNION all select COALESCE(SUM(db_userpoint),0) as num from fl_order_jingdong where @begin_time < orderTime and orderTime <= @end_time and db_userid = @userid UNION all select COALESCE(SUM(db_userpoint),0) as num from fl_order_suning where @begin_time < orderSubmitTime and orderSubmitTime <= @end_time and db_userid = @userid UNION all select COALESCE(SUM(db_userpoint),0) as num from fl_order_weipinhui where @begin_time1 < orderTime and orderTime <= @end_time1 and db_userid = @userid UNION all select COALESCE(SUM(db_userpoint),0) as num from fl_order_douyin where @begin_time2 < pay_time and pay_time <= @end_time2 and db_userid = @userid UNION all select COALESCE(SUM(db_userpoint),0) as num from fl_order_kuaishou where @begin_time < payTime and payTime <= @end_time and db_userid = @userid ) as temp", new { begin_time = DateTime.Today.AddSeconds(-1).ToString("yyyy-MM-dd HH:mm:ss"), end_time = DateTime.Today.AddDays(1).AddSeconds(-1).ToString("yyyy-MM-dd HH:mm:ss"), begin_time1 = Util.GetTimeSpan(DateTime.Today.AddSeconds(-1), true), end_time1 = Util.GetTimeSpan(DateTime.Today.AddDays(1).AddSeconds(-1), true), begin_time2 = Util.GetTimeSpan(DateTime.Today.AddSeconds(-1), false), end_time2 = Util.GetTimeSpan(DateTime.Today.AddDays(1).AddSeconds(-1), false), userid = member.id }); Replace("[今日总积分]", double.Parse(result["num"].ToString()).ToString()); LogHelper.GetSingleObj().Debug("", $"今日总积分:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); })); } if (_mess.Contains("[已退款积分]")) Replace("[已退款积分]", FindOrderInfoByState(999, member.id, OrderStateType.退款总金额)); if (_mess.Contains("[已兑换积分]") || _mess.Contains("[已兑换总额]")) { Replace("[已兑换总额]", "[已兑换积分]"); Replace("[已兑换积分]", FindAlreadyExchange(member.id)); } if (_mess.Contains("[兑换中积分]")) Replace("[兑换中积分]", session.FindRow($"select COALESCE(SUM(point),0) as num from fl_exchange_info where uid = @uid and state = 1", new { uid = member.id })["num"].ToString()); if (_mess.Contains("[下级总提成]")) Replace("[下级总提成]", member.ext_point.ToString("0.00")); #endregion #region 各种订单金额数量查询 actions.Add(new Action(delegate { var timeNow = DateTime.Now; var session1 = ApiClient.GetSession(); //[拼多多待结算数量]、[拼多多待结算金额]、[淘宝待结算数量]、[淘宝待结算金额]、[京东待结算数量]、[京东待结算金额]、[待结算总数数量]、[待结算总数金额]、[淘宝售后中订单数]、[京东售后中订单数] decimal pddPendingPoint_sleep, pddPendingPoint_pay, pddPendingPoint, alimamaPendingPoint_sleep, alimamaPendingPoint_pay, alimamaPendingPoint, jdPendingPoint_sleep, jdPendingPoint_pay, jdPendingPoint, wphPendingPoint_sleep, wphPendingPoint_pay, wphPendingPoint, dyPendingPoint_sleep, dyPendingPoint_pay, dyPendingPoint, snPendingPoint_sleep, snPendingPoint_pay, snPendingPoint, ksPendingPoint_sleep, ksPendingPoint_pay, ksPendingPoint, sumPendingPoint; pddPendingPoint_sleep = pddPendingPoint_pay = pddPendingPoint = alimamaPendingPoint_sleep = alimamaPendingPoint_pay = alimamaPendingPoint = jdPendingPoint_sleep = jdPendingPoint_pay = jdPendingPoint = wphPendingPoint_sleep = wphPendingPoint_pay = wphPendingPoint = dyPendingPoint_sleep = dyPendingPoint_pay = dyPendingPoint = snPendingPoint_sleep = snPendingPoint_pay = snPendingPoint = ksPendingPoint_sleep = ksPendingPoint_pay = ksPendingPoint = sumPendingPoint = 0m; int pddPendingCount_sleep, pddPendingCount_pay, pddPendingCount, alimamaPendingCount_sleep, alimamaPendingCount_pay, alimamaPendingCount, jdPendingCount_sleep, jdPendingCount_pay, jdPendingCount, wphPendingCount_sleep, wphPendingCount_pay, wphPendingCount, dyPendingCount_sleep, dyPendingCount_pay, dyPendingCount, snPendingCount_sleep, snPendingCount_pay, snPendingCount, ksPendingCount_sleep, ksPendingCount_pay, ksPendingCount, sumPendingCount, alimamaReturnNum, jingdongReturnNum, weipinhuiReturnNum, douyinReturnNum, suningReturnNum, kuaishouReturnNum; pddPendingCount_sleep = pddPendingCount_pay = pddPendingCount = alimamaPendingCount_sleep = alimamaPendingCount_pay = alimamaPendingCount = jdPendingCount_sleep = jdPendingCount_pay = jdPendingCount = wphPendingCount_sleep = wphPendingCount_pay = wphPendingCount = dyPendingCount_sleep = dyPendingCount_pay = dyPendingCount = snPendingCount_sleep = snPendingCount_pay = snPendingCount = ksPendingCount_sleep = ksPendingCount_pay = ksPendingCount = sumPendingCount = alimamaReturnNum = jingdongReturnNum = weipinhuiReturnNum = douyinReturnNum = suningReturnNum = kuaishouReturnNum = 0; Dictionary pddDic = null; Dictionary tbDic = null; Dictionary jdDic = null; Dictionary wphDic = null; Dictionary dyDic = null; Dictionary snDic = null; Dictionary ksDic = null; if (pddlist.FirstOrDefault(f => _mess.Contains(f)) != null) { timeNow = DateTime.Now; pddDic = FindOrderTotalInfo("fl_order_pinduoduo", member.id); if (pddDic != null) { pddPendingPoint_sleep = pddDic["point_sleep"]; pddPendingCount_sleep = (int)pddDic["count_sleep"]; pddPendingPoint_pay = pddDic["point_pay"]; pddPendingCount_pay = (int)pddDic["count_pay"]; pddPendingPoint = pddDic["point"]; pddPendingCount = (int)pddDic["count"]; } LogHelper.GetSingleObj().Debug("", $"A_pinduoduo:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (tblist.FirstOrDefault(f => _mess.Contains(f)) != null) { timeNow = DateTime.Now; tbDic = FindOrderTotalInfo("fl_order_alimama", member.id); if (tbDic != null) { alimamaPendingPoint_sleep = tbDic["point_sleep"]; alimamaPendingCount_sleep = (int)tbDic["count_sleep"]; alimamaPendingPoint_pay = tbDic["point_pay"]; alimamaPendingCount_pay = (int)tbDic["count_pay"]; alimamaPendingPoint = tbDic["point"]; alimamaPendingCount = (int)tbDic["count"]; } LogHelper.GetSingleObj().Debug("", $"A_alimama:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (jdlist.FirstOrDefault(f => _mess.Contains(f)) != null) { timeNow = DateTime.Now; jdDic = FindOrderTotalInfo("fl_order_jingdong", member.id); if (jdDic != null) { jdPendingPoint_sleep = jdDic["point_sleep"]; jdPendingCount_sleep = (int)jdDic["count_sleep"]; jdPendingPoint_pay = jdDic["point_pay"]; jdPendingCount_pay = (int)jdDic["count_pay"]; jdPendingPoint = jdDic["point"]; jdPendingCount = (int)jdDic["count"]; } LogHelper.GetSingleObj().Debug("", $"A_jingdong:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (wphlist.FirstOrDefault(f => _mess.Contains(f)) != null) { timeNow = DateTime.Now; wphDic = FindOrderTotalInfo("fl_order_weipinhui", member.id); if (wphDic != null) { wphPendingPoint_sleep = wphDic["point_sleep"]; wphPendingCount_sleep = (int)wphDic["count_sleep"]; wphPendingPoint_pay = wphDic["point_pay"]; wphPendingCount_pay = (int)wphDic["count_pay"]; wphPendingPoint = wphDic["point"]; wphPendingCount = (int)wphDic["count"]; } LogHelper.GetSingleObj().Debug("", $"A_weipinhui:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (dylist.FirstOrDefault(f => _mess.Contains(f)) != null) { timeNow = DateTime.Now; dyDic = FindOrderTotalInfo("fl_order_douyin", member.id); if (dyDic != null) { dyPendingPoint_sleep = dyDic["point_sleep"]; dyPendingCount_sleep = (int)dyDic["count_sleep"]; dyPendingPoint_pay = dyDic["point_pay"]; dyPendingCount_pay = (int)dyDic["count_pay"]; dyPendingPoint = dyDic["point"]; dyPendingCount = (int)dyDic["count"]; } LogHelper.GetSingleObj().Debug("", $"A_douyin:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (snlist.FirstOrDefault(f => _mess.Contains(f)) != null) { timeNow = DateTime.Now; snDic = FindOrderTotalInfo("fl_order_suning", member.id); if (snDic != null) { snPendingPoint_sleep = snDic["point_sleep"]; snPendingCount_sleep = (int)snDic["count_sleep"]; snPendingPoint_pay = snDic["point_pay"]; snPendingCount_pay = (int)snDic["count_pay"]; snPendingPoint = snDic["point"]; snPendingCount = (int)snDic["count"]; } LogHelper.GetSingleObj().Debug("", $"A_suning:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (kslist.FirstOrDefault(f => _mess.Contains(f)) != null) { timeNow = DateTime.Now; ksDic = FindOrderTotalInfo("fl_order_kuaishou", member.id); if (ksDic != null) { ksPendingPoint_sleep = ksDic["point_sleep"]; ksPendingCount_sleep = (int)ksDic["count_sleep"]; ksPendingPoint_pay = ksDic["point_pay"]; ksPendingCount_pay = (int)ksDic["count_pay"]; ksPendingPoint = ksDic["point"]; ksPendingCount = (int)ksDic["count"]; } LogHelper.GetSingleObj().Debug("", $"A_suning:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (list.FirstOrDefault(f => _mess.Contains(f)) != null) { if (pddDic == null) { timeNow = DateTime.Now; pddDic = FindOrderTotalInfo("fl_order_pinduoduo", member.id); if (pddDic != null) { pddPendingPoint_sleep = pddDic["point_sleep"]; pddPendingCount_sleep = (int)pddDic["count_sleep"]; pddPendingPoint_pay = pddDic["point_pay"]; pddPendingCount_pay = (int)pddDic["count_pay"]; pddPendingPoint = pddDic["point"]; pddPendingCount = (int)pddDic["count"]; } LogHelper.GetSingleObj().Debug("", $"B_pinduoduo:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (tbDic == null) { timeNow = DateTime.Now; tbDic = FindOrderTotalInfo("fl_order_alimama", member.id); if (tbDic != null) { alimamaPendingPoint_sleep = tbDic["point_sleep"]; alimamaPendingCount_sleep = (int)tbDic["count_sleep"]; alimamaPendingPoint_pay = tbDic["point_pay"]; alimamaPendingCount_pay = (int)tbDic["count_pay"]; alimamaPendingPoint = tbDic["point"]; alimamaPendingCount = (int)tbDic["count"]; } LogHelper.GetSingleObj().Debug("", $"B_alimama:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (jdDic == null) { timeNow = DateTime.Now; jdDic = FindOrderTotalInfo("fl_order_jingdong", member.id); if (jdDic != null) { jdPendingPoint_sleep = jdDic["point_sleep"]; jdPendingCount_sleep = (int)jdDic["count_sleep"]; jdPendingPoint_pay = jdDic["point_pay"]; jdPendingCount_pay = (int)jdDic["count_pay"]; jdPendingPoint = jdDic["point"]; jdPendingCount = (int)jdDic["count"]; } LogHelper.GetSingleObj().Debug("", $"B_jingdong:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (wphDic == null) { timeNow = DateTime.Now; wphDic = FindOrderTotalInfo("fl_order_weipinhui", member.id); if (wphDic != null) { wphPendingPoint_sleep = wphDic["point_sleep"]; wphPendingCount_sleep = (int)wphDic["count_sleep"]; wphPendingPoint_pay = wphDic["point_pay"]; wphPendingCount_pay = (int)wphDic["count_pay"]; wphPendingPoint = wphDic["point"]; wphPendingCount = (int)wphDic["count"]; } LogHelper.GetSingleObj().Debug("", $"B_weipinhui:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (dyDic == null) { timeNow = DateTime.Now; dyDic = FindOrderTotalInfo("fl_order_douyin", member.id); if (dyDic != null) { dyPendingPoint_sleep = dyDic["point_sleep"]; dyPendingCount_sleep = (int)dyDic["count_sleep"]; dyPendingPoint_pay = dyDic["point_pay"]; dyPendingCount_pay = (int)dyDic["count_pay"]; dyPendingPoint = dyDic["point"]; dyPendingCount = (int)dyDic["count"]; } LogHelper.GetSingleObj().Debug("", $"B_douyin:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (snDic == null) { timeNow = DateTime.Now; snDic = FindOrderTotalInfo("fl_order_suning", member.id); if (snDic != null) { snPendingPoint_sleep = snDic["point_sleep"]; snPendingCount_sleep = (int)snDic["count_sleep"]; snPendingPoint_pay = snDic["point_pay"]; snPendingCount_pay = (int)snDic["count_pay"]; snPendingPoint = snDic["point"]; snPendingCount = (int)snDic["count"]; } LogHelper.GetSingleObj().Debug("", $"B_suning:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (ksDic == null) { timeNow = DateTime.Now; ksDic = FindOrderTotalInfo("fl_order_kuaishou", member.id); if (ksDic != null) { ksPendingPoint_sleep = ksDic["point_sleep"]; ksPendingCount_sleep = (int)ksDic["count_sleep"]; ksPendingPoint_pay = ksDic["point_pay"]; ksPendingCount_pay = (int)ksDic["count_pay"]; ksPendingPoint = ksDic["point"]; ksPendingCount = (int)ksDic["count"]; } LogHelper.GetSingleObj().Debug("", $"B_kuaishou:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } sumPendingPoint = pddPendingPoint + alimamaPendingPoint + jdPendingPoint + wphPendingPoint + dyPendingPoint + snPendingPoint + ksPendingPoint; sumPendingCount = pddPendingCount + alimamaPendingCount + jdPendingCount + wphPendingCount + dyPendingCount + snPendingCount + ksPendingCount; } if (_mess.Contains("[淘宝售后中订单数]")) { timeNow = DateTime.Now; var result = session1.FindRow("select count(*) as count from fl_order_alimama where db_userid = @id and db_status = 1000", new { id = member.id }); alimamaReturnNum = int.Parse(result["count"].ToString()); LogHelper.GetSingleObj().Debug("", $"淘宝售后中订单数:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (_mess.Contains("[京东售后中订单数]")) { timeNow = DateTime.Now; var result = session1.FindRow("select count(*) as count from fl_order_jingdong where db_userid = @id and db_status = 1000", new { id = member.id }); jingdongReturnNum = int.Parse(result["count"].ToString()); LogHelper.GetSingleObj().Debug("", $"京东售后中订单数:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (_mess.Contains("[唯品会售后中订单数]")) { timeNow = DateTime.Now; var result = session1.FindRow("select count(*) as count from fl_order_weipinhui where db_userid = @id and db_status = 1000", new { id = member.id }); weipinhuiReturnNum = int.Parse(result["count"].ToString()); LogHelper.GetSingleObj().Debug("", $"唯品会售后中订单数:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (_mess.Contains("[抖音售后中订单数]")) { timeNow = DateTime.Now; var result = session1.FindRow("select count(*) as count from fl_order_douyin where db_userid = @id and db_status = 1000", new { id = member.id }); douyinReturnNum = int.Parse(result["count"].ToString()); LogHelper.GetSingleObj().Debug("", $"抖音售后中订单数:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (_mess.Contains("[苏宁售后中订单数]")) { timeNow = DateTime.Now; var result = session1.FindRow("select count(*) as count from fl_order_suning where db_userid = @id and db_status = 1000", new { id = member.id }); suningReturnNum = int.Parse(result["count"].ToString()); LogHelper.GetSingleObj().Debug("", $"苏宁售后中订单数:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } if (_mess.Contains("[快手售后中订单数]")) { timeNow = DateTime.Now; var result = session1.FindRow("select count(*) as count from fl_order_kuaishou where db_userid = @id and db_status = 1000", new { id = member.id }); kuaishouReturnNum = int.Parse(result["count"].ToString()); LogHelper.GetSingleObj().Debug("", $"快手售后中订单数:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } Replace("[淘宝售后中订单数]", alimamaReturnNum.ToString()); Replace("[京东售后中订单数]", jingdongReturnNum.ToString()); Replace("[唯品会售后中订单数]", weipinhuiReturnNum.ToString()); Replace("[抖音售后中订单数]", douyinReturnNum.ToString()); Replace("[苏宁售后中订单数]", suningReturnNum.ToString()); Replace("[快手售后中订单数]", kuaishouReturnNum.ToString()); Replace("[拼多多待结算数量]", pddPendingCount.ToString()); Replace("[拼多多待结算金额]", pddPendingPoint.ToString("0.00")); Replace("[淘宝待结算数量]", alimamaPendingCount.ToString()); Replace("[淘宝待结算金额]", alimamaPendingPoint.ToString("0.00")); Replace("[京东待结算数量]", jdPendingCount.ToString()); Replace("[京东待结算金额]", jdPendingPoint.ToString("0.00")); Replace("[唯品会待结算数量]", wphPendingCount.ToString()); Replace("[唯品会待结算金额]", wphPendingPoint.ToString("0.00")); Replace("[抖音待结算数量]", dyPendingCount.ToString()); Replace("[抖音待结算金额]", dyPendingPoint.ToString("0.00")); Replace("[苏宁待结算数量]", snPendingCount.ToString()); Replace("[苏宁待结算金额]", snPendingPoint.ToString("0.00")); Replace("[快手待结算数量]", ksPendingCount.ToString()); Replace("[快手待结算金额]", ksPendingPoint.ToString("0.00")); Replace("[待结算总数数量]", sumPendingCount.ToString()); Replace("[待结算总数金额]", sumPendingPoint.ToString("0.00")); Replace("[淘宝冻结金额]", alimamaPendingPoint_sleep.ToString("0.00")); Replace("[拼多多冻结金额]", pddPendingPoint_sleep.ToString("0.00")); Replace("[京东冻结金额]", jdPendingPoint_sleep.ToString("0.00")); Replace("[唯品会冻结金额]", wphPendingPoint_sleep.ToString("0.00")); Replace("[抖音冻结金额]", dyPendingPoint_sleep.ToString("0.00")); Replace("[苏宁冻结金额]", snPendingPoint_sleep.ToString("0.00")); Replace("[快手冻结金额]", ksPendingPoint_sleep.ToString("0.00")); Replace("[淘宝冻结订单数]", alimamaPendingCount_sleep.ToString()); Replace("[拼多多冻结订单数]", pddPendingCount_sleep.ToString()); Replace("[京东冻结订单数]", jdPendingCount_sleep.ToString()); Replace("[唯品会冻结订单数]", wphPendingCount_sleep.ToString()); Replace("[抖音冻结订单数]", dyPendingCount_sleep.ToString()); Replace("[苏宁冻结订单数]", snPendingCount_sleep.ToString()); Replace("[快手冻结订单数]", ksPendingCount_sleep.ToString()); Replace("[淘宝未收货金额]", alimamaPendingPoint_pay.ToString("0.00")); Replace("[拼多多未收货金额]", pddPendingPoint_pay.ToString("0.00")); Replace("[京东未收货金额]", jdPendingPoint_pay.ToString("0.00")); Replace("[唯品会未收货金额]", wphPendingPoint_pay.ToString("0.00")); Replace("[抖音未收货金额]", dyPendingPoint_pay.ToString("0.00")); Replace("[苏宁未收货金额]", snPendingPoint_pay.ToString("0.00")); Replace("[快手未收货金额]", ksPendingPoint_pay.ToString("0.00")); Replace("[淘宝未收货订单数]", alimamaPendingCount_pay.ToString()); Replace("[拼多多未收货订单数]", pddPendingCount_pay.ToString()); Replace("[京东未收货订单数]", jdPendingCount_pay.ToString()); Replace("[唯品会未收货订单数]", wphPendingCount_pay.ToString()); Replace("[抖音未收货订单数]", dyPendingCount_pay.ToString()); Replace("[苏宁未收货订单数]", snPendingCount_pay.ToString()); Replace("[快手未收货订单数]", ksPendingCount_pay.ToString()); Replace("[未收货积分]", "[未收货总金额]"); Replace("[待收货积分]", "[未收货总金额]"); Replace("[未收货总金额]", (alimamaPendingPoint_pay + pddPendingPoint_pay + jdPendingPoint_pay + wphPendingPoint_pay + dyPendingPoint_pay + snPendingPoint_pay + ksPendingPoint_pay).ToString("0.00")); Replace("[待结算积分]", "[冻结总金额]"); Replace("[冻结总金额]", (alimamaPendingPoint_sleep + pddPendingPoint_sleep + jdPendingPoint_sleep + wphPendingPoint_sleep + dyPendingPoint_sleep + snPendingPoint_sleep + ksPendingPoint_sleep).ToString("0.00")); Replace("[待收货订单数]", "[未收货订单数]"); Replace("[未收货订单数]", (alimamaPendingCount_pay + pddPendingCount_pay + jdPendingCount_pay + wphPendingCount_pay + dyPendingCount_pay + snPendingCount_pay + ksPendingCount_pay).ToString()); Replace("[待结算订单数]", "[冻结订单数]"); Replace("[冻结订单数]", (alimamaPendingCount_sleep + pddPendingCount_sleep + jdPendingCount_sleep + wphPendingCount_sleep + dyPendingCount_sleep + snPendingCount_sleep + ksPendingCount_sleep).ToString()); })); #endregion #region 统计邀请数据 if (_mess.Contains("[下级人数]") || _mess.Contains("[推荐人数]")) { actions.Add(new Action(delegate { var timeNow = DateTime.Now; var session1 = ApiClient.GetSession(); var temp = session1.FindRow($"select count(id) as num from fl_member_info where inviter_id = @id", new { id = member.id })["num"].ToString(); Replace("[下级人数]", "[推荐人数]"); Replace("[推荐人数]", temp); LogHelper.GetSingleObj().Debug("", $"下级人数|推荐人数:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); })); } if (_mess.Contains("[完成首单人数]")) { actions.Add(new Action(delegate { var timeNow = DateTime.Now; var session1 = ApiClient.GetSession(); var temp = session1.FindRow($"select count(id) as num from fl_member_info where inviter_id = @id and finish_order != @finish_order", new { id = member.id, finish_order = 0 })["num"].ToString(); Replace("[完成首单人数]", temp); LogHelper.GetSingleObj().Debug("", $"完成首单人数:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); })); } string UnfinishOrderNum = "0";//完成订单数 if (_mess.Contains("[未完成首单人数]")) { actions.Add(new Action(delegate { var timeNow = DateTime.Now; var session1 = ApiClient.GetSession(); var temp = session1.FindRow($"select count(id) as num from fl_member_info where inviter_id = @id and finish_order = @finish_order", new { id = member.id, finish_order = 0 })["num"].ToString(); Replace("[未完成首单人数]", temp); LogHelper.GetSingleObj().Debug("", $"未完成首单人数:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); })); } if (_mess.Contains("[三级邀请人数]")) { actions.Add(new Action(delegate { var timeNow = DateTime.Now; var session1 = ApiClient.GetSession(); var temp = session1.FindRow($@"select count(*) as num from ( select id from fl_member_info where inviter_id = @id UNION all select id from fl_member_info where inviter_id in (select id from fl_member_info where inviter_id = @id ) and inviter_id != '0' UNION all select id from fl_member_info where inviter_id in (select id from fl_member_info where inviter_id in (select id from fl_member_info where inviter_id = @id) and inviter_id != '0') and inviter_id != '0' ) as temp", new { id = member.id })["num"].ToString(); Replace("[三级邀请人数]", temp); LogHelper.GetSingleObj().Debug("", $"三级邀请人数:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); })); } if (_mess.Contains("[三级有效人数]")) { actions.Add(new Action(delegate { var timeNow = DateTime.Now; var session1 = ApiClient.GetSession(); var temp = session1.FindRow($@"select count(*) as num from ( select id from fl_member_info where inviter_id = @id and finish_order != 0 UNION all select id from fl_member_info where inviter_id in (select id from fl_member_info where inviter_id = @id) and inviter_id != '0' and finish_order != 0 UNION all select id from fl_member_info where inviter_id in (select id from fl_member_info where inviter_id in (select id from fl_member_info where inviter_id = @id) and inviter_id != '0') and inviter_id != '0' and finish_order != 0 ) as temp", new { id = member.id })["num"].ToString(); Replace("[三级有效人数]", temp); LogHelper.GetSingleObj().Debug("", $"三级有效人数:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); })); } #endregion #region 获取订单记录 if (_mess.Contains("[订单记录]")) { var timeNow = DateTime.Now; var _dics = new List(); //查阿里妈妈订单 //var list_alimama = session.Queryable().Where(f => f.db_userid == member.id).OrderBy(f => f.id, SqlSugar.OrderByType.Desc).ToPageList(1, 30); var list_alimama = session.Find("select * from fl_order_alimama where db_userid=@uid order by id desc limit 0,30", new { uid = member.id }); //this.OnLog("阿里妈妈数量:"+list_alimama.Count+",您的ID:"+ id); foreach (var aimama in list_alimama) { _dics.Add(new { orderId = aimama.trade_parent_id, title = aimama.item_title, status = aimama.db_status.ToString(), money = aimama.alipay_total_price.ToString("0.00"), fanli = aimama.db_userpoint.ToString("0.00"), nums = aimama.item_num, crtTime = aimama.create_time.ToString("yyyy-MM-dd HH:mm:ss") }); } LogHelper.GetSingleObj().Debug("", $"AA:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); timeNow = DateTime.Now; //查最近拼多多订单 var list_pinduoduo = session.Find("select * from fl_order_pinduoduo where db_userid=@uid order by id desc limit 0,30", new { uid = member.id }); foreach (var pdd in list_pinduoduo) { _dics.Add(new { orderId = pdd.order_sn, title = pdd.goods_name, status = pdd.db_status.ToString(), money = pdd.order_amount.ToString("0.00"), fanli = pdd.db_userpoint.ToString("0.00"), nums = pdd.goods_quantity, crtTime = pdd.order_create_time.ToString("yyyy-MM-dd HH:mm:ss") }); } LogHelper.GetSingleObj().Debug("", $"BB:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); timeNow = DateTime.Now; //查最近京东订单 var list_jingdong = session.Find("select * from fl_order_jingdong where db_userid=@uid order by id desc limit 0,30", new { uid = member.id }); foreach (var jd in list_jingdong) { _dics.Add(new { orderId = jd.orderId, title = jd.skuName, status = jd.db_status.ToString(), money = jd.estimateCosPrice.ToString("0.00"), fanli = jd.db_userpoint.ToString("0.00"), nums = jd.skuNum, crtTime = jd.orderTime.ToString("yyyy-MM-dd HH:mm:ss") }); } LogHelper.GetSingleObj().Debug("", $"CC:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); timeNow = DateTime.Now; //查最近唯品会订单 var list_weipinhui = session.Find("select * from fl_order_weipinhui where db_userid=@uid order by id desc limit 0,30", new { uid = member.id }); foreach (var wph in list_weipinhui) { _dics.Add(new { orderId = wph.orderSn, title = wph.goodsName, status = wph.db_status.ToString(), money = wph.commission.ToString("0.00"), fanli = wph.db_userpoint.ToString("0.00"), nums = wph.goodsCount, crtTime = Util.GetDateTime(wph.orderTime).ToString("yyyy-MM-dd HH:mm:ss") }); } //查最近抖音订单 var list_douyin = session.Find("select * from fl_order_douyin where db_userid=@uid order by id desc limit 0,30", new { uid = member.id }); foreach (var dy in list_douyin) { _dics.Add(new { orderId = dy.order_id, title = dy.product_name, status = dy.db_status.ToString(), money = Util.ConvertDouble_FenToYuan(dy.estimated_comission), fanli = dy.db_userpoint.ToString("0.00"), nums = 1, crtTime = Util.GetDateTime(dy.pay_time).ToString("yyyy-MM-dd HH:mm:ss") }); } //查最近苏宁订单 var list_suning = session.Find("select * from fl_order_suning where db_userid=@uid order by id desc limit 0,30", new { uid = member.id }); foreach (var sn in list_suning) { _dics.Add(new { orderId = sn.orderCode, title = sn.productName, status = sn.db_status.ToString(), money = double.Parse(sn.prePayCommission).ToString("0.00"), fanli = sn.db_userpoint.ToString("0.00"), nums = sn.saleNum, crtTime = sn.payTime.ToString("yyyy-MM-dd HH:mm:ss") }); } //查最近苏宁订单 var list_kuaishou = session.Find("select * from fl_order_kuaishou where db_userid=@uid order by id desc limit 0,30", new { uid = member.id }); foreach (var ks in list_kuaishou) { _dics.Add(new { orderId = ks.oid.ToString(), title = ks.itemTitle, status = ks.db_status.ToString(), money = ks.estimatedIncome.ToString("0.00"), fanli = ks.db_userpoint.ToString("0.00"), nums = ks.num, crtTime = ks.payTime.ToString("yyyy-MM-dd HH:mm:ss") }); } LogHelper.GetSingleObj().Debug("", $"DD:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); timeNow = DateTime.Now; // var count = list_alimama.Count + list_pinduoduo.Count + list_jingdong.Count; if (_dics.Count == 0) Replace("[订单记录]", "暂无记录"); else { string key = HttpHelper.ToMD5("aliorder_" + member.username).ToLower(); var _url = FindTransferAddress(TargetType.订单页, true); var url = GetOrderList(_url, key, HttpHelper.ObjectToJson(_dics)); if (string.IsNullOrWhiteSpace(url)) Replace("[订单记录]", "查询失败"); else { var url_ = string.Empty; if (ApiClient.Setting.SystemConfig.dwz_type != DwzType.不缩短域名) url_ = ApiClient.ShortURL(url).Result; else url_ = ApiClient.ShortURL(url, DwzType.快站短网址).Result; Replace("[订单记录]", url_); } } LogHelper.GetSingleObj().Debug("", $"订单记录:{(DateTime.Now - timeNow).TotalSeconds}\r\n"); } #endregion #region 邀请列表 if (_mess.Contains("[下级列表]")) { var subordinate = new StringBuilder(); var memberList = session.Find("select * from fl_member_info where inviter_id = @uid order by crt_time desc", new { uid = member.id }).Take(10).ToList(); for (int i = 0; i < memberList.Count; i++) { subordinate.AppendLine($"{i + 1}.{memberList[i].realnick}"); } Replace("[下级列表]", subordinate.ToString()); } #endregion } else if (type == typeof(ItemPoint)) { var point = item as ItemPoint; Replace("[返利积分]", point.UserPoint.ToString("0.00")); Replace("[总积分]", point.SumPoint.ToString("0.00")); Replace("[总佣金]", point.Commission.ToString("0.00")); Replace("[三级提成积分]", point.AwardThree.ToString("0.00")); Replace("[二级提成积分]", point.AwardTwo.ToString("0.00")); Replace("[一级提成积分]", point.AwardOne.ToString("0.00")); Replace("[群负责人提成积分]", point.AwardCreate.ToString("0.00")); Replace("[维权返利积分]", point.UserPoint.ToString("0.00")); } } int excute_num = 0; object lock_action = new object(); if (actions.Count > 0) { Parallel.ForEach(actions, action => action.Invoke()); } Replace("[创建时间]", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); } catch (Exception ex) { EventClient.OnEvent(null, $"{ex.Message} - {ex.StackTrace}"); } return mess.ToString(); } /// /// 统计阿里妈妈,京东,拼多多,(付款状态订单合计/冻结状态订单合计/付款和冻结状态订单合计) /// /// 表名 /// 用户id /// private Dictionary FindOrderTotalInfo(string tableName, long uid) { var sql = string.Empty; try { var sqlwhere = string.Empty; switch (tableName) { case "fl_order_pinduoduo": sqlwhere += $" and '{DateTime.Now.AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss")}' <= order_create_time"; break; case "fl_order_alimama": sqlwhere += $" and '{DateTime.Now.AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss")}' <= create_time"; break; case "fl_order_jingdong": sqlwhere += $" and '{DateTime.Now.AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss")}' <= orderTime"; break; case "fl_order_weipinhui": //下单时间为 int sqlwhere += $" and '{HttpExtend.GetTimeStamp(DateTime.Now.AddYears(-1))}' <= orderTime"; break; case "fl_order_douyin": //下单时间为 int sqlwhere += $" and '{HttpExtend.GetTimeStamp(DateTime.Now.AddYears(-1))}' <= pay_time"; break; case "fl_order_suning": sqlwhere += $" and '{DateTime.Now.AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss")}' <= payTime"; break; case "fl_order_kuaishou": sqlwhere += $" and '{DateTime.Now.AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss")}' <= payTime"; break; default: break; } var session = ApiClient.GetSession(); sql = $"select round(COALESCE(sum(db_userpoint),0) ,2) as sum ,count(id) as count from {tableName} where db_userid = @id and db_status = 1001 {sqlwhere} UNION ALL select round(COALESCE(sum(db_userpoint), 0), 2) as sum, count(id) as count from {tableName} where db_userid = @id and db_status = 1005 {sqlwhere}"; var result = session.FindTable(sql, new { id = uid }); if (result.Rows.Count != 0 && result.Rows.Count == 2) { var dic = new Dictionary(); var point_sleep = decimal.Parse(result.Rows[0]["sum"].ToString()); var count_sleep = int.Parse(result.Rows[0]["count"].ToString()); var point_pay = decimal.Parse(result.Rows[1]["sum"].ToString()); var count_pay = int.Parse(result.Rows[1]["count"].ToString()); dic.Add("point_sleep", point_sleep); dic.Add("count_sleep", count_sleep); dic.Add("point_pay", point_pay); dic.Add("count_pay", count_pay); dic.Add("point", point_sleep + point_pay); dic.Add("count", count_sleep + count_pay); return dic; } } catch (Exception ex) { EventClient.OnEvent("", $"查询积分异常:{tableName} - {uid} - {ex.Message} - {ex.StackTrace}"); LogHelper.GetSingleObj().Error("", $"查询积分异常:{tableName} - {uid} - {ex.Message} - {ex.StackTrace} - {sql}"); } return null; } private enum OrderStateType { 退款总金额 = 0, 退款订单数 = 1 } /// /// 已退款积分 /// /// /// /// /// private string FindOrderInfoByState(int status_id, long uid, OrderStateType stateType) { try { //key == "[待收货积分]" ? 1005 : key == "[已退款积分]" ? 1003 : 1001 var session = ApiClient.GetSession(); var sql = string.Empty; if (uid != 999) { if (stateType == OrderStateType.退款总金额) { sql = $@"select COALESCE(SUM(num),0) as num from (select COALESCE(SUM(db_userpoint),0) as num from fl_order_alimama where db_userid = @userid and db_status = @status UNION all select COALESCE(SUM(db_userpoint),0) as num from fl_order_pinduoduo where db_userid = @userid and db_status = @status UNION all select COALESCE(SUM(db_userpoint),0) as num from fl_order_jingdong where db_userid = @userid and db_status = @status) as temp"; return double.Parse(session.FindRow(sql, new { userid = uid, status = status_id })["num"].ToString()).ToString("0.00"); } else { sql = $@"select COALESCE(SUM(num),0) as num from (select count(*) as num from fl_order_alimama where db_userid = @userid and db_status = @status UNION all select count(*) as num from fl_order_pinduoduo where db_userid = @userid and db_status = @status UNION all select count(*) as num from fl_order_jingdong where db_userid = @userid and db_status = @status) as temp"; return session.FindRow(sql, new { userid = uid, status = status_id })["num"].ToString(); } } else { if (stateType == OrderStateType.退款总金额) { sql = $@"select COALESCE(SUM(num),0) as num from (select COALESCE(SUM(db_userpoint),0) as num from fl_order_alimama where db_userid = @userid and (db_status = @status or db_status = @status2) UNION all select COALESCE(SUM(db_userpoint),0) as num from fl_order_pinduoduo where db_userid = @userid and (db_status = @status or db_status = @status2) UNION all select COALESCE(SUM(db_userpoint),0) as num from fl_order_jingdong where db_userid = @userid and (db_status = @status or db_status = @status2)) as temp"; return double.Parse(session.FindRow(sql, new { userid = uid, status = status_id, status2 = 1003 })["num"].ToString()).ToString("0.00"); } else { sql = $@"select COALESCE(SUM(num),0) as num from (select count(*) as num from fl_order_alimama where db_userid = @userid and (db_status = @status or db_status = @status2) UNION all select count(*) as num from fl_order_pinduoduo where db_userid = @userid and (db_status = @status or db_status = @status2) UNION all select count(*) as num from fl_order_jingdong where db_userid = @userid and (db_status = @status or db_status = @status2)) as temp"; return session.FindRow(sql, new { userid = uid, status = status_id, status2 = 1003 })["num"].ToString(); } } } catch (Exception ex) { } return "0"; } #region 已兑换积分 private string FindAlreadyExchange(long uid) { try { var session = ApiClient.GetSession(); var sumPoint = double.Parse(session.FindRow("select COALESCE(SUM(point),0) as num from fl_point_hist where uid = @uid and type = '提现扣除'", new { uid = uid })["num"].ToString()); var thSumPoint = double.Parse(session.FindRow("select COALESCE(SUM(point),0) as num from fl_point_hist where uid = @uid and type = '退回积分'", new { uid = uid })["num"].ToString()); return (sumPoint + thSumPoint).ToString("0.00").Replace("-", ""); } catch (Exception ex) { EventClient.OnEvent(null, $"查询已兑换总额异常:{ex.Message} - {ex.StackTrace}"); } return "-1"; } #endregion /// /// 获取订单详情 /// /// /// /// private string GetOrderList(string _url, string key, string json) { try { var http = new HttpHelper(); var item = http.GetItem("http://api.view.52cmg.cn/api/util.asmx/SetCache"); item.Postdata = "key=" + key + "&json=" + HttpHelper.URLEncode(json, Encoding.UTF8); item.Encoding = Encoding.UTF8; item.Method = "post"; var result = http.GetHtml(item); if (!string.IsNullOrWhiteSpace(ApiClient.Setting.SystemConfig.URLTbDdxq)) _url = ApiClient.Setting.SystemConfig.URLTbDdxq; return _url.Replace("[key]", key); } catch (Exception ex) { EventClient.OnEvent(this, $"获取订单详情:{ex.Message}"); } return string.Empty; } /// /// 用户自定义变量替换 /// /// 替换的原内容 /// 替换后的内容,报错将返回原内容 internal string ReplaceUserVariate(string str) { StringBuilder strb = new StringBuilder(); strb.Append(str); try { var session = ApiClient.GetSession(); var uservariaters = session.FindUserVariates(); if (uservariaters != null && uservariaters.Count != 0) { foreach (var variater in uservariaters) { strb = strb.Replace(variater.variate, variater.data); } } return strb.ToString(); } catch (Exception ex) { } return str; } } }