DuGuYang hace 2 años
padre
commit
42dac0c475
Se han modificado 2 ficheros con 253 adiciones y 246 borrados
  1. 214 246
      AppStart/Helper/SIMPosMerchantTradeService.cs
  2. 39 0
      AppStart/Tables/SIMTradeInfo.cs

+ 214 - 246
AppStart/Helper/SIMPosMerchantTradeService.cs

@@ -69,82 +69,29 @@ namespace MySystem
                                     for (int i = DoCount; i < DoCount + Size; i++)
                                     {
                                         DataRow dr = list.Rows[i];
-                                        string OrderNo = dr["订单编码"].ToString();
-                                        string CreateDate = dr["订单创建时间"].ToString();
-                                        string PhoneNumber = dr["选择号码"].ToString();
-                                        string HasFirstCharge = dr["是否有首充"].ToString();
-                                        string FirstChargeAmount = dr["首充金额(元)"].ToString();
-                                        string Province = dr["号码归属省份"].ToString();
-                                        string City = dr["号码归属地市"].ToString();
-                                        string ProductName = dr["商品名称"].ToString();
-                                        string ActiveName = dr["促销活动名称"].ToString();
-                                        string ProductType = dr["商品类型名称"].ToString();
-                                        string ActualAmount = dr["实付金额(元)"].ToString();
-                                        string OrderStatus = dr["订单状态"].ToString();
-                                        string ActStatus = dr["激活状态名称"].ToString();
-                                        string ActDate = dr["激活时间"].ToString();
-                                        string WorkNo = dr["BOSS员工工号"].ToString();
-                                        string AccountName = dr["账号姓名"].ToString();
-                                        string SimNo = dr["SIM卡号"].ToString();
-
-                                        // PosMerchantInfo checkMer = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == PhoneNumber && m.Field5 == ActStatus);
-                                        // if (checkMer == null)
-                                        // {
-                                        string json = "{";
-                                        json += "\"OrderNo\":\"" + OrderNo + "\",";
-                                        json += "\"CreateDate\":\"" + CreateDate + "\",";
-                                        json += "\"PhoneNumber\":\"" + PhoneNumber + "\",";
-                                        json += "\"HasFirstCharge\":\"" + HasFirstCharge + "\",";
-                                        json += "\"FirstChargeAmount\":\"" + FirstChargeAmount + "\",";
-                                        json += "\"Province\":\"" + Province + "\",";
-                                        json += "\"City\":\"" + City + "\",";
-                                        json += "\"ProductName\":\"" + ProductName + "\",";
-                                        json += "\"ActiveName\":\"" + ActiveName + "\",";
-                                        json += "\"ProductType\":\"" + ProductType + "\",";
-                                        json += "\"ActualAmount\":\"" + ActualAmount + "\",";
-                                        json += "\"OrderStatus\":\"" + OrderStatus + "\",";
-                                        json += "\"ActStatus\":\"" + ActStatus + "\",";
-                                        json += "\"ActDate\":\"" + ActDate + "\",";
-                                        json += "\"WorkNo\":\"" + WorkNo + "\",";
-                                        json += "\"AccountName\":\"" + AccountName + "\",";
-                                        json += "\"SimNo\":\"" + SimNo + "\"";
-                                        json += "}";
-
-                                        spdb.BindRecord.Add(new SpModels.BindRecord()
+                                        SIMActInfo sIMActInfo = new SIMActInfo
                                         {
-                                            CreateDate = DateTime.Parse(CreateDate),
-                                            UpdateTime = DateTime.Parse(CreateDate), //机具绑定、解绑时间
-                                            CreateTime = DateTime.Parse(CreateDate), //商户操作时间
-                                            MerNewSnNo = PhoneNumber, //商户手机号
-                                            MerSnNo = SimNo, //序列号
-                                            MerName = AccountName, //商户名称
-                                            MerNo = PhoneNumber, //商户编号
-                                            Remark = ProductType,
-                                            Field1 = Province,
-                                            Field2 = ActiveName,
-                                            Field3 = ProductName,
-                                            Field4 = WorkNo,
-                                            Field5 = ActStatus,
-                                            SeoTitle = ActualAmount,
-                                            SeoKeyword = ActDate,
-                                            SeoDescription = json,
-                                            ProductType = "14",
-                                            Status = 1,
-                                        });
+                                            OrderNo = dr["订单编码"].ToString(),
+                                            CreateDate = dr["订单创建时间"].ToString(),
+                                            PhoneNumber = dr["选择号码"].ToString(),
+                                            HasFirstCharge = dr["是否有首充"].ToString(),
+                                            FirstChargeAmount = dr["首充金额(元)"].ToString(),
+                                            Province = dr["号码归属省份"].ToString(),
+                                            City = dr["号码归属地市"].ToString(),
+                                            ProductName = dr["商品名称"].ToString(),
+                                            ActiveName = dr["促销活动名称"].ToString(),
+                                            ProductType = dr["商品类型名称"].ToString(),
+                                            ActualAmount = dr["实付金额(元)"].ToString(),
+                                            OrderStatus = dr["订单状态"].ToString(),
+                                            ActStatus = dr["激活状态名称"].ToString(),
+                                            ActDate = dr["激活时间"].ToString(),
+                                            WorkNo = dr["BOSS员工工号"].ToString(),
+                                            AccountName = dr["账号姓名"].ToString(),
+                                            SimNo = dr["SIM卡号"].ToString()
+                                        };
+
+                                        AddSIMActInfo(sIMActInfo);
 
