PosPushDataNewHelper.cs 16 KB

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