HomeController.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Data;
  6. using System.Threading.Tasks;
  7. using Microsoft.AspNetCore.Mvc;
  8. using Microsoft.Extensions.Logging;
  9. using MySystem.PxcModels;
  10. using System.Threading;
  11. using Library;
  12. using LitJson;
  13. using System.Security.Cryptography;
  14. namespace MySystem.Controllers
  15. {
  16. public class HomeController : Controller
  17. {
  18. private readonly ILogger<HomeController> _logger;
  19. public HomeController(ILogger<HomeController> logger)
  20. {
  21. _logger = logger;
  22. }
  23. public IActionResult Index()
  24. {
  25. return View();
  26. }
  27. public IActionResult Error()
  28. {
  29. string isapi = Request.Headers["Api"].ToString();
  30. if (isapi != "1")
  31. {
  32. if (Response.StatusCode == 500)
  33. {
  34. return Redirect("/public/errpage/pc/500.html");
  35. }
  36. else if (Response.StatusCode == 502)
  37. {
  38. return Redirect("/public/errpage/pc/502.html");
  39. }
  40. else if (Response.StatusCode == 404)
  41. {
  42. return Redirect("/public/errpage/pc/404.html");
  43. }
  44. }
  45. return View();
  46. }
  47. // 大盟主标记扫描
  48. public string leaderflag()
  49. {
  50. WebCMSEntities db = new WebCMSEntities();
  51. List<int> ids = new List<int>();
  52. // List<PosCouponRecord> records = db.PosCouponRecord.Where(m => m.FromUserId == 597).ToList();
  53. // foreach(PosCouponRecord record in records)
  54. // {
  55. // ids.Add(record.PosCouponId);
  56. // }
  57. ids.Add(6843);
  58. List<PosCoupons> coupons = db.PosCoupons.Where(m => ids.Contains(m.Id) && m.IsUse == 1).ToList();
  59. foreach (PosCoupons coupon in coupons)
  60. {
  61. PosSns.Add(coupon.ExchangeCode);
  62. }
  63. foreach (PosCoupons coupon in coupons)
  64. {
  65. ChildNo(db, coupon.ExchangeCode, coupon.ExchangeCode, coupon.LeaderUserId);
  66. }
  67. // db.SaveChanges();
  68. db.Dispose();
  69. return "ok";
  70. }
  71. List<string> nos = new List<string>();
  72. private void ChildNo(WebCMSEntities db, string RootCheckNo, string CheckNo, int LeaderUserId)
  73. {
  74. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(CheckNo));
  75. if(apply != null)
  76. {
  77. int len = 0;
  78. string[] SnList = apply.SwapSnExpand.TrimEnd('\n').Split('\n');
  79. foreach(string sn in SnList)
  80. {
  81. if(PosSns.Contains(sn.Split(':')[0]) || nos.Contains(sn.Split(':')[0]))
  82. {
  83. len += 1;
  84. }
  85. }
  86. Orders order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount);
  87. if(order != null)
  88. {
  89. if(!string.IsNullOrEmpty(order.SnNos))
  90. {
  91. if(order.SnNos.Contains(","))
  92. {
  93. string[] SwapSnExpands = order.SnNos.TrimEnd(',').Split(',');
  94. int index = 0;
  95. foreach(string no in SwapSnExpands)
  96. {
  97. if(!nos.Contains(no) && index < len)
  98. {
  99. index += 1;
  100. nos.Add(no);
  101. ChildNo(db, RootCheckNo, no, LeaderUserId);
  102. }
  103. }
  104. }
  105. else
  106. {
  107. string[] SwapSnExpands = order.SnNos.TrimEnd('\n').Split('\n');
  108. int index = 0;
  109. foreach(string no in SwapSnExpands)
  110. {
  111. if(!nos.Contains(no) && index < len)
  112. {
  113. index += 1;
  114. nos.Add(no);
  115. ChildNo(db, RootCheckNo, no, LeaderUserId);
  116. }
  117. }
  118. }
  119. }
  120. else
  121. {
  122. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == CheckNo) ?? new MachineForSnNo();
  123. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  124. if(pos != null)
  125. {
  126. // pos.LeaderUserId = LeaderUserId;
  127. // Utils.WriteLog(LeaderUserId + ":" + pos.PosSn + ":" + apply.SwapSnExpand.TrimEnd('\n').Split('\n').Length, "大盟主奖励标记机具");
  128. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  129. Utils.WriteLog(pos.PosSn + ":" + RootCheckNo + ":" + user.MakerCode + ":" + user.RealName, "大盟主奖励标记机具");
  130. }
  131. }
  132. }
  133. }
  134. else
  135. {
  136. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == CheckNo) ?? new MachineForSnNo();
  137. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m=>m.Id == forSnNo.SnId);
  138. if(pos != null)
  139. {
  140. // pos.LeaderUserId = LeaderUserId;
  141. // Utils.WriteLog(LeaderUserId + ":" + pos.PosSn, "大盟主奖励标记机具");
  142. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  143. Utils.WriteLog(pos.PosSn + ":" + RootCheckNo + ":" + user.MakerCode + ":" + user.RealName, "大盟主奖励标记机具");
  144. }
  145. }
  146. }
  147. List<string> PosSns = new List<string>();
  148. public string ScanNos()
  149. {
  150. PosSns = new List<string>();
  151. PosSns.Add("00005002681889125851");
  152. WebCMSEntities db = new WebCMSEntities();
  153. foreach(string PosSn in PosSns)
  154. {
  155. ChildNo(db, PosSn, PosSn, 0);
  156. }
  157. db.Dispose();
  158. return "ok";
  159. }
  160. public string test()
  161. {
  162. // for (int i = 2; i <= 6; i++)
  163. // {
  164. // PosPushDataNewHelper.Trade(new MySystem.SpModels.TradeRecord()
  165. // {
  166. // TradeSnNo = "1453432669",
  167. // MerNo = "1453432669",
  168. // TradeAmount = 9.9M,
  169. // TradeSerialNo = Guid.NewGuid().ToString(),
  170. // CreateDate = DateTime.Parse("2025-0" + i + "-01 01:00:00"),
  171. // ProductType = "23",
  172. // });
  173. // }
  174. // PosPushDataNewHelper.Trade(new MySystem.SpModels.TradeRecord()
  175. // {
  176. // ErrorCode = "0.6",
  177. // ErrorMsg = "",
  178. // TradeAmount = 1002.00M,
  179. // ProductType = "12",
  180. // TradeSnNo = "00005702880118402720",
  181. // TradeType = "0",
  182. // BankCardType = "C",
  183. // Field2 = "",
  184. // Field3 = "0",
  185. // MerNo = "039350508527759",
  186. // TradeSerialNo = "20250102H00041573514Y",
  187. // CreateDate = DateTime.Parse("2025-01-02 12:25:58"),
  188. // ChannelSerial = "",
  189. // });
  190. // PosPushDataNewHelper.Deposit(new MySystem.SpModels.ActivateRecord()
  191. // {
  192. // SeoTitle = "0.00",
  193. // ProductType = "23",
  194. // SnNo = "217F8106532",
  195. // MerNo = "217F8106532",
  196. // Id = 780709,
  197. // });
  198. // PosPushDataNewHelper.Bind(new MySystem.SpModels.Merchants()
  199. // {
  200. // ProductType = "200",
  201. // SnNo = "QR939300200002",
  202. // MerNo = "L00000000000400",
  203. // MerIdcardNo = "522121********6811",
  204. // MerName = "金银新村社区服务站",
  205. // MerMobile = "139****2383",
  206. // CreateTime = DateTime.Parse("2025-06-27 10:36:00"),
  207. // }, "33");
  208. // string FeeRate = "0.63";
  209. // string FeeAmt = "0";
  210. // Dictionary<string, string> fee = PosPushDataNewHelper.GetFee("00000602H3R000100392323", FeeRate, FeeAmt, "1");
  211. // fee = PosPushDataNewHelper.GetFee2("00000602H3R000100392323", FeeRate, FeeAmt, "1");
  212. // FeeRate = fee["FeeRate"];
  213. // FeeAmt = fee["FeeAmt"];
  214. // Dictionary<string, int> userids = new Dictionary<string, int>();
  215. // string userString = function.ReadInstance("tmpdata/2.txt");
  216. // string[] user = userString.Split('\n');
  217. // foreach (string item in user)
  218. // {
  219. // string[] userInfo = item.Split('|');
  220. // userids.Add(userInfo[0], int.Parse(userInfo[1]));
  221. // }
  222. string content = function.ReadInstance("tmpdata/1.txt");
  223. string[] list = content.Split('\n');
  224. foreach(string line in list)
  225. {
  226. string[] lineData = line.Split('|');
  227. string SnNo = lineData[0];
  228. string PrizeKind = "995";
  229. // decimal PrizeAmt = decimal.Parse(function.CheckNum(lineData[2]));
  230. int BrandId = int.Parse(function.CheckInt(lineData[2]));
  231. int UserId = int.Parse(function.CheckInt(lineData[1]));
  232. Dictionary<string, object> prizeData = new Dictionary<string, object>();
  233. prizeData.Add("brand_id", BrandId);
  234. prizeData.Add("ext_field", PrizeKind);
  235. prizeData.Add("pos_sn", SnNo);
  236. prizeData.Add("user_id", UserId);
  237. // prizeData.Add("prize", PrizeAmt);
  238. string req = Newtonsoft.Json.JsonConvert.SerializeObject(prizeData);
  239. // string ids = PrizeKind == "833_02" ? "82" : "81";
  240. // function.GetWebRequest("http://logic-executor-api.kexiaoshuang.com/noauth/prize/pushbyone?n=QUEUE_KXS_HAODA_PRIZE_CONFIG_DIVISION&m=" + req + "&ids=" + ids + ",83");
  241. function.GetWebRequest("http://logic-executor-api.kexiaoshuang.com/noauth/prize/pushbyone?n=QUEUE_KXS_HAODA_PRIZE_CONFIG_DIVISION&m=" + req + "&ids=83");
  242. }
  243. return "ok";
  244. }
  245. public string setlee()
  246. {
  247. WebCMSEntities db = new WebCMSEntities();
  248. List<string> poslist = new List<string>();
  249. poslist.Add("00003102722201179816714");
  250. foreach(string PosSn in poslist)
  251. {
  252. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  253. if(pos != null)
  254. {
  255. string info = "{\"RecordId\":\"\",\"PosId\":\"" + pos.Id + "\",\"Fee\": \"0.6\",\"Kind\": \"2\",\"OpMan\": \"系统\"}";
  256. RedisDbconn.Instance.AddList("SetDepositPostQueue", info);
  257. }
  258. }
  259. db.Dispose();
  260. return "ok";
  261. }
  262. public string add()
  263. {
  264. DateTime now = DateTime.Now;
  265. WebCMSEntities db = new WebCMSEntities();
  266. List<string> poslist = new List<string>();
  267. foreach(string PosSn in poslist)
  268. {
  269. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  270. if(pos != null)
  271. {
  272. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  273. if (merchant != null)
  274. {
  275. DateTime TransferTime = pos.TransferTime == null ? DateTime.Now : pos.TransferTime.Value;
  276. //广电卡批量补盟主奖励和运营中心奖励
  277. if (pos.BrandId == 14 && pos.BuyUserId > 0 && pos.ActivationState == 1 && TransferTime < pos.BindingTime && pos.BindingTime > now.AddDays(-30) && pos.CardType > 0 && pos.CardType < 100)
  278. {
  279. if(pos.LeaderUserId > 0 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now))
  280. {
  281. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  282. }
  283. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  284. }
  285. //0押金返30的奖励批量补录
  286. // if(pos.ActivationState == 1 && (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0") && pos.CreditTrade >= 5000 && pos.CardType < 100)
  287. // {
  288. // Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  289. // if (user != null)
  290. // {
  291. // int GetUserId = user.Id;
  292. // string ParentNav = user.ParentNav;
  293. // int TopUserId = 0;
  294. // if (!string.IsNullOrEmpty(ParentNav))
  295. // {
  296. // TopUserId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  297. // }
  298. // if(pos.BindingTime.Value.AddDays(30) >= pos.ActivationTime)
  299. // {
  300. // StatService.Instance.doActiveReward(db, merchant, pos, GetUserId, ParentNav, TopUserId, 30);
  301. // if(pos.LeaderUserId > 0 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now))
  302. // {
  303. // RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  304. // }
  305. // RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  306. // }
  307. // }
  308. // }
  309. }
  310. //批量补服务费奖励
  311. // if(decimal.Parse(function.CheckNum(pos.SeoKeyword)) > 0 && pos.CardType < 100)
  312. // {
  313. // StatService.Instance.PreActPrize(db, pos, merchant, pos.SeoKeyword);
  314. // }
  315. }
  316. }
  317. db.Dispose();
  318. return "ok";
  319. }
  320. //金控自备机,补商户信息
  321. public string jkmerinfo(string sn)
  322. {
  323. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  324. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  325. var Bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == sn && m.Field1 == "解绑");
  326. if (Bind != null)
  327. {
  328. PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.MerSnNo) ?? new PxcModels.MachineForSnNo();
  329. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  330. if (pos != null)
  331. {
  332. pos.BindingState = 1;
  333. pos.BindingTime = Bind.CreateTime;
  334. pos.Status = 0;
  335. PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo);
  336. if (merFor == null)
  337. {
  338. merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
  339. {
  340. MerNo = Bind.MerNo,
  341. SnId = pos.Id,
  342. }).Entity;
  343. }
  344. else
  345. {
  346. merFor.SnId = pos.Id;
  347. }
  348. db.SaveChanges();
  349. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  350. int TopUserId = 0;
  351. if (!string.IsNullOrEmpty(user.ParentNav))
  352. {
  353. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  354. }
  355. int BrandId = pos.BrandId;
  356. PxcModels.TradeRecord trade = db.TradeRecord.FirstOrDefault(m => m.SnNo == sn) ?? new PxcModels.TradeRecord();
  357. PxcModels.PosMerchantInfo add = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == Bind.MerNo);
  358. if (add == null)
  359. {
  360. if(trade.MerchantId > 0)
  361. {
  362. add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
  363. {
  364. CreateDate = Bind.CreateTime,
  365. KqMerNo = Bind.MerNo,
  366. MerchantNo = Bind.MerNo.Length > 16 ? Bind.MerNo.Substring(0, 16) : Bind.MerNo,
  367. Id = trade.MerchantId,
  368. }).Entity;
  369. db.SaveChanges();
  370. }
  371. else
  372. {
  373. add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
  374. {
  375. CreateDate = Bind.CreateTime,
  376. KqMerNo = Bind.MerNo,
  377. MerchantNo = Bind.MerNo.Length > 16 ? Bind.MerNo.Substring(0, 16) : Bind.MerNo,
  378. }).Entity;
  379. db.SaveChanges();
  380. }
  381. }
  382. add.UpdateDate = Bind.UpdateTime;
  383. add.TopUserId = TopUserId;
  384. add.BrandId = BrandId;
  385. add.SnStoreId = pos.StoreId;
  386. add.SnType = pos.PosSnType;
  387. add.UserId = pos.UserId;
  388. add.MerStatus = 1;
  389. add.KqSnNo = Bind.MerSnNo;
  390. add.MerIdcardNo = function.CheckNull(Bind.SeoKeyword).ToUpper();
  391. add.MerRealName = Bind.MerName;
  392. add.MerchantMobile = Bind.MerNewSnNo;
  393. add.MerchantName = Bind.MerName;
  394. pos.BindMerchantId = add.Id;
  395. pos.LastMerchantId = add.Id;
  396. db.SaveChanges();
  397. RedisDbconn.Instance.AddList("DepositReturnStatQueue", add.Id.ToString());
  398. PxcModels.Users buser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new PxcModels.Users();
  399. if(buser.BusinessFlag == 1)
  400. {
  401. bool checkMer = db.BusinessPartnerMerchant.Any(m => m.MerchantId == add.Id);
  402. if(!checkMer)
  403. {
  404. PxcModels.BusinessPartnerPos bpos = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id) ?? new PxcModels.BusinessPartnerPos();
  405. db.BusinessPartnerMerchant.Add(new PxcModels.BusinessPartnerMerchant()
  406. {
  407. CreateDate = DateTime.Now,
  408. MerNo = Bind.MerNo,
  409. MerchantId = add.Id,
  410. PartnerId = bpos.PartnerId,
  411. UserId = pos.BuyUserId,
  412. });
  413. db.SaveChanges();
  414. }
  415. }
  416. }
  417. }
  418. spdb.Dispose();
  419. db.Dispose();
  420. return "ok";
  421. }
  422. public string sycnTrade(int Id)
  423. {
  424. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  425. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id);
  426. if(merchant != null)
  427. {
  428. DepositReturnStatService.Instance.DoSomething(db, merchant);
  429. }
  430. return "ok";
  431. }
  432. public string addprize()
  433. {
  434. List<int> ids = new List<int>();
  435. foreach(int id in ids)
  436. {
  437. RedisDbconn.Instance.AddList("LeaderPrizeQueue", id);
  438. }
  439. return "ok";
  440. }
  441. public string addprize2()
  442. {
  443. List<int> ids = new List<int>();
  444. foreach(int id in ids)
  445. {
  446. RedisDbconn.Instance.AddList("OperatePrizeQueue", id);
  447. }
  448. return "ok";
  449. }
  450. public string addprize3()
  451. {
  452. List<int> ids = new List<int>();
  453. foreach(int id in ids)
  454. {
  455. LeaderApplyCouponsHelper.Instance.addprize(id);
  456. }
  457. return "ok";
  458. }
  459. public string addprize4(int id)
  460. {
  461. RedisDbconn.Instance.AddList("PosCouponPrizeQueue2", id.ToString());
  462. return "ok";
  463. }
  464. public string pushwifi()
  465. {
  466. List<string> snnos = new List<string>();
  467. List<string> snnos2 = new List<string>();
  468. WebCMSEntities db = new WebCMSEntities();
  469. List<WifiTradeRecord> list = db.WifiTradeRecord.Where(m => snnos.Contains(m.SnNo) && !snnos2.Contains(m.SnNo)).ToList();
  470. foreach(WifiTradeRecord sub in list)
  471. {
  472. decimal TradeAmt = sub.TradeAmount / sub.Duration;
  473. TradeAmt = PublicFunction.NumberFormat(TradeAmt);
  474. //推送wifi交易给java
  475. PosPushDataNewHelper.Trade(new MySystem.SpModels.TradeRecord()
  476. {
  477. TradeSnNo = sub.SnNo,
  478. MerNo = sub.SnNo,
  479. TradeAmount = TradeAmt,
  480. TradeSerialNo = Guid.NewGuid().ToString(),
  481. CreateDate = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 01:00:00"),
  482. ProductType = sub.BrandId.ToString(),
  483. });
  484. }
  485. db.Dispose();
  486. return "ok";
  487. }
  488. }
  489. }