فهرست منبع

接收到消息直接加到sp数据库

lcl 1 سال پیش
والد
کامیت
fcc2f841c1
1فایلهای تغییر یافته به همراه180 افزوده شده و 144 حذف شده
  1. 180 144
      AppStart/Service/SycnSpBindService.cs

+ 180 - 144
AppStart/Service/SycnSpBindService.cs

@@ -20,159 +20,195 @@ namespace MySystem
             {
                 RadioCardItem Bind = Newtonsoft.Json.JsonConvert.DeserializeObject<RadioCardItem>(content);
                 WebCMSEntities spdb = new WebCMSEntities();
-                PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
-                DateTime start = DateTime.Now.AddDays(-60);
-                PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.iccId) ?? new PxcModels.MachineForSnNo();
-                PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
-                if (pos != null)
+
+                spdb.BindRecord.Add(new SpModels.BindRecord()
+                {
+                    CreateDate = DateTime.Parse(Bind.orderCreateTime),
+                    UpdateTime = DateTime.Parse(Bind.orderCreateTime), //机具绑定、解绑时间
+                    CreateTime = DateTime.Parse(Bind.orderCreateTime), //商户操作时间
+                    MerNewSnNo = Bind.phoneNo, //商户手机号
+                    MerSnNo = Bind.iccId, //序列号
+                    MerName = Bind.phoneNo, //商户名称
+                    MerNo = Bind.phoneNo, //商户编号
+                    Remark = Bind.productTypeName,
+                    Field1 = Bind.province,
+                    // Field2 = sIMActInfo.ActiveName,
+                    Field3 = Bind.productName,
+                    Field4 = Bind.jobId,
+                    Field5 = Bind.activationStatusName,
+                    SeoTitle = Bind.paidInAmount.ToString("f2"),
+                    SeoKeyword = Bind.activationStatusName,
+                    ProductType = "14",
+                    Status = 1,
+                });
+
+                spdb.Merchants.Add(new SpModels.Merchants()
                 {
-                    string KindName = Bind.productTypeName; //商品类型名称
-                    string Name = Bind.productName; //商品名称
-                    pos.BindingState = 1;
-                    pos.BindingTime = DateTime.Parse(Bind.orderCreateTime);
-                    pos.Status = 0;
-                    pos.IsFirst = 1;
-                    if(Name == "激活后补卡")
-                    {
-                        PxcModels.MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.phoneNo);
-                        if(forMerNo != null)
-                        {
-                            PxcModels.PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forMerNo.SnId);
-                            if(oldpos != null)
-                            {
-                                oldpos.IsFirst = 0;
-                                pos.BindingState = oldpos.BindingState;
-                                pos.BindingTime = oldpos.BindingTime;
-                                pos.ActivationState = oldpos.ActivationState;
-                                pos.ActivationTime = oldpos.ActivationTime;
-                            }
-                        }
-                    }
+                    SnNo = Bind.iccId,
+                    CreateTime = DateTime.Parse(Bind.orderCreateTime),
+                    UpdateTime = DateTime.Parse(Bind.orderCreateTime),
+                    AgentName = Bind.phoneNo,
+                    MerRealName = Bind.phoneNo,
+                    MerMobile = Bind.phoneNo,
+                    MerNo = Bind.phoneNo,
+                    MerName = Bind.phoneNo,
+                    ProductType = "14",
+                    Status = 1,
+                });
+
+                // PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
+                // DateTime start = DateTime.Now.AddDays(-60);
+                // PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.iccId) ?? new PxcModels.MachineForSnNo();
+                // PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
+                // if (pos != null)
+                // {
+                //     string KindName = Bind.productTypeName; //商品类型名称
+                //     string Name = Bind.productName; //商品名称
+                //     pos.BindingState = 1;
+                //     pos.BindingTime = DateTime.Parse(Bind.orderCreateTime);
+                //     pos.Status = 0;
+                //     pos.IsFirst = 1;
+                //     if(Name == "激活后补卡")
+                //     {
+                //         PxcModels.MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.phoneNo);
+                //         if(forMerNo != null)
+                //         {
+                //             PxcModels.PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forMerNo.SnId);
+                //             if(oldpos != null)
+                //             {
+                //                 oldpos.IsFirst = 0;
+                //                 pos.BindingState = oldpos.BindingState;
+                //                 pos.BindingTime = oldpos.BindingTime;
+                //                 pos.ActivationState = oldpos.ActivationState;
+                //                 pos.ActivationTime = oldpos.ActivationTime;
+                //             }
+                //         }
+                //     }
 
