PosPushDataNewHelper.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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, string rnd = "")
  15. {
  16. try
  17. {
  18. string ProductType = mer.ProductType;
  19. if (ProductType == "30" && mer.SeoTitle == "PAPER_CODE") ProductType = "51";
  20. if(ProductType == "22")
  21. {
  22. ProductType = GetLiShuaBrand(mer.SnNo);
  23. }
  24. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  25. dataContent.Add("pos_sn", mer.SnNo); //机具sn
  26. dataContent.Add("mer_no", mer.MerNo); //商户号
  27. dataContent.Add("id_card", mer.MerIdcardNo); //商户身份证
  28. dataContent.Add("mer_name", mer.MerName); //商户姓名
  29. dataContent.Add("mer_mobile", mer.MerMobile); //商户手机号
  30. dataContent.Add("request_id", getRequestId(mer.SnNo + mer.MerNo + rnd, "bind")); //流水号
  31. dataContent.Add("bind_time", mer.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  32. dataContent.Add("brand", int.Parse(function.CheckInt(ProductType))); //品牌
  33. if(ProductType == "29")
  34. {
  35. dataContent.Add("user_id", mer.QueryCount); //创客ID
  36. }
  37. if(ProductType == "51")
  38. {
  39. Push("qr_bind", dataContent);
  40. }
  41. else
  42. {
  43. Push("bind", dataContent);
  44. }
  45. }
  46. catch (Exception ex)
  47. {
  48. Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送绑定数据异常");
  49. }
  50. }
  51. public static void Bind0(BindRecord mer)
  52. {
  53. try
  54. {
  55. if(mer.ProductType == "22")
  56. {
  57. mer.ProductType = GetLiShuaBrand(mer.MerSnNo);
  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("id_card", ""); //商户身份证
  63. dataContent.Add("mer_name", mer.MerName); //商户姓名
  64. dataContent.Add("mer_mobile", mer.MerNo); //商户手机号
  65. dataContent.Add("request_id", getRequestId(mer.Id, "bind")); //流水号
  66. dataContent.Add("bind_time", mer.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  67. dataContent.Add("brand", int.Parse(function.CheckInt(mer.ProductType))); //品牌
  68. Push("bind", dataContent);
  69. }
  70. catch (Exception ex)
  71. {
  72. Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送绑定数据异常");
  73. }
  74. }
  75. public static void Bind2(MerchantRecord mer)
  76. {
  77. try
  78. {
  79. if(mer.ProductType == "22")
  80. {
  81. mer.ProductType = GetLiShuaBrand(mer.MerSnNo);
  82. }
  83. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  84. dataContent.Add("pos_sn", mer.MerSnNo); //机具sn
  85. dataContent.Add("mer_no", mer.MerNo); //商户号
  86. dataContent.Add("id_card", mer.LegalIdCard); //商户身份证
  87. dataContent.Add("mer_name", mer.MerName); //商户姓名
  88. dataContent.Add("mer_mobile", ""); //商户手机号
  89. dataContent.Add("request_id", getRequestId(mer.Id, "merchant")); //流水号
  90. dataContent.Add("bind_time", mer.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  91. dataContent.Add("brand", int.Parse(function.CheckInt(mer.ProductType))); //品牌
  92. Push("bind", dataContent);
  93. }
  94. catch (Exception ex)
  95. {
  96. Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送绑定数据异常");
  97. }
  98. }
  99. //解绑数据
  100. public static void UnBind(UnBindRecord mer)
  101. {
  102. try
  103. {
  104. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  105. dataContent.Add("pos_sn", mer.MerSnNo); //机具sn
  106. dataContent.Add("mer_no", mer.MerNo); //商户号
  107. dataContent.Add("request_id", getRequestId(mer.Id, "unbind")); //流水号
  108. dataContent.Add("un_bind_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  109. dataContent.Add("brand", int.Parse(function.CheckInt(mer.ProductType))); //品牌
  110. Push("un_bind", dataContent);
  111. }
  112. catch (Exception ex)
  113. {
  114. Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送解绑数据异常");
  115. }
  116. }
  117. //换绑数据
  118. public static void ChangeBind(ChangeBindRecord mer)
  119. {
  120. try
  121. {
  122. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  123. dataContent.Add("request_id", getRequestId(mer.Id, "changebind")); //流水号
  124. dataContent.Add("mer_no", mer.MerNo); //商户号
  125. dataContent.Add("source_pos_sn", mer.MerSnNo); //来源机具sn
  126. dataContent.Add("source_brand", int.Parse(function.CheckInt(mer.ProductType))); //来源品牌
  127. dataContent.Add("to_pos_sn", mer.MerNewSnNo); //兑换机具sn
  128. dataContent.Add("to_brand", int.Parse(function.CheckInt(mer.ProductType))); //兑换品牌
  129. dataContent.Add("change_bind_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //换绑时间
  130. Push("change_bind", dataContent);
  131. }
  132. catch (Exception ex)
  133. {
  134. Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送换绑数据异常");
  135. }
  136. }
  137. //押金数据
  138. public static void Deposit(ActivateRecord act)
  139. {
  140. try
  141. {
  142. List<string> BrandIds = new List<string>();
  143. decimal TradeAmount = decimal.Parse(function.CheckNum(act.SeoTitle));
  144. BrandIds.Add("1");
  145. BrandIds.Add("4");
  146. BrandIds.Add("6");
  147. BrandIds.Add("8");
  148. BrandIds.Add("9");
  149. BrandIds.Add("15");
  150. BrandIds.Add("22");
  151. BrandIds.Add("27");
  152. BrandIds.Add("30");
  153. BrandIds.Add("33");
  154. if(BrandIds.Contains(act.ProductType))
  155. {
  156. TradeAmount = TradeAmount / 100;
  157. }
  158. if(act.ProductType == "22")
  159. {
  160. act.ProductType = GetLiShuaBrand(act.SnNo);
  161. }
  162. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  163. dataContent.Add("pos_sn", act.SnNo); //机具sn
  164. dataContent.Add("mer_no", act.MerNo); //商户号
  165. if(Utils.Instance.IsWifi(int.Parse(act.ProductType)) || Utils.Instance.IsHaoDa(int.Parse(act.ProductType)))
  166. {
  167. dataContent.Add("request_id", getRequestId(act.SnNo + act.MerMobile, "deposit")); //流水号
  168. }
  169. else
  170. {
  171. dataContent.Add("request_id", getRequestId(act.Id, "deposit")); //流水号
  172. }
  173. if(act.ProductType == "14")
  174. {
  175. dataContent.Add("deposit_amount", 0); //押金金额
  176. }
  177. else
  178. {
  179. dataContent.Add("deposit_amount", TradeAmount); //押金金额
  180. }
  181. dataContent.Add("trade_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  182. dataContent.Add("card_type", 1); //卡类型
  183. dataContent.Add("brand", int.Parse(function.CheckInt(act.ProductType))); //品牌
  184. if(act.ProductType == "29")
  185. {
  186. dataContent.Add("ext_field", act.Field4); //押金活动编码
  187. }
  188. else if(act.ProductType == "36")
  189. {
  190. dataContent.Add("ext_field", act.Field3); //奖励金额
  191. }
  192. else if(act.ProductType == "14" && (function.CheckNull(act.SeoKeyword).Contains("双百套餐") || act.SnNo.StartsWith("CS")))
  193. {
  194. dataContent.Add("fee_amt", TradeAmount); //秒到费
  195. }
  196. Push("deposit", dataContent);
  197. }
  198. catch (Exception ex)
  199. {
  200. Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送押金数据异常");
  201. }
  202. }
  203. public static void Deposit(TradeRecord trade)
  204. {
  205. try
  206. {
  207. List<string> BrandIds = new List<string>();
  208. decimal TradeAmount = trade.TradeAmount;
  209. BrandIds.Add("1");
  210. BrandIds.Add("4");
  211. BrandIds.Add("6");
  212. // BrandIds.Add("7");
  213. BrandIds.Add("8");
  214. BrandIds.Add("9");
  215. BrandIds.Add("15");
  216. BrandIds.Add("22");
  217. BrandIds.Add("27");
  218. BrandIds.Add("30");
  219. BrandIds.Add("33");
  220. if(BrandIds.Contains(trade.ProductType))
  221. {
  222. TradeAmount = TradeAmount / 100;
  223. }
  224. if(trade.ProductType == "22")
  225. {
  226. trade.ProductType = GetLiShuaBrand(trade.TradeSnNo);
  227. }
  228. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  229. dataContent.Add("pos_sn", trade.TradeSnNo); //机具sn
  230. dataContent.Add("mer_no", trade.MerNo); //商户号
  231. dataContent.Add("request_id", getRequestId(trade.Id, "deposit1")); //流水号
  232. dataContent.Add("deposit_amount", TradeAmount); //押金金额
  233. dataContent.Add("trade_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  234. dataContent.Add("card_type", 1); //卡类型
  235. dataContent.Add("brand", int.Parse(function.CheckInt(trade.ProductType))); //品牌
  236. Push("deposit", dataContent);
  237. }
  238. catch (Exception ex)
  239. {
  240. Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送押金数据异常");
  241. }
  242. }
  243. //激活数据
  244. public static void Active(ActivateRecord act)
  245. {
  246. try
  247. {
  248. if(act.ProductType == "22")
  249. {
  250. act.ProductType = GetLiShuaBrand(act.SnNo);
  251. }
  252. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  253. dataContent.Add("pos_sn", act.SnNo); //机具sn
  254. dataContent.Add("mobile", act.MerMobile); //商户号
  255. dataContent.Add("request_id", getRequestId(act.Id, "active")); //流水号
  256. dataContent.Add("activation_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  257. dataContent.Add("brand", int.Parse(function.CheckInt(act.ProductType))); //品牌
  258. Push("active", dataContent);
  259. }
  260. catch (Exception ex)
  261. {
  262. Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送激活数据异常");
  263. }
  264. }
  265. //交易数据
  266. public static void Trade(TradeRecord trade)
  267. {
  268. try
  269. {
  270. string ProductType = trade.ProductType;
  271. if (ProductType == "30" && trade.TradeSnNo.StartsWith("LKLYSMZCFYH")) ProductType = "51";
  272. int QrPayFlag = 0;
  273. int BankCardType = 1;
  274. string FeeRate = function.CheckNum(trade.ErrorCode);
  275. string FeeAmt = function.CheckNum(trade.ErrorMsg);
  276. if (ProductType == "51")
  277. {
  278. FeeRate = "0.63";
  279. FeeAmt = "3";
  280. }
  281. List<string> BrandIds = new List<string>();
  282. decimal TradeAmount = trade.TradeAmount;
  283. BrandIds.Add("1");
  284. BrandIds.Add("4");
  285. BrandIds.Add("6");
  286. BrandIds.Add("7");
  287. BrandIds.Add("8");
  288. BrandIds.Add("9");
  289. BrandIds.Add("15");
  290. BrandIds.Add("22");
  291. BrandIds.Add("27");
  292. BrandIds.Add("30");
  293. BrandIds.Add("33");
  294. if(BrandIds.Contains(ProductType))
  295. {
  296. TradeAmount = TradeAmount / 100;
  297. }
  298. if(ProductType == "22")
  299. {
  300. ProductType = GetLiShuaBrand(trade.TradeSnNo);
  301. }
  302. if (ProductType == "1" || ProductType == "27")
  303. {
  304. if (trade.TradeType == "02") QrPayFlag = 1;
  305. BankCardType = int.Parse(trade.BankCardType);
  306. decimal feeRateStr = decimal.Parse(FeeRate) * 100;
  307. FeeRate = feeRateStr.ToString().TrimEnd('0');
  308. if(FeeRate != "0") FeeRate = FeeRate.TrimEnd('0');
  309. if(FeeAmt != "0" && !string.IsNullOrEmpty(FeeAmt)) FeeAmt = FeeAmt.TrimEnd('0');
  310. }
  311. else if (ProductType == "2")
  312. {
  313. if (trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
  314. if (trade.TradeType == "CREDIT_BY_CARD")
  315. {
  316. BankCardType = 1;
  317. }
  318. else
  319. {
  320. BankCardType = 0;
  321. }
  322. FeeRate = FeeRate.Replace("0.00", "0.");
  323. }
  324. else if (ProductType == "4")
  325. {
  326. if (trade.TradeType == "200") QrPayFlag = 1;
  327. if (trade.BankCardType == "100")
  328. {
  329. BankCardType = 1;
  330. }
  331. else if (trade.BankCardType == "200")
  332. {
  333. BankCardType = 0;
  334. }
  335. decimal feeRateStr = decimal.Parse(FeeRate) / 10000;
  336. FeeRate = feeRateStr.ToString().TrimEnd('0');
  337. if(FeeRate != "0") FeeRate = FeeRate.TrimEnd('0');
  338. if(FeeAmt != "0" && !string.IsNullOrEmpty(FeeAmt)) FeeAmt = FeeAmt.TrimEnd('0');
  339. }
  340. else if (ProductType == "6" || ProductType == "22" || ProductType == "33")
  341. {
  342. if (trade.BankCardType == "02" || trade.BankCardType == "12" || trade.BankCardType == "30" || trade.BankCardType == "31" || trade.BankCardType == "M3" || trade.Field2 == "1517")
  343. {
  344. BankCardType = 1;
  345. }
  346. else
  347. {
  348. BankCardType = 0;
  349. }
  350. }
  351. else if (ProductType == "7")
  352. {
  353. if (trade.BankCardType == "OA" || trade.BankCardType == "CC" || trade.BankCardType == "SCC")
  354. {
  355. BankCardType = 1;
  356. }
  357. else
  358. {
  359. BankCardType = 0;
  360. }
  361. }
  362. else if (ProductType == "8" || ProductType == "9")
  363. {
  364. if (trade.TradeType == "200") QrPayFlag = 1;
  365. if (trade.BankCardType == "100")
  366. {
  367. BankCardType = 1;
  368. }
  369. else if (trade.BankCardType == "200")
  370. {
  371. BankCardType = 0;
  372. }
  373. decimal feeRateStr = decimal.Parse(FeeRate) / 10000;
  374. FeeRate = feeRateStr.ToString().TrimEnd('0');
  375. if(FeeRate != "0") FeeRate = FeeRate.TrimEnd('0');
  376. if(FeeAmt != "0" && !string.IsNullOrEmpty(FeeAmt)) FeeAmt = FeeAmt.TrimEnd('0');
  377. }
  378. else if (ProductType == "10" || ProductType == "11")
  379. {
  380. if (trade.TradeType == "F010") QrPayFlag = 1;
  381. if (trade.BankCardType == "01")
  382. {
  383. BankCardType = 1;
  384. }
  385. else if (trade.BankCardType == "00")
  386. {
  387. BankCardType = 0;
  388. }
  389. FeeRate = FeeRate.Replace("0.00", "0.");
  390. }
  391. else if (ProductType == "12") //盒易付
  392. {
  393. if (trade.Field3 == "1") QrPayFlag = 1;
  394. if (trade.BankCardType == "C" || trade.TradeType == "1" || trade.TradeType == "2" || trade.TradeType == "3")
  395. {
  396. BankCardType = 1;
  397. }
  398. else if (trade.BankCardType == "D")
  399. {
  400. BankCardType = 0;
  401. }
  402. }
  403. else if (ProductType == "15")
  404. {
  405. if (trade.BankCardType == "02")
  406. {
  407. BankCardType = 1;
  408. }
  409. else
  410. {
  411. BankCardType = 0;
  412. }
  413. if(FeeAmt != "0") FeeAmt = FeeAmt.TrimEnd('0');
  414. }
  415. else if (ProductType == "30") //拉卡拉
  416. {
  417. if (trade.BankCardType == "01" || trade.BankCardType == "61" || trade.BankCardType == "91" || trade.BankCardType == "92")
  418. {
  419. BankCardType = 1;
  420. }
  421. else
  422. {
  423. BankCardType = 0;
  424. }
  425. }
  426. else if (ProductType == "34") //联动掌中宝
  427. {
  428. if (trade.TradeType == "QuickPass") QrPayFlag = 1;
  429. if (trade.BankCardType == "CC" || trade.TradeType == "AliPay" || trade.TradeType == "Wechat")
  430. {
  431. BankCardType = 1;
  432. }
  433. else
  434. {
  435. BankCardType = 0;
  436. }
  437. }
  438. else if (Utils.Instance.IsWifi(int.Parse(ProductType)))
  439. {
  440. FeeRate = "0.60";
  441. FeeAmt = trade.ErrorMsg;
  442. }
  443. Dictionary<string, string> fee = GetFee(trade.TradeSnNo, FeeRate, FeeAmt, ProductType);
  444. FeeRate = fee["FeeRate"];
  445. FeeAmt = fee["FeeAmt"];
  446. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  447. dataContent.Add("pos_sn", trade.TradeSnNo); //机具sn
  448. dataContent.Add("mer_no", trade.MerNo); //商户号
  449. dataContent.Add("request_id", trade.TradeSerialNo); //流水号
  450. dataContent.Add("trade_amount", TradeAmount); //交易金额
  451. dataContent.Add("trade_time", trade.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  452. dataContent.Add("brand", int.Parse(function.CheckInt(ProductType))); //品牌
  453. dataContent.Add("card_type", BankCardType); //卡类型
  454. dataContent.Add("qr_pay_flag", QrPayFlag); //云闪付标记
  455. dataContent.Add("fee_rate", FeeRate); //费率
  456. dataContent.Add("fee_amt", FeeAmt); //秒到费
  457. if(ProductType == "14")
  458. {
  459. dataContent.Add("is_first", 1);
  460. }
  461. if(ProductType == "23" || ProductType == "24" || ProductType == "25" || ProductType == "26" || ProductType == "32")
  462. {
  463. dataContent.Add("ext_field", trade.ChannelSerial);
  464. }
  465. if(ProductType == "51")
  466. {
  467. Push("lkb_trade", dataContent);
  468. }
  469. else
  470. {
  471. Push("trade", dataContent);
  472. }
  473. }
  474. catch (Exception ex)
  475. {
  476. Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送交易数据异常");
  477. }
  478. }
  479. public static void Push(string dataType, Dictionary<string, object> dataContent)
  480. {
  481. Dictionary<string, object> data = new Dictionary<string, object>();
  482. data.Add("data_type", dataType);
  483. data.Add("data_content", dataContent);
  484. // if(RedisDbconn.Instance.Get<string>("KxsPosDataQueueStatus") == "1")
  485. // {
  486. // RedisDbconn.Instance.AddList("KxsPosDataQueue", Newtonsoft.Json.JsonConvert.SerializeObject(data));
  487. // }
  488. PosPushHelper.Instance.DoSomeThing(Newtonsoft.Json.JsonConvert.SerializeObject(data));
  489. }
  490. public static string getRequestId(int id, string type)
  491. {
  492. if(id > 0)
  493. {
  494. return function.MD5_32(id.ToString() + type);
  495. }
  496. return DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  497. }
  498. public static string getRequestId(string str, string type)
  499. {
  500. return function.MD5_32(str + type);
  501. }
  502. public static string GetLiShuaBrand(string PosSn)
  503. {
  504. string brand = "22";
  505. JavaProductModels.WebCMSEntities db = new JavaProductModels.WebCMSEntities();
  506. JavaProductModels.KxsMachine pos = db.KxsMachine.FirstOrDefault(m => m.PosSn == PosSn);
  507. if(pos != null)
  508. {
  509. brand = pos.BrandId.ToString();
  510. }
  511. db.Dispose();
  512. return brand;
  513. }
  514. public static Dictionary<string, string> GetFee(string PosSn, string FeeRate, string FeeAmt, string ProductType)
  515. {
  516. Dictionary<string, string> result = new Dictionary<string, string>();
  517. try
  518. {
  519. if(decimal.Parse(FeeRate) > 0.63M) FeeRate = "0.63";
  520. List<int> BrandIds = new List<int>();
  521. BrandIds.Add(7);
  522. BrandIds.Add(10);
  523. BrandIds.Add(11);
  524. BrandIds.Add(12);
  525. BrandIds.Add(13);
  526. BrandIds.Add(15);
  527. BrandIds.Add(16);
  528. BrandIds.Add(22);
  529. Utils.WriteLog("start");
  530. bool op = false;
  531. if(ProductType == "1" || ProductType == "27")
  532. {
  533. op = true;
  534. }
  535. else if(BrandIds.Contains(int.Parse(ProductType)))
  536. {
  537. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  538. op = db.TmpTradeNo.Any(m => m.RecordNo == PosSn);
  539. db.Dispose();
  540. }
  541. if(op)
  542. {
  543. PosFeeItem pos = RedisDbconn.Instance.Get<PosFeeItem>("PosFee:" + PosSn);
  544. if(pos == null)
  545. {
  546. JavaProductModels.WebCMSEntities db = new JavaProductModels.WebCMSEntities();
  547. JavaProductModels.KxsMachine p = db.KxsMachine.FirstOrDefault(m => m.PosSn == PosSn && BrandIds.Contains(m.BrandId));
  548. pos = new PosFeeItem() { PosSn = p.PosSn, FeeRate = p.MachineRatio, FeeAmt = p.SecondFee };
  549. RedisDbconn.Instance.Set("PosFee:" + PosSn, pos);
  550. db.Dispose();
  551. }
  552. if(pos != null)
  553. {
  554. result.Add("FeeRate", pos.FeeRate.ToString("f2"));
  555. result.Add("FeeAmt", pos.FeeAmt.ToString("f2"));
  556. }
  557. else
  558. {
  559. result.Add("FeeRate", FeeRate);
  560. result.Add("FeeAmt", FeeAmt);
  561. }
  562. }
  563. else
  564. {
  565. result.Add("FeeRate", FeeRate);
  566. result.Add("FeeAmt", FeeAmt);
  567. }
  568. Utils.WriteLog("end");
  569. }
  570. catch
  571. {
  572. result.Add("FeeRate", FeeRate);
  573. result.Add("FeeAmt", FeeAmt);
  574. }
  575. return result;
  576. }
  577. public static Dictionary<string, string> GetFee2(string PosSn, string FeeRate, string FeeAmt, string ProductType)
  578. {
  579. Dictionary<string, string> result = new Dictionary<string, string>();
  580. try
  581. {
  582. if(decimal.Parse(FeeRate) > 0.63M) FeeRate = "0.63";
  583. List<int> BrandIds = new List<int>();
  584. BrandIds.Add(1);
  585. BrandIds.Add(7);
  586. BrandIds.Add(10);
  587. BrandIds.Add(11);
  588. BrandIds.Add(15);
  589. BrandIds.Add(16);
  590. BrandIds.Add(27);
  591. Utils.WriteLog("start");
  592. if(BrandIds.Contains(int.Parse(ProductType)))
  593. {
  594. JavaProductModels.WebCMSEntities db = new JavaProductModels.WebCMSEntities();
  595. JavaProductModels.KxsMachine pos = db.KxsMachine.FirstOrDefault(m => m.PosSn == PosSn && BrandIds.Contains(m.BrandId));
  596. if(pos != null)
  597. {
  598. result.Add("FeeRate", pos.MachineRatio.ToString("f2"));
  599. result.Add("FeeAmt", pos.SecondFee.ToString("f2"));
  600. }
  601. else
  602. {
  603. result.Add("FeeRate", FeeRate);
  604. result.Add("FeeAmt", FeeAmt);
  605. }
  606. }
  607. else
  608. {
  609. result.Add("FeeRate", FeeRate);
  610. result.Add("FeeAmt", FeeAmt);
  611. }
  612. Utils.WriteLog("end");
  613. }
  614. catch
  615. {
  616. result.Add("FeeRate", FeeRate);
  617. result.Add("FeeAmt", FeeAmt);
  618. }
  619. return result;
  620. }
  621. }
  622. }