Przeglądaj źródła

添加大盟主标记逻辑

lcl 10 miesięcy temu
rodzic
commit
cb47222328
2 zmienionych plików z 88 dodań i 0 usunięć
  1. 87 0
      AppStart/Helper/PosCouponExchangeHelper.cs
  2. 1 0
      Startup.cs

+ 87 - 0
AppStart/Helper/PosCouponExchangeHelper.cs

@@ -0,0 +1,87 @@
+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 PosCouponExchangeHelper
+{
+    public readonly static PosCouponExchangeHelper Instance = new PosCouponExchangeHelper();
+    private PosCouponExchangeHelper()
+    {
+    }
+
+    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>("PosCouponExchangeQueue");
+                if(!string.IsNullOrEmpty(content))
+                {
+                    WebCMSEntities db = new WebCMSEntities();
+                    DoSomething(db, content);
+                    db.Dispose();
+                }
+            }
+            catch (Exception ex)
+            {
+                function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "电签券对大机券异常");
+            }
+            Thread.Sleep(60000);
+        }
+    }
+
+    public void DoSomething(WebCMSEntities db, string content)
+    {
+        JsonData data = JsonMapper.ToObject(content);
+        int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
+        string CouponCodes = data["CouponCodes"].ToString(); //券列表
+        Dictionary<string, object> Obj = new Dictionary<string, object>();
+        List<string> Codes = CouponCodes.Split(',').ToList();
+        List<int> LeaderUserIds = new List<int>();
+        int BeforeUserId = 0;
+        int AfterUserId = 0;
+        int index = 0;
+        IQueryable<PosCoupons> list = db.PosCoupons.Where(m => Codes.Contains(m.ExchangeCode) && m.UserId == UserId && m.IsLock == 0 && m.IsUse == 0).OrderBy(m => m.CreateDate);
+        foreach(PosCoupons sub in list)
+        {
+            index += 1;
+            if(index % 2 == 1) BeforeUserId = sub.LeaderUserId;
+            if(index % 2 == 0)
+            {
+                AfterUserId = sub.LeaderUserId;
+                if(BeforeUserId > 0 && AfterUserId > 0) LeaderUserIds.Add(AfterUserId);
+                if(BeforeUserId == 0 && AfterUserId > 0) LeaderUserIds.Add(AfterUserId);
+                if(BeforeUserId > 0 && AfterUserId == 0) LeaderUserIds.Add(BeforeUserId);
+                if(BeforeUserId == 0 && AfterUserId == 0) LeaderUserIds.Add(0);
+                BeforeUserId = 0;
+                AfterUserId = 0;
+            }
+            sub.UserId = 0;
+        }
+        db.SaveChanges();
+        int Count = Codes.Count % 2;
+        index = 0;
+        IQueryable<PosCoupons> chklist = db.PosCoupons.Where(m => m.QueryCount == 2 && m.UserId == 0 && m.IsLock == 0 && m.IsUse == 0).Take(Count);
+        foreach(PosCoupons sub in chklist)
+        {
+            index += 1;
+            sub.UserId = UserId;
+            sub.LeaderUserId = LeaderUserIds[index];
+        }
+        db.SaveChanges();
+    }
+}

+ 1 - 0
Startup.cs

@@ -245,6 +245,7 @@ namespace MySystem
                 UpUserSaveService.Instance.Start(); //每天凌晨保存头一天的创客关系数据
                 HyfAddPrizeService.Instance.Start(); //盒力四射加码奖励发放
                 PrizeFlowRecordService.Instance.Start(); //奖励返现逻辑日志记录
+                PosCouponExchangeHelper.Instance.Start(); //电签券兑换大机券
             // }