SycnSpBindService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.SpModels;
  5. using Library;
  6. using LitJson;
  7. using System.Threading;
  8. namespace MySystem
  9. {
  10. public class SycnSpBindService
  11. {
  12. public readonly static SycnSpBindService Instance = new SycnSpBindService();
  13. private SycnSpBindService()
  14. { }
  15. public bool SimDo(string content)
  16. {
  17. try
  18. {
  19. RadioCardItem Bind = Newtonsoft.Json.JsonConvert.DeserializeObject<RadioCardItem>(content);
  20. WebCMSEntities spdb = new WebCMSEntities();
  21. //{"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":"山东省"}
  22. 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.paidInAmount + "\",\"OrderStatus\":\"" + Bind.orderStatus + "\",\"ActStatus\":\"" + Bind.activationStatusName + "\",\"ActDate\":\"" + Bind.activationTime + "\",\"WorkNo\":\"" + Bind.jobId + "\",\"AccountName\":\"\",\"SimNo\":\"" + Bind.iccId + "\",\"PosSn\":\"" + Bind.posSn + "\"}";
  23. spdb.BindRecord.Add(new SpModels.BindRecord()
  24. {
  25. CreateDate = DateTime.Parse(Bind.orderCreateTime),
  26. UpdateTime = DateTime.Parse(Bind.orderCreateTime), //机具绑定、解绑时间
  27. CreateTime = DateTime.Parse(Bind.orderCreateTime), //商户操作时间
  28. MerNewSnNo = Bind.phoneNo, //商户手机号
  29. MerSnNo = Bind.posSn, //序列号
  30. MerName = Bind.phoneNo, //商户名称
  31. MerNo = Bind.phoneNo, //商户编号
  32. Remark = Bind.productTypeName,
  33. AgentName = Bind.iccId,
  34. Field1 = Bind.province,
  35. // Field2 = sIMActInfo.ActiveName,
  36. Field3 = Bind.productName,
  37. Field4 = Bind.jobId,
  38. Field5 = Bind.activationStatusName,
  39. SeoTitle = Bind.paidInAmount.ToString("f2"),
  40. SeoKeyword = Bind.activationTime,
  41. SeoDescription = json,
  42. ProductType = "14",
  43. Status = 1,
  44. });
  45. spdb.Merchants.Add(new SpModels.Merchants()
  46. {
  47. SnNo = Bind.posSn,
  48. CreateTime = DateTime.Parse(Bind.orderCreateTime),
  49. UpdateTime = DateTime.Parse(Bind.orderCreateTime),
  50. AgentName = Bind.phoneNo,
  51. MerRealName = Bind.phoneNo,
  52. MerMobile = Bind.phoneNo,
  53. MerNo = Bind.phoneNo,
  54. MerName = Bind.phoneNo,
  55. ProductType = "14",
  56. Status = 1,
  57. });
  58. // PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  59. // DateTime start = DateTime.Now.AddDays(-60);
  60. // PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.iccId) ?? new PxcModels.MachineForSnNo();
  61. // PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  62. // if (pos != null)
  63. // {
  64. // string KindName = Bind.productTypeName; //商品类型名称
  65. // string Name = Bind.productName; //商品名称
  66. // pos.BindingState = 1;
  67. // pos.BindingTime = DateTime.Parse(Bind.orderCreateTime);
  68. // pos.Status = 0;
  69. // pos.IsFirst = 1;
  70. // if(Name == "激活后补卡")
  71. // {
  72. // PxcModels.MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.phoneNo);
  73. // if(forMerNo != null)
  74. // {
  75. // PxcModels.PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forMerNo.SnId);
  76. // if(oldpos != null)
  77. // {
  78. // oldpos.IsFirst = 0;
  79. // pos.BindingState = oldpos.BindingState;
  80. // pos.BindingTime = oldpos.BindingTime;
  81. // pos.ActivationState = oldpos.ActivationState;
  82. // pos.ActivationTime = oldpos.ActivationTime;
  83. // }
  84. // }
  85. // }
  86. // decimal ActualAmount = Bind.paidInAmount; //实付金额
  87. // string ActStatus = Bind.activationStatusName; //激活状态名称
  88. // if (KindName == "基础套餐" && Name == "双百套餐" && ActStatus == "已激活" && ActualAmount >= 100)
  89. // {
  90. // pos.Detail = "0";
  91. // }
  92. // else
  93. // {
  94. // pos.Detail = "1";
  95. // }
  96. // PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.phoneNo);
  97. // if (merFor == null)
  98. // {
  99. // merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
  100. // {
  101. // MerNo = Bind.phoneNo,
  102. // SnId = pos.Id,
  103. // }).Entity;
  104. // }
  105. // else
  106. // {
  107. // merFor.SnId = pos.Id;
  108. // }
  109. // PxcModels.PosMerchantInfo add = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == Bind.phoneNo && m.KqSnNo == Bind.iccId);
  110. // if (add == null)
  111. // {
  112. // add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
  113. // {
  114. // CreateDate = DateTime.Parse(Bind.orderCreateTime),
  115. // KqMerNo = Bind.phoneNo,
  116. // KqSnNo = Bind.iccId,
  117. // MerchantNo = Bind.phoneNo.Length > 16 ? Bind.phoneNo.Substring(0, 16) : Bind.phoneNo,
  118. // }).Entity;
  119. // db.SaveChanges();
  120. // }
  121. // string json = Newtonsoft.Json.JsonConvert.SerializeObject(Bind);
  122. // string ProductName = ""; //商品名称
  123. // string ActivityName = ""; //促销活动名称
  124. // string ProductTypeName = ""; //商品类型名称
  125. // string ActStatusName = ""; //激活状态名称
  126. // string ActAmount = ""; //实付金额
  127. // string EmployeeNo = ""; //员工工号
  128. // string EmployeeName = ""; //员工姓名
  129. // if(!string.IsNullOrEmpty(json))
  130. // {
  131. // JsonData jsonObj = JsonMapper.ToObject(json);
  132. // ProductName = jsonObj["productName"].ToString();
  133. // ProductTypeName = jsonObj["productTypeName"].ToString();
  134. // ActAmount = jsonObj["paidInAmount"].ToString();
  135. // ActStatusName = jsonObj["activationStatusName"].ToString();
  136. // EmployeeNo = jsonObj["jobId"].ToString();
  137. // }
  138. // PxcModels.SimposMerchantInfo sim = db.SimposMerchantInfo.FirstOrDefault(m => m.KqMerNo == Bind.phoneNo);
  139. // if (sim == null)
  140. // {
  141. // sim = db.SimposMerchantInfo.Add(new PxcModels.SimposMerchantInfo()
  142. // {
  143. // Id = add.Id,
  144. // CreateDate = DateTime.Parse(Bind.orderCreateTime),
  145. // KqMerNo = Bind.phoneNo,
  146. // MerchantNo = Bind.phoneNo.Length > 16 ? Bind.phoneNo.Substring(0, 16) : Bind.phoneNo,
  147. // }).Entity;
  148. // db.SaveChanges();
  149. // }
  150. // sim.KqSnNo = Bind.iccId;
  151. // sim.ProductName = ProductName;
  152. // sim.ActivityName = ActivityName;
  153. // sim.ProductTypeName = ProductTypeName;
  154. // sim.ActStatusName = ActStatusName;
  155. // sim.ActAmount = decimal.Parse(ActAmount);
  156. // sim.EmployeeNo = EmployeeNo;
  157. // sim.EmployeeName = EmployeeName;
  158. // pos.BindMerchantId = add.Id;
  159. // pos.LastMerchantId = add.Id;
  160. // if(pos.CardType < 2)
  161. // {
  162. // pos.IsPurchase = 1;
  163. // }
  164. // // sim.UpdateDate = Bind.UpdateTime;
  165. // sim.TopUserId = 1;
  166. // sim.BrandId = pos.BrandId;
  167. // sim.SnStoreId = pos.StoreId;
  168. // if(ActStatus == "已激活")
  169. // {
  170. // sim.MerStandardDate = DateTime.Now;
  171. // sim.ActiveStatus = 1;
  172. // }
  173. // sim.UserId = pos.UserId;
  174. // // sim.MgrName = Bind.MerName;
  175. // sim.MerStatus = 1;
  176. // sim.KqSnNo = pos.PosSn;
  177. // // sim.MerRealName = Bind.MerName;
  178. // sim.MerchantMobile = Bind.phoneNo;
  179. // sim.MerchantName = Bind.phoneNo;
  180. // sim.Type = pos.CardType + 1;
  181. // db.SaveChanges();
  182. // string IdBrand = pos.UserId + "_" + pos.BrandId;
  183. // PxcModels.UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  184. // if (MachineData == null)
  185. // {
  186. // MachineData = db.UserMachineData.Add(new PxcModels.UserMachineData()
  187. // {
  188. // IdBrand = IdBrand,
  189. // }).Entity;
  190. // db.SaveChanges();
  191. // }
  192. // MachineData.BindCount += 1;
  193. // MachineData.UnBindCount -= 1;
  194. // if(Bind.activationStatusName == "已激活")
  195. // {
  196. // bool PrizeFlag = pos.CardType > 0;
  197. // SycnSpTradeService.Instance.ActPos(db, pos, 0, 30, PrizeFlag, Bind.activationTime);
  198. // }
  199. // db.SaveChanges();
  200. // }
  201. spdb.SaveChanges();
  202. spdb.Dispose();
  203. // db.SaveChanges();
  204. // db.Dispose();
  205. return true;
  206. }
  207. catch (Exception ex)
  208. {
  209. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP绑定数据到MAIN异常");
  210. return false;
  211. }
  212. }
  213. }
  214. }