SetDepositService.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using System.Threading;
  8. using MySystem.PxcModels;
  9. using System.Security.Cryptography;
  10. using System.Text;
  11. namespace MySystem
  12. {
  13. public class SetDepositService
  14. {
  15. public readonly static SetDepositService Instance = new SetDepositService();
  16. private SetDepositService()
  17. { }
  18. public void Start()
  19. {
  20. Thread th = new Thread(dosomething);
  21. th.IsBackground = true;
  22. th.Start();
  23. }
  24. public void dosomething()
  25. {
  26. while (true)
  27. {
  28. string data = RedisDbconn.Instance.RPop<string>("SetDepositQueue");
  29. if (!string.IsNullOrEmpty(data))
  30. {
  31. try
  32. {
  33. WebCMSEntities db = new WebCMSEntities();
  34. JsonData jsonObj = JsonMapper.ToObject(data);
  35. string PosIds = jsonObj["PosId"].ToString();
  36. int Kind = int.Parse(function.CheckInt(jsonObj["Kind"].ToString()));
  37. int RecordId = 0;
  38. if(data.Contains("\"RecordId\""))
  39. {
  40. RecordId = int.Parse(function.CheckInt(jsonObj["RecordId"].ToString()));
  41. }
  42. string OpMan = jsonObj["OpMan"].ToString();
  43. if(!string.IsNullOrEmpty(PosIds))
  44. {
  45. List<int> ids = new List<int>();
  46. string[] PosIdList = PosIds.Split(',');
  47. foreach(string sub in PosIdList)
  48. {
  49. ids.Add(int.Parse(sub));
  50. }
  51. List<KqProducts> brands = db.KqProducts.ToList();
  52. List<PosMachinesTwo> poslist = db.PosMachinesTwo.Where(m => ids.Contains(m.Id)).ToList();
  53. List<int> mids = poslist.Select(m => m.BindMerchantId).ToList();
  54. List<PosMerchantInfo> merchantlist = db.PosMerchantInfo.Where(m => mids.Contains(m.Id)).ToList();
  55. Dictionary<int, List<PosMachinesTwo>> userPosList = new Dictionary<int, List<PosMachinesTwo>>();
  56. Dictionary<int, List<PosMachinesTwo>> hintPosList = new Dictionary<int, List<PosMachinesTwo>>();
  57. foreach(PosMachinesTwo pos in poslist)
  58. {
  59. PosMerchantInfo merchant = merchantlist.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  60. if(merchant != null)
  61. {
  62. decimal Fee = Kind == 1 ? 0.63M : 0.6M;
  63. if(Kind == 0)
  64. {
  65. // pos.UpFeeFlag = 1;
  66. // pos.UpFeeMan = OpMan;
  67. // pos.UpFeeDate = DateTime.Now;
  68. // merchant.Status = 1;
  69. // merchant.SeoKeyword = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  70. }
  71. else if(Kind == 1)
  72. {
  73. pos.UpFeeFlag = 1;
  74. pos.UpFeeMan = OpMan;
  75. pos.UpFeeDate = DateTime.Now;
  76. merchant.Status = 1;
  77. // merchant.SeoKeyword = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  78. }
  79. else if(Kind == 2)
  80. {
  81. pos.DownFeeFlag = 1;
  82. pos.DownFeeMan = OpMan;
  83. pos.DownFeeDate = DateTime.Now;
  84. // if(pos.BrandId == 12 || pos.BrandId == 13)
  85. // {
  86. // pos.DownFee = 0.6M;
  87. // }
  88. // else
  89. // {
  90. pos.DownFee = 0.63M;
  91. // }
  92. merchant.Status = 0;
  93. // merchant.SeoKeyword = "";
  94. // SetRecordResult(db, RecordId, 1);
  95. }
  96. else if(Kind == 3)
  97. {
  98. pos.DownFeeFlag = 1;
  99. pos.DownFeeMan = OpMan;
  100. pos.DownFeeDate = DateTime.Now;
  101. pos.DownFee = 0.6M;
  102. merchant.Status = 0;
  103. // merchant.SeoKeyword = "";
  104. // SetRecordResult(db, RecordId, 1);
  105. }
  106. db.SaveChanges();
  107. pos.QueryCount = Kind;
  108. if(Kind == 0) //85天调升提醒
  109. {
  110. if(hintPosList.ContainsKey(pos.BuyUserId))
  111. {
  112. hintPosList[pos.BuyUserId].Add(pos);
  113. }
  114. else
  115. {
  116. List<PosMachinesTwo> subPos = new List<PosMachinesTwo>();
  117. subPos.Add(pos);
  118. hintPosList.Add(pos.BuyUserId, subPos);
  119. }
  120. }
  121. if(Kind > 0) //只有调降发消息
  122. {
  123. if(userPosList.ContainsKey(pos.BuyUserId))
  124. {
  125. userPosList[pos.BuyUserId].Add(pos);
  126. }
  127. else
  128. {
  129. List<PosMachinesTwo> subPos = new List<PosMachinesTwo>();
  130. subPos.Add(pos);
  131. userPosList.Add(pos.BuyUserId, subPos);
  132. }
  133. }
  134. if(Kind > 1)
  135. {
  136. RedisDbconn.Instance.AddList("SetDepositPostQueue", data);
  137. }
  138. }
  139. }
  140. foreach(int UserId in hintPosList.Keys)
  141. {
  142. string snhtml = "", snhtml2 = "";
  143. foreach (var item in hintPosList[UserId])
  144. {
  145. var mer = merchantlist.FirstOrDefault(m => m.Id == item.BindMerchantId) ?? new PosMerchantInfo();
  146. var brand = brands.FirstOrDefault(m => m.Id == item.BrandId) ?? new KqProducts();
  147. if(item.BrandId == 12 || item.BrandId == 13)
  148. {
  149. snhtml2 += "<div style='margin-bottom: .48rem;'><div class='f16'>商户姓名:" + mer.MerRealName + "</div>";
  150. snhtml2 += "<div class='f16'>机具品牌:" + brand.Name + "</div>";
  151. snhtml2 += "<div class='f16'>SN:" + item.PosSn + "</div>";
  152. }
  153. else
  154. {
  155. snhtml += "<div style='margin-bottom: .48rem;'><div class='f16'>商户姓名:" + mer.MerRealName + "</div>";
  156. snhtml += "<div class='f16'>机具品牌:" + brand.Name + "</div>";
  157. snhtml += "<div class='f16'>SN:" + item.PosSn + "</div>";
  158. }
  159. string DownFeeDate = item.DownFeeDate == null ? "" : item.DownFeeDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  160. }
  161. if(!string.IsNullOrEmpty(snhtml))
  162. {
  163. snhtml = "<div style='margin-bottom: .48rem;'>" + snhtml + "</div>";
  164. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  165. {
  166. UserId = Convert.ToInt32(UserId), //创客
  167. Title = "机具费率即将调升提醒", //标题
  168. Content = "<div class='f16' style='margin-bottom: .72rem'>您的部分机具已绑定满85天,5天后该机具刷卡费率将恢复0.63+3,如需调整费率,请前往我的商户-商户详情中点击调整</div>" + snhtml, //内容
  169. Summary = "您的部分机具已绑定满85天,5天后该机具刷卡费率将恢复0.63+3,如需调整费率,请前往我的商户-商户详情中点击调整",
  170. CreateDate = DateTime.Now,
  171. }));
  172. }
  173. if(!string.IsNullOrEmpty(snhtml2))
  174. {
  175. snhtml2 = "<div style='margin-bottom: .48rem;'>" + snhtml2 + "</div>";
  176. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  177. {
  178. UserId = Convert.ToInt32(UserId), //创客
  179. Title = "机具费率即将调升提醒", //标题
  180. Content = "<div class='f16' style='margin-bottom: .72rem'>您的部分机具已绑定满85天,5天后该机具刷卡费率将恢复0.63,如需调整费率,请前往我的商户-商户详情中点击调整</div>" + snhtml2, //内容
  181. Summary = "您的部分机具已绑定满85天,5天后该机具刷卡费率将恢复0.63,如需调整费率,请前往我的商户-商户详情中点击调整",
  182. CreateDate = DateTime.Now,
  183. }));
  184. }
  185. }
  186. foreach(int UserId in userPosList.Keys)
  187. {
  188. string snhtml = "", snhtml2 = "";
  189. foreach (var items in userPosList[UserId])
  190. {
  191. var mer = merchantlist.FirstOrDefault(m => m.Id == items.BindMerchantId) ?? new PosMerchantInfo();
  192. var brand = brands.FirstOrDefault(m => m.Id == items.BrandId) ?? new KqProducts();
  193. if(items.QueryCount == 1)
  194. {
  195. snhtml += "<div style='margin-bottom: .48rem;'><div class='f16'>商户姓名:" + mer.MerRealName + "</div>";
  196. snhtml += "<div class='f16'>机具品牌:" + brand.Name + "</div>";
  197. snhtml += "<div class='f16'>SN:" + items.PosSn + "</div>";
  198. string DownFeeDate = items.DownFeeDate == null ? "" : items.DownFeeDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  199. }
  200. else if(items.QueryCount == 2)
  201. {
  202. snhtml2 += "<div style='margin-bottom: .48rem;'><div class='f16'>商户姓名:" + mer.MerRealName + "</div>";
  203. snhtml2 += "<div class='f16'>机具品牌:" + brand.Name + "</div>";
  204. snhtml2 += "<div class='f16'>SN:" + items.PosSn + "</div>";
  205. string DownFeeDate = items.DownFeeDate == null ? "" : items.DownFeeDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  206. if(items.BrandId == 12 || items.BrandId == 13)
  207. {
  208. snhtml2 += "<div class='f16'>当前费率:0.6%</div>";
  209. }
  210. else
  211. {
  212. snhtml2 += "<div class='f16'>当前费率:0.63%</div>";
  213. }
  214. snhtml2 += "<div class='f16'>费率调整时间:" + DownFeeDate + "</div>";
  215. }
  216. }
  217. if(!string.IsNullOrEmpty(snhtml))
  218. {
  219. snhtml = "<div style='margin-bottom: .48rem;'>" + snhtml + "</div>";
  220. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  221. {
  222. UserId = Convert.ToInt32(UserId), //创客
  223. Title = "机具费率即将调升提醒", //标题
  224. Content = "<div class='f16' style='margin-bottom: .72rem'>您的部分机具已绑定满85天,5天后该机具刷卡费率将恢复0.63%,如需调整费率,请前往我的商户-商户详情中点击调整</div>" + snhtml, //内容
  225. Summary = "您的部分机具已绑定满85天,5天后该机具刷卡费率将恢复0.63%,如需调整费率,请前往我的商户-商户详情中点击调整",
  226. CreateDate = DateTime.Now,
  227. }));
  228. }
  229. else if(!string.IsNullOrEmpty(snhtml2))
  230. {
  231. snhtml2 = "<div style='margin-bottom: .48rem;'>" + snhtml2 + "</div>";
  232. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  233. {
  234. UserId = Convert.ToInt32(UserId), //创客
  235. Title = "商户费率变更通知", //标题
  236. Content = "<div class='f16' style='margin-bottom: .72rem'>您的商户刷卡交易费率已变更成功!</div>" + snhtml2, //内容
  237. Summary = "您的商户刷卡交易费率已变更成功!",
  238. CreateDate = DateTime.Now,
  239. }));
  240. }
  241. }
  242. }
  243. db.Dispose();
  244. }
  245. catch (Exception ex)
  246. {
  247. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "设置费率队列异常");
  248. }
  249. }
  250. else
  251. {
  252. Thread.Sleep(500);
  253. }
  254. }
  255. }
  256. private void SetRecordResult(WebCMSEntities db, int RecordId, int Status, string Note = "")
  257. {
  258. if(RecordId > 0)
  259. {
  260. PosMachinesFeeChangeRecord record = db.PosMachinesFeeChangeRecord.FirstOrDefault(m => m.Id == RecordId);
  261. if(record != null)
  262. {
  263. record.Status = Status;
  264. record.SeoDescription = Note;
  265. }
  266. }
  267. }
  268. }
  269. }