-                                        spdb.Merchants.Add(new SpModels.Merchants()
-                                        {
-                                            SnNo = SimNo,
-                                            CreateTime = DateTime.Parse(CreateDate),
-                                            UpdateTime = DateTime.Parse(CreateDate),
-                                            AgentName = AccountName,
-                                            MerRealName = AccountName,
-                                            MerMobile = PhoneNumber,
-                                            MerNo = PhoneNumber,
-                                            MerName = AccountName,
-                                            ProductType = "14",
-                                            Status = 1,
-                                        });
                                         SuccessCount += 1;
                                     }
                                     DoCount += Size;
@@ -185,165 +132,47 @@ namespace MySystem
                                     for (int i = DoCount; i < DoCount + Size; i++)
                                     {
                                         DataRow dr = list.Rows[i];
-                                        string Mobile = dr["用户手机号"].ToString();
-                                        string SimNo = dr["SIM卡号"].ToString();
-                                        string CreateMonth = dr["入网月份"].ToString();
-                                        string SettleMonth = dr["结算月份"].ToString();
-                                        string SettleTime = dr["结算账期"].ToString();
-                                        string SettleSpace = dr["结算场景"].ToString();
-                                        string BusinessType = dr["业务类型"].ToString();
-                                        string Province = dr["用户省份"].ToString();
-                                        string City = dr["用户地市"].ToString();
-                                        string Team = dr["团队归属"].ToString();
-                                        string WorkName = dr["行销宝姓名"].ToString();
-                                        string WorkNo = dr["行销宝工号"].ToString();
-                                        string ProductName = dr["商品名称"].ToString();
-                                        string TotalAmount = dr["账单总金额"].ToString();
-                                        string InAmount = dr["套内金额"].ToString();
-                                        string OutAmount = dr["套外金额"].ToString();
-                                        string UserStatus = dr["用户状态"].ToString();
-                                        string ChannelCode = dr["渠道编码"].ToString();
-                                        string ChannelName = dr["渠道名称"].ToString();
-                                        string OrderCreateTime = dr["订单创建时间"].ToString();
-                                        string OrderStatus = dr["订单状态"].ToString();
-                                        string ActTime = dr["激活时间"].ToString();
-                                        string SourceProductName = dr["原订单商品名称"].ToString();
-                                        string ProductType = dr["商品类型名称"].ToString();
-                                        string ActivityName = dr["促销活动名称"].ToString();
-                                        string Percent = dr["分成比例"].ToString();
-                                        string OrgDivi = dr["机构分成"].ToString();
-
-                                        string json = "{";
-                                        json += "\"Mobile\":\"" + Mobile + "\",";
-                                        json += "\"SimNo\":\"" + SimNo + "\",";
-                                        json += "\"CreateMonth\":\"" + CreateMonth + "\",";
-                                        json += "\"SettleMonth\":\"" + SettleMonth + "\",";
-                                        json += "\"SettleTime\":\"" + SettleTime + "\",";
-                                        json += "\"SettleSpace\":\"" + SettleSpace + "\",";
-                                        json += "\"BusinessType\":\"" + BusinessType + "\",";
-                                        json += "\"Province\":\"" + Province + "\",";
-                                        json += "\"City\":\"" + City + "\",";
-                                        json += "\"Team\":\"" + Team + "\",";
-                                        json += "\"WorkName\":\"" + WorkName + "\",";
-                                        json += "\"WorkNo\":\"" + WorkNo + "\",";
-                                        json += "\"ProductName\":\"" + ProductName + "\",";
-                                        json += "\"TotalAmount\":\"" + TotalAmount + "\",";
-                                        json += "\"InAmount\":\"" + InAmount + "\",";
-                                        json += "\"OutAmount\":\"" + OutAmount + "\",";
-                                        json += "\"UserStatus\":\"" + UserStatus + "\",";
-                                        json += "\"ChannelCode\":\"" + ChannelCode + "\",";
-                                        json += "\"ChannelName\":\"" + ChannelName + "\",";
-                                        json += "\"OrderCreateTime\":\"" + OrderCreateTime + "\",";
-                                        json += "\"OrderStatus\":\"" + OrderStatus + "\",";
-                                        json += "\"ActTime\":\"" + ActTime + "\",";
-                                        json += "\"SourceProductName\":\"" + SourceProductName + "\",";
-                                        json += "\"ProductType\":\"" + ProductType + "\",";
-                                        json += "\"ActivityName\":\"" + ActivityName + "\",";
-                                        json += "\"Percent\":\"" + Percent + "\",";
-                                        json += "\"OrgDivi\":\"" + OrgDivi + "\"";
-                                        json += "}";
-
-                                        bool op = true;
-                                        string OrderNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
-                                        decimal TotalAmountNum = decimal.Parse(function.CheckNum(numberString: TotalAmount));
-                                        DateTime CreateDate = DateTime.Parse(OrderCreateTime);
-                                        string CheckDate = DateTime.Now.AddMonths(-3).ToString("yyyyMM");
-                                        if (int.Parse(CreateMonth) >= int.Parse(CheckDate)) op = false;
-                                        if (OrderStatus == "待激活") op = false;
-                                        if (UserStatus.Contains("注销") || UserStatus.Contains("欠费"))
+                                        SIMTradeInfo sIMTradeInfo = new SIMTradeInfo
                                         {
-                                            op = false;
-                                            SimposMerchantInfo checkSimMer = db.SimposMerchantInfo.FirstOrDefault(m => m.KqMerNo == Mobile && m.KqSnNo == SimNo);
-                                            if (checkSimMer != null)
-                                            {
-                                                checkSimMer.Status = -1;
-                                                if (UserStatus.Contains("欠费") && checkSimMer.Status != -1)
-                                                {
-                                                    checkSimMer.Status = -2;
-                                                }
-                                                db.SaveChanges();
-                                            }
-                                            PosMerchantInfo checkMer = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == Mobile && m.KqSnNo == SimNo);
-                                            if (checkMer != null)
-                                            {
-                                                checkMer.Status = -1;
-                                                if (UserStatus.Contains("欠费") && checkMer.Status != -1)
-                                                {
-                                                    checkMer.Status = -2;
-                                                }
-                                                db.SaveChanges();
-                                            }
-                                            PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == SimNo);
-                                            if (pos != null)
-                                            {
-                                                pos.Status = -1;
-                                                if (UserStatus.Contains("欠费") && pos.Status != -1)
-                                                {
-                                                    pos.Status = -2;
-                                                }
-                                                db.SaveChanges();
-                                            }
-                                        }
-                                        if (UserStatus.Contains("正常"))
-                                        {
-                                            SimposMerchantInfo checkSimMer = db.SimposMerchantInfo.FirstOrDefault(m => m.KqMerNo == Mobile && m.KqSnNo == SimNo);
-                                            if (checkSimMer != null)
-                                            {
-                                                if (checkSimMer.Status == -2) checkSimMer.Status = 0;
-                                                db.SaveChanges();
-                                            }
-                                            PosMerchantInfo checkMer = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == Mobile && m.KqSnNo == SimNo);
-                                            if (checkMer != null)
-                                            {
-                                                if (checkMer.Status == -2) checkMer.Status = 1;
-                                                db.SaveChanges();
-                                            }
+                                            Mobile = dr["用户手机号"].ToString(),
+                                            SimNo = dr["SIM卡号"].ToString(),
+                                            CreateMonth = dr["入网月份"].ToString(),
+                                            SettleMonth = dr["结算月份"].ToString(),
+                                            SettleTime = dr["结算账期"].ToString(),
+                                            SettleSpace = dr["结算场景"].ToString(),
+                                            BusinessType = dr["业务类型"].ToString(),
+                                            Province = dr["用户省份"].ToString(),
+                                            City = dr["用户地市"].ToString(),
+                                            Team = dr["团队归属"].ToString(),
+                                            WorkName = dr["行销宝姓名"].ToString(),
+                                            WorkNo = dr["行销宝工号"].ToString(),
+                                            ProductName = dr["商品名称"].ToString(),
+                                            TotalAmount = dr["账单总金额"].ToString(),
+                                            InAmount = dr["套内金额"].ToString(),
+                                            OutAmount = dr["套外金额"].ToString(),
+                                            UserStatus = dr["用户状态"].ToString(),
+                                            ChannelCode = dr["渠道编码"].ToString(),
+                                            ChannelName = dr["渠道名称"].ToString(),
+                                            OrderCreateTime = dr["订单创建时间"].ToString(),
+                                            OrderStatus = dr["订单状态"].ToString(),
+                                            ActTime = dr["激活时间"].ToString(),
+                                            SourceProductName = dr["原订单商品名称"].ToString(),
+                                            ProductType = dr["商品类型名称"].ToString(),
+                                            ActivityName = dr["促销活动名称"].ToString(),
+                                            Percent = dr["分成比例"].ToString(),
+                                            OrgDivi = dr["机构分成"].ToString()
+                                        };
 
