فهرست منبع

wifi设备激活后预扣款处理

lcl 1 سال پیش
والد
کامیت
9e3f976784

BIN
.DS_Store


BIN
AppStart/.DS_Store


+ 4 - 1
AppStart/Helper/SycnSpServer/SycnSpMerchantService.cs

@@ -205,7 +205,7 @@ namespace MySystem
                                 }
 
                                 //WIFI设备默认设置押金
-                                if(pos.BrandId >= 23 && pos.BrandId <= 26 && pos.ActivationState == 0)
+                                if(Utils.Instance.IsWifi(pos.BrandId) && pos.ActivationState == 0)
                                 {
                                     if(Mer.Field1 != "v2")
                                     {
@@ -248,6 +248,9 @@ namespace MySystem
 
                                     //推送激活数据给MQ
                                     Utils.Instance.SendActData(pos);
+
+                                    //wifi预扣款处理
+                                    RedisDbconn.Instance.AddList("WifiWithholdBackQueue", "{\"UserId\":\"" + pos.BuyUserId + "\",\"SnNo\":\"" + pos.PosSn + "\"}");
                                 }
 
                                 //推送数据给java

+ 8 - 8
AppStart/Helper/WifiWarningService.cs

@@ -28,15 +28,15 @@ namespace MySystem
             {
                 try
                 {
-                    if(DateTime.Now.Hour > 2 && DateTime.Now.Hour < 4 && DateTime.Now >= DateTime.Parse("2024-10-30 00:00:00"))
-                    {
-                        string chk = function.ReadInstance("/WifiWithhold/" + DateTime.Now.ToString("yyyyMMdd") + ".txt");
-                        if(string.IsNullOrEmpty(chk))
-                        {
-                            function.WritePage("/WifiWithhold/", "" + DateTime.Now.ToString("yyyyMMdd") + ".txt", DateTime.Now.ToString());
+                    // if(DateTime.Now.Hour > 2 && DateTime.Now.Hour < 4 && DateTime.Now >= DateTime.Parse("2024-10-30 00:00:00"))
+                    // {
+                    //     string chk = function.ReadInstance("/WifiWithhold/" + DateTime.Now.ToString("yyyyMMdd") + ".txt");
+                    //     if(string.IsNullOrEmpty(chk))
+                    //     {
+                    //         function.WritePage("/WifiWithhold/", "" + DateTime.Now.ToString("yyyyMMdd") + ".txt", DateTime.Now.ToString());
                             WifiWithhold();
-                        }
-                    }
+                    //     }
+                    // }
                 }
                 catch (Exception ex)
                 {

+ 84 - 0
AppStart/Helper/WifiWithholdBackService.cs

@@ -0,0 +1,84 @@
+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 WifiWithholdBackService
+    {
+        public readonly static WifiWithholdBackService Instance = new WifiWithholdBackService();
+        private WifiWithholdBackService()
+        { }
+
+
+        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>("WifiWithholdBackQueue");
+                    if(!string.IsNullOrEmpty(content))
+                    {
+                        function.WriteLog("content:" + content, "Wifi预扣款激活处理");
+                        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.Remark == "WIFI超时未激活扣款" && m.LockFlag == 0);
+                        if(back != null)
+                        {
+                            back.LockFlag = 1;
+                            db.SaveChanges();
+                            function.WriteLog("预扣款数据:" + Newtonsoft.Json.JsonConvert.SerializeObject(back), "Wifi预扣款激活处理");
+                            ChargeAmount = back.ChargeAmount;
+                            function.WriteLog("预扣款是否已扣:" + back.Status, "Wifi预扣款激活处理");
+                            if(back.Status == 1)
+                            {
+                                Utils.Instance.OpAccount(back.UserId, ChargeAmount, 134, false);
+                                doBack = false;
+                            }
+                            db.ToChargeBackRecord.Remove(back);
+                            back.LockFlag = 0;
+                            db.SaveChanges();
+                        }
+                        db.Dispose();
+
+                        //减少账户预扣总额
+                        function.WriteLog("是否减少账户预扣总额:" + doBack, "Wifi预扣款激活处理");
+                        if(doBack)
+                        {
+                            Utils.Instance.ToChargeAmount(UserId, -ChargeAmount);
+                            function.WriteLog("减少账户预扣总额:" + ChargeAmount, "Wifi预扣款激活处理");
+                        }
+
+                        Thread.Sleep(500);
+                    }
+                    else
+                    {
+                        Thread.Sleep(30000);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "Wifi预扣款激活处理异常");
+                    Thread.Sleep(300000);
+                }
+            }
+        }
+    }
+}

+ 8 - 8
AppStart/Helper/WifiWithholdService.cs

@@ -28,15 +28,15 @@ namespace MySystem
             {
                 try
                 {
-                    if(DateTime.Now.Hour > 3 && DateTime.Now.Hour < 5 && DateTime.Now >= DateTime.Parse("2024-10-30 00:00:00"))
-                    {
-                        string chk = function.ReadInstance("/WifiWithhold/" + DateTime.Now.ToString("yyyyMMdd") + ".txt");
-                        if(string.IsNullOrEmpty(chk))
-                        {
-                            function.WritePage("/WifiWithhold/", "" + DateTime.Now.ToString("yyyyMMdd") + ".txt", DateTime.Now.ToString());
+                    // if(DateTime.Now.Hour > 3 && DateTime.Now.Hour < 5 && DateTime.Now >= DateTime.Parse("2024-10-30 00:00:00"))
+                    // {
+                    //     string chk = function.ReadInstance("/WifiWithhold/" + DateTime.Now.ToString("yyyyMMdd") + ".txt");
+                    //     if(string.IsNullOrEmpty(chk))
+                    //     {
+                    //         function.WritePage("/WifiWithhold/", "" + DateTime.Now.ToString("yyyyMMdd") + ".txt", DateTime.Now.ToString());
                             WifiWithhold();
-                        }
-                    }
+                    //     }
+                    // }
                 }
                 catch (Exception ex)
                 {

+ 1 - 0
Startup.cs

@@ -205,6 +205,7 @@ namespace MySystem
                 SycnMerchantTradeService.Instance.Start(); //同步商户交易额
                 WifiWarningService.Instance.Start(); //wifi设备过期提醒
                 WifiWithholdService.Instance.Start(); //wifi设备过期预扣款
+                WifiWithholdBackService.Instance.Start(); //wifi设备激活后预扣款处理
 
                 MessageCenterService.Instance.Start(); // 消息队列
                 LeaderTimeoutSendMessageService.Instance.Start(); //盟主过期消息提醒