浏览代码

服务费逻辑调整
过期机具扣费逻辑

lichunlei 2 年之前
父节点
当前提交
18e229cf7c
共有 3 个文件被更改,包括 202 次插入5 次删除
  1. 188 0
      AppStart/Helper/PosExpiredHelper.cs
  2. 10 3
      AppStart/UserMonthFeeHelper.cs
  3. 4 2
      Startup.cs

+ 188 - 0
AppStart/Helper/PosExpiredHelper.cs

@@ -0,0 +1,188 @@
+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 PosExpiredHelper
+{
+    public readonly static PosExpiredHelper Instance = new PosExpiredHelper();
+    private PosExpiredHelper()
+    {
+    }
+
+    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>("PosExpiredRingQueue");
+                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)
+    {
+        DateTime now = DateTime.Now;
+        List<int> BuyUserIds = db.PosMachinesTwo.Select(m => new { m.BuyUserId, m.RecycEndDate, m.Status, m.BindingState }).Where(m => m.RecycEndDate < now && m.Status > -1 && m.BindingState == 0).ToList().Select(m => m.BuyUserId).ToList();
+        foreach(int BuyUserId in BuyUserIds)
+        {
+            RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
+            {
+                UserId = Convert.ToInt32(BuyUserId), //创客
+                Title = "机具循环过期提醒", //标题
+                Content = "尊敬的创客您好<br />您的部分机具循环已过期,请在五日内完成激活或联系在线客服回寄该机具。", //内容
+                Summary = "尊敬的创客您好,您的部分机具循环已过期,请在五日内完成激活或联系在线客服回寄该机具。",
+                CreateDate = DateTime.Now,
+            }));
+        }
+    }
+
+
+
+
+
+    public void StartPay()
+    {
+        Thread th = new Thread(DoPay);
+        th.IsBackground = true;
+        th.Start();
+    }
+
+    private void DoPay()
+    {
+        while (true)
+        {
+            try
+            {
+                string content = RedisDbconn.Instance.RPop<string>("PosExpiredPayQueue");
+                if(!string.IsNullOrEmpty(content))
+                {
+                    WebCMSEntities db = new WebCMSEntities();
+                    using (var tran = db.Database.BeginTransaction())
+                    {
+                        try
+                        {
+                            GoPay(db);
+                            tran.Commit();
+                        }
+                        catch(Exception ex)
+                        {
+                            tran.Rollback();
+                            function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "过期机具扣费异常");
+                        }
+                    }
+                    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 GoPay(WebCMSEntities db)
+    {
+        List<int> BrandIdList = new List<int>();
+        BrandIdList.Add(3);
+        BrandIdList.Add(5);
+        BrandIdList.Add(9);
+        DateTime now = DateTime.Now;
+        bool op = true;
+        Dictionary<int, decimal> UserList = new Dictionary<int, decimal>();
+        while(op)
+        {
+            var PosList = db.PosMachinesTwo.Select(m => new { m.Id, m.BuyUserId, m.RecycEndDate, m.Status, m.BindingState, m.BrandId, m.ScanQrTrade }).Where(m => m.RecycEndDate < now && m.Status > -1 && m.BindingState == 0 && m.ScanQrTrade < 999).OrderBy(m => m.Id).Take(50).ToList();
+            if(PosList.Count > 0)
+            {
+                foreach(var Pos in PosList)
+                {
+                    decimal PayMoney = 200;
+                    if(BrandIdList.Contains(Pos.BrandId))
+                    {
+                        PayMoney = 300;
+                    }
+                    PayMoney -= Pos.ScanQrTrade;
+                    UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == Pos.BuyUserId) ?? new UserAccount();
+                    if(account.BalanceAmount > 0)
+                    {
+                        if(account.BalanceAmount > PayMoney)
+                        {
+                            if(UserList.ContainsKey(Pos.BrandId))
+                            {
+                                UserList[Pos.BrandId] += PayMoney;
+                            }
+                            else
+                            {
+                                UserList.Add(Pos.BrandId, PayMoney);
+                            }
+                            account.BalanceAmount -= PayMoney;
+                        }
+                        else
+                        {
+                            PayMoney = account.BalanceAmount;
+                            if(UserList.ContainsKey(Pos.BrandId))
+                            {
+                                UserList[Pos.BrandId] += PayMoney;
+                            }
+                            else
+                            {
+                                UserList.Add(Pos.BrandId, PayMoney);
+                            }
+                            account.BalanceAmount = 0;
+                        }
+                        PosMachinesTwo EditPos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Pos.Id);
+                        if(EditPos != null)
+                        {
+                            EditPos.ScanQrTrade += PayMoney;
+                            if(BrandIdList.Contains(Pos.BrandId) && EditPos.ScanQrTrade >= 150)
+                            {
+                                EditPos.ScanQrTrade = 999;
+                            }
+                            else if(!BrandIdList.Contains(Pos.BrandId) && EditPos.ScanQrTrade >= 100)
+                            {
+                                EditPos.ScanQrTrade = 999;
+                            }
+                        }
+                    }
+                }
+                db.SaveChanges();
+            }
+            else
+            {
+                op = false;
+            }
+        }
+        foreach(int UserId in UserList.Keys)
+        {
+            AlipayPayBack2Service.Instance.ChangeAccount(db, new Orders(), UserId, -UserList[UserId], 124);
+        }
+    }
+}

+ 10 - 3
AppStart/UserMonthFeeHelper.cs

@@ -31,9 +31,16 @@ public class UserMonthFeeHelper
                 string content = RedisDbconn.Instance.RPop<string>("UserMonthFeeQueue");
                 if(!string.IsNullOrEmpty(content))
                 {
-                    WebCMSEntities db = new WebCMSEntities();
-                    DoSomething(db, int.Parse(content));
-                    db.Dispose();
+                    if(content == "end")
+                    {
+                        RedisDbconn.Instance.AddList("PosExpiredPayQueue", "1");
+                    }
+                    else
+                    {
+                        WebCMSEntities db = new WebCMSEntities();
+                        DoSomething(db, int.Parse(content));
+                        db.Dispose();
+                    }
                 }
                 else
                 {

+ 4 - 2
Startup.cs

@@ -224,9 +224,11 @@ namespace MySystem
             OperateStockService.Instance.Start(); //运营中心库存实时更新
             StoreApplyHelper.Instance.ResetStoreReserve(); //重置分仓额度
             LeaderApplyCouponsHelper.Instance.Start(); //盟主储蓄金申请机具券打标记
-            UserMonthFeeHelper.Instance.Start(); //每月创客服务费
-            // UserMonthFeeHelper.Instance.Start2(); //临时扣创客服务费
+            // UserMonthFeeHelper.Instance.Start(); //每月创客服务费
+            UserMonthFeeHelper.Instance.Start2(); //临时扣创客服务费
             DepositReturnService.Instance.Start(); //退押金到支付宝余额
+            // PosExpiredHelper.Instance.Start(); //过期机具提醒
+            // PosExpiredHelper.Instance.StartPay(); //过期机具扣费
 
             // StatService.Instance.StartPosActNum(); //实时统计激活数
             // StatService.Instance.StartNewUserNum(); //实时统计新增创客数