Browse Source

调整购买分仓额度逻辑

lichunlei 2 years ago
parent
commit
501ae489be
2 changed files with 34 additions and 12 deletions
  1. 30 8
      AppStart/Timer/StoreApplyHelper.cs
  2. 4 4
      Startup.cs

+ 30 - 8
AppStart/Timer/StoreApplyHelper.cs

@@ -35,7 +35,7 @@ public class StoreApplyHelper
                     if(string.IsNullOrEmpty(check))
                     {
                         function.WritePage("/StoreApply/", DateTime.Now.ToString("yyyyMM") + ".txt", DateTime.Now.ToString());
-
+                        // OtherMySqlConn.connstr = 
                         db.SaveChanges();
                     }
                 }
@@ -64,23 +64,47 @@ public class StoreApplyHelper
             WebCMSEntities db = new WebCMSEntities();
             try
             {
-                string data = RedisDbconn.Instance.Get<string>("StoreApplyQueue");
+                string data = RedisDbconn.Instance.RPop<string>("StoreApplyQueue");
                 if(!string.IsNullOrEmpty(data))
                 {
+                    function.WriteLog("data:" + data, "分仓向总仓申请机具日志");
                     JsonData jsonObj = JsonMapper.ToObject(data);
                     if(jsonObj["Kind"].ToString() == "1")
                     {
+                        function.WriteLog("1", "分仓向总仓申请机具日志");
                         int OrderId = int.Parse(jsonObj["Data"]["OrderId"].ToString());
                         Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId);
                         if(order != null)
                         {
-                            decimal TotalPrice = order.TotalPrice;
+                            function.WriteLog("2", "分仓向总仓申请机具日志");
                             UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId);
-                            if(account != null)
+                            if (account == null)
                             {
-                                account.TempAmount += TotalPrice;
-                                account.ValidAmount += TotalPrice;
+                                account = db.UserAccount.Add(new UserAccount()
+                                {
+                                    Id = order.UserId,
+                                    UserId = order.UserId,
+                                }).Entity;
+                                db.SaveChanges();
                             }
+                            decimal TotalPrice = order.TotalPrice * 2;
+                            decimal BeforeTotalAmount = account.TempAmount; //变更前总金额
+                            account.TempAmount += TotalPrice;
+                            account.ValidAmount += TotalPrice;
+                            decimal AfterTotalAmount = account.TempAmount; //变更后总金额
+                            StoreHouseAmountRecord record = db.StoreHouseAmountRecord.Add(new StoreHouseAmountRecord()
+                            {
+                                CreateDate = DateTime.Now,
+                                UpdateDate = DateTime.Now,
+                                OperateType = 1,
+                                AmountType = 1,
+                                AfterAmount = AfterTotalAmount,
+                                BeforeAmount = BeforeTotalAmount,
+                                UseAmount = TotalPrice,
+                                UserId = order.UserId,
+                                QueryCount = order.Id,
+                            }).Entity;
+                            db.SaveChanges();
                         }
                     }
                     db.SaveChanges();
@@ -91,8 +115,6 @@ public class StoreApplyHelper
                 function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "分仓向总仓申请机具线程异常");
             }
             db.Dispose();
-            function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "分仓向总仓申请机具线程日志");
-            Thread.Sleep(60000);
         }
     }
 }

+ 4 - 4
Startup.cs

@@ -92,7 +92,7 @@ namespace MySystem
 
             // services.AddHostedService<TimerStatTimer>(); //实时统计创客、激活商户数
             // services.AddHostedService<PosTradeStatTimer>(); // 统计头天的交易额、商户型创客、激活奖励、开机奖励
-            // services.AddHostedService<AlipayPayBack2Timer>(); //支付宝回调处理
+            services.AddHostedService<AlipayPayBack2Timer>(); //支付宝回调处理
 
             //services.AddHttpContextAccessor();
 
@@ -203,14 +203,14 @@ namespace MySystem
             // RedPackageHelper.Instance.Start(); //每天生成300个红包
             // RedPackageHelper.Instance.StartStatTop10(); //红包活动统计排行
             // RedPackageHelper.Instance.StartSendPrize(); //红包活动发奖
-            // BalancePayBackService.Instance.Start(); //余额支付队列
-            // ReservePayBackService.Instance.Start(); //储备金支付队列
+            BalancePayBackService.Instance.Start(); //余额支付队列
+            ReservePayBackService.Instance.Start(); //储备金支付队列
             // LeaderPrizeService.Instance.Start(); //大盟主奖励发奖
             // MessageCenterService.Instance.Start(); // 消息队列
             // RecommendActStatService.Instance.Start(); //推荐王奖励数据统计
             //必须打开的
 
-
+            StoreApplyHelper.Instance.StartEverTime();
             // StatService.Instance.StartPosActNum(); //实时统计激活数
             // StatService.Instance.StartNewUserNum(); //实时统计新增创客数
             // StatService.Instance.StatProfit(); //实时统计创客收益