فهرست منبع

调整广电卡奖励逻辑

lcl 2 سال پیش
والد
کامیت
58356e3e4e
4فایلهای تغییر یافته به همراه151 افزوده شده و 63 حذف شده
  1. 3 4
      AppStart/Helper/StatService.cs
  2. 126 54
      AppStart/Helper/SycnSpServer/SycnSpBindService.cs
  3. 21 5
      AppStart/Helper/SycnSpServer/SycnSpTradeService.cs
  4. 1 0
      Startup.cs

+ 3 - 4
AppStart/Helper/StatService.cs

@@ -143,7 +143,7 @@ namespace MySystem
                 try
                 {
                     function.WriteLog(DateTime.Now.ToString() + ":start", "实时处理广电卡激活奖励");
-                    
+                    StartSimActiveDo();
                     function.WriteLog(DateTime.Now.ToString() + ":end\n\n", "实时处理广电卡激活奖励");
                 }
                 catch (Exception ex)
@@ -158,7 +158,6 @@ namespace MySystem
         {
             WebCMSEntities db = new WebCMSEntities();
             DateTime yesterday = DateTime.Now.AddDays(-30);
-            DateTime today = DateTime.Now.AddMinutes(-10);
             IQueryable<PosMachinesTwo> posList = db.PosMachinesTwo.Where(m => m.ActivationState == 1 && m.BrandId == 14 && m.Detail != "1");
             if (posid > 0)
             {
@@ -166,7 +165,7 @@ namespace MySystem
             }
             else
             {
-                posList = posList.Where(m => m.ActivationTime >= yesterday && m.ActivationTime < today);
+                posList = posList.Where(m => m.ActivationTime >= yesterday);
             }
             foreach (PosMachinesTwo pos in posList.ToList())
             {
@@ -1133,7 +1132,7 @@ namespace MySystem
                         int PosId = int.Parse(content);
                         Thread.Sleep(1000);
                         WebCMSEntities db = new WebCMSEntities();
-                        PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == PosId && m.ActivationState == 1 && !string.IsNullOrEmpty(m.SeoKeyword) && m.SeoKeyword != "0" && (m.CreditTrade >= 1000 || m.BrandId == 14));
+                        PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == PosId && m.ActivationState == 1 && ((!string.IsNullOrEmpty(m.SeoKeyword) && m.SeoKeyword != "0" && m.CreditTrade >= 1000) || m.BrandId == 14));
                         if (pos != null)
                         {
                             function.WriteLog("sn:" + pos.PosSn, "开机奖励发放日志");

+ 126 - 54
AppStart/Helper/SycnSpServer/SycnSpBindService.cs

@@ -31,7 +31,7 @@ namespace MySystem
                     PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
                     DateTime start = DateTime.Now.AddDays(-5);
                     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.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 && m.ProductType != "14" && m.Status == 1).OrderByDescending(m => m.Id).ToList();
                     foreach (var Bind in Binds)
                     {
                         var tran = db.Database.BeginTransaction();
@@ -94,54 +94,6 @@ namespace MySystem
                                     pos.BindingTime = Bind.CreateTime;
                                     pos.Status = 0;
 
-                                    //广电卡逻辑
-                                    if(pos.BrandId == 14)
-                                    {
-                                        string KindName = Bind.Remark; //商品类型名称
-                                        string Name = Bind.Field3; //商品名称
-                                        decimal ActualAmount = decimal.Parse(function.CheckNum(Bind.SeoTitle)); //实付金额
-                                        string ActStatus = Bind.Field5; //激活状态名称
-                                        if (KindName == "基础套餐" && Name == "双百套餐" && ActStatus == "已激活" && ActualAmount >= 100)
-                                        {
-                                            // if (function.CheckNull(Bind.Field3).Contains("元"))
-                                            // {
-                                            //     string[] data = Bind.Field3.Split(new string[] { "元" }, StringSplitOptions.None);
-                                            //     string dataTmp = data[0];
-                                            //     string resultNum = "";
-                                            //     for (int i = dataTmp.Length - 1; i >= 0; i--)
-                                            //     {
-                                            //         string checkStr = dataTmp.Substring(i, 1);
-                                            //         if (function.IsInt(checkStr) || checkStr == ".")
-                                            //         {
-                                            //             resultNum = checkStr + resultNum;
-                                            //         }
-                                            //         else
-                                            //         {
-                                            //             break;
-                                            //         }
-                                            //     }
-                                            //     decimal Deposit = decimal.Parse(function.CheckNum(resultNum));
-                                            //     if (Deposit > 0)
-                                            //     {
-                                            //         pos.SeoKeyword = Deposit.ToString();
-                                            //     }
-                                            //     else
-                                            //     {
-                                            //         pos.Detail = "1";
-                                            //     }
-                                            // }
-                                            // else
-                                            // {
-                                            //     pos.Detail = "1";
-                                            // }
-                                            pos.Detail = "0";
-                                        }
-                                        else
-                                        {
-                                            pos.Detail = "1";
-                                        }
-                                    }
-
                                     PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo);
                                     if (merFor == null)
                                     {
@@ -178,11 +130,6 @@ namespace MySystem
                                     MachineData.UnBindCount -= 1;
                                     db.SaveChanges();
 
-                                    if(pos.BrandId == 14 && Bind.Field5 == "已激活")
-                                    {
-                                        SycnSpTradeService.Instance.ActPos(db, pos, 0, 30);
-                                    }
-
                                     if(pos.BuyUserId == 0 && pos.PreUserId > 0)
                                     {
                                         // RedisDbconn.Instance.Set("CheckUserBindPrePos:" + pos.PreUserId, "您的名下有已绑定的预发机 sn:" + pos.PosSn + " 尚未申请,绑定30分钟内申请即可免费自动补录,请前往客小爽产品中点击机具申请继续完成申请");
@@ -214,5 +161,130 @@ namespace MySystem
                 Thread.Sleep(1000);
             }
         }
