SycnSpBindService.cs 11 KB

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