Browse Source

Merge branch 'feat-lcl-吱客宝' into release-mainserver

lcl 11 months ago
parent
commit
69f5c963eb

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

@@ -27,11 +27,14 @@ namespace MySystem
             {
             {
                 try
                 try
                 {
                 {
+                    List<string> BrandIds = new List<string>();
+                    BrandIds.Add("14");
+                    BrandIds.Add("17");
                     WebCMSEntities spdb = new WebCMSEntities();
                     WebCMSEntities spdb = new WebCMSEntities();
                     PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
                     PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
                     DateTime start = DateTime.Now.AddDays(-30);
                     DateTime start = DateTime.Now.AddDays(-30);
                     int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/BindRecordId.txt")));
                     int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/BindRecordId.txt")));
-                    var Binds = spdb.BindRecord.Select(m => new { m.Id, m.CreateTime, m.Status, m.MerNo, m.MerSnNo, m.ProductType, m.Remark, m.Field1, m.Field2, m.Field3, m.Field5, m.SeoTitle }).Where(m => m.Id >= StartId && m.CreateTime >= start && m.ProductType != "14" && m.Status == 1).OrderByDescending(m => m.Id).ToList();
+                    var Binds = spdb.BindRecord.Select(m => new { m.Id, m.CreateTime, m.Status, m.MerNo, m.MerSnNo, m.ProductType, m.Remark, m.Field1, m.Field2, m.Field3, m.Field5, m.SeoTitle }).Where(m => m.Id >= StartId && m.CreateTime >= start && !BrandIds.Contains(m.ProductType) && m.Status == 1).OrderByDescending(m => m.Id).ToList();
                     foreach (var Bind in Binds)
                     foreach (var Bind in Binds)
                     {
                     {
                         var tran = db.Database.BeginTransaction();
                         var tran = db.Database.BeginTransaction();

+ 145 - 0
AppStart/Helper/SycnSpServer/SycnSpBindZkbService.cs

@@ -0,0 +1,145 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using MySystem.SpModels;
+using Library;
+using LitJson;
+using System.Threading;
+
+namespace MySystem
+{
+    public class SycnSpBindZkbService
+    {
+        public readonly static SycnSpBindZkbService Instance = new SycnSpBindZkbService();
+        private SycnSpBindZkbService()
+        { }
+
+        public void Start()
+        {
+            Thread th = new Thread(StartDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartDo()
+        {
+            while (true)
+            {
+                try
+                {
+                    List<string> BrandIds = new List<string>();
+                    BrandIds.Add("17");
+                    WebCMSEntities spdb = new WebCMSEntities();
+                    PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
+                    DateTime start = DateTime.Now.AddDays(-30);
+                    int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/BindRecordId.txt")));
+                    var Binds = spdb.BindRecord.Where(m => m.Id >= StartId && m.CreateTime >= start && BrandIds.Contains(m.ProductType) && m.Status == 1).OrderByDescending(m => m.Id).ToList();
+                    foreach (var Bind in Binds)
+                    {
+                        var tran = db.Database.BeginTransaction();
+                        try
+                        {
+                            PxcModels.UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == Bind.Field3) ?? new PxcModels.UserForMakerCode();
+                            PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new PxcModels.Users();
+
+                            PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == Bind.MerSnNo);
+                            if (pos == null)
+                            {
+                                pos = db.PosMachinesTwo.Add(new PxcModels.PosMachinesTwo()
+                                {
+                                    CreateDate = DateTime.Now,
+                                    PosSn = Bind.MerSnNo, //SN编号
+                                    BrandId = 17, //产品类型
+                                    BatchNo = Bind.Field1,
+                                    DeviceName = "吱客宝",
+                                    BuyUserId = user.Id,
+                                    UserId = user.Id,
+                                    BindingState = 1,
+                                    BindingTime = Bind.CreateTime,
+                                    ActivationState = 1,
+                                    ActivationTime = Bind.CreateTime,
+                                }).Entity;
+                                db.SaveChanges();
+                            }
+
+                            PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqSnNo == Bind.MerSnNo);
+                            if (merchant == null)
+                            {
+                                merchant = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
+                                {
+                                    CreateDate = DateTime.Now,
+                                    MerStandardDate = DateTime.Now,
+                                    KqSnNo = Bind.MerSnNo, //SN编号
+                                    KqMerNo = Bind.MerNo, //商户号
+                                    MerchantNo = Bind.MerNo,
+                                    MerchantName = Bind.MerName,
+                                    MerRealName = Bind.MerName,
+                                    MerStatus = 1,
+                                    ActiveStatus = 1,
+                                    BrandId = 17, //产品类型
+                                    UserId = user.Id,
+                                    MerIdcardNo = Bind.SeoKeyword,
+                                    MerchantMobile = Bind.MerNewSnNo,
+                                }).Entity;
+                                db.SaveChanges();
+                            }
+                            pos.BindMerchantId = merchant.Id;
+
+                            PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.MerSnNo);
+                            if (posFor == null)
+                            {
+                                posFor = db.MachineForSnNo.Add(new PxcModels.MachineForSnNo()
+                                {
+                                    SnNo = Bind.MerSnNo,
+                                    SnId = pos.Id,
+                                }).Entity;
+                            }
+                            else
+                            {
+                                posFor.SnId = pos.Id;
+                            }
+                            PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo);
+                            if (merFor == null)
+                            {
+                                merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
+                                {
+                                    MerNo = Bind.MerNo,
+                                    SnId = pos.Id,
+                                }).Entity;
+                            }
+                            else
+                            {
+                                merFor.SnId = pos.Id;
+                            }
+                            db.SaveChanges();
+
+                            BindRecord edit = spdb.BindRecord.FirstOrDefault(m => m.Id == Bind.Id);
+                            if (edit != null)
+                            {
+                                edit.Status = 2;
+                                spdb.SaveChanges();
+                            }
+                            tran.Commit();
+                        }
+                        catch (Exception ex)
+                        {
+                            tran.Rollback();
+                            function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Bind.Id, "同步SP吱客宝绑定数据到MAIN异常");
+                        }
+                        tran.Dispose();
+                    }
+                    spdb.SaveChanges();
+                    spdb.Dispose();
+                    db.SaveChanges();
+                    db.Dispose();
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP绑定数据到MAIN异常");
+                }
+                Thread.Sleep(1000);
+            }
+        }
+    
+    }
+}

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

