PosPushDataNewHelper.cs 16 KB

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