PosPushDataNewHelper.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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", getRequestId(mer.Id, "bind")); //流水号
  24. dataContent.Add("bind_time", mer.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  25. dataContent.Add("brand", int.Parse(function.CheckInt(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", getRequestId(mer.Id, "merchant")); //流水号
  44. dataContent.Add("bind_time", mer.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  45. dataContent.Add("brand", int.Parse(function.CheckInt(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", getRequestId(mer.Id, "unbind")); //流水号
  62. dataContent.Add("un_bind_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  63. dataContent.Add("brand", int.Parse(function.CheckInt(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", getRequestId(mer.Id, "changebind")); //流水号
  78. dataContent.Add("mer_no", mer.MerNo); //商户号
  79. dataContent.Add("source_pos_sn", mer.MerSnNo); //来源机具sn
  80. dataContent.Add("source_brand", int.Parse(function.CheckInt(mer.ProductType))); //来源品牌
  81. dataContent.Add("to_pos_sn", mer.MerNewSnNo); //兑换机具sn
  82. dataContent.Add("to_brand", int.Parse(function.CheckInt(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", getRequestId(act.Id, "deposit")); //流水号
  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", int.Parse(function.CheckInt(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", getRequestId(trade.Id, "deposit1")); //流水号
  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", int.Parse(function.CheckInt(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", getRequestId(act.Id, "active")); //流水号
  137. dataContent.Add("activation_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  138. dataContent.Add("brand", int.Parse(function.CheckInt(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. int BankCardType = 1;
  153. if (trade.ProductType == "1")
  154. {
  155. if (trade.TradeType == "02") QrPayFlag = 1;
  156. BankCardType = int.Parse(trade.BankCardType);
  157. }
  158. else if (trade.ProductType == "2")
  159. {
  160. if (trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
  161. if (trade.TradeType == "CREDIT_BY_CARD")
  162. {
  163. BankCardType = 1;
  164. }
  165. else
  166. {
  167. BankCardType = 0;
  168. }
  169. }
  170. else if (trade.ProductType == "4")
  171. {
  172. if (trade.TradeType == "200") QrPayFlag = 1;
  173. if (trade.BankCardType == "100")
  174. {
  175. BankCardType = 1;
  176. }
  177. else if (trade.BankCardType == "200")
  178. {
  179. BankCardType = 0;
  180. }
  181. }
  182. else if (trade.ProductType == "6")
  183. {
  184. if (trade.BankCardType == "02" || trade.BankCardType == "12")
  185. {
  186. BankCardType = 1;
  187. }
  188. else
  189. {
  190. BankCardType = 0;
  191. }
  192. }
  193. else if (trade.ProductType == "7")
  194. {
  195. if (trade.BankCardType == "OA" || trade.BankCardType == "CC" || trade.BankCardType == "SCC")
  196. {
  197. BankCardType = 1;
  198. }
  199. else
  200. {
  201. BankCardType = 0;
  202. }
  203. }
  204. else if (trade.ProductType == "8" || trade.ProductType == "9")
  205. {
  206. if (trade.TradeType == "200") QrPayFlag = 1;
  207. if (trade.BankCardType == "100")
  208. {
  209. BankCardType = 1;
  210. }
  211. else if (trade.BankCardType == "200")
  212. {
  213. BankCardType = 0;
  214. }
  215. }
  216. else if (trade.ProductType == "10" || trade.ProductType == "11")
  217. {
  218. if (trade.TradeType == "F010") QrPayFlag = 1;
  219. if (trade.BankCardType == "01")
  220. {
  221. BankCardType = 1;
  222. }
  223. else if (trade.BankCardType == "00")
  224. {
  225. BankCardType = 0;
  226. }
  227. }
  228. else if (trade.ProductType == "12") //盒易付
  229. {
  230. if (trade.Field3 == "1") QrPayFlag = 1;
  231. if (trade.BankCardType == "C")
  232. {
  233. BankCardType = 1;
  234. }
  235. else if (trade.BankCardType == "D")
  236. {
  237. BankCardType = 0;
  238. }
  239. }
  240. else if (trade.ProductType == "15")
  241. {
  242. if (trade.BankCardType == "02")
  243. {
  244. BankCardType = 1;
  245. }
  246. else
  247. {
  248. BankCardType = 0;
  249. }
  250. }
  251. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  252. dataContent.Add("pos_sn", trade.TradeSnNo); //机具sn
  253. dataContent.Add("mer_no", trade.MerNo); //商户号
  254. dataContent.Add("request_id", trade.TradeSerialNo); //流水号
  255. dataContent.Add("trade_amount", trade.TradeAmount); //交易金额
  256. dataContent.Add("trade_time", trade.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  257. dataContent.Add("brand", int.Parse(function.CheckInt(trade.ProductType))); //品牌
  258. dataContent.Add("card_type", BankCardType); //卡类型
  259. dataContent.Add("qr_pay_flag", QrPayFlag); //云闪付标记
  260. Push("trade", dataContent);
  261. }
  262. catch (Exception ex)
  263. {
  264. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送交易数据异常");
  265. }
  266. }
  267. public static void Push(string dataType, Dictionary<string, object> dataContent)
  268. {
  269. Dictionary<string, object> data = new Dictionary<string, object>();
  270. data.Add("data_type", dataType);
  271. data.Add("data_content", dataContent);
  272. RedisDbconn.Instance.AddList("KxsPosDataQueue", Newtonsoft.Json.JsonConvert.SerializeObject(data));
  273. }
  274. public static string getRequestId(int id, string type)
  275. {
  276. if(id > 0)
  277. {
  278. return function.MD5_32(id.ToString() + type);
  279. }
  280. return DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  281. }
  282. }
  283. }