PosPushDataNewHelper.cs 17 KB

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