瀏覽代碼

扣机具货款改为机具号
添加机具激活,清理预扣款队列

lcl 1 年之前
父節點
當前提交
67c6ebed71

+ 83 - 0
AppStart/Helper/PosWithholdService.cs

@@ -0,0 +1,83 @@
+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 PosWithholdService
+    {
+        public readonly static PosWithholdService Instance = new PosWithholdService();
+        private PosWithholdService()
+        { }
+
+        
+        // ·若扣款已扣,则返还创客余额
+        // ·若扣款未扣,则删除该条扣款
+        public void Start()
+        {
+            Thread th = new Thread(StartDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartDo()
+        {
+            while (true)
+            {
+                try
+                {
+                    string content = RedisDbconn.Instance.RPop<string>("PosWithholdQueue");
+                    if(!string.IsNullOrEmpty(content))
+                    {
+                        function.WriteLog("content:" + content, "过期机具扣款机具申请");
+                        JsonData jsonObj = JsonMapper.ToObject(content);
+                        int UserId = int.Parse(function.CheckInt(jsonObj["UserId"].ToString()));
+                        string SnNo = jsonObj["SnNo"].ToString();
+                        WebCMSEntities db = new WebCMSEntities();
+                        decimal ChargeAmount = 0;
+                        bool doBack = true; //是否减少账户预扣总额
+                        ToChargeBackRecord back = db.ToChargeBackRecord.FirstOrDefault(m => m.UserId == UserId && m.Field1 == SnNo && m.ChargeType == 124 && m.Remark.StartsWith("循环过期"));
+                        if(back != null)
+                        {
+                            function.WriteLog("扣款数据:" + Newtonsoft.Json.JsonConvert.SerializeObject(back), "过期机具扣款机具申请");
+                            ChargeAmount = back.ChargeAmount;
+                            function.WriteLog("扣款是否已扣:" + back.Status, "过期机具扣款机具申请");
+                            if(back.Status == 1)
+                            {
+                                Utils.Instance.OpAccount(back.UserId, ChargeAmount, 138, false);
+                                doBack = false;
+                            }
+                            db.ToChargeBackRecord.Remove(back);
+                            db.SaveChanges();
+
+                            //减少账户预扣总额
+                            function.WriteLog("是否减少账户预扣总额:" + doBack, "过期机具扣款机具申请");
+                            if(doBack)
+                            {
+                                Utils.Instance.ToChargeAmount(UserId, -ChargeAmount);
+                                function.WriteLog("减少账户预扣总额:" + ChargeAmount, "过期机具扣款机具申请");
+                            }
+                        }
+                        db.Dispose();
+
+                        Thread.Sleep(500);
+                    }
+                    else
+                    {
+                        Thread.Sleep(30000);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "过期机具扣款机具申请异常");
+                    Thread.Sleep(300000);
+                }
+            }
+        }
+    }
+}

+ 2 - 0
AppStart/Helper/SycnSpServer/SycnSpTradeService.cs

@@ -843,6 +843,8 @@ namespace MySystem
                     //统计激活数
                     RedisDbconn.Instance.AddList("StatActQueue", "{\"TradeDate\":\"" + now.ToString("yyyyMMdd") + "\",\"UserId\":\"" + pos.BuyUserId + "\",\"BrandId\":\"" + pos.BrandId + "\"}");
                 }
+                //清理预扣款
+                RedisDbconn.Instance.AddList("PosWithholdQueue", "{\"UserId\":\"" + pos.BuyUserId + "\",\"SnNo\":\"" + pos.PosSn + "\"}");
             }
         }
 

+ 1 - 1
AppStart/Helper/TimeOutPosChargeService.cs

@@ -162,7 +162,7 @@ namespace MySystem
                 if (record.ChargeType == 124)//过期机具货款扣费
                 {
                     ChangeType = 124;
-                    Remark = "扣机具货款";
+                    Remark = items.Field1;
                 }
                 if (record.ChargeType == 1)//普通预扣款
                 {

+ 1 - 0
Startup.cs

@@ -192,6 +192,7 @@ namespace MySystem
                 PrePosRingService.Instance.Start(); //预发未申请提醒
                 PrePosWithholdService.Instance.Start(); //预发机过期未申请提交到预扣款
                 PrePosWithholdService.Instance.StartPre(); //预发机申请成功,处理预扣款
+                PosWithholdService.Instance.Start(); //过期机具激活,清理预扣款
                 SycnMerchantTradeService.Instance.Start(); //同步商户交易额
 
                 MessageCenterService.Instance.Start(); // 消息队列