-                                            PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == SimNo);
-                                            if (pos != null && pos.Status < 0)
-                                            {
-                                                if (pos.Status == -2)
-                                                {
-                                                    pos.Status = 0;
-                                                }
-                                                db.SaveChanges();
-                                            }
-                                        }
+                                        AddSIMTradeInfo(sIMTradeInfo);
 
-                                        if (TotalAmountNum > 0 && op)
-                                        {
-                                            spdb.TradeRecord.Add(new SpModels.TradeRecord()
-                                            {
-                                                CreateDate = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM-20 HH:mm:ss")), //创建时间
-                                                TradeSerialNo = OrderNo, //订单编号
-                                                AgentNo = WorkName + WorkNo, //一级服务商编号
-                                                MerNo = Mobile, //商户编
-                                                TradeSnNo = SimNo, //sim卡号
-                                                ChannelSerial = OrderNo, //请求号
-                                                TradeAmount = TotalAmountNum, //账单总金额
-                                                TradeStatus = OrderStatus, //订单状态
-                                                TradeDate = CreateMonth,
-                                                TradeTime = CreateDate.ToString("yyyyMMdd"),
-                                                BankCardType = "01",
-                                                TradeType = "01",
-                                                ProductType = "14",
-                                                Status = 1,
-                                                Field1 = ProductName,
-                                                Field2 = SourceProductName,
-                                                Field3 = ProductType,
-                                                Field4 = BusinessType,
-                                                SeoDescription = json,
-                                            });
-
-                                            spdb.SaveChanges();
-                                        }
+                                        SuccessCount += 1;
                                     }
                                     DoCount += Size;
                                     db.SaveChanges();
                                     tran.Commit();
                                     if (DoCount >= list.Rows.Count)
                                     {
-                                        RedisDbconn.Instance.Set("SIMPosMerchantTradeCheckImport:" + checkKey, "success|");
+                                        RedisDbconn.Instance.Set("SIMPosMerchantTradeCheckImport:" + checkKey, "success|" + SuccessCount);
                                         RedisDbconn.Instance.SetExpire("SIMPosMerchantTradeCheckImport:" + checkKey, 60000);
                                     }
                                 }
