Просмотр исходного кода

检查订单是否在队列里

lcl 1 год назад
Родитель
Сommit
65a5e3b627
3 измененных файлов с 71 добавлено и 0 удалено
  1. 1 0
      Startup.cs
  2. 69 0
      Util/HaoDa/ProfitCheckHelper.cs
  3. 1 0
      Util/HaoDa/ProfitHelper.cs

+ 1 - 0
Startup.cs

@@ -161,6 +161,7 @@ namespace MySystem
                 ProfitHelper.Instance.StartListenWxTrade(); //返现队列-微信
                 ProfitHelper.Instance.StartSetDivi(); //设置订单当前返现金额
                 ProfitHelper.Instance.StartListenProfit(); //每月分润
+                ProfitCheckHelper.Instance.Start(); //检查订单是否在队列里
 
                 AlipayPayBackFeeService.Instance.Start();
                 ActiveRewardService.Instance.StartAct();

+ 69 - 0
Util/HaoDa/ProfitCheckHelper.cs

@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Data;
+using MySystem.Models.Main;
+using Library;
+using System.Threading;
+using Microsoft.Extensions.Hosting;
+using System.Threading.Tasks;
+using LitJson;
+
+namespace MySystem
+{
+    public class ProfitCheckHelper
+    {
+        public readonly static ProfitCheckHelper Instance = new ProfitCheckHelper();
+        private ProfitCheckHelper()
+        {
+        }
+
+        #region 检查订单是否在队列里
+        public void Start()
+        {
+            Thread th = new Thread(StartDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+        public void StartDo()
+        {
+            while (true)
+            {
+                string orderidstring = RedisDbconn.Instance.RPop<string>("ConsumerProfitCheck");
+                if (!string.IsNullOrEmpty(orderidstring))
+                {
+                    DoSomeThing(orderidstring);
+                    Thread.Sleep(2000);
+                }
+                else
+                {
+                    Thread.Sleep(60000);
+                }
+            }
+        }
+
+        public void DoSomeThing(string orderidstring)
+        { 
+            try
+            {
+                int orderId = int.Parse(function.CheckInt(orderidstring));
+                WebCMSEntities db = new WebCMSEntities();
+                ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == orderId);
+                if(order != null)
+                {
+                    var list = RedisDbconn.Instance.GetList<ConsumerOrders>("ConsumerOrdersHd:Divi:" + order.PayMode + ":" + order.MerchantId);
+                    if(!list.Any(m => m.Id == orderId) && !db.ConsumerProfit.Any(m => m.OrderId == orderId))
+                    {
+                        RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":List", order.Id.ToString());
+                    }
+                }
+                db.Dispose();
+            }
+            catch(Exception ex)
+            {
+                function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "检查订单是否在队列里异常");
+            }
+        }
+        #endregion
+    }
+}

+ 1 - 0
Util/HaoDa/ProfitHelper.cs

@@ -242,6 +242,7 @@ namespace MySystem
                 {
                     LogHelper.Instance.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":" + ex.ToString(), "自定义分润程序监听队列异常");
                     tran.Rollback();
+                    RedisDbconn.Instance.AddList("ConsumerProfitCheck", orderidstring);
                 }
             }
             db.Dispose();