SetDepositService.cs 12 KB

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