PosPushDataNewHelper.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. if(mer.ProductType == "14")
  25. {
  26. dataContent.Add("request_id", getRequestId(mer.Id + function.get_Random(5), "bind")); //流水号
  27. }
  28. else
  29. {
  30. dataContent.Add("request_id", getRequestId(mer.Id, "bind")); //流水号
  31. }
  32. dataContent.Add("bind_time", mer.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  33. dataContent.Add("brand", int.Parse(function.CheckInt(mer.ProductType))); //品牌
  34. Push("bind", dataContent);
  35. }
  36. catch (Exception ex)
  37. {
  38. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送绑定数据异常");
  39. }
  40. }
  41. public static void Bind0(BindRecord mer)
  42. {
  43. try
  44. {
  45. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  46. dataContent.Add("pos_sn", mer.MerSnNo); //机具sn
  47. dataContent.Add("mer_no", mer.MerNo); //商户号
  48. dataContent.Add("id_card", ""); //商户身份证
  49. dataContent.Add("mer_name", mer.MerName); //商户姓名
  50. dataContent.Add("mer_mobile", mer.MerNo); //商户手机号
  51. dataContent.Add("request_id", getRequestId(mer.Id, "bind")); //流水号
  52. dataContent.Add("bind_time", mer.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  53. dataContent.Add("brand", int.Parse(function.CheckInt(mer.ProductType))); //品牌
  54. Push("bind", dataContent);
  55. }
  56. catch (Exception ex)
  57. {
  58. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送绑定数据异常");
  59. }
  60. }
  61. public static void Bind2(MerchantRecord mer)
  62. {
  63. try
  64. {
  65. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  66. dataContent.Add("pos_sn", mer.MerSnNo); //机具sn
  67. dataContent.Add("mer_no", mer.MerNo); //商户号
  68. dataContent.Add("id_card", mer.LegalIdCard); //商户身份证
  69. dataContent.Add("mer_name", mer.MerName); //商户姓名
  70. dataContent.Add("mer_mobile", ""); //商户手机号
  71. dataContent.Add("request_id", getRequestId(mer.Id, "merchant")); //流水号
  72. dataContent.Add("bind_time", mer.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  73. dataContent.Add("brand", int.Parse(function.CheckInt(mer.ProductType))); //品牌
  74. Push("bind", dataContent);
  75. }
  76. catch (Exception ex)
  77. {
  78. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送绑定数据异常");
  79. }
  80. }
  81. //解绑数据
  82. public static void UnBind(UnBindRecord mer)
  83. {
  84. try
  85. {
  86. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  87. dataContent.Add("pos_sn", mer.MerSnNo); //机具sn
  88. dataContent.Add("mer_no", mer.MerNo); //商户号
  89. dataContent.Add("request_id", getRequestId(mer.Id, "unbind")); //流水号
  90. dataContent.Add("un_bind_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  91. dataContent.Add("brand", int.Parse(function.CheckInt(mer.ProductType))); //品牌
  92. Push("un_bind", dataContent);
  93. }
  94. catch (Exception ex)
  95. {
  96. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送解绑数据异常");
  97. }
  98. }
  99. //换绑数据
  100. public static void ChangeBind(ChangeBindRecord mer)
  101. {
  102. try
  103. {
  104. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  105. dataContent.Add("request_id", getRequestId(mer.Id, "changebind")); //流水号
  106. dataContent.Add("mer_no", mer.MerNo); //商户号
  107. dataContent.Add("source_pos_sn", mer.MerSnNo); //来源机具sn
  108. dataContent.Add("source_brand", int.Parse(function.CheckInt(mer.ProductType))); //来源品牌
  109. dataContent.Add("to_pos_sn", mer.MerNewSnNo); //兑换机具sn
  110. dataContent.Add("to_brand", int.Parse(function.CheckInt(mer.ProductType))); //兑换品牌
  111. dataContent.Add("change_bind_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //换绑时间
  112. Push("change_bind", dataContent);
  113. }
  114. catch (Exception ex)
  115. {
  116. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送换绑数据异常");
  117. }
  118. }
  119. //押金数据
  120. public static void Deposit(ActivateRecord act)
  121. {
  122. try
  123. {
  124. List<string> BrandIds = new List<string>();
  125. decimal TradeAmount = decimal.Parse(function.CheckNum(act.SeoTitle));
  126. BrandIds.Add("1");
  127. BrandIds.Add("4");
  128. BrandIds.Add("6");
  129. BrandIds.Add("8");
  130. BrandIds.Add("9");
  131. BrandIds.Add("15");
  132. BrandIds.Add("22");
  133. BrandIds.Add("27");
  134. BrandIds.Add("30");
  135. if(BrandIds.Contains(act.ProductType))
  136. {
  137. TradeAmount = TradeAmount / 100;
  138. }
  139. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  140. dataContent.Add("pos_sn", act.SnNo); //机具sn
  141. dataContent.Add("mer_no", act.MerNo); //商户号
  142. dataContent.Add("request_id", getRequestId(act.Id, "deposit")); //流水号
  143. if(act.ProductType == "14")
  144. {
  145. dataContent.Add("deposit_amount", 0); //押金金额
  146. }
  147. else
  148. {
  149. dataContent.Add("deposit_amount", TradeAmount); //押金金额
  150. }
  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(act.ProductType))); //品牌
  154. if(act.ProductType == "29")
  155. {
  156. dataContent.Add("ext_field", act.Field4); //押金活动编码
  157. }
  158. else if(act.ProductType == "14")
  159. {
  160. dataContent.Add("fee_amt", TradeAmount); //秒到费
  161. }
  162. Push("deposit", dataContent);
  163. }
  164. catch (Exception ex)
  165. {
  166. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送押金数据异常");
  167. }
  168. }
  169. public static void Deposit(TradeRecord trade)
  170. {
  171. try
  172. {
  173. List<string> BrandIds = new List<string>();
  174. decimal TradeAmount = trade.TradeAmount;
  175. BrandIds.Add("1");
  176. BrandIds.Add("4");
  177. BrandIds.Add("6");
  178. // BrandIds.Add("7");
  179. BrandIds.Add("8");
  180. BrandIds.Add("9");
  181. BrandIds.Add("15");
  182. BrandIds.Add("22");
  183. BrandIds.Add("27");
  184. BrandIds.Add("30");
  185. if(BrandIds.Contains(trade.ProductType))
  186. {
  187. TradeAmount = TradeAmount / 100;
  188. }
  189. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  190. dataContent.Add("pos_sn", trade.TradeSnNo); //机具sn
  191. dataContent.Add("mer_no", trade.MerNo); //商户号
  192. dataContent.Add("request_id", getRequestId(trade.Id, "deposit1")); //流水号
  193. dataContent.Add("deposit_amount", TradeAmount); //押金金额
  194. dataContent.Add("trade_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  195. dataContent.Add("card_type", 1); //卡类型
  196. dataContent.Add("brand", int.Parse(function.CheckInt(trade.ProductType))); //品牌
  197. Push("deposit", dataContent);
  198. }
  199. catch (Exception ex)
  200. {
  201. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送押金数据异常");
  202. }
  203. }
  204. //激活数据
  205. public static void Active(ActivateRecord act)
  206. {
  207. try
  208. {
  209. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  210. dataContent.Add("pos_sn", act.SnNo); //机具sn
  211. dataContent.Add("mobile", act.MerMobile); //商户号
  212. dataContent.Add("request_id", getRequestId(act.Id, "active")); //流水号
  213. dataContent.Add("activation_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  214. dataContent.Add("brand", int.Parse(function.CheckInt(act.ProductType))); //品牌
  215. Push("active", dataContent);
  216. }
  217. catch (Exception ex)
  218. {
  219. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送激活数据异常");
  220. }
  221. }
  222. //交易数据
  223. public static void Trade(TradeRecord trade)
  224. {
  225. try
  226. {
  227. int QrPayFlag = 0;
  228. int BankCardType = 1;
  229. string FeeRate = function.CheckNum(trade.ErrorCode);
  230. string FeeAmt = function.CheckNum(trade.ErrorMsg);
  231. List<string> BrandIds = new List<string>();
  232. decimal TradeAmount = trade.TradeAmount;
  233. BrandIds.Add("1");
  234. BrandIds.Add("4");
  235. BrandIds.Add("6");
  236. BrandIds.Add("7");
  237. BrandIds.Add("8");
  238. BrandIds.Add("9");
  239. BrandIds.Add("15");
  240. BrandIds.Add("22");
  241. BrandIds.Add("27");
  242. BrandIds.Add("30");
  243. if(BrandIds.Contains(trade.ProductType))
  244. {
  245. TradeAmount = TradeAmount / 100;
  246. }
  247. if (trade.ProductType == "1" || trade.ProductType == "27")
  248. {
  249. if (trade.TradeType == "02") QrPayFlag = 1;
  250. BankCardType = int.Parse(trade.BankCardType);
  251. decimal feeRateStr = decimal.Parse(FeeRate) * 100;
  252. FeeRate = feeRateStr.ToString().TrimEnd('0');
  253. if(FeeRate != "0") FeeRate = FeeRate.TrimEnd('0');
  254. if(FeeAmt != "0" && !string.IsNullOrEmpty(FeeAmt)) FeeAmt = FeeAmt.TrimEnd('0');
  255. }
  256. else if (trade.ProductType == "2")
  257. {
  258. if (trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
  259. if (trade.TradeType == "CREDIT_BY_CARD")
  260. {
  261. BankCardType = 1;
  262. }
  263. else
  264. {
  265. BankCardType = 0;
  266. }
  267. FeeRate = FeeRate.Replace("0.00", "0.");
  268. }
  269. else if (trade.ProductType == "4")
  270. {
  271. if (trade.TradeType == "200") QrPayFlag = 1;
  272. if (trade.BankCardType == "100")
  273. {
  274. BankCardType = 1;
  275. }
  276. else if (trade.BankCardType == "200")
  277. {
  278. BankCardType = 0;
  279. }
  280. decimal feeRateStr = decimal.Parse(FeeRate) / 10000;
  281. FeeRate = feeRateStr.ToString().TrimEnd('0');
  282. if(FeeRate != "0") FeeRate = FeeRate.TrimEnd('0');
  283. if(FeeAmt != "0" && !string.IsNullOrEmpty(FeeAmt)) FeeAmt = FeeAmt.TrimEnd('0');
  284. }
  285. else if (trade.ProductType == "6")
  286. {
  287. if (trade.BankCardType == "02" || trade.BankCardType == "12")
  288. {
  289. BankCardType = 1;
  290. }
  291. else
  292. {
  293. BankCardType = 0;
  294. }
  295. }
  296. else if (trade.ProductType == "7")
  297. {
  298. if (trade.BankCardType == "OA" || trade.BankCardType == "CC" || trade.BankCardType == "SCC")
  299. {
  300. BankCardType = 1;
  301. }
  302. else
  303. {
  304. BankCardType = 0;
  305. }
  306. }
  307. else if (trade.ProductType == "8" || trade.ProductType == "9")
  308. {
  309. if (trade.TradeType == "200") QrPayFlag = 1;
  310. if (trade.BankCardType == "100")
  311. {
  312. BankCardType = 1;
  313. }
  314. else if (trade.BankCardType == "200")
  315. {
  316. BankCardType = 0;
  317. }
  318. decimal feeRateStr = decimal.Parse(FeeRate) / 10000;
  319. FeeRate = feeRateStr.ToString().TrimEnd('0');
  320. if(FeeRate != "0") FeeRate = FeeRate.TrimEnd('0');
  321. if(FeeAmt != "0" && !string.IsNullOrEmpty(FeeAmt)) FeeAmt = FeeAmt.TrimEnd('0');
  322. }
  323. else if (trade.ProductType == "10" || trade.ProductType == "11")
  324. {
  325. if (trade.TradeType == "F010") QrPayFlag = 1;
  326. if (trade.BankCardType == "01")
  327. {
  328. BankCardType = 1;
  329. }
  330. else if (trade.BankCardType == "00")
  331. {
  332. BankCardType = 0;
  333. }
  334. FeeRate = FeeRate.Replace("0.00", "0.");
  335. }
  336. else if (trade.ProductType == "12") //盒易付
  337. {
  338. if (trade.Field3 == "1") QrPayFlag = 1;
  339. if (trade.BankCardType == "C")
  340. {
  341. BankCardType = 1;
  342. }
  343. else if (trade.BankCardType == "D")
  344. {
  345. BankCardType = 0;
  346. }
  347. }
  348. else if (trade.ProductType == "15")
  349. {
  350. if (trade.BankCardType == "02")
  351. {
  352. BankCardType = 1;
  353. }
  354. else
  355. {
  356. BankCardType = 0;
  357. }
  358. if(FeeAmt != "0") FeeAmt = FeeAmt.TrimEnd('0');
  359. }
  360. else if (Utils.Instance.IsWifi(int.Parse(trade.ProductType)))
  361. {
  362. FeeRate = "0.60";
  363. FeeAmt = trade.ErrorMsg;
  364. }
  365. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  366. dataContent.Add("pos_sn", trade.TradeSnNo); //机具sn
  367. dataContent.Add("mer_no", trade.MerNo); //商户号
  368. dataContent.Add("request_id", trade.TradeSerialNo); //流水号
  369. dataContent.Add("trade_amount", TradeAmount); //交易金额
  370. dataContent.Add("trade_time", trade.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  371. dataContent.Add("brand", int.Parse(function.CheckInt(trade.ProductType))); //品牌
  372. dataContent.Add("card_type", BankCardType); //卡类型
  373. dataContent.Add("qr_pay_flag", QrPayFlag); //云闪付标记
  374. dataContent.Add("fee_rate", FeeRate); //费率
  375. dataContent.Add("fee_amt", FeeAmt); //秒到费
  376. if(trade.ProductType == "14")
  377. {
  378. dataContent.Add("is_first", 1);
  379. }
  380. if(trade.ProductType == "23" || trade.ProductType == "24" || trade.ProductType == "25" || trade.ProductType == "26" || trade.ProductType == "32")
  381. {
  382. dataContent.Add("ext_field", trade.ChannelSerial);
  383. }
  384. Push("trade", dataContent);
  385. }
  386. catch (Exception ex)
  387. {
  388. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送交易数据异常");
  389. }
  390. }
  391. public static void Push(string dataType, Dictionary<string, object> dataContent)
  392. {
  393. Dictionary<string, object> data = new Dictionary<string, object>();
  394. data.Add("data_type", dataType);
  395. data.Add("data_content", dataContent);
  396. // if(RedisDbconn.Instance.Get<string>("KxsPosDataQueueStatus") == "1")
  397. // {
  398. // RedisDbconn.Instance.AddList("KxsPosDataQueue", Newtonsoft.Json.JsonConvert.SerializeObject(data));
  399. // }
  400. PosPushHelper.Instance.DoSomeThing(Newtonsoft.Json.JsonConvert.SerializeObject(data));
  401. }
  402. public static string getRequestId(int id, string type)
  403. {
  404. if(id > 0)
  405. {
  406. return function.MD5_32(id.ToString() + type);
  407. }
  408. return DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  409. }
  410. public static string getRequestId(string str, string type)
  411. {
  412. return function.MD5_32(str + type);
  413. }
  414. }
  415. }