lichunlei 3 роки тому
батько
коміт
c6db859b42
2 змінених файлів з 75 додано та 0 видалено
  1. 74 0
      AppStart/Timer/RedPackageHelper.cs
  2. 1 0
      Startup.cs

+ 74 - 0
AppStart/Timer/RedPackageHelper.cs

@@ -147,4 +147,78 @@ public class RedPackageHelper
             Thread.Sleep(60000);
         }
     }
+
+
+    public void StartSendPrize()
+    {
+        Thread th = new Thread(StartSendPrizeDo);
+        th.IsBackground = true;
+        th.Start();
+    }
+
+    private void StartSendPrizeDo()
+    {
+        while (true)
+        {
+            string content = RedisDbconn.Instance.RPop<string>("RedPrizeQueue");
+            if (!string.IsNullOrEmpty(content))
+            {
+                try
+                {
+                    using (WebCMSEntities db = new WebCMSEntities())
+                    {
+                        int Id = int.Parse(function.CheckInt(content));
+                        ActivityRedPackageJoins item = db.ActivityRedPackageJoins.FirstOrDefault(m => m.Id == Id);
+                        if (item != null)
+                        {
+                            int ParentUserId = item.UserId;
+                            UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == ParentUserId);
+                            if (account == null)
+                            {
+                                account = db.UserAccount.Add(new UserAccount()
+                                {
+                                    Id = ParentUserId,
+                                    UserId = ParentUserId,
+                                }).Entity;
+                                db.SaveChanges();
+                            }
+                            decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
+                            decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
+                            decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
+                            account.BalanceAmount += item.PrizeAmt;
+                            account.TotalAmount += item.PrizeAmt;
+                            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 = ParentUserId, //创客
+                                ChangeType = 31, //变动类型
+                                ChangeAmount = item.PrizeAmt, //变更金额
+                                BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
+                                AfterTotalAmount = AfterTotalAmount, //变更后总金额
+                                BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
+                                AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
+                                BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
+                                AfterBalanceAmount = AfterBalanceAmount, //变更后余额
+                                QueryCount = item.Id,
+                            }).Entity;
+                            db.SaveChanges();
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(ex.ToString(), "领取红包奖励异常");
+                }
+                Thread.Sleep(200);
+            }
+            else
+            {
+                Thread.Sleep(60000);
+            }
+        }
+    }
 }

+ 1 - 0
Startup.cs

@@ -235,6 +235,7 @@ namespace MySystem
 
             // RedPackageHelper.Instance.Start();
             RedPackageHelper.Instance.StartStatTop10();
+            RedPackageHelper.Instance.StartSendPrize();
             // StatService.Instance.StatUserLevel();
             // StatService.Instance.StartEverDay("2022-05-11");
             // ProfitHelper.Instance.StatProfit("202204"); //统计分润