PosPushDataNewHelper.cs 18 KB

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