Explorar o código

修改创客服务费逻辑

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

+ 58 - 9
AppStart/Helper/SycnProfitServiceV2.cs

@@ -46,7 +46,8 @@ namespace MySystem
                         {
                             DoTradeProfit2(BrandId, date, SysUserName);
                             DoSubsidyProfit2(BrandId, date);
-                            RedisDbconn.Instance.AddList("UserMonthFeeQueue", "1");
+                            DoUserServiceFee();
+                            // RedisDbconn.Instance.AddList("UserMonthFeeQueue", "1");
                         }
                         function.WriteLog(DateTime.Now.ToString() + "\r\n\r\n", "同步分润数据");
                     }
@@ -134,11 +135,11 @@ namespace MySystem
                             decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
                             decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
                             decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
-                            account.BalanceAmount += ProfitAmount;
-                            account.TotalAmount += ProfitAmount;
-                            decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
+                            // account.BalanceAmount += ProfitAmount;
+                            // account.TotalAmount += ProfitAmount;
+                            decimal AfterTotalAmount = account.TotalAmount + ProfitAmount; //变更后总金额
                             decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
-                            decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
+                            decimal AfterBalanceAmount = account.BalanceAmount + ProfitAmount; //变更后余额
                             UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
                             {
                                 CreateDate = DateTime.Now,
@@ -155,6 +156,17 @@ namespace MySystem
                                 AfterBalanceAmount = AfterBalanceAmount, //变更后余额
                                 Remark = DirectFlag == 1 ? "直拓商户分润" : "品牌推广服务费",
                             }).Entity;
+                            UserProfit profit = db.UserProfit.FirstOrDefault(m => m.Id == UserId);
+                            if (profit == null)
+                            {
+                                profit = db.UserProfit.Add(new UserProfit()
+                                {
+                                    Id = UserId,
+                                    UserId = UserId,
+                                }).Entity;
+                                db.SaveChanges();
+                            }
+                            profit.ProfitRate += ProfitAmount;
                             db.SaveChanges();
                             tran.Commit();
                         }
@@ -253,11 +265,11 @@ namespace MySystem
                             decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
                             decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
                             decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
-                            account.BalanceAmount += ProfitMoney;
-                            account.TotalAmount += ProfitMoney;
-                            decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
+                            // account.BalanceAmount += ProfitMoney;
+                            // account.TotalAmount += ProfitMoney;
+                            decimal AfterTotalAmount = account.TotalAmount + ProfitMoney; //变更后总金额
                             decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
-                            decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
+                            decimal AfterBalanceAmount = account.BalanceAmount + ProfitMoney; //变更后余额
                             UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
                             {
                                 CreateDate = DateTime.Now,
@@ -274,6 +286,17 @@ namespace MySystem
                                 AfterBalanceAmount = AfterBalanceAmount, //变更后余额
                                 Remark = "直拓商户补贴",
                             }).Entity;
+                            UserProfit profit = db.UserProfit.FirstOrDefault(m => m.Id == UserId);
+                            if (profit == null)
+                            {
+                                profit = db.UserProfit.Add(new UserProfit()
+                                {
+                                    Id = UserId,
+                                    UserId = UserId,
+                                }).Entity;
+                                db.SaveChanges();
+                            }
+                            profit.ProfitRate += ProfitMoney;
                             db.SaveChanges();
                             tran.Commit();
                         }
@@ -379,7 +402,33 @@ namespace MySystem
 
         #endregion
 
+        #region 扣创客服务费
 
+        private void DoUserServiceFee()
+        {
+            WebCMSEntities db = new WebCMSEntities();
+            var list = db.UserProfit.Select(m => new { m.Id, m.ProfitRate }).ToList();
+            foreach(var item in list)
+            {
+                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);
+            }
+            db.Dispose();
+        }
+
+        #endregion