Kaynağa Gözat

wifi解绑逻辑

lcl 11 ay önce
ebeveyn
işleme
72e768f942

BIN
.DS_Store


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

@@ -273,6 +273,10 @@ namespace MySystem
                                 }
                                 tran.Commit();
                             }
+                            else if (Mer.Field2 == "解绑" && Mer.ProductType == "23")
+                            {
+                                RedisDbconn.Instance.AddList("WifiUnBindQueue", Mer.SnNo);
+                            }
                             else
                             {
                                 Merchants edit = spdb.Merchants.FirstOrDefault(m => m.Id == Mer.Id);

+ 79 - 0
AppStart/WifiUnBindHelper.cs

@@ -0,0 +1,79 @@
+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 WifiUnBindHelper
+{
+    public readonly static WifiUnBindHelper Instance = new WifiUnBindHelper();
+    private WifiUnBindHelper()
+    {
+    }
+
+    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>("WifiUnBindQueue");
+                if(!string.IsNullOrEmpty(content))
+                {
+                    WebCMSEntities db = new WebCMSEntities();
+                    DoSomething(db, content);
+                    db.Dispose();
+                }
+                else
+                {
+                    Thread.Sleep(60000);
+                }
+            }
+            catch (Exception ex)
+            {
+                function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "WIFI解绑异常");
+            }
+            function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "WIFI解绑日志");
+        }
+    }
+
+    public void DoSomething(WebCMSEntities db, string SnNo)
+    {
+        PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == SnNo) ?? new PosMachinesTwo();
+        PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
+        if(merchant != null)
+        {
+            //备份解绑的商户信息
+            CustomerSqlConn.op("insert into PosMerchantInfoBak select * from PosMerchantInfo where Id=" + pos.BindMerchantId, MysqlConn.SqlConnStr);
+            MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
+            if (forMerNo != null)
+            {
+                db.MachineForMerNo.Remove(forMerNo);
+            }
+            pos.BindMerchantId = 0;
+            pos.BindingState = 0;
+            pos.BindingTime = null;
+            db.PosMerchantInfo.Remove(merchant);
+            db.SaveChanges();
+        }
+
+        string TradeDate = DateTime.Now.ToString("yyyyMMdd");
+        WifiTradeRecord trade = db.WifiTradeRecord.FirstOrDefault(m => m.SnNo == SnNo);
+        if(trade != null)
+        {
+            
+            db.SaveChanges();
+        }
+    }
+}