@@ -398,6 +227,7 @@ namespace MySystem
                             if (jsonObj["resultCode"].ToString() == "1")
                             {
                                 SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
+                                var tran = spdb.Database.BeginTransaction();
                                 var data = jsonObj["data"]["records"];
                                 for (int i = 0; i < data.Count; i++)
                                 {
@@ -408,30 +238,32 @@ namespace MySystem
                                     {
                                         // {"orderNo":"B20240311214052744568","orderCreateTime":"03/11/2024 21:40:53","phoneNo":"19288438825","firstCharge":"否","initialChargeAmount":"0.00","province":"贵州省","city":"毕节市","productName":"双百套餐","promotionName":null,"productTypeName":"基础套餐","paidInAmount":"100.00","orderStatus":"已完成","activationStatusName":"已激活","activationTime":"03/11/2024 21:51:47","jobId":"VCH010198795","iccId":"89861500232320197354"}
 
-                                        SIMActInfo sIMActInfo = new SIMActInfo();
-
-                                        sIMActInfo.OrderNo = data["orderNo"].ToString(); //订单编码
-                                        sIMActInfo.CreateDate = data["orderCreateTime"].ToString(); //订单创建时间
-                                        sIMActInfo.PhoneNumber = data["phoneNo"].ToString(); //选择号码
-                                        sIMActInfo.HasFirstCharge = data["firstCharge"].ToString(); //是否有首充
-                                        sIMActInfo.FirstChargeAmount = data["initialChargeAmount"].ToString(); //首充金额(元)
-                                        sIMActInfo.Province = data["province"].ToString(); //号码归属省份
-                                        sIMActInfo.City = data["city"].ToString(); //号码归属地市
-                                        sIMActInfo.ProductName = data["productName"].ToString(); //商品名称
-                                        sIMActInfo.ActiveName = data["promotionName"].ToString(); //促销活动名称
-                                        sIMActInfo.ProductType = data["productTypeName"].ToString(); //商品类型名称
-                                        sIMActInfo.ActualAmount = data["paidInAmount"].ToString(); //实付金额(元)
-                                        sIMActInfo.OrderStatus = data["orderStatus"].ToString(); //订单状态
-                                        sIMActInfo.ActStatus = data["activationStatusName"].ToString(); //激活状态名称
-                                        sIMActInfo.ActDate = data["activationTime"].ToString(); //激活时间
-                                        sIMActInfo.WorkNo = data["jobId"].ToString(); //BOSS员工工号
-                                        // sIMActInfo.AccountName = data[""].ToString(); //账号姓名
-                                        sIMActInfo.AccountName = ""; //账号姓名
-                                        sIMActInfo.SimNo = iccId; //SIM卡号
+                                        SIMActInfo sIMActInfo = new SIMActInfo
+                                        {
+                                            OrderNo = data["orderNo"].ToString(), //订单编码
+                                            CreateDate = data["orderCreateTime"].ToString(), //订单创建时间
+                                            PhoneNumber = data["phoneNo"].ToString(), //选择号码
+                                            HasFirstCharge = data["firstCharge"].ToString(), //是否有首充
+                                            FirstChargeAmount = data["initialChargeAmount"].ToString(), //首充金额(元)
+                                            Province = data["province"].ToString(), //号码归属省份
+                                            City = data["city"].ToString(), //号码归属地市
+                                            ProductName = data["productName"].ToString(), //商品名称
+                                            ActiveName = data["promotionName"].ToString(), //促销活动名称
+                                            ProductType = data["productTypeName"].ToString(), //商品类型名称
+                                            ActualAmount = data["paidInAmount"].ToString(), //实付金额(元)
+                                            OrderStatus = data["orderStatus"].ToString(), //订单状态
+                                            ActStatus = data["activationStatusName"].ToString(), //激活状态名称
+                                            ActDate = data["activationTime"].ToString(), //激活时间
+                                            WorkNo = data["jobId"].ToString(), //BOSS员工工号
+                                                                               // sIMActInfo.AccountName = data[""].ToString(); //账号姓名
+                                            AccountName = "", //账号姓名
+                                            SimNo = iccId //SIM卡号
+                                        };
 
-                                        AddSIMSpInfo(sIMActInfo);
+                                        AddSIMActInfo(sIMActInfo);
                                     }
                                 }
+                                tran.Dispose();
                             }
                         }
                     }
