SetDepositService.cs 11 KB

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