using System; using System.Collections.Generic; using System.Linq; using MySystem.SpModels; using Library; using LitJson; using System.Threading; namespace MySystem { public class SycnSpBindService { public readonly static SycnSpBindService Instance = new SycnSpBindService(); private SycnSpBindService() { } public bool SimDo(string content) { try { RadioCardItem Bind = Newtonsoft.Json.JsonConvert.DeserializeObject(content); WebCMSEntities spdb = new WebCMSEntities(); //{"activationStatusName":"已激活","activationTime":"04/27/2024 19:27:57","city":"滨州市","firstCharge":"否","iccId":"89861500152420011245","initialChargeAmount":0.00,"jobId":"VCH010203378","orderCreateTime":"04/27/2024 19:22:50","orderNo":"B20240427192249832266","orderStatus":"已完成","paidInAmount":100.00,"phoneNo":"19216292182","productName":"双百套餐","productTypeName":"基础套餐","province":"山东省"} //{"activationStatusName":"已激活","activationTime":"2024-07-08 17:33:05","city":"茂名市","initialChargeAmount":10000,"orderCreateTime":"2024-06-19 13:24:10","phoneNo":"19272097639","posSn":"CS00000000001607","productName":"升龙卡","promotionName":"升龙卡","province":"广东省"} string json = "{\"OrderNo\":\"" + Bind.orderNo + "\",\"CreateDate\":\"" + Bind.orderCreateTime + "\",\"PhoneNumber\":\"" + Bind.phoneNo + "\",\"HasFirstCharge\":\"" + Bind.firstCharge + "\",\"FirstChargeAmount\":\"0\",\"Province\":\"" + Bind.province + "\",\"City\":\"" + Bind.city + "\",\"ProductName\":\"" + Bind.productName + "\",\"ActiveName\":\"\",\"ProductType\":\"" + Bind.productTypeName + "\",\"ActualAmount\":\"" + Bind.initialChargeAmount + "\",\"OrderStatus\":\"" + Bind.orderStatus + "\",\"ActStatus\":\"" + Bind.activationStatusName + "\",\"ActDate\":\"" + Bind.activationTime + "\",\"WorkNo\":\"" + Bind.jobId + "\",\"AccountName\":\"\",\"SimNo\":\"" + Bind.iccId + "\",\"PosSn\":\"" + Bind.posSn + "\"}"; spdb.BindRecord.Add(new SpModels.BindRecord() { CreateDate = DateTime.Parse(Bind.activationTime), UpdateTime = DateTime.Parse(Bind.activationTime), //机具绑定、解绑时间 CreateTime = DateTime.Parse(Bind.activationTime), //商户操作时间 MerNewSnNo = Bind.phoneNo, //商户手机号 MerSnNo = Bind.posSn, //序列号 MerName = Bind.phoneNo, //商户名称 MerNo = Bind.phoneNo, //商户编号 Remark = Bind.productTypeName, AgentName = Bind.iccId, Field1 = Bind.province, // Field2 = sIMActInfo.ActiveName, Field3 = Bind.productName, Field4 = Bind.jobId, Field5 = Bind.activationStatusName, SeoTitle = Bind.initialChargeAmount.ToString("f2"), SeoKeyword = Bind.activationTime, SeoDescription = json, ProductType = "14", Status = 1, }); spdb.Merchants.Add(new SpModels.Merchants() { SnNo = Bind.posSn, CreateTime = DateTime.Parse(Bind.activationTime), UpdateTime = DateTime.Parse(Bind.activationTime), 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"; // } // 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; // } // // 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; // 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(); return true; } catch (Exception ex) { Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP绑定数据到MAIN异常"); return false; } } } }