Sfoglia il codice sorgente

优化分润效率

lichunlei 3 anni fa
parent
commit
72672b77b9

+ 60 - 49
AppStart/Helper/SycnProfitServiceV2.cs

@@ -102,65 +102,76 @@ namespace MySystem
         {
             WebCMSEntities db = new WebCMSEntities();
             OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
-            
-            DataTable dt = OtherMySqlConn.dtable("select UserId,DirectFlag,ProfitAmount from ProfitRecord where BrandId=" + BrandId + " and SeoTitle='" + date + "' and Version=0 and UserId>0");
-            function.WriteLog("分润:" + BrandId + ":" + dt.Rows.Count, "同步分润数据");
-            int index = 0;
-            foreach (DataRow dr in dt.Rows)
+            int startid = 0;
+            bool op = true;
+            while(op)
             {
-                index += 1;
-                int UserId = int.Parse(dr["UserId"].ToString());
-                int DirectFlag = int.Parse(dr["DirectFlag"].ToString());
-                decimal ProfitAmount = decimal.Parse(dr["ProfitAmount"].ToString());
-                var tran = db.Database.BeginTransaction();
-                try
+                DataTable dt = OtherMySqlConn.dtable("select Id,UserId,DirectFlag,ProfitAmount from ProfitRecord where Id>" + startid + " and BrandId=" + BrandId + " and SeoTitle='" + date + "' and Version=0 and UserId>0 order by Id limit 200");
+                if(dt.Rows.Count > 0)
                 {
-                    UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
-                    if (account == null)
+                    function.WriteLog("分润:" + BrandId + ":" + dt.Rows.Count, "同步分润数据");
+                    int index = 0;
+                    foreach (DataRow dr in dt.Rows)
                     {
-                        account = db.UserAccount.Add(new UserAccount()
+                        index += 1;
+                        int UserId = int.Parse(dr["UserId"].ToString());
+                        int DirectFlag = int.Parse(dr["DirectFlag"].ToString());
+                        decimal ProfitAmount = decimal.Parse(dr["ProfitAmount"].ToString());
+                        var tran = db.Database.BeginTransaction();
+                        try
                         {
-                            Id = UserId,
-                            UserId = UserId,
-                        }).Entity;
-                        db.SaveChanges();
+                            UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
+                            if (account == null)
+                            {
+                                account = db.UserAccount.Add(new UserAccount()
+                                {
+                                    Id = UserId,
+                                    UserId = UserId,
+                                }).Entity;
+                                db.SaveChanges();
+                            }
+                            decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
+                            decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
+                            decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
+                            account.BalanceAmount += ProfitAmount;
+                            account.TotalAmount += ProfitAmount;
+                            decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
+                            decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
+                            decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
+                            UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
+                            {
+                                CreateDate = DateTime.Now,
+                                UpdateDate = DateTime.Now,
+                                UserId = UserId, //创客
+                                ProductType = BrandId,
+                                ChangeType = 1, //变动类型
+                                ChangeAmount = ProfitAmount, //变更金额
+                                BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
+                                AfterTotalAmount = AfterTotalAmount, //变更后总金额
+                                BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
+                                AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
+                                BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
+                                AfterBalanceAmount = AfterBalanceAmount, //变更后余额
+                                Remark = DirectFlag == 1 ? "直拓商户分润" : "品牌推广服务费",
+                            }).Entity;
+                            db.SaveChanges();
+                            tran.Commit();
+                        }
+                        catch (Exception ex)
+                        {
+                            function.WriteLog(DateTime.Now.ToString() + "\n" + UserId + "," + ProfitAmount + "\n" + ex.ToString(), "同步到余额异常");
+                            tran.Rollback();
+                        }
+                        startid = int.Parse(dr["Id"].ToString());
+                        function.WriteLog(index.ToString(), "同步分润数据");
                     }
-                    decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
-                    decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
-                    decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
-                    account.BalanceAmount += ProfitAmount;
-                    account.TotalAmount += ProfitAmount;
-                    decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
-                    decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
-                    decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
-                    UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
-                    {
-                        CreateDate = DateTime.Now,
-                        UpdateDate = DateTime.Now,
-                        UserId = UserId, //创客
-                        ProductType = BrandId,
-                        ChangeType = 1, //变动类型
-                        ChangeAmount = ProfitAmount, //变更金额
-                        BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
-                        AfterTotalAmount = AfterTotalAmount, //变更后总金额
-                        BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
-                        AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
-                        BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
-                        AfterBalanceAmount = AfterBalanceAmount, //变更后余额
-                        Remark = DirectFlag == 1 ? "直拓商户分润" : "品牌推广服务费",
-                    }).Entity;
-                    db.SaveChanges();
-                    tran.Commit();
                 }
-                catch (Exception ex)
+                else
                 {
-                    function.WriteLog(DateTime.Now.ToString() + "\n" + UserId + "," + ProfitAmount + "\n" + ex.ToString(), "同步到余额异常");
-                    tran.Rollback();
+                    op = false;
                 }
-                function.WriteLog(index.ToString(), "同步分润数据");
             }
             OtherMySqlConn.dtable("update ProfitRecord set Version=1 where BrandId=" + BrandId + " and SeoTitle='" + date + "' and Version=0 and UserId>0");
-                
             db.Dispose();
         }
 

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

@@ -482,7 +482,7 @@ namespace MySystem.Areas.Admin.Controllers
                     userIds += pos.BuyUserId + ",";
                 }
 
-                if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 6)
+                if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 2 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6)
                 {
                     // PosId:机具Id
                     // Kind:1或2,1为费率0.63,2为费率0.6