-                    decimal ActualAmount = Bind.paidInAmount; //实付金额
-                    string ActStatus = Bind.activationStatusName; //激活状态名称
-                    if (KindName == "基础套餐" && Name == "双百套餐" && ActStatus == "已激活" && ActualAmount >= 100)
-                    {
-                        pos.Detail = "0";
-                    }
-                    else
-                    {
-                        pos.Detail = "1";
-                    }
+                //     decimal ActualAmount = Bind.paidInAmount; //实付金额
+                //     string ActStatus = Bind.activationStatusName; //激活状态名称
+                //     if (KindName == "基础套餐" && Name == "双百套餐" && ActStatus == "已激活" && ActualAmount >= 100)
+                //     {
+                //         pos.Detail = "0";
+                //     }
+                //     else
+                //     {
+                //         pos.Detail = "1";
+                //     }
 
-                    PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.phoneNo);
-                    if (merFor == null)
-                    {
-                        merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
-                        {
-                            MerNo = Bind.phoneNo,
-                            SnId = pos.Id,
-                        }).Entity;
-                    }
-                    else
-                    {
-                        merFor.SnId = pos.Id;
-                    }
+                //     PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.phoneNo);
+                //     if (merFor == null)
+                //     {
+                //         merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
+                //         {
+                //             MerNo = Bind.phoneNo,
+                //             SnId = pos.Id,
+                //         }).Entity;
+                //     }
+                //     else
+                //     {
+                //         merFor.SnId = pos.Id;
+                //     }
 
-                    PxcModels.PosMerchantInfo add = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == Bind.phoneNo && m.KqSnNo == Bind.iccId);
-                    if (add == null)
-                    {
-                        add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
-                        {
-                            CreateDate = DateTime.Parse(Bind.orderCreateTime),
-                            KqMerNo = Bind.phoneNo,
-                            KqSnNo = Bind.iccId,
-                            MerchantNo = Bind.phoneNo.Length > 16 ? Bind.phoneNo.Substring(0, 16) : Bind.phoneNo,
-                        }).Entity;
-                        db.SaveChanges();
-                    }
-                    string json = Newtonsoft.Json.JsonConvert.SerializeObject(Bind);
-                    string ProductName = ""; //商品名称
-                    string ActivityName = ""; //促销活动名称
-                    string ProductTypeName = ""; //商品类型名称
-                    string ActStatusName = ""; //激活状态名称
-                    string ActAmount = ""; //实付金额
-                    string EmployeeNo = ""; //员工工号
-                    string EmployeeName = ""; //员工姓名
-                    if(!string.IsNullOrEmpty(json))
-                    {
-                        JsonData jsonObj = JsonMapper.ToObject(json);
-                        ProductName = jsonObj["productName"].ToString();
-                        ProductTypeName = jsonObj["productTypeName"].ToString();
-                        ActAmount = jsonObj["paidInAmount"].ToString();
-                        ActStatusName = jsonObj["activationStatusName"].ToString();
-                        EmployeeNo = jsonObj["jobId"].ToString();
-                    }
-                    PxcModels.SimposMerchantInfo sim = db.SimposMerchantInfo.FirstOrDefault(m => m.KqMerNo == Bind.phoneNo);
-                    if (sim == null)
-                    {                                    
-                        sim = db.SimposMerchantInfo.Add(new PxcModels.SimposMerchantInfo()
-                        {
-                            Id = add.Id,
-                            CreateDate = DateTime.Parse(Bind.orderCreateTime),
-                            KqMerNo = Bind.phoneNo,
-                            MerchantNo = Bind.phoneNo.Length > 16 ? Bind.phoneNo.Substring(0, 16) : Bind.phoneNo,
-                        }).Entity;
-                        db.SaveChanges();
-                    }
-                    sim.KqSnNo = Bind.iccId;
-                    sim.ProductName = ProductName;
-                    sim.ActivityName = ActivityName;
-                    sim.ProductTypeName = ProductTypeName;
-                    sim.ActStatusName = ActStatusName;
-                    sim.ActAmount = decimal.Parse(ActAmount);
-                    sim.EmployeeNo = EmployeeNo;
-                    sim.EmployeeName = EmployeeName;
-                    pos.BindMerchantId = add.Id;
-                    pos.LastMerchantId = add.Id;
-                    if(pos.CardType < 2)
-                    {
-                        pos.IsPurchase = 1;
-                    }
+                //     PxcModels.PosMerchantInfo add = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == Bind.phoneNo && m.KqSnNo == Bind.iccId);
+                //     if (add == null)
+                //     {
+                //         add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
+                //         {
+                //             CreateDate = DateTime.Parse(Bind.orderCreateTime),
+                //             KqMerNo = Bind.phoneNo,
+                //             KqSnNo = Bind.iccId,
+                //             MerchantNo = Bind.phoneNo.Length > 16 ? Bind.phoneNo.Substring(0, 16) : Bind.phoneNo,
+                //         }).Entity;
+                //         db.SaveChanges();
+                //     }
+                //     string json = Newtonsoft.Json.JsonConvert.SerializeObject(Bind);
+                //     string ProductName = ""; //商品名称
+                //     string ActivityName = ""; //促销活动名称
+                //     string ProductTypeName = ""; //商品类型名称
+                //     string ActStatusName = ""; //激活状态名称
+                //     string ActAmount = ""; //实付金额
+                //     string EmployeeNo = ""; //员工工号
+                //     string EmployeeName = ""; //员工姓名
+                //     if(!string.IsNullOrEmpty(json))
+                //     {
+                //         JsonData jsonObj = JsonMapper.ToObject(json);
+                //         ProductName = jsonObj["productName"].ToString();
+                //         ProductTypeName = jsonObj["productTypeName"].ToString();
+                //         ActAmount = jsonObj["paidInAmount"].ToString();
+                //         ActStatusName = jsonObj["activationStatusName"].ToString();
+                //         EmployeeNo = jsonObj["jobId"].ToString();
+                //     }
+                //     PxcModels.SimposMerchantInfo sim = db.SimposMerchantInfo.FirstOrDefault(m => m.KqMerNo == Bind.phoneNo);
+                //     if (sim == null)
+                //     {                                    
+                //         sim = db.SimposMerchantInfo.Add(new PxcModels.SimposMerchantInfo()
+                //         {
+                //             Id = add.Id,
+                //             CreateDate = DateTime.Parse(Bind.orderCreateTime),
+                //             KqMerNo = Bind.phoneNo,
+                //             MerchantNo = Bind.phoneNo.Length > 16 ? Bind.phoneNo.Substring(0, 16) : Bind.phoneNo,
+                //         }).Entity;
+                //         db.SaveChanges();
+                //     }
+                //     sim.KqSnNo = Bind.iccId;
+                //     sim.ProductName = ProductName;
+                //     sim.ActivityName = ActivityName;
+                //     sim.ProductTypeName = ProductTypeName;
+                //     sim.ActStatusName = ActStatusName;
+                //     sim.ActAmount = decimal.Parse(ActAmount);
+                //     sim.EmployeeNo = EmployeeNo;
+                //     sim.EmployeeName = EmployeeName;
+                //     pos.BindMerchantId = add.Id;
+                //     pos.LastMerchantId = add.Id;
+                //     if(pos.CardType < 2)
+                //     {
+                //         pos.IsPurchase = 1;
+                //     }
 
