lcl 1 жил өмнө
parent
commit
923e300860

+ 319 - 0
AppStart/Helper/StatTradeCheckService.cs

@@ -0,0 +1,319 @@
+using System;
+using System.Collections.Generic;
+using Library;
+using LitJson;
+using System.Linq;
+using System.Data;
+using System.Threading;
+using MySystem.PxcModels;
+
+namespace MySystem
+{
+    public class StatTradeCheckService
+    {
+        public readonly static StatTradeCheckService Instance = new StatTradeCheckService();
+        private StatTradeCheckService()
+        { }
+
+
+
+
+
+
+        // 统计交易额V2
+        public void Start()
+        {
+            Thread th = new Thread(StartDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+        public void StartDo()
+        {
+            while (true)
+            {
+                string content = RedisDbconn.Instance.RPop<string>("StatTradeCheckQueue");
+                if(!string.IsNullOrEmpty(content))
+                {
+                    StatTradeAmountDo(content);
+                    Thread.Sleep(1);
+                }
+                else
+                {
+                    Thread.Sleep(10000);
+                }
+            }
+        }
+        public void StatTradeAmountDo(string date)
+        {
+            function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
+            try
+            {
+                int pageNum = 0;
+                bool check = true;
+                while(check)
+                {
+                    string sql = "";
+                    DataTable dt = CustomerSqlConn.dtable("select UserId,ParentNav,BrandId,BankCardType,QrPayFlag,MerHelpFlag,Version,CapFlag,VipFlag,PayType,DATE_FORMAT(CreateDate,'%Y%m%d'),sum(TradeAmount),count(Id),SnNo from TradeRecord where Id>20000000 and ActStatus=1 and BrandId!=14 and UserId>0 and CreateDate>='" + date + " 00:00:00' and CreateDate<='" + date + " 23:59:59' group by UserId,ParentNav,BrandId,BankCardType,QrPayFlag,MerHelpFlag,Version,CapFlag,VipFlag,PayType,DATE_FORMAT(CreateDate,'%Y%m%d'),SnNo order by UserId limit " + pageNum + ",50", AppConfig.Base.TmpReadSqlConn);
+                    if(dt.Rows.Count > 0)
+                    {
+                        foreach (DataRow dr in dt.Rows)
+                        {
+                            int UserId = int.Parse(dr["UserId"].ToString());
+                            string SnNo = dr["SnNo"].ToString();
+                            string ParentNav = dr["ParentNav"].ToString();
+                            int BrandId = int.Parse(dr["BrandId"].ToString());
+                            int BankCardType = int.Parse(dr["BankCardType"].ToString());
+                            int QrPayFlag = int.Parse(dr["QrPayFlag"].ToString());
+                            int MerHelpFlag = int.Parse(dr["MerHelpFlag"].ToString());
+                            int Version = int.Parse(dr["Version"].ToString());
+                            int CapFlag = int.Parse(dr["CapFlag"].ToString());
+                            int VipFlag = int.Parse(dr["VipFlag"].ToString());
+                            int PayType = int.Parse(dr["PayType"].ToString());
+                            string TradeDate = dr[10].ToString();
+                            decimal TradeAmount = decimal.Parse(dr[11].ToString());
+                            int TradeCount = 1;
+                            string TradeMonth = TradeDate.Substring(0, 6);
+                            ParentNav += "," + UserId + ",";
+                            string[] UserIdList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
+
+                            WebCMSEntities db = new WebCMSEntities();
+                            PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == SnNo) ?? new PosMachinesTwo();
+                            db.Dispose();
+
+                            if(Version < 2)
+                            {
+                                //个人业绩
+                                decimal ProfitDirectDebitTradeAmt = 0;
+                                decimal ProfitDirectDebitCapTradeAmt = 0;
+                                decimal ProfitDirectDebitCapNum = 0;
+                                decimal HelpDirectDebitTradeAmt = 0;
+                                decimal HelpDirectDebitCapTradeAmt = 0;
+                                decimal HelpDirectDebitCapNum = 0;
+                                decimal NotHelpDirectDebitTradeAmt = 0;
+                                decimal NotHelpDirectDebitCapTradeAmt = 0;
+                                decimal NotHelpDirectDebitCapNum = 0;
+                                decimal ProfitDirectTradeAmt = 0;
+                                decimal HelpDirectTradeAmt = 0;
+                                decimal NotHelpDirectTradeAmt = 0;
+                                if (BankCardType == 0)
+                                {
+                                    if (Version == 1)
+                                    {
+                                        ProfitDirectDebitTradeAmt += TradeAmount;
+                                        if (CapFlag == 1)
+                                        {
+                                            ProfitDirectDebitCapTradeAmt += TradeAmount;
+                                            ProfitDirectDebitCapNum += TradeCount;
+                                        }
+                                    }
+                                    else if (MerHelpFlag == 1)
+                                    {
+                                        HelpDirectDebitTradeAmt += TradeAmount;
+                                        if (CapFlag == 1)
+                                        {
+                                            HelpDirectDebitCapTradeAmt += TradeAmount;
+                                            HelpDirectDebitCapNum += TradeCount;
+                                        }
+                                    }
+                                    else
+                                    {
+                                        NotHelpDirectDebitTradeAmt += TradeAmount;
+                                        if (CapFlag == 1)
+                                        {
+                                            NotHelpDirectDebitCapTradeAmt += TradeAmount;
+                                            NotHelpDirectDebitCapNum += TradeCount;
+                                        }
+                                    }
+                                }
+                                else if (BankCardType != 0)
+                                {
+                                    if (Version == 1)
+                                    {
+                                        ProfitDirectTradeAmt += TradeAmount;
+                                    }
+                                    else if (MerHelpFlag == 1)
+                                    {
+                                        HelpDirectTradeAmt += TradeAmount;
+                                    }
+                                    else
+                                    {
+                                        NotHelpDirectTradeAmt += TradeAmount;
+                                    }
+                                }
+                                sql += InsertOrUpdate("TradeDaySummary", "ProfitDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitDirectTradeAmt,HelpDirectTradeAmt,NotHelpDirectTradeAmt", ProfitDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitDirectTradeAmt + "," + HelpDirectTradeAmt + "," + NotHelpDirectTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
+                                if (pos.BindingTime < DateTime.Parse("2023-07-01 00:00:00"))
+                                {
+                                    sql += InsertOrUpdate("TradeDaySummaryBefore", "ProfitDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitDirectTradeAmt,HelpDirectTradeAmt,NotHelpDirectTradeAmt", ProfitDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitDirectTradeAmt + "," + HelpDirectTradeAmt + "," + NotHelpDirectTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
+                                }
+                                else
+                                {
+                                    sql += InsertOrUpdate("TradeDaySummaryAfter", "ProfitDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitDirectTradeAmt,HelpDirectTradeAmt,NotHelpDirectTradeAmt", ProfitDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitDirectTradeAmt + "," + HelpDirectTradeAmt + "," + NotHelpDirectTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
+                                }
+
+                                //团队业绩
+                                foreach(string SubUserId in UserIdList)
+                                {
+                                    decimal ProfitNonDirectDebitTradeAmt = 0;
+                                    ProfitDirectDebitCapTradeAmt = 0;
+                                    ProfitDirectDebitCapNum = 0;
+                                    decimal HelpNonDirectDebitTradeAmt = 0;
+                                    HelpDirectDebitCapTradeAmt = 0;
+                                    HelpDirectDebitCapNum = 0;
+                                    decimal NotHelpNonDirectDebitTradeAmt = 0;
+                                    NotHelpDirectDebitCapTradeAmt = 0;
+                                    NotHelpDirectDebitCapNum = 0;
+                                    decimal ProfitNonDirectTradeAmt = 0;
+                                    decimal HelpNonDirectTradeAmt = 0;
+                                    decimal NotHelpNonDirectTradeAmt = 0;
+                                    if (BankCardType == 0)
+                                    {
+                                        if (Version == 1)
+                                        {
+                                            ProfitNonDirectDebitTradeAmt += TradeAmount;
+                                            if (CapFlag == 1)
+                                            {
+                                                ProfitDirectDebitCapTradeAmt += TradeAmount;
+                                                ProfitDirectDebitCapNum += TradeCount;
+                                            }
+                                        }
+                                        else if (MerHelpFlag == 1)
+                                        {
+                                            HelpNonDirectDebitTradeAmt += TradeAmount;
+                                            if (CapFlag == 1)
+                                            {
+                                                HelpDirectDebitCapTradeAmt += TradeAmount;
+                                                HelpDirectDebitCapNum += TradeCount;
+                                            }
+                                        }
+                                        else
+                                        {
+                                            NotHelpNonDirectDebitTradeAmt += TradeAmount;
+                                            if (CapFlag == 1)
+                                            {
+                                                NotHelpDirectDebitCapTradeAmt += TradeAmount;
+                                                NotHelpDirectDebitCapNum += TradeCount;
+                                            }
+                                        }
+                                    }
+                                    else if (BankCardType != 0)
+                                    {
+                                        if (Version == 1)
+                                        {
+                                            ProfitNonDirectTradeAmt += TradeAmount;
+                                        }
+                                        else if (MerHelpFlag == 1)
+                                        {
+                                            HelpNonDirectTradeAmt += TradeAmount;
+                                        }
+                                        else
+                                        {
+                                            NotHelpNonDirectTradeAmt += TradeAmount;
+                                        }
+                                    }
+                                    sql += InsertOrUpdate("TradeDaySummary", "ProfitNonDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpNonDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpNonDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitNonDirectTradeAmt,HelpNonDirectTradeAmt,NotHelpNonDirectTradeAmt", ProfitNonDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpNonDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpNonDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitNonDirectTradeAmt + "," + HelpNonDirectTradeAmt + "," + NotHelpNonDirectTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
+                                    if (pos.BindingTime < DateTime.Parse("2023-07-01 00:00:00"))
+                                    {
+                                        sql += InsertOrUpdate("TradeDaySummaryBefore", "ProfitNonDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpNonDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpNonDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitNonDirectTradeAmt,HelpNonDirectTradeAmt,NotHelpNonDirectTradeAmt", ProfitNonDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpNonDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpNonDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitNonDirectTradeAmt + "," + HelpNonDirectTradeAmt + "," + NotHelpNonDirectTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
+                                    }
+                                    else
+                                    {
+                                        sql += InsertOrUpdate("TradeDaySummaryAfter", "ProfitNonDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpNonDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpNonDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitNonDirectTradeAmt,HelpNonDirectTradeAmt,NotHelpNonDirectTradeAmt", ProfitNonDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpNonDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpNonDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitNonDirectTradeAmt + "," + HelpNonDirectTradeAmt + "," + NotHelpNonDirectTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
+                                    }
+                                }
+                            }
+                            else
+                            {
+                                decimal ProfitDebitTradeAmt = 0;
+                                decimal ProfitDebitCapTradeAmt = 0;
+                                decimal ProfitDebitCapNum = 0;
+                                decimal ProfitTradeAmt = 0;
+                                if (BankCardType == 0)
+                                {
+                                    if (Version == 2)
+                                    {
+                                        ProfitDebitTradeAmt += TradeAmount;
+                                        if (CapFlag == 1)
+                                        {
+                                            ProfitDebitCapTradeAmt += TradeAmount;
+                                            ProfitDebitCapNum += TradeCount;
+                                        }
+                                    }
+                                }
+                                else if (BankCardType != 0)
+                                {
+                                    if (Version == 2)
+                                    {
+                                        ProfitTradeAmt += TradeAmount;
+                                    }
+                                }
+                                sql += InsertOrUpdate("TradeDaySummary2", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
+                                if (pos.BindingTime < DateTime.Parse("2023-07-01 00:00:00"))
+                                {
+                                    sql += InsertOrUpdate("TradeDaySummary2Before", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
+                                }
+                                else
+                                {
+                                    sql += InsertOrUpdate("TradeDaySummary2After", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
+                                }
+                                foreach(string SubUserId in UserIdList)
+                                {
+                                    sql += InsertOrUpdate("TradeDaySummary2", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
+                                    if (pos.BindingTime < DateTime.Parse("2023-07-01 00:00:00"))
+                                    {
+                                        sql += InsertOrUpdate("TradeDaySummary2Before", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
+                                    }
+                                    else
+                                    {
+                                        sql += InsertOrUpdate("TradeDaySummary2After", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
+                                    }
+                                }
+                            }
+                        }
+                        pageNum += 1;
+                    }
+                    else
+                    {
+                        check = false;
+                    }
+                    CustomerSqlConn.op(sql, AppConfig.Base.SqlConn);
+                }
+            }
+            catch (Exception ex)
+            {
+                function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计交易额异常");
+            }
+            function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
+        }
+
+        public string InsertOrUpdate(string table, string fields, string vals, string condition)
+        {
+            string sql = "";
+            string check = RedisDbconn.Instance.Get<string>("statreset:" + table + ":" + function.MD5_16(condition));
+            if(string.IsNullOrEmpty(check))
+            {
+                RedisDbconn.Instance.Set("statreset:" + table + ":" + function.MD5_16(condition), fields + "#cut#" + vals);
+                RedisDbconn.Instance.SetExpire("statreset:" + table + ":" + function.MD5_16(condition), 3600);
+                string[] conditionList = condition.Split(new string[]{ " and " }, StringSplitOptions.None);
+                foreach(string sub in conditionList)
+                {
+                    string[] subCondition = sub.Split('=');
+                    fields += "," + subCondition[0];
+                    vals += "," + subCondition[1];
+                }
+                sql = "insert into " + table + " (" + fields + ") values (" + vals + ");\n";
+            }
+            else
+            {
+                string setVals = "";
+                string[] fieldList = fields.Split(',');
+                string[] valList = vals.Split(',');
+                for (int i = 0; i < fieldList.Length; i++)
+                {
+                    setVals += fieldList[i] + "=" + fieldList[i] + "+" + valList[i] + ",";
+                }
+                sql = "update " + table + " set " + setVals.TrimEnd(',') + " where " + condition + ";\n";
+            }
+            return sql;
+        }
+    }
+}

+ 308 - 0
AppStart/Helper/StatTradeService.cs

@@ -0,0 +1,308 @@
+using System;
+using System.Collections.Generic;
+using Library;
+using LitJson;
+using System.Linq;
+using System.Data;
+using System.Threading;
+using MySystem.PxcModels;
+
+namespace MySystem
+{
+    public class StatTradeService
+    {
+        public readonly static StatTradeService Instance = new StatTradeService();
+        private StatTradeService()
+        { }
+
+
+
+
+
+
+        // 统计交易额V2
+        public void Start()
+        {
+            Thread th = new Thread(StartDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+        public void StartDo()
+        {
+            while (true)
+            {
+                string content = RedisDbconn.Instance.RPop<string>("StatTradeQueue");
+                if(!string.IsNullOrEmpty(content))
+                {
+                    StatTradeAmountDo(content);
+                    Thread.Sleep(1);
+                }
+                else
+                {
+                    Thread.Sleep(10000);
+                }
+            }
+        }
+        public void StatTradeAmountDo(string Id)
+        {
+            function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
+            try
+            {
+                DataTable dt = CustomerSqlConn.dtable("select UserId,ParentNav,BrandId,BankCardType,QrPayFlag,MerHelpFlag,Version,CapFlag,VipFlag,PayType,DATE_FORMAT(CreateDate,'%Y%m%d'),TradeAmount,SnNo from TradeRecord where Id=" + Id + " and BrandId!=14 and ActStatus=1 and QueryCount=0 and UserId>0", AppConfig.Base.TmpReadSqlConn);
+                if (dt.Rows.Count > 0)
+                {
+                    string sql = "";
+                    DataRow dr = dt.Rows[0];
+                    int UserId = int.Parse(dr["UserId"].ToString());
+                    string SnNo = dr["SnNo"].ToString();
+                    string ParentNav = dr["ParentNav"].ToString();
+                    int BrandId = int.Parse(dr["BrandId"].ToString());
+                    int BankCardType = int.Parse(dr["BankCardType"].ToString());
+                    int QrPayFlag = int.Parse(dr["QrPayFlag"].ToString());
+                    int MerHelpFlag = int.Parse(dr["MerHelpFlag"].ToString());
+                    int Version = int.Parse(dr["Version"].ToString());
+                    int CapFlag = int.Parse(dr["CapFlag"].ToString());
+                    int VipFlag = int.Parse(dr["VipFlag"].ToString());
+                    int PayType = int.Parse(dr["PayType"].ToString());
+                    string TradeDate = dr[10].ToString();
+                    decimal TradeAmount = decimal.Parse(dr[11].ToString());
+                    int TradeCount = 1;
+                    string TradeMonth = TradeDate.Substring(0, 6);
+                    ParentNav += "," + UserId + ",";
+                    string[] UserIdList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
+
+                    WebCMSEntities db = new WebCMSEntities();
+                    PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == SnNo) ?? new PosMachinesTwo();
+                    db.Dispose();
+
+                    if(Version < 2)
+                    {
+                        //个人业绩
+                        decimal ProfitDirectDebitTradeAmt = 0;
+                        decimal ProfitDirectDebitCapTradeAmt = 0;
+                        decimal ProfitDirectDebitCapNum = 0;
+                        decimal HelpDirectDebitTradeAmt = 0;
+                        decimal HelpDirectDebitCapTradeAmt = 0;
+                        decimal HelpDirectDebitCapNum = 0;
+                        decimal NotHelpDirectDebitTradeAmt = 0;
+                        decimal NotHelpDirectDebitCapTradeAmt = 0;
+                        decimal NotHelpDirectDebitCapNum = 0;
+                        decimal ProfitDirectTradeAmt = 0;
+                        decimal HelpDirectTradeAmt = 0;
+                        decimal NotHelpDirectTradeAmt = 0;
+                        if (BankCardType == 0)
+                        {
+                            if (Version == 1)
+                            {
+                                ProfitDirectDebitTradeAmt += TradeAmount;
+                                if (CapFlag == 1)
+                                {
+                                    ProfitDirectDebitCapTradeAmt += TradeAmount;
+                                    ProfitDirectDebitCapNum += TradeCount;
+                                }
+                            }
+                            else if (MerHelpFlag == 1)
+                            {
+                                HelpDirectDebitTradeAmt += TradeAmount;
+                                if (CapFlag == 1)
+                                {
+                                    HelpDirectDebitCapTradeAmt += TradeAmount;
+                                    HelpDirectDebitCapNum += TradeCount;
+                                }
+                            }
+                            else
+                            {
+                                NotHelpDirectDebitTradeAmt += TradeAmount;
+                                if (CapFlag == 1)
+                                {
+                                    NotHelpDirectDebitCapTradeAmt += TradeAmount;
+                                    NotHelpDirectDebitCapNum += TradeCount;
+                                }
+                            }
+                        }
+                        else if (BankCardType != 0)
+                        {
+                            if (Version == 1)
+                            {
+                                ProfitDirectTradeAmt += TradeAmount;
+                            }
+                            else if (MerHelpFlag == 1)
+                            {
+                                HelpDirectTradeAmt += TradeAmount;
+                            }
+                            else
+                            {
+                                NotHelpDirectTradeAmt += TradeAmount;
+                            }
+                        }
+                        sql += InsertOrUpdate("TradeDaySummary", "ProfitDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitDirectTradeAmt,HelpDirectTradeAmt,NotHelpDirectTradeAmt", ProfitDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitDirectTradeAmt + "," + HelpDirectTradeAmt + "," + NotHelpDirectTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
+                        if (pos.BindingTime < DateTime.Parse("2023-07-01 00:00:00"))
+                        {
+                            sql += InsertOrUpdate("TradeDaySummaryBefore", "ProfitDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitDirectTradeAmt,HelpDirectTradeAmt,NotHelpDirectTradeAmt", ProfitDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitDirectTradeAmt + "," + HelpDirectTradeAmt + "," + NotHelpDirectTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
+                        }
+                        else
+                        {
+                            sql += InsertOrUpdate("TradeDaySummaryAfter", "ProfitDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitDirectTradeAmt,HelpDirectTradeAmt,NotHelpDirectTradeAmt", ProfitDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitDirectTradeAmt + "," + HelpDirectTradeAmt + "," + NotHelpDirectTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
+                        }
+
+                        //团队业绩
+                        foreach(string SubUserId in UserIdList)
+                        {
+                            decimal ProfitNonDirectDebitTradeAmt = 0;
+                            ProfitDirectDebitCapTradeAmt = 0;
+                            ProfitDirectDebitCapNum = 0;
+                            decimal HelpNonDirectDebitTradeAmt = 0;
+                            HelpDirectDebitCapTradeAmt = 0;
+                            HelpDirectDebitCapNum = 0;
+                            decimal NotHelpNonDirectDebitTradeAmt = 0;
+                            NotHelpDirectDebitCapTradeAmt = 0;
+                            NotHelpDirectDebitCapNum = 0;
+                            decimal ProfitNonDirectTradeAmt = 0;
+                            decimal HelpNonDirectTradeAmt = 0;
+                            decimal NotHelpNonDirectTradeAmt = 0;
+                            if (BankCardType == 0)
+                            {
+                                if (Version == 1)
+                                {
+                                    ProfitNonDirectDebitTradeAmt += TradeAmount;
+                                    if (CapFlag == 1)
+                                    {
+                                        ProfitDirectDebitCapTradeAmt += TradeAmount;
+                                        ProfitDirectDebitCapNum += TradeCount;
+                                    }
+                                }
+                                else if (MerHelpFlag == 1)
+                                {
+                                    HelpNonDirectDebitTradeAmt += TradeAmount;
+                                    if (CapFlag == 1)
+                                    {
+                                        HelpDirectDebitCapTradeAmt += TradeAmount;
+                                        HelpDirectDebitCapNum += TradeCount;
+                                    }
+                                }
+                                else
+                                {
+                                    NotHelpNonDirectDebitTradeAmt += TradeAmount;
+                                    if (CapFlag == 1)
+                                    {
+                                        NotHelpDirectDebitCapTradeAmt += TradeAmount;
+                                        NotHelpDirectDebitCapNum += TradeCount;
+                                    }
+                                }
+                            }
+                            else if (BankCardType != 0)
+                            {
+                                if (Version == 1)
+                                {
+                                    ProfitNonDirectTradeAmt += TradeAmount;
+                                }
+                                else if (MerHelpFlag == 1)
+                                {
+                                    HelpNonDirectTradeAmt += TradeAmount;
+                                }
+                                else
+                                {
+                                    NotHelpNonDirectTradeAmt += TradeAmount;
+                                }
+                            }
+                            sql += InsertOrUpdate("TradeDaySummary", "ProfitNonDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpNonDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpNonDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitNonDirectTradeAmt,HelpNonDirectTradeAmt,NotHelpNonDirectTradeAmt", ProfitNonDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpNonDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpNonDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitNonDirectTradeAmt + "," + HelpNonDirectTradeAmt + "," + NotHelpNonDirectTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
+                            if (pos.BindingTime < DateTime.Parse("2023-07-01 00:00:00"))
+                            {
+                                sql += InsertOrUpdate("TradeDaySummaryBefore", "ProfitNonDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpNonDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpNonDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitNonDirectTradeAmt,HelpNonDirectTradeAmt,NotHelpNonDirectTradeAmt", ProfitNonDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpNonDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpNonDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitNonDirectTradeAmt + "," + HelpNonDirectTradeAmt + "," + NotHelpNonDirectTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
+                            }
+                            else
+                            {
+                                sql += InsertOrUpdate("TradeDaySummaryAfter", "ProfitNonDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpNonDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpNonDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitNonDirectTradeAmt,HelpNonDirectTradeAmt,NotHelpNonDirectTradeAmt", ProfitNonDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpNonDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpNonDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitNonDirectTradeAmt + "," + HelpNonDirectTradeAmt + "," + NotHelpNonDirectTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
+                            }
+                        }
+                    }
+                    else
+                    {
+                        decimal ProfitDebitTradeAmt = 0;
+                        decimal ProfitDebitCapTradeAmt = 0;
+                        decimal ProfitDebitCapNum = 0;
+                        decimal ProfitTradeAmt = 0;
+                        if (BankCardType == 0)
+                        {
+                            if (Version == 2)
+                            {
+                                ProfitDebitTradeAmt += TradeAmount;
+                                if (CapFlag == 1)
+                                {
+                                    ProfitDebitCapTradeAmt += TradeAmount;
+                                    ProfitDebitCapNum += TradeCount;
+                                }
+                            }
+                        }
+                        else if (BankCardType != 0)
+                        {
+                            if (Version == 2)
+                            {
+                                ProfitTradeAmt += TradeAmount;
+                            }
+                        }
+                        sql += InsertOrUpdate("TradeDaySummary2", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
+                        if (pos.BindingTime < DateTime.Parse("2023-07-01 00:00:00"))
+                        {
+                            sql += InsertOrUpdate("TradeDaySummary2Before", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
+                        }
+                        else
+                        {
+                            sql += InsertOrUpdate("TradeDaySummary2After", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
+                        }
+                        foreach(string SubUserId in UserIdList)
+                        {
+                            sql += InsertOrUpdate("TradeDaySummary2", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
+                            if (pos.BindingTime < DateTime.Parse("2023-07-01 00:00:00"))
+                            {
+                                sql += InsertOrUpdate("TradeDaySummary2Before", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
+                            }
+                            else
+                            {
+                                sql += InsertOrUpdate("TradeDaySummary2After", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
+                            }
+                        }
+                    }
+                    sql += "update TradeRecord set QueryCount=1 where Id=" + Id + ";\n";
+                    CustomerSqlConn.op(sql, AppConfig.Base.SqlConn);
+                }
+            }
+            catch (Exception ex)
+            {
+                function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计交易额异常");
+            }
+            function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
+        }
+
+        public string InsertOrUpdate(string table, string fields, string vals, string condition)
+        {
+            string sql = "";
+            string check = RedisDbconn.Instance.Get<string>("stat:" + table + ":" + function.MD5_16(condition));
+            if(string.IsNullOrEmpty(check))
+            {
+                RedisDbconn.Instance.Set("stat:" + table + ":" + function.MD5_16(condition), fields + "#cut#" + vals);
+                RedisDbconn.Instance.SetExpire("stat:" + table + ":" + function.MD5_16(condition), 3600 * 36);
+                string[] conditionList = condition.Split(new string[]{ " and " }, StringSplitOptions.None);
+                foreach(string sub in conditionList)
+                {
+                    string[] subCondition = sub.Split('=');
+                    fields += "," + subCondition[0];
+                    vals += "," + subCondition[1];
+                }
+                sql = "insert into " + table + " (" + fields + ") values (" + vals + ");\n";
+            }
+            else
+            {
+                string setVals = "";
+                string[] fieldList = fields.Split(',');
+                string[] valList = vals.Split(',');
+                for (int i = 0; i < fieldList.Length; i++)
+                {
+                    setVals += fieldList[i] + "=" + fieldList[i] + "+" + valList[i] + ",";
+                }
+                sql = "update " + table + " set " + setVals.TrimEnd(',') + " where " + condition + ";\n";
+            }
+            return sql;
+        }
+    }
+}

+ 25 - 22
Startup.cs

@@ -99,42 +99,45 @@ namespace MySystem
             initMain();
             
             //必须打开的
-            StatService.Instance.StartEverDayV2(); //实时统计交易额
-            Stat2Service.Instance.Start(); //实时统计归档交易额
-            StatService.Instance.StartOther(); //补充统计交易额
-            StatService.Instance.StartPosActNum(); //实时统计激活数
-            StatService.Instance.StartNewUserNum(); //实时统计新增创客数
-            StatHelpProfitService.Instance.StartUserTrade();
-            StatHelpProfitService.Instance.ResetMaxTradeAmount(); //每月重置助利宝最大交易总额
-            OperateService.Instance.Start(); //统计运营中心发货量
-            OperateService.Instance.StartPosActNum(); //统计运营中心激活量
-            OperateService.Instance.StartPosCouponSaleNum(); //统计运营中心机具券销售量
+            // StatService.Instance.StartEverDayV2(); //实时统计交易额
+            // Stat2Service.Instance.Start(); //实时统计归档交易额
+            // StatService.Instance.StartOther(); //补充统计交易额
+            // StatService.Instance.StartPosActNum(); //实时统计激活数
+            // StatService.Instance.StartNewUserNum(); //实时统计新增创客数
+            // StatHelpProfitService.Instance.StartUserTrade();
+            // StatHelpProfitService.Instance.ResetMaxTradeAmount(); //每月重置助利宝最大交易总额
+            // OperateService.Instance.Start(); //统计运营中心发货量
+            // OperateService.Instance.StartPosActNum(); //统计运营中心激活量
+            // OperateService.Instance.StartPosCouponSaleNum(); //统计运营中心机具券销售量
             
-            StatNewService.Instance.StartStat(); //实时统计交易额RDS
-            StatNewService.Instance.StartMer(); //实时统计商户交易额到RDS
-            StatNewService.Instance.StartAct(); //统计激活数到RDS
+            // StatNewService.Instance.StartStat(); //实时统计交易额RDS
+            // StatNewService.Instance.StartMer(); //实时统计商户交易额到RDS
+            // StatNewService.Instance.StartAct(); //统计激活数到RDS
 
-            AddRecordService.Instance.StartTradeRecord(); //RDS交易记录队列
-            AddRecordService.Instance.StartUserAccountRecord(); //RDS收支明细队列
+            // AddRecordService.Instance.StartTradeRecord(); //RDS交易记录队列
+            // AddRecordService.Instance.StartUserAccountRecord(); //RDS收支明细队列
 
-            StatNewService.Instance.CreateTable(); //创建RDS分表
+            // StatNewService.Instance.CreateTable(); //创建RDS分表
             
-            StatHelpProfitService.Instance.AddUserHelpProfit(); //补创客助利宝交易额
+            // StatHelpProfitService.Instance.AddUserHelpProfit(); //补创客助利宝交易额
             
-            StatResetService.Instance.Start(); //重置创客交易额
+            // StatResetService.Instance.Start(); //重置创客交易额
             // ProfitService.Instance.AddRds(); //补RDS数据
             //必须打开的
 
+            StatTradeService.Instance.Start();
+            StatTradeCheckService.Instance.Start();
+
         }
 
         private void initMain()
         {
             string conn = Configuration["Setting:SqlConnStr"];
             string dbName = "KxsMainServer";
-            if(Library.ConfigurationManager.EnvironmentFlag == 2)
-            {
-                dbName = "KxsProfitServer";
-            }
+            // if(Library.ConfigurationManager.EnvironmentFlag == 2)
+            // {
+            //     dbName = "KxsProfitServer";
+            // }
             Dictionary<string, Dictionary<string, string>> tables = new Dictionary<string, Dictionary<string, string>>();
             System.Data.DataTable tablecollection = Library.CustomerSqlConn.dtable("select DISTINCT TABLE_NAME from information_schema.columns where table_schema = '" + dbName + "'", conn);
             foreach (System.Data.DataRow subtable in tablecollection.Rows)

+ 1 - 1
appsettings.Development.json

@@ -18,7 +18,7 @@
     "SourceHost": "http://bs.kexiaoshuang.com/",
     "Database": "KxsMainServer",
     "SqlConnStr": "server=47.109.31.237;port=3306;user=KxsMainServer;password=FrW8ZfxlcaVdm1r0;database=KxsMainServer;charset=utf8;",
-    "ReadSqlConnStr": "server=47.109.31.237;port=3306;user=KxsMainServer;password=FrW8ZfxlcaVdm1r0;database=KxsMainServer;charset=utf8;",
+    "ReadSqlConnStr": "server=rr-2vc53lrwpwm1ewscogo.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=KxsProfitServer;password=FrW8ZfxlcaVdm1r0;database=KxsProfitServer;charset=utf8;DefaultCommandTimeout=600;",
     "StatSqlConnStr": "server=47.109.31.237;port=3306;user=KxsMainServer;password=FrW8ZfxlcaVdm1r0;database=KxsStatServer;charset=utf8;",
     "ProfitSqlConnStr": "server=47.109.31.237;port=3306;user=KxsProfitServer;password=FrW8ZfxlcaVdm1r0;database=KxsProfitServer;charset=utf8;",
     "OpSqlConnStr": "server=47.109.31.237;port=3306;user=KxsOpServer;password=r7jwZ8ydLoeswDR4;database=KxsOpServer;charset=utf8;",