@@ -27,12 +27,15 @@ namespace MySystem
             {
             {
                 try
                 try
                 {
                 {
+                    List<string> BrandIds = new List<string>();
+                    BrandIds.Add("14");
+                    BrandIds.Add("17");
                     WebCMSEntities spdb = new WebCMSEntities();
                     WebCMSEntities spdb = new WebCMSEntities();
                     PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
                     PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
                     DateTime start = DateTime.Now.AddDays(-10);
                     DateTime start = DateTime.Now.AddDays(-10);
                     DateTime end = DateTime.Now.AddMinutes(-1);
                     DateTime end = DateTime.Now.AddMinutes(-1);
                     int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/TradeRecordId.txt")));
                     int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/TradeRecordId.txt")));
-                    IQueryable<TradeRecord> trades = spdb.TradeRecord.Where(m => m.Id >= StartId && m.ProductType != "14" && m.CreateDate >= start && m.Status == 1).OrderBy(m => m.CreateDate).Take(20);
+                    IQueryable<TradeRecord> trades = spdb.TradeRecord.Where(m => m.Id >= StartId && !BrandIds.Contains(m.ProductType) && m.CreateDate >= start && m.Status == 1).OrderBy(m => m.CreateDate).Take(20);
                     foreach (TradeRecord trade in trades.ToList())
                     foreach (TradeRecord trade in trades.ToList())
                     {
                     {
                         bool op = true;
                         bool op = true;

+ 142 - 0
AppStart/Helper/SycnSpServer/SycnSpTradeZkbService.cs

@@ -0,0 +1,142 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using MySystem.SpModels;
+using Library;
+using LitJson;
+using System.Threading;
+
+namespace MySystem
+{
+    public class SycnSpTradeZkbService
+    {
+        public readonly static SycnSpTradeZkbService Instance = new SycnSpTradeZkbService();
+        private SycnSpTradeZkbService()
+        { }
+
+        public void Start()
+        {
+            Thread th = new Thread(StartDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartDo()
+        {
+            while (true)
+            {
+                try
+                {
+                    List<string> BrandIds = new List<string>();
+                    BrandIds.Add("17");
+                    WebCMSEntities spdb = new WebCMSEntities();
+                    PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
+                    DateTime start = DateTime.Now.AddDays(-10);
+                    DateTime end = DateTime.Now.AddMinutes(-1);
+                    int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/TradeRecordId.txt")));
+                    IQueryable<TradeRecord> trades = spdb.TradeRecord.Where(m => m.Id >= StartId && BrandIds.Contains(m.ProductType) && m.CreateDate >= start && m.Status == 1).OrderBy(m => m.CreateDate).Take(20);
+                    foreach (TradeRecord trade in trades.ToList())
+                    {
+                        PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
+                        PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
+                        if (pos != null)
+                        {
+                            PxcModels.KqProducts brand = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new PxcModels.KqProducts();
+                            if (pos.BindMerchantId > 0)
+                            {
+                                PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
+                                int TopUserId = 0;
+                                if (!string.IsNullOrEmpty(user.ParentNav))
+                                {
+                                    TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
+                                }
+                                bool check = db.SpOrderNos.Any(m => m.OrderNo == trade.TradeSerialNo);
+                                if (!check)
+                                {
+                                    decimal TradeAmount = trade.TradeAmount / 100;
+                                    int BankCardType = 1;
+                                    int QrPayFlag = 0;
+                                    int VipFlag = 0;
+                                    int PayType = 0;
+                                    int BrandId = pos.BrandId;
+                                    int ActStatus = pos.ActivationState;
+                                    if (TradeAmount > 0)
+                                    {
+                                        PxcModels.TradeRecord add = db.TradeRecord.Add(new PxcModels.TradeRecord()
+                                        {
+                                            ParentNav = user.ParentNav,
+                                            CreateDate = trade.CreateDate,
+                                            UpdateDate = trade.UpdateDate,
+                                            RecordNo = trade.TradeSerialNo, //单号
+                                            UserId = pos.UserId, //创客
+                                            MerchantId = pos.BindMerchantId, //商户
+                                            MerNo = trade.MerNo, //渠道商户编号
+                                            MerHelpFlag = 0,
+                                            HelpMonthCount = 0, //扶持第几个月
+                                            MerBuddyType = user.MerchantType, //商户创客类型
+                                            SnNo = trade.TradeSnNo, //渠道SN号
+                                            TradeSerialNo = trade.ChannelSerial, //交易流水号
+                                            TradeAmount = TradeAmount, //交易金额
+                                            BankCardType = BankCardType, //银行卡类型
+                                            QrPayFlag = QrPayFlag, //云闪付标识
+                                            VipFlag = VipFlag, //会员标记
+                                            PayType = PayType, //支付方式
+                                            BrandId = BrandId, //品牌
+                                            Remark = trade.Remark, //备注
+                                            TopUserId = TopUserId, //顶级创客
+                                            MerUserId = pos.UserId, //商户直属创客M
+                                            ActStatus = ActStatus,
+                                            CreateMan = trade.AgentNo,
+                                            UpdateMan = trade.BankCardType,
+                                            SeoKeyword = trade.SerEntryMode,
+                                            SeoDescription = trade.TradeType,
+                                            TradeDate = pos.BindingTime,
+                                        }).Entity;
+                                        db.SaveChanges();
+                                    }
+                                    db.SpOrderNos.Add(new PxcModels.SpOrderNos()
+                                    {
+                                        OrderNo = trade.TradeSerialNo
+                                    });
+                                    db.SaveChanges();
+                                }
+                                TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
+                                if (edit != null)
+                                {
+                                    edit.Status = 2;
+                                }
+                                spdb.SaveChanges();
+                            }
+                            else
+                            {
+                                TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
+                                if (edit != null)
+                                {
+                                    edit.Status = 0;
+                                }
+                                spdb.SaveChanges();
+                            }
+                        }
+                        else
+                        {
+                            TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
+                            if (edit != null)
+                            {
+                                edit.Status = 0;
+                            }
+                            spdb.SaveChanges();
+                        }
+                    }
+                    spdb.Dispose();
+                    db.Dispose();
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP吱客宝交易数据到MAIN异常");
+                }
+                Thread.Sleep(500);
+            }
+        }
+
+    }
+}

+ 2 - 0
Startup.cs

@@ -169,10 +169,12 @@ namespace MySystem
             // if(Library.ConfigurationManager.EnvironmentFlag == 2)
             // if(Library.ConfigurationManager.EnvironmentFlag == 2)
             // {
             // {
                 SycnSpBindService.Instance.Start(); //同步SP绑定数据
                 SycnSpBindService.Instance.Start(); //同步SP绑定数据
+                SycnSpBindZkbService.Instance.Start(); //同步吱客宝SP绑定数据
                 SycnSpBindService.Instance.StartSim(); //同步SP广电卡绑定数据
                 SycnSpBindService.Instance.StartSim(); //同步SP广电卡绑定数据
                 SycnSpMerchantService.Instance.Start(); //同步SP商户数据
                 SycnSpMerchantService.Instance.Start(); //同步SP商户数据
                 SycnSpActiveService.Instance.Start(); //同步SP激活数据
                 SycnSpActiveService.Instance.Start(); //同步SP激活数据
                 SycnSpTradeService.Instance.Start(); //同步SP交易数据
                 SycnSpTradeService.Instance.Start(); //同步SP交易数据
+                SycnSpTradeZkbService.Instance.Start(); //同步吱客宝SP交易数据
                 SycnSpTradeService.Instance.StartSim(); //同步SP广电卡交易数据
                 SycnSpTradeService.Instance.StartSim(); //同步SP广电卡交易数据
                 SycnSpTradeService.Instance.StartTradeStatus(); //恢复原始交易没有统计上的数据
                 SycnSpTradeService.Instance.StartTradeStatus(); //恢复原始交易没有统计上的数据
                 SycnSpChangeBindService.Instance.Start(); //同步SP换绑数据
                 SycnSpChangeBindService.Instance.Start(); //同步SP换绑数据