-                    // sim.UpdateDate = Bind.UpdateTime;
-                    sim.TopUserId = 1;
-                    sim.BrandId = pos.BrandId;
-                    sim.SnStoreId = pos.StoreId;
-                    if(ActStatus == "已激活")
-                    {
-                        sim.MerStandardDate = DateTime.Now;
-                        sim.ActiveStatus = 1;
-                    }
-                    sim.UserId = pos.UserId;
-                    // sim.MgrName = Bind.MerName;
-                    sim.MerStatus = 1;
-                    sim.KqSnNo = pos.PosSn;
-                    // sim.MerRealName = Bind.MerName;
-                    sim.MerchantMobile = Bind.phoneNo;
-                    sim.MerchantName = Bind.phoneNo;
-                    sim.Type = pos.CardType + 1;
-                    db.SaveChanges();
+                //     // sim.UpdateDate = Bind.UpdateTime;
+                //     sim.TopUserId = 1;
+                //     sim.BrandId = pos.BrandId;
+                //     sim.SnStoreId = pos.StoreId;
+                //     if(ActStatus == "已激活")
+                //     {
+                //         sim.MerStandardDate = DateTime.Now;
+                //         sim.ActiveStatus = 1;
+                //     }
+                //     sim.UserId = pos.UserId;
+                //     // sim.MgrName = Bind.MerName;
+                //     sim.MerStatus = 1;
+                //     sim.KqSnNo = pos.PosSn;
+                //     // sim.MerRealName = Bind.MerName;
+                //     sim.MerchantMobile = Bind.phoneNo;
+                //     sim.MerchantName = Bind.phoneNo;
+                //     sim.Type = pos.CardType + 1;
+                //     db.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;
+                //     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.activationStatusName == "已激活")
-                    {
-                        bool PrizeFlag = pos.CardType > 0;
-                        SycnSpTradeService.Instance.ActPos(db, pos, 0, 30, PrizeFlag, Bind.activationTime);
-                    }
-                    db.SaveChanges();
-                }
+                //     if(Bind.activationStatusName == "已激活")
+                //     {
+                //         bool PrizeFlag = pos.CardType > 0;
+                //         SycnSpTradeService.Instance.ActPos(db, pos, 0, 30, PrizeFlag, Bind.activationTime);
+                //     }
+                //     db.SaveChanges();
+                // }
                 spdb.SaveChanges();
                 spdb.Dispose();
-                db.SaveChanges();
-                db.Dispose();
+                // db.SaveChanges();
+                // db.Dispose();
                 return true;
             }
             catch (Exception ex)