+
+
+        public void StartSim()
+        {
+            Thread th = new Thread(StartSimDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartSimDo()
+        {
+            while (true)
+            {
+                try
+                {
+                    WebCMSEntities spdb = new WebCMSEntities();
+                    PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
+                    DateTime start = DateTime.Now.AddDays(-5);
+                    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();
+                    foreach (var Bind in Binds)
+                    {
+                        try
+                        {
+                            PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.MerSnNo) ?? new PxcModels.MachineForSnNo();
+                            PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
+                            if (pos != null)
+                            {
+                                pos.BindingState = 1;
+                                pos.BindingTime = Bind.CreateTime;
+                                pos.Status = 0;
+
+                                string KindName = Bind.Remark; //商品类型名称
+                                string Name = Bind.Field3; //商品名称
+                                decimal ActualAmount = decimal.Parse(function.CheckNum(Bind.SeoTitle)); //实付金额
+                                string ActStatus = Bind.Field5; //激活状态名称
+                                if (KindName == "基础套餐" && Name == "双百套餐" && ActStatus == "已激活" && ActualAmount >= 100)
+                                {
+                                    pos.Detail = "0";
+                                }
+                                else
+                                {
+                                    pos.Detail = "1";
+                                }
+
+                                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;
+                                }
+
+                                PxcModels.PosMerchantInfo add = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == Bind.MerNo);
+                                if (add == null)
+                                {
+                                    add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
+                                    {
+                                        CreateDate = Bind.CreateTime,
+                                        KqMerNo = Bind.MerNo,
+                                        MerchantNo = Bind.MerNo.Length > 16 ? Bind.MerNo.Substring(0, 16) : Bind.MerNo,
+                                    }).Entity;
+                                    db.SaveChanges();
+                                }
+                                pos.BindMerchantId = add.Id;
+                                pos.LastMerchantId = add.Id;
+                                pos.IsFirst = 1;
+                                pos.SeoKeyword = "0.01";
+                                db.SaveChanges();
+
+                                BindRecord edit = spdb.BindRecord.FirstOrDefault(m => m.Id == Bind.Id);
+                                if (edit != null)
+                                {
+                                    edit.Status = 2;
+                                    spdb.SaveChanges();
+                                }
+
+                                string IdBrand = pos.UserId + "_" + pos.BrandId;
+                                PxcModels.UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
+                                if (MachineData == null)
+                                {
+                                    MachineData = db.UserMachineData.Add(new PxcModels.UserMachineData()
+                                    {
+                                        IdBrand = IdBrand,
+                                    }).Entity;
+                                    db.SaveChanges();
+                                }
+                                MachineData.BindCount += 1;
+                                MachineData.UnBindCount -= 1;
+
+                                if(Bind.Field5 == "已激活")
+                                {
+                                    bool PrizeFlag = pos.Detail != "1";
+                                    if(pos.IsPurchase == 1)
+                                    {
+                                        PrizeFlag = false;
+                                    }
+                                    SycnSpTradeService.Instance.ActPos(db, pos, 0, 30, PrizeFlag);
+                                }
+                                db.SaveChanges();
+                            }
+                        }
+                        catch (Exception ex)
+                        {
+                            function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Bind.Id, "同步SP绑定数据到MAIN异常");
+                        }
+                    }
+                    spdb.SaveChanges();
+                    spdb.Dispose();
+                    db.SaveChanges();
+                    db.Dispose();
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP绑定数据到MAIN异常");
+                }
+                Thread.Sleep(1000);
+            }
+        }
     }
 }

