lichunlei 3 anni fa
parent
commit
5a33b61612

+ 66 - 17
AppStart/Helper/SycnProfitServiceV2.cs

@@ -25,7 +25,7 @@ namespace MySystem
         {
             while (true)
             {
-                string content = RedisDbconn.Instance.RPop<string>("SycnProfitQueue2");
+                string content = RedisDbconn.Instance.RPop<string>("SycnProfitQueue3");
                 if (!string.IsNullOrEmpty(content))
                 {
                     try
@@ -38,7 +38,7 @@ namespace MySystem
                         string SysUserName = data[3];
                         if (OpType == 0)
                         {
-                            DoTradeProfit(BrandId, date, SysUserName);
+                            // DoTradeProfit(BrandId, date, SysUserName);
                             DoSubsidyProfit(BrandId, date);
                         }
                         else if (OpType == 1)
@@ -182,7 +182,7 @@ namespace MySystem
             WebCMSEntities db = new WebCMSEntities();
             OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
             
-            OtherMySqlConn.op("insert into SubsidyRecord (CreateDate,CreateMan,SeoTitle,ParentNav,BrandId,UserId,ProfitAmount) select now(),'root','" + date + "',(select ParentNav from Users where Id=p.SubsidyUserId)," + BrandId + ",SubsidyUserId,sum(SubsidyProfitRate) from ProfitSubsidyDetail p where Status=0 and BrandId=" + BrandId + " and TradeMonth='" + date + "' GROUP BY SubsidyUserId");
+            OtherMySqlConn.op("insert into SubsidyRecord (CreateDate,SeoKeyword,SeoTitle,ParentNav,BrandId,UserId,ProfitAmount) select now(),'root','" + date + "',(select ParentNav from Users where Id=p.SubsidyUserId)," + BrandId + ",SubsidyUserId,sum(SubsidyProfitRate) from ProfitSubsidyDetail p where Status=0 and BrandId=" + BrandId + " and TradeMonth='" + date + "' GROUP BY SubsidyUserId");
 
             DataTable dt = OtherMySqlConn.dtable("select SubsidyUserId,sum(SubsidyProfitRate) from ProfitSubsidyDetail where Status=0 and BrandId=" + BrandId + " and TradeMonth='" + date + "' GROUP BY SubsidyUserId");
             function.WriteLog("补贴:" + BrandId + ":" + dt.Rows.Count, "同步补贴数据");
@@ -194,25 +194,13 @@ namespace MySystem
                 decimal ProfitMoney = decimal.Parse(dr[1].ToString());
                 try
                 {
-                    Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
-                    string IdBrand = UserId + "_" + BrandId;
-                    UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
-                    if (MachineData == null)
-                    {
-                        MachineData = db.UserMachineData.Add(new UserMachineData()
-                        {
-                            IdBrand = IdBrand,
-                        }).Entity;
-                        db.SaveChanges();
-                    }
-                    MachineData.OtherProfit += ProfitMoney;
-                    db.SaveChanges();
+                    string content = UserId + "|" + BrandId + "|" + ProfitMoney + "|" + index;
+                    RedisDbconn.Instance.AddList("DoSubsidyProfitQueue", content);
                 }
                 catch (Exception ex)
                 {
                     function.WriteLog(DateTime.Now.ToString() + "\n" + UserId + "," + ProfitMoney + "\n" + ex.ToString(), "同步到补贴异常");
                 }
-                function.WriteLog(index.ToString(), "同步补贴数据");
             }
             OtherMySqlConn.dtable("update ProfitSubsidyDetail set Status=1 where Status=0 and BrandId=" + BrandId + " and TradeMonth='" + date + "'");
                 
@@ -379,5 +367,66 @@ namespace MySystem
         }
 
         #endregion
+
+
+
+
+
+
+
+
+
+
+
+
+
+        public void StartSubsidy()
+        {
+            Thread th = new Thread(StartSubsidyDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartSubsidyDo()
+        {
+            while (true)
+            {
+                string content = RedisDbconn.Instance.RPop<string>("DoSubsidyProfitQueue");
+                if (!string.IsNullOrEmpty(content))
+                {
+                    try
+                    {
+                        string[] data = content.Split('|');
+                        int UserId = int.Parse(data[0]);
+                        int BrandId = int.Parse(data[1]);
+                        decimal ProfitMoney = decimal.Parse(data[2]);
+                        int index = int.Parse(data[3]);
+                        WebCMSEntities db = new WebCMSEntities();
+                        Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
+                        string IdBrand = UserId + "_" + BrandId;
+                        UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
+                        if (MachineData == null)
+                        {
+                            MachineData = db.UserMachineData.Add(new UserMachineData()
+                            {
+                                IdBrand = IdBrand,
+                            }).Entity;
+                            db.SaveChanges();
+                        }
+                        MachineData.OtherProfit += ProfitMoney;
+                        db.SaveChanges();
+                        function.WriteLog(index.ToString() + "--" + DateTime.Now.ToString(), "同步补贴数据");
+                    }
+                    catch (Exception ex)
+                    {
+                        function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "同步补贴队列数据异常");
+                    }
+                }
+                else
+                {
+                    Thread.Sleep(1000);
+                }
+            }
+        }
     }
 }

