PosPushDataNewHelper.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. List<string> BrandIds = new List<string>();
  189. decimal TradeAmount = trade.TradeAmount;
  190. BrandIds.Add("1");
  191. BrandIds.Add("4");
  192. BrandIds.Add("6");
  193. BrandIds.Add("7");
  194. BrandIds.Add("8");
  195. BrandIds.Add("9");
  196. BrandIds.Add("15");
  197. BrandIds.Add("22");
  198. BrandIds.Add("27");
  199. BrandIds.Add("30");
  200. if(BrandIds.Contains(trade.ProductType))
  201. {
  202. TradeAmount = TradeAmount / 100;
  203. }
  204. if (trade.ProductType == "1")
  205. {
  206. if (trade.TradeType == "02") QrPayFlag = 1;
  207. BankCardType = int.Parse(trade.BankCardType);
  208. }
  209. else if (trade.ProductType == "2")
  210. {
  211. if (trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
  212. if (trade.TradeType == "CREDIT_BY_CARD")
  213. {
  214. BankCardType = 1;
  215. }
  216. else
  217. {
  218. BankCardType = 0;
  219. }
  220. }
  221. else if (trade.ProductType == "4")
  222. {
  223. if (trade.TradeType == "200") QrPayFlag = 1;
  224. if (trade.BankCardType == "100")
  225. {
  226. BankCardType = 1;
  227. }
  228. else if (trade.BankCardType == "200")
  229. {
  230. BankCardType = 0;
  231. }
  232. }
  233. else if (trade.ProductType == "6")
  234. {
  235. if (trade.BankCardType == "02" || trade.BankCardType == "12")
  236. {
  237. BankCardType = 1;
  238. }
  239. else
  240. {
  241. BankCardType = 0;
  242. }
  243. }
  244. else if (trade.ProductType == "7")
  245. {
  246. if (trade.BankCardType == "OA" || trade.BankCardType == "CC" || trade.BankCardType == "SCC")
  247. {
  248. BankCardType = 1;
  249. }
  250. else
  251. {
  252. BankCardType = 0;
  253. }
  254. }
  255. else if (trade.ProductType == "8" || trade.ProductType == "9")
  256. {
  257. if (trade.TradeType == "200") QrPayFlag = 1;
  258. if (trade.BankCardType == "100")
  259. {
  260. BankCardType = 1;
  261. }
  262. else if (trade.BankCardType == "200")
  263. {
  264. BankCardType = 0;
  265. }
  266. }
  267. else if (trade.ProductType == "10" || trade.ProductType == "11")
  268. {
  269. if (trade.TradeType == "F010") QrPayFlag = 1;
  270. if (trade.BankCardType == "01")
  271. {
  272. BankCardType = 1;
  273. }
  274. else if (trade.BankCardType == "00")
  275. {
  276. BankCardType = 0;
  277. }
  278. }
  279. else if (trade.ProductType == "12") //盒易付
  280. {
  281. if (trade.Field3 == "1") QrPayFlag = 1;
  282. if (trade.BankCardType == "C")
  283. {
  284. BankCardType = 1;
  285. }
  286. else if (trade.BankCardType == "D")
  287. {
  288. BankCardType = 0;
  289. }
  290. }
  291. else if (trade.ProductType == "15")
  292. {
  293. if (trade.BankCardType == "02")
  294. {
  295. BankCardType = 1;
  296. }
  297. else
  298. {
  299. BankCardType = 0;
  300. }
  301. }
  302. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  303. dataContent.Add("pos_sn", trade.TradeSnNo); //机具sn
  304. dataContent.Add("mer_no", trade.MerNo); //商户号
  305. dataContent.Add("request_id", trade.TradeSerialNo); //流水号
  306. dataContent.Add("trade_amount", TradeAmount); //交易金额
  307. dataContent.Add("trade_time", trade.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  308. dataContent.Add("brand", int.Parse(function.CheckInt(trade.ProductType))); //品牌
  309. dataContent.Add("card_type", BankCardType); //卡类型
  310. dataContent.Add("qr_pay_flag", QrPayFlag); //云闪付标记
  311. Push("trade", dataContent);
  312. }
  313. catch (Exception ex)
  314. {
  315. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送交易数据异常");
  316. }
  317. }
  318. public static void Push(string dataType, Dictionary<string, object> dataContent)
  319. {
  320. Dictionary<string, object> data = new Dictionary<string, object>();
  321. data.Add("data_type", dataType);
  322. data.Add("data_content", dataContent);
  323. RedisDbconn.Instance.AddList("KxsPosDataQueue", Newtonsoft.Json.JsonConvert.SerializeObject(data));
  324. }
  325. public static string getRequestId(int id, string type)
  326. {
  327. if(id > 0)
  328. {
  329. return function.MD5_32(id.ToString() + type);
  330. }
  331. return DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  332. }
  333. }
  334. }