SycnSpBindService.cs 12 KB

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