PosPushDataNewHelper.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Library;
  5. using MySystem.SpModels;
  6. namespace MySystem
  7. {
  8. public class PosPushDataNewHelper
  9. {
  10. public readonly static PosPushDataNewHelper Instance = new PosPushDataNewHelper();
  11. private PosPushDataNewHelper()
  12. { }
  13. //绑定数据
  14. public static void Bind(Merchants mer)
  15. {
  16. try
  17. {
  18. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  19. dataContent.Add("pos_sn", mer.SnNo); //机具sn
  20. dataContent.Add("mer_no", mer.MerNo); //商户号
  21. dataContent.Add("id_card", mer.MerIdcardNo); //商户身份证
  22. dataContent.Add("mer_name", mer.MerName); //商户姓名
  23. dataContent.Add("mer_mobile", mer.MerMobile); //商户手机号
  24. dataContent.Add("request_id", getRequestId(mer.Id, "bind")); //流水号
  25. dataContent.Add("bind_time", mer.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  26. dataContent.Add("brand", int.Parse(function.CheckInt(mer.ProductType))); //品牌
  27. Push("bind", dataContent);
  28. }
  29. catch (Exception ex)
  30. {
  31. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送绑定数据异常");
  32. }
  33. }
  34. public static void Bind(MerchantRecord mer)
  35. {
  36. try
  37. {
  38. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  39. dataContent.Add("pos_sn", mer.MerSnNo); //机具sn
  40. dataContent.Add("mer_no", mer.MerNo); //商户号
  41. dataContent.Add("id_card", mer.LegalIdCard); //商户身份证
  42. dataContent.Add("mer_name", mer.MerName); //商户姓名
  43. dataContent.Add("mer_mobile", ""); //商户手机号
  44. dataContent.Add("request_id", getRequestId(mer.Id, "merchant")); //流水号
  45. dataContent.Add("bind_time", mer.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  46. dataContent.Add("brand", int.Parse(function.CheckInt(mer.ProductType))); //品牌
  47. Push("bind", dataContent);
  48. }
  49. catch (Exception ex)
  50. {
  51. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送绑定数据异常");
  52. }
  53. }
  54. //解绑数据
  55. public static void UnBind(UnBindRecord mer)
  56. {
  57. try
  58. {
  59. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  60. dataContent.Add("pos_sn", mer.MerSnNo); //机具sn
  61. dataContent.Add("mer_no", mer.MerNo); //商户号
  62. dataContent.Add("request_id", getRequestId(mer.Id, "unbind")); //流水号
  63. dataContent.Add("un_bind_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  64. dataContent.Add("brand", int.Parse(function.CheckInt(mer.ProductType))); //品牌
  65. Push("un_bind", dataContent);
  66. }
  67. catch (Exception ex)
  68. {
  69. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送解绑数据异常");
  70. }
  71. }
  72. //换绑数据
  73. public static void ChangeBind(ChangeBindRecord mer)
  74. {
  75. try
  76. {
  77. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  78. dataContent.Add("request_id", getRequestId(mer.Id, "changebind")); //流水号
  79. dataContent.Add("mer_no", mer.MerNo); //商户号
  80. dataContent.Add("source_pos_sn", mer.MerSnNo); //来源机具sn
  81. dataContent.Add("source_brand", int.Parse(function.CheckInt(mer.ProductType))); //来源品牌
  82. dataContent.Add("to_pos_sn", mer.MerNewSnNo); //兑换机具sn
  83. dataContent.Add("to_brand", int.Parse(function.CheckInt(mer.ProductType))); //兑换品牌
  84. dataContent.Add("change_bind_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //换绑时间
  85. Push("change_bind", dataContent);
  86. }
  87. catch (Exception ex)
  88. {
  89. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送换绑数据异常");
  90. }
  91. }
  92. //押金数据
  93. public static void Deposit(ActivateRecord act)
  94. {
  95. try
  96. {
  97. List<string> BrandIds = new List<string>();
  98. decimal TradeAmount = decimal.Parse(function.CheckNum(act.SeoTitle));
  99. BrandIds.Add("1");
  100. BrandIds.Add("4");
  101. BrandIds.Add("6");
  102. BrandIds.Add("7");
  103. BrandIds.Add("8");
  104. BrandIds.Add("9");
  105. BrandIds.Add("15");
  106. BrandIds.Add("22");
  107. BrandIds.Add("30");
  108. if(BrandIds.Contains(act.ProductType))
  109. {
  110. TradeAmount = TradeAmount / 100;
  111. }
  112. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  113. dataContent.Add("pos_sn", act.SnNo); //机具sn
  114. dataContent.Add("mer_no", act.MerNo); //商户号
  115. dataContent.Add("request_id", getRequestId(act.Id, "deposit")); //流水号
  116. dataContent.Add("deposit_amount", TradeAmount); //押金金额
  117. dataContent.Add("trade_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  118. dataContent.Add("card_type", 1); //卡类型
  119. dataContent.Add("brand", int.Parse(function.CheckInt(act.ProductType))); //品牌
  120. Push("deposit", dataContent);
  121. }
  122. catch (Exception ex)
  123. {
  124. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送押金数据异常");
  125. }
  126. }
  127. public static void Deposit(TradeRecord trade)
  128. {
  129. try
  130. {
  131. List<string> BrandIds = new List<string>();
  132. decimal TradeAmount = trade.TradeAmount;
  133. BrandIds.Add("1");
  134. BrandIds.Add("4");
  135. BrandIds.Add("6");
  136. BrandIds.Add("7");
  137. BrandIds.Add("8");
  138. BrandIds.Add("9");
  139. BrandIds.Add("15");
  140. BrandIds.Add("22");
  141. BrandIds.Add("30");
  142. if(BrandIds.Contains(trade.ProductType))
  143. {
  144. TradeAmount = TradeAmount / 100;
  145. }
  146. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  147. dataContent.Add("pos_sn", trade.TradeSnNo); //机具sn
  148. dataContent.Add("mer_no", trade.MerNo); //商户号
  149. dataContent.Add("request_id", getRequestId(trade.Id, "deposit1")); //流水号
  150. dataContent.Add("deposit_amount", TradeAmount); //押金金额
  151. dataContent.Add("trade_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  152. dataContent.Add("card_type", 1); //卡类型
  153. dataContent.Add("brand", int.Parse(function.CheckInt(trade.ProductType))); //品牌
  154. Push("deposit", dataContent);
  155. }
  156. catch (Exception ex)
  157. {
  158. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送押金数据异常");
  159. }
  160. }
  161. //激活数据
  162. public static void Active(ActivateRecord act)
  163. {
  164. try
  165. {
  166. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  167. dataContent.Add("pos_sn", act.SnNo); //机具sn
  168. dataContent.Add("mobile", act.MerMobile); //商户号
  169. dataContent.Add("request_id", getRequestId(act.Id, "active")); //流水号
  170. dataContent.Add("activation_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  171. dataContent.Add("brand", int.Parse(function.CheckInt(act.ProductType))); //品牌
  172. Push("active", dataContent);
  173. }
  174. catch (Exception ex)
  175. {
  176. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送激活数据异常");
  177. }
  178. }
  179. //交易数据
  180. public static void Trade(TradeRecord trade)
  181. {
  182. try
  183. {
  184. int QrPayFlag = 0;
  185. int BankCardType = 1;
  186. List<string> BrandIds = new List<string>();
  187. decimal TradeAmount = trade.TradeAmount;
  188. BrandIds.Add("1");
  189. BrandIds.Add("4");
  190. BrandIds.Add("6");
  191. BrandIds.Add("7");
  192. BrandIds.Add("8");
  193. BrandIds.Add("9");
  194. BrandIds.Add("15");
  195. BrandIds.Add("22");
  196. BrandIds.Add("30");
  197. if(BrandIds.Contains(trade.ProductType))
  198. {
  199. TradeAmount = TradeAmount / 100;
  200. }
  201. if (trade.ProductType == "1")
  202. {
  203. if (trade.TradeType == "02") QrPayFlag = 1;
  204. BankCardType = int.Parse(trade.BankCardType);
  205. }
  206. else if (trade.ProductType == "2")
  207. {
  208. if (trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
  209. if (trade.TradeType == "CREDIT_BY_CARD")
  210. {
  211. BankCardType = 1;
  212. }
  213. else
  214. {
  215. BankCardType = 0;
  216. }
  217. }
  218. else if (trade.ProductType == "4")
  219. {
  220. if (trade.TradeType == "200") QrPayFlag = 1;
  221. if (trade.BankCardType == "100")
  222. {
  223. BankCardType = 1;
  224. }
  225. else if (trade.BankCardType == "200")
  226. {
  227. BankCardType = 0;
  228. }
  229. }
  230. else if (trade.ProductType == "6")
  231. {
  232. if (trade.BankCardType == "02" || trade.BankCardType == "12")
  233. {
  234. BankCardType = 1;
  235. }
  236. else
  237. {
  238. BankCardType = 0;
  239. }
  240. }
  241. else if (trade.ProductType == "7")
  242. {
  243. if (trade.BankCardType == "OA" || trade.BankCardType == "CC" || trade.BankCardType == "SCC")
  244. {
  245. BankCardType = 1;
  246. }
  247. else
  248. {
  249. BankCardType = 0;
  250. }
  251. }
  252. else if (trade.ProductType == "8" || trade.ProductType == "9")
  253. {
  254. if (trade.TradeType == "200") QrPayFlag = 1;
  255. if (trade.BankCardType == "100")
  256. {
  257. BankCardType = 1;
  258. }
  259. else if (trade.BankCardType == "200")
  260. {
  261. BankCardType = 0;
  262. }
  263. }
  264. else if (trade.ProductType == "10" || trade.ProductType == "11")
  265. {
  266. if (trade.TradeType == "F010") QrPayFlag = 1;
  267. if (trade.BankCardType == "01")
  268. {
  269. BankCardType = 1;
  270. }
  271. else if (trade.BankCardType == "00")
  272. {
  273. BankCardType = 0;
  274. }
  275. }
  276. else if (trade.ProductType == "12") //盒易付
  277. {
  278. if (trade.Field3 == "1") QrPayFlag = 1;
  279. if (trade.BankCardType == "C")
  280. {
  281. BankCardType = 1;
  282. }
  283. else if (trade.BankCardType == "D")
  284. {
  285. BankCardType = 0;
  286. }
  287. }
  288. else if (trade.ProductType == "15")
  289. {
  290. if (trade.BankCardType == "02")
  291. {
  292. BankCardType = 1;
  293. }
  294. else
  295. {
  296. BankCardType = 0;
  297. }
  298. }
  299. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  300. dataContent.Add("pos_sn", trade.TradeSnNo); //机具sn
  301. dataContent.Add("mer_no", trade.MerNo); //商户号
  302. dataContent.Add("request_id", trade.TradeSerialNo); //流水号
  303. dataContent.Add("trade_amount", TradeAmount); //交易金额
  304. dataContent.Add("trade_time", trade.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  305. dataContent.Add("brand", int.Parse(function.CheckInt(trade.ProductType))); //品牌
  306. dataContent.Add("card_type", BankCardType); //卡类型
  307. dataContent.Add("qr_pay_flag", QrPayFlag); //云闪付标记
  308. Push("trade", dataContent);
  309. }
  310. catch (Exception ex)
  311. {
  312. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送交易数据异常");
  313. }
  314. }
  315. public static void Push(string dataType, Dictionary<string, object> dataContent)
  316. {
  317. Dictionary<string, object> data = new Dictionary<string, object>();
  318. data.Add("data_type", dataType);
  319. data.Add("data_content", dataContent);
  320. RedisDbconn.Instance.AddList("KxsPosDataQueue", Newtonsoft.Json.JsonConvert.SerializeObject(data));
  321. }
  322. public static string getRequestId(int id, string type)
  323. {
  324. if(id > 0)
  325. {
  326. return function.MD5_32(id.ToString() + type);
  327. }
  328. return DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  329. }
  330. }
  331. }