@@ -448,7 +280,7 @@ namespace MySystem
         /// 添加广电卡激活数据
         /// </summary>
         /// <param name="sIMActInfo"></param>
-        public void AddSIMSpInfo(SIMActInfo sIMActInfo)
+        public void AddSIMActInfo(SIMActInfo sIMActInfo)
         {
             SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
 
@@ -511,5 +343,141 @@ namespace MySystem
             spdb.SaveChanges();
         }
 
+
+        /// <summary>
+        /// 添加广电卡激活数据
+        /// </summary>
+        /// <param name="sIMActInfo"></param>
+        public void AddSIMTradeInfo(SIMTradeInfo sIMTradeInfo)
+        {
+            WebCMSEntities db = new WebCMSEntities();
+            SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
+
+            string json = "{";
+            json += "\"Mobile\":\"" + sIMTradeInfo.Mobile + "\",";
+            json += "\"SimNo\":\"" + sIMTradeInfo.SimNo + "\",";
+            json += "\"CreateMonth\":\"" + sIMTradeInfo.CreateMonth + "\",";
+            json += "\"SettleMonth\":\"" + sIMTradeInfo.SettleMonth + "\",";
+            json += "\"SettleTime\":\"" + sIMTradeInfo.SettleTime + "\",";
+            json += "\"SettleSpace\":\"" + sIMTradeInfo.SettleSpace + "\",";
+            json += "\"BusinessType\":\"" + sIMTradeInfo.BusinessType + "\",";
+            json += "\"Province\":\"" + sIMTradeInfo.Province + "\",";
+            json += "\"City\":\"" + sIMTradeInfo.City + "\",";
+            json += "\"Team\":\"" + sIMTradeInfo.Team + "\",";
+            json += "\"WorkName\":\"" + sIMTradeInfo.WorkName + "\",";
+            json += "\"WorkNo\":\"" + sIMTradeInfo.WorkNo + "\",";
+            json += "\"ProductName\":\"" + sIMTradeInfo.ProductName + "\",";
+            json += "\"TotalAmount\":\"" + sIMTradeInfo.TotalAmount + "\",";
+            json += "\"InAmount\":\"" + sIMTradeInfo.InAmount + "\",";
+            json += "\"OutAmount\":\"" + sIMTradeInfo.OutAmount + "\",";
+            json += "\"UserStatus\":\"" + sIMTradeInfo.UserStatus + "\",";
+            json += "\"ChannelCode\":\"" + sIMTradeInfo.ChannelCode + "\",";
+            json += "\"ChannelName\":\"" + sIMTradeInfo.ChannelName + "\",";
+            json += "\"OrderCreateTime\":\"" + sIMTradeInfo.OrderCreateTime + "\",";
+            json += "\"OrderStatus\":\"" + sIMTradeInfo.OrderStatus + "\",";
+            json += "\"ActTime\":\"" + sIMTradeInfo.ActTime + "\",";
+            json += "\"SourceProductName\":\"" + sIMTradeInfo.SourceProductName + "\",";
+            json += "\"ProductType\":\"" + sIMTradeInfo.ProductType + "\",";
+            json += "\"ActivityName\":\"" + sIMTradeInfo.ActivityName + "\",";
+            json += "\"Percent\":\"" + sIMTradeInfo.Percent + "\",";
+            json += "\"OrgDivi\":\"" + sIMTradeInfo.OrgDivi + "\"";
+            json += "}";
+
+            bool op = true;
+            string OrderNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
+            decimal TotalAmountNum = decimal.Parse(function.CheckNum(numberString: sIMTradeInfo.TotalAmount));
+            DateTime CreateDate = DateTime.Parse(sIMTradeInfo.OrderCreateTime);
+            string CheckDate = DateTime.Now.AddMonths(-3).ToString("yyyyMM");
+            if (int.Parse(sIMTradeInfo.CreateMonth) >= int.Parse(CheckDate)) op = false;
+            if (sIMTradeInfo.OrderStatus == "待激活") op = false;
+            if (sIMTradeInfo.UserStatus.Contains("注销") || sIMTradeInfo.UserStatus.Contains("欠费"))
+            {
+                op = false;
+                SimposMerchantInfo checkSimMer = db.SimposMerchantInfo.FirstOrDefault(m => m.KqMerNo == sIMTradeInfo.Mobile && m.KqSnNo == sIMTradeInfo.SimNo);
+                if (checkSimMer != null)
+                {
+                    checkSimMer.Status = -1;
+                    if (sIMTradeInfo.UserStatus.Contains("欠费") && checkSimMer.Status != -1)
+                    {
+                        checkSimMer.Status = -2;
+                    }
+                    db.SaveChanges();
+                }
+                PosMerchantInfo checkMer = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == sIMTradeInfo.Mobile && m.KqSnNo == sIMTradeInfo.SimNo);
+                if (checkMer != null)
+                {
+                    checkMer.Status = -1;
+                    if (sIMTradeInfo.UserStatus.Contains("欠费") && checkMer.Status != -1)
+                    {
+                        checkMer.Status = -2;
+                    }
+                    db.SaveChanges();
+                }
+                PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == sIMTradeInfo.SimNo);
+                if (pos != null)
+                {
+                    pos.Status = -1;
+                    if (sIMTradeInfo.UserStatus.Contains("欠费") && pos.Status != -1)
+                    {
+                        pos.Status = -2;
+                    }
+                    db.SaveChanges();
+                }
+            }
+            if (sIMTradeInfo.UserStatus.Contains("正常"))
+            {
+                SimposMerchantInfo checkSimMer = db.SimposMerchantInfo.FirstOrDefault(m => m.KqMerNo == sIMTradeInfo.Mobile && m.KqSnNo == sIMTradeInfo.SimNo);
+                if (checkSimMer != null)
+                {
+                    if (checkSimMer.Status == -2) checkSimMer.Status = 0;
+                    db.SaveChanges();
+                }
+                PosMerchantInfo checkMer = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == sIMTradeInfo.Mobile && m.KqSnNo == sIMTradeInfo.SimNo);
+                if (checkMer != null)
+                {
+                    if (checkMer.Status == -2) checkMer.Status = 1;
+                    db.SaveChanges();
+                }
+
+                PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == sIMTradeInfo.SimNo);
+                if (pos != null && pos.Status < 0)
+                {
+                    if (pos.Status == -2)
+                    {
+                        pos.Status = 0;
+                    }
+                    db.SaveChanges();
+                }
+            }
+
+            if (TotalAmountNum > 0 && op)
+            {
+                spdb.TradeRecord.Add(new SpModels.TradeRecord()
+                {
+                    CreateDate = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM-20 HH:mm:ss")), //创建时间
+                    TradeSerialNo = OrderNo, //订单编号
+                    AgentNo = sIMTradeInfo.WorkName + sIMTradeInfo.WorkNo, //一级服务商编号
+                    MerNo = sIMTradeInfo.Mobile, //商户编
+                    TradeSnNo = sIMTradeInfo.SimNo, //sim卡号
+                    ChannelSerial = OrderNo, //请求号
+                    TradeAmount = TotalAmountNum, //账单总金额
+                    TradeStatus = sIMTradeInfo.OrderStatus, //订单状态
+                    TradeDate = sIMTradeInfo.CreateMonth,
+                    TradeTime = CreateDate.ToString("yyyyMMdd"),
+                    BankCardType = "01",
+                    TradeType = "01",
+                    ProductType = "14",
+                    Status = 1,
+                    Field1 = sIMTradeInfo.ProductName,
+                    Field2 = sIMTradeInfo.SourceProductName,
+                    Field3 = sIMTradeInfo.ProductType,
+                    Field4 = sIMTradeInfo.BusinessType,
+                    SeoDescription = json,
+                });
+
+                spdb.SaveChanges();
+            }
+        }
+
     }
 }

