PosPushDataNewHelper.cs 21 KB

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