Explorar o código

金控分润完毕则扣服务费

lichunlei %!s(int64=3) %!d(string=hai) anos
pai
achega
cd2666d9b9
Modificáronse 1 ficheiros con 33 adicións e 15 borrados
  1. 33 15
      AppStart/Helper/SycnProfitServiceV2.cs

+ 33 - 15
AppStart/Helper/SycnProfitServiceV2.cs

@@ -46,8 +46,10 @@ namespace MySystem
                         {
                             DoTradeProfit2(BrandId, date, SysUserName);
                             DoSubsidyProfit2(BrandId, date);
-                            DoUserServiceFee();
-                            // RedisDbconn.Instance.AddList("UserMonthFeeQueue", "1");
+                            if(BrandId == 1)
+                            {
+                                DoUserServiceFee();
+                            }
                         }
                         function.WriteLog(DateTime.Now.ToString() + "\r\n\r\n", "同步分润数据");
                     }
@@ -407,24 +409,40 @@ namespace MySystem
         private void DoUserServiceFee()
         {
             WebCMSEntities db = new WebCMSEntities();
-            var list = db.UserProfit.Select(m => new { m.Id, m.ProfitRate }).ToList();
-            foreach(var item in list)
+            int startId = 0;
+            bool op = true;
+            while(op)
             {
-                UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == item.Id);
-                if (account == null)
+                var list = db.UserProfit.Select(m => new { m.Id, m.ProfitRate }).Where(m => m.Id > startId).OrderBy(m => m.Id).Take(50).ToList();
+                if(list.Count > 0)
                 {
-                    account = db.UserAccount.Add(new UserAccount()
+                    foreach(var item in list)
                     {
-                        Id = item.Id,
-                        UserId = item.Id,
-                    }).Entity;
-                    db.SaveChanges();
+                        UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == item.Id);
+                        if (account == null)
+                        {
+                            account = db.UserAccount.Add(new UserAccount()
+                            {
+                                Id = item.Id,
+                                UserId = item.Id,
+                            }).Entity;
+                            db.SaveChanges();
+                        }
+                        account.BalanceAmount += item.ProfitRate;
+                        account.TotalAmount += item.ProfitRate;
+                        db.SaveChanges();
+                        RedisDbconn.Instance.AddList("UserMonthFeeQueue", item.Id.ToString());
+                        startId = item.Id;
+                    }
+                    list.Clear();
+                    Thread.Sleep(100);
+                }
+                else
+                {
+                    op = false;
                 }
-                account.BalanceAmount += item.ProfitRate;
-                account.TotalAmount += item.ProfitRate;
-                db.SaveChanges();
-                RedisDbconn.Instance.AddList("UserMonthFeeQueue", item.Id);
             }
+            RedisDbconn.Instance.AddList("UserMonthFeeQueue", "end");
             db.Dispose();
         }