SetDepositService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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) && Kind > 0)
  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. foreach(PosMachinesTwo pos in poslist)
  57. {
  58. PosMerchantInfo merchant = merchantlist.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  59. if(merchant != null)
  60. {
  61. decimal Fee = Kind == 1 ? 0.63M : 0.6M;
  62. if(Kind == 1)
  63. {
  64. pos.UpFeeFlag = 1;
  65. pos.UpFeeMan = OpMan;
  66. pos.UpFeeDate = DateTime.Now;
  67. merchant.Status = 1;
  68. merchant.SeoKeyword = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  69. }
  70. else if(Kind == 2)
  71. {
  72. pos.DownFeeFlag = 1;
  73. pos.DownFeeMan = OpMan;
  74. pos.DownFeeDate = DateTime.Now;
  75. merchant.Status = 0;
  76. merchant.SeoKeyword = "";
  77. SetRecordResult(db, RecordId, 1);
  78. }
  79. db.SaveChanges();
  80. pos.QueryCount = Kind;
  81. if(userPosList.ContainsKey(pos.BuyUserId))
  82. {
  83. userPosList[pos.BuyUserId].Add(pos);
  84. }
  85. else
  86. {
  87. List<PosMachinesTwo> subPos = new List<PosMachinesTwo>();
  88. subPos.Add(pos);
  89. userPosList.Add(pos.BuyUserId, subPos);
  90. }
  91. }
  92. }
  93. foreach(int UserId in userPosList.Keys)
  94. {
  95. string snhtml = "", snhtml2 = "";
  96. foreach (var items in userPosList[UserId])
  97. {
  98. var mer = merchantlist.FirstOrDefault(m => m.Id == items.BindMerchantId) ?? new PosMerchantInfo();
  99. var brand = brands.FirstOrDefault(m => m.Id == items.BrandId) ?? new KqProducts();
  100. if(items.QueryCount == 1)
  101. {
  102. snhtml += "<div style='margin-bottom: .48rem;'><div class='f12'>商户姓名:" + mer.MerRealName + "</div>";
  103. snhtml += "<div class='f12'>机具品牌:" + brand.Name + "</div>";
  104. snhtml += "<div class='f12'>SN:" + items.PosSn + "</div>";
  105. string DownFeeDate = items.DownFeeDate == null ? "" : items.DownFeeDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  106. }
  107. else if(items.QueryCount == 2)
  108. {
  109. snhtml2 += "<div style='margin-bottom: .48rem;'><div class='f12'>商户姓名:" + mer.MerRealName + "</div>";
  110. snhtml2 += "<div class='f12'>机具品牌:" + brand.Name + "</div>";
  111. snhtml2 += "<div class='f12'>SN:" + items.PosSn + "</div>";
  112. string DownFeeDate = items.DownFeeDate == null ? "" : items.DownFeeDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  113. snhtml2 += "<div class='f12'>当前费率:0.6%</div>";
  114. snhtml2 += "<div class='f12'>费率调整时间:" + DownFeeDate + "</div>";
  115. }
  116. }
  117. if(!string.IsNullOrEmpty(snhtml))
  118. {
  119. snhtml = "<div style='margin-bottom: .48rem;'>" + snhtml + "</div>";
  120. // RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  121. // {
  122. // UserId = Convert.ToInt32(UserId), //创客
  123. // Title = "商户费率变更通知", //标题
  124. // Content = "<div class='f12' style='margin-bottom: .72rem'>您的部分机具已绑定超过180天,刷卡费率已自动变更为0.63%,如需调整费率,请前往我的商户-商户详情中调整费率</div>" + snhtml, //内容
  125. // Summary = "您的部分机具已绑定超过180天,刷卡费率已自动变更为0.63%,如需调整费率,请前往我的商户-商户详情中调整费率",
  126. // CreateDate = DateTime.Now,
  127. // }));
  128. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  129. {
  130. UserId = Convert.ToInt32(UserId), //创客
  131. Title = "机具费率即将调升提醒", //标题
  132. Content = "<div class='f16' style='margin-bottom: .72rem'>您的部分机具已绑定满178天,48小时后该机具刷卡费率将恢复0.63%,如需调整费率,请前往我的商户-商户详情中点击调整</div>" + snhtml, //内容
  133. Summary = "您的部分机具已绑定满178天,48小时后该机具刷卡费率将恢复0.63%,如需调整费率,请前往我的商户-商户详情中点击调整",
  134. CreateDate = DateTime.Now,
  135. }));
  136. }
  137. else if(!string.IsNullOrEmpty(snhtml2))
  138. {
  139. snhtml2 = "<div style='margin-bottom: .48rem;'>" + snhtml2 + "</div>";
  140. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  141. {
  142. UserId = Convert.ToInt32(UserId), //创客
  143. Title = "商户费率变更通知", //标题
  144. Content = "<div class='f12' style='margin-bottom: .72rem'>您的商户刷卡交易费率已变更成功!</div>" + snhtml2, //内容
  145. Summary = "您的商户刷卡交易费率已变更成功!",
  146. CreateDate = DateTime.Now,
  147. }));
  148. }
  149. }
  150. }
  151. db.Dispose();
  152. }
  153. catch (Exception ex)
  154. {
  155. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "设置费率队列异常");
  156. }
  157. }
  158. else
  159. {
  160. Thread.Sleep(60000);
  161. }
  162. }
  163. }
  164. private void SetRecordResult(WebCMSEntities db, int RecordId, int Status, string Note = "")
  165. {
  166. if(RecordId > 0)
  167. {
  168. PosMachinesFeeChangeRecord record = db.PosMachinesFeeChangeRecord.FirstOrDefault(m => m.Id == RecordId);
  169. if(record != null)
  170. {
  171. record.Status = Status;
  172. record.SeoDescription = Note;
  173. }
  174. }
  175. }
  176. }
  177. }