Procházet zdrojové kódy

增加创客服务器费队列

lichunlei před 2 roky
rodič
revize
e2c9006bd8
2 změnil soubory, kde provedl 64 přidání a 0 odebrání
  1. 63 0
      AppStart/UserMonthFeeHelper.cs
  2. 1 0
      Startup.cs

+ 63 - 0
AppStart/UserMonthFeeHelper.cs

@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Linq;
+using System.Data;
+using MySystem;
+using MySystem.PxcModels;
+using Library;
+using LitJson;
+
+public class UserMonthFeeHelper
+{
+    public readonly static UserMonthFeeHelper Instance = new UserMonthFeeHelper();
+    private UserMonthFeeHelper()
+    {
+    }
+
+    public void Start()
+    {
+        Thread th = new Thread(DoWorks);
+        th.IsBackground = true;
+        th.Start();
+    }
+
+    private void DoWorks()
+    {
+        while (true)
+        {
+            try
+            {
+                string content = RedisDbconn.Instance.RPop<string>("UserMonthFeeQueue");
+                if(!string.IsNullOrEmpty(content))
+                {
+                    WebCMSEntities db = new WebCMSEntities();
+                    DoSomething(db);
+                    db.Dispose();
+                }
+            }
+            catch (Exception ex)
+            {
+                function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "创客每月月费扣款异常");
+            }
+            function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "创客每月月费扣款日志");
+            Thread.Sleep(60000);
+        }
+    }
+
+    public void DoSomething(WebCMSEntities db)
+    {
+        var Users = db.UserAccount.Select(m => new { m.Id, m.BalanceAmount }).Where(m => m.BalanceAmount > 0).ToList();
+        foreach(var User in Users)
+        {
+            if(User.BalanceAmount > 10)
+            {
+                AlipayPayBack2Service.Instance.ChangeAccount(db, new Orders(), User.Id, -10, 125);
+            }
+            else
+            {
+                AlipayPayBack2Service.Instance.ChangeAccount(db, new Orders(), User.Id, -User.BalanceAmount, 125);
+            }
+        }
+    }
+}

+ 1 - 0
Startup.cs

@@ -221,6 +221,7 @@ namespace MySystem
             OperateStockService.Instance.Start(); //运营中心库存实时更新
             StoreApplyHelper.Instance.ResetStoreReserve(); //重置分仓额度
             // LeaderApplyCouponsHelper.Instance.Start(); //盟主储蓄金申请机具券打标记
+            UserMonthFeeHelper.Instance.Start(); //每月创客服务费
 
             // StatService.Instance.StartPosActNum(); //实时统计激活数
             // StatService.Instance.StartNewUserNum(); //实时统计新增创客数