PosPushDataNewHelper.cs 27 KB

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