PublicChangePosFee.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using System.Text.RegularExpressions;
  6. using MySystem.Models;
  7. using Library;
  8. using NPOI.SS.UserModel;
  9. using NPOI.XSSF.UserModel;
  10. using Microsoft.AspNetCore.Mvc;
  11. using System.IO;
  12. using LitJson;
  13. /// <summary>
  14. /// 设置机具服务费
  15. /// </summary>
  16. namespace MySystem
  17. {
  18. public class PublicChangePosFee
  19. {
  20. public static WebCMSEntities db = new WebCMSEntities();
  21. #region 金控-设置押金
  22. public static string SetJKDeposit(string SnIds,string DepositId)
  23. {
  24. // string DepositId = "299";
  25. string check = RedisDbconn.Instance.Get<string>("SetJKPosDepositWait:" + SnIds);
  26. if (!string.IsNullOrEmpty(check))
  27. {
  28. return "操作频繁,请稍后再试";
  29. }
  30. RedisDbconn.Instance.Set("SetJKPosDepositWait:" + SnIds, SnIds);
  31. RedisDbconn.Instance.SetExpire("SetJKPosDepositWait:" + SnIds, 10);
  32. Dictionary<string, object> Obj = new Dictionary<string, object>();
  33. string[] SnIdList = SnIds.Split(',');
  34. foreach (string SnId in SnIdList)
  35. {
  36. int SnIdNum = int.Parse(SnId);
  37. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum && m.BindingState == 0 && (string.IsNullOrEmpty(m.SeoKeyword) || m.SeoKeyword == "0"));
  38. if (pos == null)
  39. {
  40. return "机具" + pos.PosSn + "已设置押金,请勿重复设置";
  41. }
  42. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + DepositId, "金控-设置押金-返回报文");
  43. string content = function.GetWebRequest("http://sp.kexiaoshuang.com/api/test/SetDeposit?sn=" + pos.PosSn + "&num=" + DepositId);
  44. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "金控-设置押金-返回报文");
  45. if (content == "fail")
  46. {
  47. return "机具" + pos.PosSn + "设置失败";
  48. }
  49. JsonData jsonObj = JsonMapper.ToObject(content);
  50. if (jsonObj["code"].ToString() != "000000")
  51. {
  52. return jsonObj["message"].ToString();
  53. }
  54. content = jsonObj["data"].ToString();
  55. content = PublicImportDataService.Instance.Decrypt(content);
  56. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "金控-设置押金-返回报文");
  57. JsonData contentObj = JsonMapper.ToObject(content);
  58. if (contentObj["respCode"].ToString() != "00")
  59. {
  60. return contentObj["respMsg"].ToString();
  61. }
  62. var BeforeDeposit = 0;
  63. if (string.IsNullOrEmpty(pos.PrizeParams))
  64. {
  65. BeforeDeposit = 299;
  66. }
  67. else
  68. {
  69. BeforeDeposit = int.Parse(pos.PrizeParams);
  70. }
  71. decimal amount = decimal.Parse(DepositId);
  72. pos.PrizeParams = amount.ToString("f0");
  73. db.SaveChanges();
  74. }
  75. return "设置成功";
  76. }
  77. #endregion
  78. #region 开店宝-设置押金
  79. public static string SetKDBDeposit(string SnIds,string DepositId)
  80. {
  81. // string DepositId = "473";
  82. string check = RedisDbconn.Instance.Get<string>("SetKDBPosDepositWait:" + SnIds);
  83. if (!string.IsNullOrEmpty(check))
  84. {
  85. return "操作频繁,请稍后再试";
  86. }
  87. RedisDbconn.Instance.Set("SetKDBPosDepositWait:" + SnIds, SnIds);
  88. RedisDbconn.Instance.SetExpire("SetKDBPosDepositWait:" + SnIds, 10);
  89. string[] SnIdList = SnIds.Split(',');
  90. foreach (string SnId in SnIdList)
  91. {
  92. int SnIdNum = int.Parse(SnId);
  93. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum && m.BindingState == 0 && (string.IsNullOrEmpty(m.SeoKeyword) || m.SeoKeyword == "0"));
  94. if (pos == null)
  95. {
  96. return "机具" + pos.PosSn + "已设置押金,请勿重复设置";
  97. }
  98. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + DepositId, "开店宝-设置押金-返回报文");
  99. string content = PublicImportDataService.Instance.ModifyDeposit(pos.PosSn, DepositId);
  100. if (content == "fail")
  101. {
  102. return "机具" + pos.PosSn + "设置失败";
  103. }
  104. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "开店宝-设置押金-返回报文");
  105. var BeforeDeposit = 0;
  106. if (string.IsNullOrEmpty(pos.PrizeParams))
  107. {
  108. BeforeDeposit = 299;
  109. }
  110. else
  111. {
  112. BeforeDeposit = int.Parse(pos.PrizeParams);
  113. }
  114. decimal amount = decimal.Parse(PublicImportDataService.Instance.GetDepositAmount(DepositId));
  115. pos.PrizeParams = amount.ToString("f0");
  116. db.SaveChanges();
  117. }
  118. return "设置成功";
  119. }
  120. #endregion
  121. #region 乐刷-设置押金
  122. public static string SetLSDeposit(string SnIds,string DepositId)
  123. {
  124. // string DepositId = "300";
  125. string check = RedisDbconn.Instance.Get<string>("SetLSPosDepositWait:" + SnIds);
  126. if (!string.IsNullOrEmpty(check))
  127. {
  128. return "操作频繁,请稍后再试";
  129. }
  130. RedisDbconn.Instance.Set("SetLSPosDepositWait:" + SnIds, SnIds);
  131. RedisDbconn.Instance.SetExpire("SetLSPosDepositWait:" + SnIds, 10);
  132. Dictionary<string, object> Obj = new Dictionary<string, object>();
  133. string[] SnIdList = SnIds.Split(',');
  134. foreach (string SnId in SnIdList)
  135. {
  136. int SnIdNum = int.Parse(SnId);
  137. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum && m.BindingState == 0 && (string.IsNullOrEmpty(m.SeoKeyword) || m.SeoKeyword == "0"));
  138. if (pos == null)
  139. {
  140. return "机具" + pos.PosSn + "已设置押金,请勿重复设置";
  141. }
  142. string OldId = "", NewId = "";
  143. if (DepositId == "100")
  144. {
  145. NewId = "704067039039856640";
  146. }
  147. else if (DepositId == "200")
  148. {
  149. NewId = "709820183485095936";
  150. }
  151. else if (DepositId == "300")
  152. {
  153. NewId = "709820390742437888";
  154. }
  155. string content = PublicImportDataService.Instance.QueryActiveForConfig(pos.PosSn, pos.BrandId);
  156. JsonData jsonObj = JsonMapper.ToObject(content);
  157. if (jsonObj["code"].ToString() == "0")
  158. {
  159. OldId = jsonObj["data"]["posMarket"]["id"].ToString();
  160. }
  161. jsonObj = JsonMapper.ToObject(content);
  162. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + OldId + ":" + NewId, "乐刷-设置押金-返回报文");
  163. content = PublicImportDataService.Instance.SetDepositForLS(pos.PosSn, OldId, NewId, pos.BrandId);
  164. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "乐刷-设置押金-返回报文");
  165. if (content == "fail")
  166. {
  167. return "机具" + pos.PosSn + "设置失败";
  168. }
  169. jsonObj = JsonMapper.ToObject(content);
  170. if (jsonObj["code"].ToString() != "0")
  171. {
  172. return jsonObj["msg"].ToString();
  173. }
  174. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "乐刷-设置押金-返回报文");
  175. var BeforeDeposit = 0;
  176. if (string.IsNullOrEmpty(pos.PrizeParams))
  177. {
  178. BeforeDeposit = 299;
  179. }
  180. else
  181. {
  182. BeforeDeposit = int.Parse(pos.PrizeParams);
  183. }
  184. decimal amount = decimal.Parse(DepositId);
  185. if (pos.BrandId == 4 || pos.BrandId == 5)
  186. {
  187. amount -= 1;
  188. }
  189. pos.PrizeParams = amount.ToString("f0");
  190. db.SaveChanges();
  191. }
  192. return "设置成功";
  193. }
  194. #endregion
  195. #region 立刷-设置押金
  196. public static string SetLISDeposit(string SnIds,string DepositId)
  197. {
  198. // string DepositId = "249";
  199. string check = RedisDbconn.Instance.Get<string>("SetLISPosDepositWait:" + SnIds);
  200. if (!string.IsNullOrEmpty(check))
  201. {
  202. return "操作频繁,请稍后再试";
  203. }
  204. RedisDbconn.Instance.Set("SetLISPosDepositWait:" + SnIds, SnIds);
  205. RedisDbconn.Instance.SetExpire("SetLISPosDepositWait:" + SnIds, 10);
  206. Dictionary<string, object> Obj = new Dictionary<string, object>();
  207. string[] SnIdList = SnIds.Split(',');
  208. foreach (string SnId in SnIdList)
  209. {
  210. int SnIdNum = int.Parse(SnId);
  211. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum && m.BindingState == 0 && (string.IsNullOrEmpty(m.SeoKeyword) || m.SeoKeyword == "0"));
  212. if (pos == null)
  213. {
  214. return "机具" + pos.PosSn + "已设置押金,请勿重复设置";
  215. }
  216. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + DepositId, "立刷-设置押金-返回报文");
  217. string content = PublicImportDataService.Instance.SetLiSDeposit(pos.PosSn, int.Parse(DepositId));
  218. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "立刷-设置押金-返回报文");
  219. JsonData jsonObj = JsonMapper.ToObject(content);
  220. if (jsonObj["ret_code"].ToString() != "00")
  221. {
  222. return jsonObj["ret_msg"].ToString();
  223. }
  224. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "立刷-设置押金-返回报文");
  225. var BeforeDeposit = 0;
  226. if (string.IsNullOrEmpty(pos.PrizeParams))
  227. {
  228. if (RelationClass.GetKqProductBrandInfo(pos.BrandId) == "立刷云电签")
  229. {
  230. BeforeDeposit = 249;
  231. }
  232. else
  233. {
  234. BeforeDeposit = 299;
  235. }
  236. }
  237. else
  238. {
  239. BeforeDeposit = int.Parse(pos.PrizeParams);
  240. }
  241. pos.PrizeParams = DepositId;
  242. db.SaveChanges();
  243. }
  244. return "设置成功";
  245. }
  246. #endregion
  247. #region 盛付通-设置押金
  248. public static string SetSFTDeposit(string SnIds,string DepositId)
  249. {
  250. // string DepositId = "2021POS299";
  251. string check = RedisDbconn.Instance.Get<string>("SetSFTPosDepositWait:" + SnIds);
  252. if (!string.IsNullOrEmpty(check))
  253. {
  254. return "操作频繁,请稍后再试";
  255. }
  256. RedisDbconn.Instance.Set("SetSFTPosDepositWait:" + SnIds, SnIds);
  257. RedisDbconn.Instance.SetExpire("SetSFTPosDepositWait:" + SnIds, 10);
  258. Dictionary<string, object> Obj = new Dictionary<string, object>();
  259. string[] SnIdList = SnIds.Split(',');
  260. foreach (string SnId in SnIdList)
  261. {
  262. int SnIdNum = int.Parse(SnId);
  263. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum && m.BindingState == 0 && (string.IsNullOrEmpty(m.SeoKeyword) || m.SeoKeyword == "0"));
  264. if (pos == null)
  265. {
  266. return "机具" + pos.PosSn + "已设置押金,请勿重复设置";
  267. }
  268. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + DepositId, "盛付通-设置押金-返回报文");
  269. string content = PublicImportDataService.Instance.SetDepositForSft(pos.PosSn, DepositId);
  270. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "盛付通-设置押金-返回报文");
  271. JsonData jsonObj = JsonMapper.ToObject(content);
  272. if (jsonObj["respCode"].ToString() != "00")
  273. {
  274. return jsonObj["errorMsg"].ToString();
  275. }
  276. var BeforeDeposit = 0;
  277. if (string.IsNullOrEmpty(pos.PrizeParams))
  278. {
  279. BeforeDeposit = 299;
  280. }
  281. else
  282. {
  283. BeforeDeposit = int.Parse(pos.PrizeParams);
  284. }
  285. pos.PrizeParams = DepositId.Replace("2021POS", "");
  286. db.SaveChanges();
  287. }
  288. return "设置成功";
  289. }
  290. #endregion
  291. #region 海科-设置押金
  292. public static string SetHKDeposit(string SnIds,string DepositId)
  293. {
  294. // string DepositId = "300";
  295. string check = RedisDbconn.Instance.Get<string>("SetHKPosDepositWait:" + SnIds);
  296. if (!string.IsNullOrEmpty(check))
  297. {
  298. return "操作频繁,请稍后再试";
  299. }
  300. RedisDbconn.Instance.Set("SetHKPosDepositWait:" + SnIds, SnIds);
  301. RedisDbconn.Instance.SetExpire("SetHkPosDepositWait:" + SnIds, 10);
  302. Dictionary<string, object> Obj = new Dictionary<string, object>();
  303. string[] SnIdList = SnIds.Split(',');
  304. foreach (string SnId in SnIdList)
  305. {
  306. int SnIdNum = int.Parse(SnId);
  307. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum && m.BindingState == 0 && (string.IsNullOrEmpty(m.SeoKeyword) || m.SeoKeyword == "0"));
  308. if (pos == null)
  309. {
  310. return "机具" + pos.PosSn + "已设置押金,请勿重复设置";
  311. }
  312. string OldId = "", NewId = "";
  313. if (DepositId == "100")
  314. {
  315. NewId = pos.BrandId == 8 ? "202207011718129" : "202207011718197";
  316. }
  317. else if (DepositId == "200")
  318. {
  319. NewId = pos.BrandId == 8 ? "747200504467566592" : "747199934126108672";
  320. }
  321. else if (DepositId == "300")
  322. {
  323. NewId = pos.BrandId == 8 ? "747193472108732416" : "747193820156276736";
  324. }
  325. string content = PublicImportDataService.Instance.QueryActiveForConfigHK(pos.PosSn, pos.BrandId);
  326. JsonData jsonObj = JsonMapper.ToObject(content);
  327. if (jsonObj["code"].ToString() == "0")
  328. {
  329. OldId = jsonObj["data"]["posMarket"]["id"].ToString();
  330. }
  331. jsonObj = JsonMapper.ToObject(content);
  332. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + OldId + ":" + NewId, "海科-设置押金-返回报文");
  333. content = PublicImportDataService.Instance.SetDepositForHK(pos.PosSn, OldId, NewId, pos.BrandId);
  334. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "海科-设置押金-返回报文");
  335. if (content == "fail")
  336. {
  337. return "机具" + pos.PosSn + "设置失败";
  338. }
  339. jsonObj = JsonMapper.ToObject(content);
  340. if (jsonObj["code"].ToString() != "0")
  341. {
  342. return jsonObj["msg"].ToString();
  343. }
  344. decimal amount = decimal.Parse(DepositId);
  345. var BeforeDeposit = 0;
  346. if (string.IsNullOrEmpty(pos.PrizeParams))
  347. {
  348. BeforeDeposit = 299;
  349. }
  350. else
  351. {
  352. BeforeDeposit = int.Parse(pos.PrizeParams);
  353. }
  354. if (pos.BrandId == 8 || pos.BrandId == 9)
  355. {
  356. amount -= 1;
  357. }
  358. pos.PrizeParams = amount.ToString("f0");
  359. db.SaveChanges();
  360. }
  361. return "设置成功";
  362. }
  363. #endregion
  364. #region 联动-设置押金
  365. public static string SetLDDeposit(string SnIds,string DepositId)
  366. {
  367. // string DepositId = "299";
  368. string check = RedisDbconn.Instance.Get<string>("SetLDPosDepositWait:" + SnIds);
  369. if (!string.IsNullOrEmpty(check))
  370. {
  371. return "操作频繁,请稍后再试";
  372. }
  373. RedisDbconn.Instance.Set("SetLDPosDepositWait:" + SnIds, SnIds);
  374. RedisDbconn.Instance.SetExpire("SetLDPosDepositWait:" + SnIds, 10);
  375. Dictionary<string, object> Obj = new Dictionary<string, object>();
  376. string[] SnIdList = SnIds.Split(',');
  377. foreach (string SnId in SnIdList)
  378. {
  379. int SnIdNum = int.Parse(SnId);
  380. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum && m.BindingState == 0 && (string.IsNullOrEmpty(m.SeoKeyword) || m.SeoKeyword == "0"));
  381. if (pos == null)
  382. {
  383. return "机具" + pos.PosSn + "已设置押金,请勿重复设置";
  384. }
  385. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + DepositId, "联动-设置押金-返回报文");
  386. string content = PublicImportDataService.Instance.LDServiceFee(pos.PosSn, int.Parse(DepositId), pos.BrandId);
  387. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "联动-设置押金-返回报文");
  388. JsonData jsonObj = JsonMapper.ToObject(content);
  389. if (jsonObj["code"].ToString() != "000000")
  390. {
  391. return jsonObj["msg"].ToString();
  392. }
  393. var BeforeDeposit = 0;
  394. if (string.IsNullOrEmpty(pos.PrizeParams))
  395. {
  396. BeforeDeposit = 299;
  397. }
  398. else
  399. {
  400. BeforeDeposit = int.Parse(pos.PrizeParams);
  401. }
  402. decimal amount = decimal.Parse(DepositId);
  403. pos.PrizeParams = amount.ToString("f0");
  404. db.SaveChanges();
  405. }
  406. return "设置成功";
  407. }
  408. #endregion
  409. #region 盒易付-设置押金
  410. public static string SetHYFDeposit(string SnIds,string DepositId)
  411. {
  412. // string DepositId = "299";
  413. string check = RedisDbconn.Instance.Get<string>("SetHYFPosDepositWait:" + SnIds);
  414. if (!string.IsNullOrEmpty(check))
  415. {
  416. return "操作频繁,请稍后再试";
  417. }
  418. RedisDbconn.Instance.Set("SetHYFPosDepositWait:" + SnIds, SnIds);
  419. RedisDbconn.Instance.SetExpire("SetHYFPosDepositWait:" + SnIds, 10);
  420. Dictionary<string, object> Obj = new Dictionary<string, object>();
  421. string[] SnIdList = SnIds.Split(',');
  422. foreach (string SnId in SnIdList)
  423. {
  424. int SnIdNum = int.Parse(SnId);
  425. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum && m.BindingState == 0 && (string.IsNullOrEmpty(m.SeoKeyword) || m.SeoKeyword == "0"));
  426. if (pos == null)
  427. {
  428. return "机具" + pos.PosSn + "已设置押金,请勿重复设置";
  429. }
  430. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + DepositId, "盒易付-设置押金-返回报文");
  431. string content = PublicImportDataService.Instance.BoxServiceFee(pos.PosSn, DepositId);
  432. function.WriteLog(DateTime.Now.ToString() + "\n" + content, "盒易付-设置押金-返回报文");
  433. if (content == "fail")
  434. {
  435. return "机具" + pos.PosSn + "设置失败";
  436. }
  437. JsonData jsonObj = JsonMapper.ToObject(content);
  438. if (jsonObj["resultCode"].ToString() != "1")
  439. {
  440. return jsonObj["errorDesc"].ToString();
  441. }
  442. var BeforeDeposit = 0;
  443. if (string.IsNullOrEmpty(pos.PrizeParams))
  444. {
  445. BeforeDeposit = 299;
  446. }
  447. else
  448. {
  449. BeforeDeposit = int.Parse(pos.PrizeParams);
  450. }
  451. decimal amount = decimal.Parse(DepositId);
  452. pos.PrizeParams = amount.ToString("f0");
  453. db.SaveChanges();
  454. }
  455. return "设置成功";
  456. }
  457. #endregion
  458. }
  459. }