PosPushDataNewHelper.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. if(Utils.Instance.IsWifi(int.Parse(act.ProductType)) || Utils.Instance.IsHaoDa(int.Parse(act.ProductType)))
  140. {
  141. dataContent.Add("request_id", getRequestId(act.SnNo + act.MerMobile, "deposit")); //流水号
  142. }
  143. else
  144. {
  145. dataContent.Add("request_id", getRequestId(act.Id, "deposit")); //流水号
  146. }
  147. if(act.ProductType == "14")
  148. {
  149. dataContent.Add("deposit_amount", 0); //押金金额
  150. }
  151. else
  152. {
  153. dataContent.Add("deposit_amount", TradeAmount); //押金金额
  154. }
  155. dataContent.Add("trade_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  156. dataContent.Add("card_type", 1); //卡类型
  157. dataContent.Add("brand", int.Parse(function.CheckInt(act.ProductType))); //品牌
  158. if(act.ProductType == "29")
  159. {
  160. dataContent.Add("ext_field", act.Field4); //押金活动编码
  161. }
  162. else if(act.ProductType == "14" && function.CheckNull(act.SeoKeyword).Contains("双百套餐"))
  163. {
  164. dataContent.Add("fee_amt", TradeAmount); //秒到费
  165. }
  166. Push("deposit", dataContent);
  167. }
  168. catch (Exception ex)
  169. {
  170. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送押金数据异常");
  171. }
  172. }
  173. public static void Deposit(TradeRecord trade)
  174. {
  175. try
  176. {
  177. List<string> BrandIds = new List<string>();
  178. decimal TradeAmount = trade.TradeAmount;
  179. BrandIds.Add("1");
  180. BrandIds.Add("4");
  181. BrandIds.Add("6");
  182. // BrandIds.Add("7");
  183. BrandIds.Add("8");
  184. BrandIds.Add("9");
  185. BrandIds.Add("15");
  186. BrandIds.Add("22");
  187. BrandIds.Add("27");
  188. BrandIds.Add("30");
  189. if(BrandIds.Contains(trade.ProductType))
  190. {
  191. TradeAmount = TradeAmount / 100;
  192. }
  193. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  194. dataContent.Add("pos_sn", trade.TradeSnNo); //机具sn
  195. dataContent.Add("mer_no", trade.MerNo); //商户号
  196. dataContent.Add("request_id", getRequestId(trade.Id, "deposit1")); //流水号
  197. dataContent.Add("deposit_amount", TradeAmount); //押金金额
  198. dataContent.Add("trade_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  199. dataContent.Add("card_type", 1); //卡类型
  200. dataContent.Add("brand", int.Parse(function.CheckInt(trade.ProductType))); //品牌
  201. Push("deposit", dataContent);
  202. }
  203. catch (Exception ex)
  204. {
  205. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送押金数据异常");
  206. }
  207. }
  208. //激活数据
  209. public static void Active(ActivateRecord act)
  210. {
  211. try
  212. {
  213. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  214. dataContent.Add("pos_sn", act.SnNo); //机具sn
  215. dataContent.Add("mobile", act.MerMobile); //商户号
  216. dataContent.Add("request_id", getRequestId(act.Id, "active")); //流水号
  217. dataContent.Add("activation_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  218. dataContent.Add("brand", int.Parse(function.CheckInt(act.ProductType))); //品牌
  219. Push("active", dataContent);
  220. }
  221. catch (Exception ex)
  222. {
  223. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送激活数据异常");
  224. }
  225. }
  226. //交易数据
  227. public static void Trade(TradeRecord trade)
  228. {
  229. try
  230. {
  231. int QrPayFlag = 0;
  232. int BankCardType = 1;
  233. string FeeRate = function.CheckNum(trade.ErrorCode);
  234. string FeeAmt = function.CheckNum(trade.ErrorMsg);
  235. List<string> BrandIds = new List<string>();
  236. decimal TradeAmount = trade.TradeAmount;
  237. BrandIds.Add("1");
  238. BrandIds.Add("4");
  239. BrandIds.Add("6");
  240. BrandIds.Add("7");
  241. BrandIds.Add("8");
  242. BrandIds.Add("9");
  243. BrandIds.Add("15");
  244. BrandIds.Add("22");
  245. BrandIds.Add("27");
  246. BrandIds.Add("30");
  247. if(BrandIds.Contains(trade.ProductType))
  248. {
  249. TradeAmount = TradeAmount / 100;
  250. }
  251. if (trade.ProductType == "1" || trade.ProductType == "27")
  252. {
  253. if (trade.TradeType == "02") QrPayFlag = 1;
  254. BankCardType = int.Parse(trade.BankCardType);
  255. decimal feeRateStr = decimal.Parse(FeeRate) * 100;
  256. FeeRate = feeRateStr.ToString().TrimEnd('0');
  257. if(FeeRate != "0") FeeRate = FeeRate.TrimEnd('0');
  258. if(FeeAmt != "0" && !string.IsNullOrEmpty(FeeAmt)) FeeAmt = FeeAmt.TrimEnd('0');
  259. }
  260. else if (trade.ProductType == "2")
  261. {
  262. if (trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
  263. if (trade.TradeType == "CREDIT_BY_CARD")
  264. {
  265. BankCardType = 1;
  266. }
  267. else
  268. {
  269. BankCardType = 0;
  270. }
  271. FeeRate = FeeRate.Replace("0.00", "0.");
  272. }
  273. else if (trade.ProductType == "4")
  274. {
  275. if (trade.TradeType == "200") QrPayFlag = 1;
  276. if (trade.BankCardType == "100")
  277. {
  278. BankCardType = 1;
  279. }
  280. else if (trade.BankCardType == "200")
  281. {
  282. BankCardType = 0;
  283. }
  284. decimal feeRateStr = decimal.Parse(FeeRate) / 10000;
  285. FeeRate = feeRateStr.ToString().TrimEnd('0');
  286. if(FeeRate != "0") FeeRate = FeeRate.TrimEnd('0');
  287. if(FeeAmt != "0" && !string.IsNullOrEmpty(FeeAmt)) FeeAmt = FeeAmt.TrimEnd('0');
  288. }
  289. else if (trade.ProductType == "6")
  290. {
  291. if (trade.BankCardType == "02" || trade.BankCardType == "12")
  292. {
  293. BankCardType = 1;
  294. }
  295. else
  296. {
  297. BankCardType = 0;
  298. }
  299. }
  300. else if (trade.ProductType == "7")
  301. {
  302. if (trade.BankCardType == "OA" || trade.BankCardType == "CC" || trade.BankCardType == "SCC")
  303. {
  304. BankCardType = 1;
  305. }
  306. else
  307. {
  308. BankCardType = 0;
  309. }
  310. }
  311. else if (trade.ProductType == "8" || trade.ProductType == "9")
  312. {
  313. if (trade.TradeType == "200") QrPayFlag = 1;
  314. if (trade.BankCardType == "100")
  315. {
  316. BankCardType = 1;
  317. }
  318. else if (trade.BankCardType == "200")
  319. {
  320. BankCardType = 0;
  321. }
  322. decimal feeRateStr = decimal.Parse(FeeRate) / 10000;
  323. FeeRate = feeRateStr.ToString().TrimEnd('0');
  324. if(FeeRate != "0") FeeRate = FeeRate.TrimEnd('0');
  325. if(FeeAmt != "0" && !string.IsNullOrEmpty(FeeAmt)) FeeAmt = FeeAmt.TrimEnd('0');
  326. }
  327. else if (trade.ProductType == "10" || trade.ProductType == "11")
  328. {
  329. if (trade.TradeType == "F010") QrPayFlag = 1;
  330. if (trade.BankCardType == "01")
  331. {
  332. BankCardType = 1;
  333. }
  334. else if (trade.BankCardType == "00")
  335. {
  336. BankCardType = 0;
  337. }
  338. FeeRate = FeeRate.Replace("0.00", "0.");
  339. }
  340. else if (trade.ProductType == "12") //盒易付
  341. {
  342. if (trade.Field3 == "1") QrPayFlag = 1;
  343. if (trade.BankCardType == "C")
  344. {
  345. BankCardType = 1;
  346. }
  347. else if (trade.BankCardType == "D")
  348. {
  349. BankCardType = 0;
  350. }
  351. }
  352. else if (trade.ProductType == "15")
  353. {
  354. if (trade.BankCardType == "02")
  355. {
  356. BankCardType = 1;
  357. }
  358. else
  359. {
  360. BankCardType = 0;
  361. }
  362. if(FeeAmt != "0") FeeAmt = FeeAmt.TrimEnd('0');
  363. }
  364. else if (Utils.Instance.IsWifi(int.Parse(trade.ProductType)))
  365. {
  366. FeeRate = "0.60";
  367. FeeAmt = trade.ErrorMsg;
  368. }
  369. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  370. dataContent.Add("pos_sn", trade.TradeSnNo); //机具sn
  371. dataContent.Add("mer_no", trade.MerNo); //商户号
  372. dataContent.Add("request_id", trade.TradeSerialNo); //流水号
  373. dataContent.Add("trade_amount", TradeAmount); //交易金额
  374. dataContent.Add("trade_time", trade.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  375. dataContent.Add("brand", int.Parse(function.CheckInt(trade.ProductType))); //品牌
  376. dataContent.Add("card_type", BankCardType); //卡类型
  377. dataContent.Add("qr_pay_flag", QrPayFlag); //云闪付标记
  378. dataContent.Add("fee_rate", FeeRate); //费率
  379. dataContent.Add("fee_amt", FeeAmt); //秒到费
  380. if(trade.ProductType == "14")
  381. {
  382. dataContent.Add("is_first", 1);
  383. }
  384. if(trade.ProductType == "23" || trade.ProductType == "24" || trade.ProductType == "25" || trade.ProductType == "26" || trade.ProductType == "32")
  385. {
  386. dataContent.Add("ext_field", trade.ChannelSerial);
  387. }
  388. Push("trade", dataContent);
  389. }
  390. catch (Exception ex)
  391. {
  392. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送交易数据异常");
  393. }
  394. }
  395. public static void Push(string dataType, Dictionary<string, object> dataContent)
  396. {
  397. Dictionary<string, object> data = new Dictionary<string, object>();
  398. data.Add("data_type", dataType);
  399. data.Add("data_content", dataContent);
  400. // if(RedisDbconn.Instance.Get<string>("KxsPosDataQueueStatus") == "1")
  401. // {
  402. // RedisDbconn.Instance.AddList("KxsPosDataQueue", Newtonsoft.Json.JsonConvert.SerializeObject(data));
  403. // }
  404. PosPushHelper.Instance.DoSomeThing(Newtonsoft.Json.JsonConvert.SerializeObject(data));
  405. }
  406. public static string getRequestId(int id, string type)
  407. {
  408. if(id > 0)
  409. {
  410. return function.MD5_32(id.ToString() + type);
  411. }
  412. return DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  413. }
  414. public static string getRequestId(string str, string type)
  415. {
  416. return function.MD5_32(str + type);
  417. }
  418. }
  419. }