+ 39 - 0
AppStart/Tables/SIMTradeInfo.cs

@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+/// <summary>
+/// 广电卡交易实体
+/// </summary>
+namespace MySystem
+{
+    public class SIMTradeInfo
+    {
+        public string Mobile { get; set; } //用户手机号
+        public string SimNo { get; set; } //SIM卡号
+        public string CreateMonth { get; set; } //入网月份
+        public string SettleMonth { get; set; } //结算月份
+        public string SettleTime { get; set; } //结算账期
+        public string SettleSpace { get; set; } //结算场景
+        public string BusinessType { get; set; } //业务类型
+        public string Province { get; set; } //用户省份
+        public string City { get; set; } //用户地市
+        public string Team { get; set; } //团队归属
+        public string WorkName { get; set; } //行销宝姓名
+        public string WorkNo { get; set; } //行销宝工号
+        public string ProductName { get; set; } //商品名称
+        public string TotalAmount { get; set; } //账单总金额
+        public string InAmount { get; set; } //套内金额
+        public string OutAmount { get; set; } //套外金额
+        public string UserStatus { get; set; } //用户状态
+        public string ChannelCode { get; set; } //渠道编码
+        public string ChannelName { get; set; } //渠道名称
+        public string OrderCreateTime { get; set; } //订单创建时间
+        public string OrderStatus { get; set; } //订单状态
+        public string ActTime { get; set; } //激活时间
+        public string SourceProductName { get; set; } //原订单商品名称
+        public string ProductType { get; set; } //商品类型名称
+        public string ActivityName { get; set; } //促销活动名称
+        public string Percent { get; set; } //分成比例
+        public string OrgDivi { get; set; } //机构分成
+
+    }
+}