Эх сурвалжийг харах

增加队列:划拨后检查机具激活状态并自动补录

lcl 1 жил өмнө
parent
commit
57388da76b

+ 98 - 0
AppStart/Helper/AddActService.cs

@@ -0,0 +1,98 @@
+using System;
+using System.Collections.Generic;
+using Library;
+using LitJson;
+using System.Linq;
+using System.Data;
+using System.Threading;
+using MySystem.PxcModels;
+
+namespace MySystem
+{
+    public class AddActService
+    {
+        public readonly static AddActService Instance = new AddActService();
+        private AddActService()
+        { }
+
+        public void Start()
+        {
+            Thread th = new Thread(dosomething);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void dosomething()
+        {
+            while (true)
+            {
+                string data = RedisDbconn.Instance.RPop<string>("AddActQueue");
+                if (!string.IsNullOrEmpty(data))
+                {
+                    try
+                    {
+                        int PosId = int.Parse(function.CheckInt(data));                    
+                        WebCMSEntities db = new WebCMSEntities();
+                        PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == PosId);
+                        if(pos != null)
+                        {
+                            decimal CheckMoney = 1000;
+                            int CheckDays = 30;
+                            DateTime now = DateTime.Now;
+                            //判断激活条件并激活
+                            DateTime TransferTime = pos.TransferTime == null ? DateTime.Now : pos.TransferTime.Value;
+                            if (pos.CreditTrade >= CheckMoney && pos.BuyUserId > 0 && pos.ActivationState == 0 && TransferTime.AddMinutes(-30) < pos.BindingTime)
+                            {
+                                pos.ActivationState = 1;
+                                pos.ActivationTime = DateTime.Now;
+                                function.WriteLog("机具" + pos.PosSn, "开机奖励在激活中监控");
+                                PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
+                                if (merchant != null)
+                                {
+                                    merchant.ActiveStatus = 1;
+                                    merchant.MerStandardDate = DateTime.Now;
+                                    db.SaveChanges();
+                                    function.WriteLog("商户" + merchant.KqMerNo, "开机奖励在激活中监控");
+
+                                    // 推荐王逻辑(激活)
+                                    string SendData = "{\"Kind\":\"3\",\"Data\":{\"UserId\":\"" + pos.BuyUserId + "\",\"PosId\":\"" + pos.Id + "\",\"TradeMonth\":\"" + DateTime.Now.ToString("yyyyMM") + "\"}}";
+                                    RedisDbconn.Instance.AddList("RecommendActStatQueue", SendData);
+
+                                    //发放开机奖励
+                                    function.WriteLog("首台" + pos.IsFirst, "开机奖励在激活中监控");
+                                    if(pos.IsFirst == 1 && pos.BindingTime > DateTime.Now.AddDays(-CheckDays))
+                                    {
+                                        RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
+                                    }
+                                }
+                                //发放大盟主奖励
+                                if(pos.LeaderUserId > 0 && pos.IsFirst == 1 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now) && pos.BindingTime > DateTime.Now.AddDays(-CheckDays))
+                                {
+                                    RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
+                                }
+                                //发放运营中心奖励
+                                if(pos.IsFirst == 1 && pos.BindingTime > DateTime.Now.AddDays(-CheckDays))
+                                {
+                                    RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
+                                }
+                                AlipayPayBack2Service.Instance.ActReserveBack(pos.OpId, pos.OpReserve1, pos.OpReserve2, pos.OpReserve3);
+
+                                //补激活前的交易
+                                RedisDbconn.Instance.AddList("AddTradeRecordByPosIdQueue", pos.Id.ToString());
+                            }
+                            db.Dispose();
+                        }
+                    }
+                    catch (Exception ex)
+                    {                        
+                        function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "划拨后检查机具激活状态并自动补录异常");
+                    }
+                }
+                else
+                {
+                    Thread.Sleep(500);
+                }
+            }
+        }
+    }
+}

+ 1 - 1
Startup.cs

@@ -201,7 +201,7 @@ namespace MySystem
             RedPackageV2Helper.Instance.StartSendPrize(); //红包活动发奖
             ActRewardService.Instance.Start(); //发放激活奖励
             HelpProfitPreMerchantHelper.Instance.Start(); //助利宝每天增加指定数量商机
-            // LeaderCompPrizeHelper.Instance.Start(); //每天计算领导人达标奖
+            AddActService.Instance.Start(); //划拨后检查机具激活状态,并自动补录
 
             MessageCenterService.Instance.Start(); // 消息队列
             SetFeeFlagService.Instance.Start(); //118天提前通知创客费率调升消息