PosPushDataNewHelper.cs 16 KB

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