+ 1 - 1
Areas/Admin/Controllers/MainServer/ProfitRewardRecordController.cs

@@ -527,7 +527,7 @@ namespace MySystem.Areas.Admin.Controllers
                 function.WritePage("/Balance/" + BrandId + "/", date + OpTypeString + ".txt", DateTime.Now.ToString());
                 // DoTradeProfit(BrandId, date, OpType);
                 // DoSubsidyProfit(BrandId, date, OpType);
-                RedisDbconn.Instance.AddList("SycnProfitQueue2", BrandId + "#cut#" + date + "#cut#" + OpType + "#cut#" + SysUserName);
+                RedisDbconn.Instance.AddList("SycnProfitQueue3", BrandId + "#cut#" + date + "#cut#" + OpType + "#cut#" + SysUserName);
                 return "success";
             }
             return date + "分润已同步,请勿重复操作";

+ 8 - 7
Startup.cs

@@ -132,12 +132,13 @@ namespace MySystem
                     pattern: "{controller=Home}/{action=Index}/{Id?}");
             });
 
-            ResetUserTradeService.Instance.Start();
-            ResetMerchantTradeService.Instance.Start();
+            // ResetUserTradeService.Instance.Start();
+            // ResetMerchantTradeService.Instance.Start();
             SycnProfitServiceV2.Instance.Start();
-            SycnHelpProfitService.Instance.Start();
-            ExcelHelper.Instance.Start();
-            TestHelper.Instance.Start();
+            SycnProfitServiceV2.Instance.StartSubsidy();
+            // SycnHelpProfitService.Instance.Start();
+            // ExcelHelper.Instance.Start();
+            // TestHelper.Instance.Start();
         }
 
 
@@ -152,11 +153,11 @@ namespace MySystem
         {
             Dictionary<string, Dictionary<string, string>> tables = new Dictionary<string, Dictionary<string, string>>();
             Library.OtherMySqlConn.connstr = Configuration["Setting:SqlConnStr"];
-            System.Data.DataTable tablecollection = Library.OtherMySqlConn.dtable("select DISTINCT TABLE_NAME from information_schema.columns where table_schema = 'KxsMainServer'");
+            System.Data.DataTable tablecollection = Library.OtherMySqlConn.dtable("select DISTINCT TABLE_NAME from information_schema.columns where table_schema = 'KxsMainServer2'");
             foreach (System.Data.DataRow subtable in tablecollection.Rows)
             {
                 Dictionary<string, string> Columns = new Dictionary<string, string>();
-                System.Data.DataTable columncollection = Library.OtherMySqlConn.dtable("select COLUMN_NAME,DATA_TYPE from information_schema.columns where table_schema = 'KxsMainServer' and TABLE_NAME='" + subtable["TABLE_NAME"].ToString() + "'");
+                System.Data.DataTable columncollection = Library.OtherMySqlConn.dtable("select COLUMN_NAME,DATA_TYPE from information_schema.columns where table_schema = 'KxsMainServer2' and TABLE_NAME='" + subtable["TABLE_NAME"].ToString() + "'");
                 foreach (System.Data.DataRow column in columncollection.Rows)
                 {
                     string datatype = column["DATA_TYPE"].ToString();