PosPushDataNewHelper.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using MySystem.SpModels;
  5. namespace MySystem
  6. {
  7. public class PosPushDataNewHelper
  8. {
  9. public readonly static PosPushDataNewHelper Instance = new PosPushDataNewHelper();
  10. private PosPushDataNewHelper()
  11. { }
  12. //绑定数据
  13. public static void Bind(Merchants mer)
  14. {
  15. try
  16. {
  17. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  18. dataContent.Add("pos_sn", mer.SnNo); //机具sn
  19. dataContent.Add("mer_no", mer.MerNo); //商户号
  20. dataContent.Add("id_card", mer.SeoKeyword); //商户身份证
  21. dataContent.Add("mer_name", mer.MerName); //商户姓名
  22. dataContent.Add("mer_mobile", mer.MerMobile); //商户手机号
  23. dataContent.Add("request_id", mer.CreateTime.Value.ToString("yyyyMMddHHmmssfff") + function.get_Random(8)); //流水号
  24. dataContent.Add("bind_time", mer.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  25. dataContent.Add("brand", mer.ProductType); //品牌
  26. Push("bind", dataContent);
  27. }
  28. catch (Exception ex)
  29. {
  30. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送绑定数据异常");
  31. }
  32. }
  33. public static void Bind(MerchantRecord mer)
  34. {
  35. try
  36. {
  37. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  38. dataContent.Add("pos_sn", mer.MerSnNo); //机具sn
  39. dataContent.Add("mer_no", mer.MerNo); //商户号
  40. dataContent.Add("id_card", mer.LegalIdCard); //商户身份证
  41. dataContent.Add("mer_name", mer.MerName); //商户姓名
  42. dataContent.Add("mer_mobile", ""); //商户手机号
  43. dataContent.Add("request_id", mer.CreateTime.Value.ToString("yyyyMMddHHmmssfff") + function.get_Random(8)); //流水号
  44. dataContent.Add("bind_time", mer.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  45. dataContent.Add("brand", mer.ProductType); //品牌
  46. Push("bind", dataContent);
  47. }
  48. catch (Exception ex)
  49. {
  50. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送绑定数据异常");
  51. }
  52. }
  53. //解绑数据
  54. public static void UnBind(UnBindRecord mer)
  55. {
  56. try
  57. {
  58. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  59. dataContent.Add("pos_sn", mer.MerSnNo); //机具sn
  60. dataContent.Add("mer_no", mer.MerNo); //商户号
  61. dataContent.Add("request_id", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8)); //流水号
  62. dataContent.Add("un_bind_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  63. dataContent.Add("brand", mer.ProductType); //品牌
  64. Push("un_bind", dataContent);
  65. }
  66. catch (Exception ex)
  67. {
  68. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送解绑数据异常");
  69. }
  70. }
  71. //换绑数据
  72. public static void ChangeBind(ChangeBindRecord mer)
  73. {
  74. try
  75. {
  76. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  77. dataContent.Add("request_id", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8)); //流水号
  78. dataContent.Add("mer_no", mer.MerNo); //商户号
  79. dataContent.Add("source_pos_sn", mer.MerSnNo); //来源机具sn
  80. dataContent.Add("source_brand", mer.ProductType); //来源品牌
  81. dataContent.Add("to_pos_sn", mer.MerNewSnNo); //兑换机具sn
  82. dataContent.Add("to_brand", mer.ProductType); //兑换品牌
  83. dataContent.Add("change_bind_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //换绑时间
  84. Push("change_bind", dataContent);
  85. }
  86. catch (Exception ex)
  87. {
  88. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送换绑数据异常");
  89. }
  90. }
  91. //押金数据
  92. public static void Deposit(ActivateRecord act)
  93. {
  94. try
  95. {
  96. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  97. dataContent.Add("pos_sn", act.SnNo); //机具sn
  98. dataContent.Add("mer_no", act.MerNo); //商户号
  99. dataContent.Add("request_id", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8)); //流水号
  100. dataContent.Add("deposit_amount", act.SeoTitle); //押金金额
  101. dataContent.Add("trade_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  102. dataContent.Add("brand", act.ProductType); //品牌
  103. Push("deposit", dataContent);
  104. }
  105. catch (Exception ex)
  106. {
  107. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送押金数据异常");
  108. }
  109. }
  110. public static void Deposit(TradeRecord trade)
  111. {
  112. try
  113. {
  114. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  115. dataContent.Add("pos_sn", trade.TradeSnNo); //机具sn
  116. dataContent.Add("mer_no", trade.MerNo); //商户号
  117. dataContent.Add("request_id", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8)); //流水号
  118. dataContent.Add("deposit_amount", trade.TradeAmount); //押金金额
  119. dataContent.Add("trade_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  120. dataContent.Add("brand", trade.ProductType); //品牌
  121. Push("deposit", dataContent);
  122. }
  123. catch (Exception ex)
  124. {
  125. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送押金数据异常");
  126. }
  127. }
  128. //激活数据
  129. public static void Active(ActivateRecord act)
  130. {
  131. try
  132. {
  133. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  134. dataContent.Add("pos_sn", act.SnNo); //机具sn
  135. dataContent.Add("mobile", act.MerMobile); //商户号
  136. dataContent.Add("request_id", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8)); //流水号
  137. dataContent.Add("activation_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  138. dataContent.Add("brand", act.ProductType); //品牌
  139. Push("active", dataContent);
  140. }
  141. catch (Exception ex)
  142. {
  143. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送激活数据异常");
  144. }
  145. }
  146. //交易数据
  147. public static void Trade(TradeRecord trade)
  148. {
  149. try
  150. {
  151. int QrPayFlag = 0;
  152. if (trade.ProductType == "1")
  153. {
  154. if (trade.TradeType == "02") QrPayFlag = 1;
  155. }
  156. else if (trade.ProductType == "2")
  157. {
  158. if (trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
  159. }
  160. else if (trade.ProductType == "4")
  161. {
  162. if (trade.TradeType == "200") QrPayFlag = 1;
  163. }
  164. else if (trade.ProductType == "8" || trade.ProductType == "9")
  165. {
  166. if (trade.TradeType == "200") QrPayFlag = 1;
  167. }
  168. else if (trade.ProductType == "10" || trade.ProductType == "11")
  169. {
  170. if (trade.TradeType == "F010") QrPayFlag = 1;
  171. }
  172. else if (trade.ProductType == "12") //盒易付
  173. {
  174. if (trade.Field3 == "1") QrPayFlag = 1;
  175. }
  176. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  177. dataContent.Add("pos_sn", trade.TradeSnNo); //机具sn
  178. dataContent.Add("mer_no", trade.MerNo); //商户号
  179. dataContent.Add("request_id", trade.TradeSerialNo); //流水号
  180. dataContent.Add("trade_amount", trade.TradeAmount); //交易金额
  181. dataContent.Add("trade_time", trade.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  182. dataContent.Add("brand", trade.ProductType); //品牌
  183. dataContent.Add("card_type", trade.BankCardType); //卡类型
  184. dataContent.Add("qr_pay_flag", QrPayFlag); //云闪付标记
  185. Push("trade", dataContent);
  186. }
  187. catch (Exception ex)
  188. {
  189. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送交易数据异常");
  190. }
  191. }
  192. public static void Push(string dataType, Dictionary<string, object> dataContent)
  193. {
  194. Dictionary<string, object> data = new Dictionary<string, object>();
  195. data.Add("data_type", dataType);
  196. data.Add("data_content", dataContent);
  197. RedisDbconn.Instance.AddList("KxsPosDataQueue", Newtonsoft.Json.JsonConvert.SerializeObject(data));
  198. }
  199. }
  200. }