+ 21 - 5
AppStart/Helper/SycnSpServer/SycnSpTradeService.cs

@@ -464,18 +464,25 @@ namespace MySystem
         }
 
         //机具激活逻辑
-        public void ActPos(PxcModels.WebCMSEntities db, PxcModels.PosMachinesTwo pos, decimal CheckMoney, int CheckDays)
+        public void ActPos(PxcModels.WebCMSEntities db, PxcModels.PosMachinesTwo pos, decimal CheckMoney, int CheckDays, bool PrizeFlag = true)
         {
             DateTime now = DateTime.Now;
             DateTime TransferTime = pos.TransferTime == null ? DateTime.Now : pos.TransferTime.Value;
-            if (pos.CreditTrade >= CheckMoney && pos.BuyUserId > 0 && pos.ActivationState == 0 && TransferTime.AddMinutes(-30) < pos.BindingTime)
+            int minute = 30;
+            if(pos.BrandId == 14)
+            {
+                minute = 0;
+            }
+            if (pos.CreditTrade >= CheckMoney && pos.BuyUserId > 0 && pos.ActivationState == 0 && TransferTime.AddMinutes(-minute) < pos.BindingTime)
             {
                 pos.ActivationState = 1;
                 pos.ActivationTime = DateTime.Now;
                 function.WriteLog("机具" + pos.PosSn, "开机奖励在激活中监控");
+                function.WriteLog("PrizeFlag:" + PrizeFlag, "开机奖励在激活中监控");
                 PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
                 if (merchant != null)
                 {
+                    function.WriteLog("查询到商户", "开机奖励在激活中监控");
                     merchant.ActiveStatus = 1;
                     merchant.MerStandardDate = DateTime.Now;
                     db.SaveChanges();
@@ -484,19 +491,28 @@ namespace MySystem
 
                     //发放开机奖励
                     function.WriteLog("首台" + pos.IsFirst, "开机奖励在激活中监控");
-                    if(pos.IsFirst == 1 && pos.BindingTime > DateTime.Now.AddDays(-CheckDays))
+                    if(pos.IsFirst == 1 && pos.BindingTime > DateTime.Now.AddDays(-CheckDays) && PrizeFlag)
                     {
+                        function.WriteLog("开机奖发放", "开机奖励在激活中监控");
                         RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
                     }
                 }
+                else if(pos.BrandId == 14 && pos.IsFirst == 1 && pos.BindingTime > DateTime.Now.AddDays(-CheckDays) && PrizeFlag)
+                {
+                    function.WriteLog("开机奖发放", "开机奖励在激活中监控");
+                    RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
+                }
                 //发放大盟主奖励
-                if (pos.LeaderUserId > 0 && pos.IsFirst == 1 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now) && pos.BindingTime > DateTime.Now.AddDays(-CheckDays))
+                function.WriteLog("大盟主---PrizeFlag:" + PrizeFlag + ";LeaderUserId:" + pos.LeaderUserId + ";pos.IsFirst:" + pos.IsFirst + ";pos.BindingTime:" + pos.BindingTime + ";DateTime.Now.AddDays(-CheckDays):" + DateTime.Now.AddDays(-CheckDays) + ";", "开机奖励在激活中监控");
+                if (pos.LeaderUserId > 0 && pos.IsFirst == 1 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now) && pos.BindingTime > DateTime.Now.AddDays(-CheckDays) && PrizeFlag)
                 {
+                    function.WriteLog("大盟主奖发放", "开机奖励在激活中监控");
                     RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
                 }
                 //发放运营中心奖励
-                if (pos.IsFirst == 1 && pos.BindingTime > DateTime.Now.AddDays(-CheckDays))
+                if (pos.IsFirst == 1 && pos.BindingTime > DateTime.Now.AddDays(-CheckDays) && PrizeFlag)
                 {
+                    function.WriteLog("运营中心奖发放", "开机奖励在激活中监控");
                     RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
                 }
                 AlipayPayBack2Service.Instance.ActReserveBack(pos.OpId, pos.OpReserve1, pos.OpReserve2, pos.OpReserve3);

+ 1 - 0
Startup.cs

@@ -167,6 +167,7 @@ namespace MySystem
             if(Library.ConfigurationManager.EnvironmentFlag == 2)
             {
                 SycnSpBindService.Instance.Start(); //同步SP绑定数据
+                SycnSpBindService.Instance.StartSim(); //同步SP广电卡绑定数据
                 SycnSpMerchantService.Instance.Start(); //同步SP商户数据
                 SycnSpActiveService.Instance.Start(); //同步SP激活数据
                 SycnSpTradeService.Instance.Start(); //同步SP交易数据