HomeController.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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. // Library.function.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. Library.function.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. // Library.function.WriteLog(LeaderUserId + ":" + pos.PosSn, "大盟主奖励标记机具");
  142. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  143. Library.function.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. // WebCMSEntities db = new WebCMSEntities();
  163. // AlipayPayBack2Service.Instance.DoOrderV2(db, 269424);
  164. // db.Dispose();
  165. // List<int> ids = new List<int>();
  166. // foreach(int id in ids)
  167. // {
  168. // TradeChangeService.Instance.StatTradeAmount(id, 2, 1);
  169. // }
  170. // OpModels.WebCMSEntities db = new OpModels.WebCMSEntities();
  171. // PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == "8610086012" && m.ActivationState == 0 && !string.IsNullOrEmpty(m.SeoKeyword) && m.SeoKeyword != "0" && (m.CreditTrade >= 1000 || m.BrandId == 14));
  172. // if(pos != null)
  173. // {
  174. // SycnSpTradeService.Instance.ActPos(db, pos, 0, 30);
  175. // }
  176. // AlipayPayBack2Service.Instance.OperateAmountChange(db, 392, 40000, 2, 1, "商城购机");
  177. // AlipayPayBack2Service.Instance.OperateAmountChange(db, 392, 40000, 1, 2, "商城购机");
  178. // db.Dispose();
  179. string result = "";
  180. // result += SetDepositPostService.Instance.ModifyFee("00005002681889119293", 0.0063M, "3") + "\n\n";
  181. // result += SetDepositPostService.Instance.SetFeeForSft("39103661", "0.6300", "3") + "\n\n";
  182. // Dictionary<string, string> headers = new Dictionary<string, string>();
  183. // string token = "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImQyN2E2OGY0NzY0MjRiMzJiNjhhM2JlMTc1ZjQ4OGE3In0.xjKmh1Pu9_DvwI-zpML8Z3oqKs99PQW-9aBg-ru2i-xQZYC3yKEtJ_H1_bcw2byGNnMNXMPRlBoDegLpSebXDA";
  184. // headers.Add("Authorization", "Bearer " + token);
  185. // string str = "{\"feedback_type\":\"1\",\"content\":\"电饭锅电饭锅大范甘迪\"}";
  186. // string resultJson = Encrypt(str, "CBTU1dD4Kd5pyiGWTsI10jRQ3SvKusSV", "DYgjCEIMVrj2W9xN");
  187. // string ApiResponse = function.PostWebRequest("http://47.108.118.29:8080/v1/cybmain/feedback/feedSave", resultJson, headers, "application/json");
  188. // string ApiResponse = function.GetWebRequest("http://47.108.118.29:8080/v1/cybmain/app/authorization");
  189. //{"status":1,"messge":null,"data":{"userId":1,"token":"eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImQyN2E2OGY0NzY0MjRiMzJiNjhhM2JlMTc1ZjQ4OGE3In0.xjKmh1Pu9_DvwI-zpML8Z3oqKs99PQW-9aBg-ru2i-xQZYC3yKEtJ_H1_bcw2byGNnMNXMPRlBoDegLpSebXDA","loginTime":1699331586502,"expireTime":1699417986502,"ipaddr":null,"loginLocation":null,"browser":null,"os":null,"user":null},"other":null,"code":"1","timestamp":null}
  190. // List<string> ids = new List<string>();
  191. // foreach(string id in ids)
  192. // {
  193. // RedisDbconn.Instance.AddList("OpenRewardQueue", id);
  194. // RedisDbconn.Instance.AddList("LeaderPrizeQueue", id);
  195. // RedisDbconn.Instance.AddList("OperatePrizeQueue", id);
  196. // }
  197. // DataTable dt = CustomerSqlConn.dtable("select KqMerNo from PosMerchantInfo where Id in (select BindMerchantId from PosMachinesTwo where BrandId in (12,13) and DownFeeFlag=1 and DownFeeDate>'2023-11-10 00:00:00')", MysqlConn.SqlConnStr);
  198. // foreach(DataRow dr in dt.Rows)
  199. // {
  200. // SetDepositPostService.Instance.BoxFee(dr["KqMerNo"].ToString(), "0.60");
  201. // }
  202. // DataTable dt = CustomerSqlConn.dtable("select Id,DownFeeMan from PosMachinesTwo where BrandId in (12,13) and DownFeeFlag=1 and DownFeeDate>='2023-12-01 00:00:00' order by DownFeeDate desc", MysqlConn.ReadSqlConnStr);
  203. // foreach(DataRow dr in dt.Rows)
  204. // {
  205. // RedisDbconn.Instance.AddList("SetDepositPostQueue", "{\"RecordId\":\"\",\"PosId\":\"" + dr["Id"].ToString() + "\",\"Fee\": \"0.6\",\"Kind\": \"2\",\"OpMan\": \"" + dr["DownFeeMan"].ToString() + "\"}");
  206. // }
  207. WebCMSEntities db = new WebCMSEntities();
  208. // var poslist = db.PosMachinesTwo.Select(m => new { m.Id, m.BrandId, m.CardType, m.IsPurchase, m.PosSn }).Where(m => m.BrandId == 14 && m.CardType == 2 && m.IsPurchase == 1).ToList();
  209. // foreach(var pos in poslist)
  210. // {
  211. // bool check = db.MachineApply.Any(m => m.SwapSnExpand.Contains(pos.PosSn));
  212. // if(!check)
  213. // {
  214. // PosMachinesTwo edit = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.Id);
  215. // if(edit != null)
  216. // {
  217. // edit.IsPurchase = 0;
  218. // db.SaveChanges();
  219. // }
  220. // }
  221. // }
  222. List<string> ordernos = new List<string>();
  223. ordernos.Add("BM2023120100390512426698471");
  224. foreach(string orderno in ordernos)
  225. {
  226. Orders order = db.Orders.FirstOrDefault(m => m.OrderNo == orderno);
  227. if(order != null)
  228. {
  229. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  230. int ParentUserId = user.ParentUserId;
  231. bool buyPrize = false;
  232. bool OncePrizeFlag4 = true;
  233. int leaderFlag = 0;
  234. while (ParentUserId > 0)
  235. {
  236. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  237. if (puser.LeaderLevel > 0)
  238. {
  239. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  240. if (acccount.LeaderReserve >= 400 * 1 && !buyPrize)
  241. {
  242. //购机奖励
  243. AlipayPayBack2Service.Instance.OpAccount(db, order, puser.Id, 100, 1);
  244. buyPrize = true;
  245. }
  246. if (acccount.LeaderReserve >= 400 * 1 && puser.LeaderLevel > leaderFlag && leaderFlag < 2 && OncePrizeFlag4)
  247. {
  248. //扣减备用金
  249. AlipayPayBack2Service.Instance.OpReserve(db, order, puser.Id, 400 * 1, 2, order.UserId, "购机奖励");
  250. //返回到余额
  251. AlipayPayBack2Service.Instance.OpLeaderAccount(db, order, puser.Id, 400, 1);
  252. leaderFlag = puser.LeaderLevel;
  253. OncePrizeFlag4 = false;
  254. }
  255. }
  256. ParentUserId = puser.ParentUserId;
  257. }
  258. //购买盟主奖励
  259. decimal Prize = decimal.Parse(function.CheckNum(PublicFunction.GetPublicParam(db, "BigLeaderPrize")));
  260. if(Prize > 0)
  261. {
  262. AlipayPayBack2Service.Instance.LeaderRecommendPrize(db, order, 565, Prize, 122);
  263. }
  264. }
  265. }
  266. db.Dispose();
  267. return result;
  268. }
  269. public string Encrypt(string plainText, string keyString, string ivString)
  270. {
  271. byte[] cipherData;
  272. Aes aes = Aes.Create();
  273. aes.Key = System.Text.Encoding.UTF8.GetBytes(keyString);
  274. aes.IV = System.Text.Encoding.UTF8.GetBytes(ivString);
  275. aes.Mode = CipherMode.CBC;
  276. aes.Padding = PaddingMode.PKCS7;
  277. ICryptoTransform cipher = aes.CreateEncryptor(aes.Key, aes.IV);
  278. using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
  279. {
  280. using (CryptoStream cs = new CryptoStream(ms, cipher, CryptoStreamMode.Write))
  281. {
  282. using (System.IO.StreamWriter sw = new System.IO.StreamWriter(cs))
  283. {
  284. sw.Write(plainText);
  285. }
  286. }
  287. cipherData = ms.ToArray();
  288. }
  289. return Convert.ToBase64String(cipherData);
  290. }
  291. public string setlee()
  292. {
  293. WebCMSEntities db = new WebCMSEntities();
  294. List<string> poslist = new List<string>();
  295. poslist.Add("00003102722201179816714");
  296. foreach(string PosSn in poslist)
  297. {
  298. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  299. if(pos != null)
  300. {
  301. string info = "{\"RecordId\":\"\",\"PosId\":\"" + pos.Id + "\",\"Fee\": \"0.6\",\"Kind\": \"2\",\"OpMan\": \"系统\"}";
  302. RedisDbconn.Instance.AddList("SetDepositPostQueue", info);
  303. }
  304. }
  305. db.Dispose();
  306. return "ok";
  307. }
  308. public string lsprize(int id = 0)
  309. {
  310. // StatService.Instance.activePrizeWithoutDeposit6(id);
  311. // WebCMSEntities db = new WebCMSEntities();
  312. // List<string> poslist = new List<string>();
  313. // poslist.Add("N6220Y02004331");
  314. // poslist.Add("N6220Y02004411");
  315. // poslist.Add("N6220Y02006392");
  316. // poslist.Add("N6220Y02008090");
  317. // poslist.Add("N6220Y02014659");
  318. // poslist.Add("N6220Y02016352");
  319. // poslist.Add("N6220Y02018426");
  320. // poslist.Add("N6220Y02009475");
  321. // poslist.Add("N6220Y02009601");
  322. // poslist.Add("N6220Y02009630");
  323. // poslist.Add("N6220Y02010111");
  324. // poslist.Add("N6220Y02010795");
  325. // poslist.Add("N6220Y02011199");
  326. // poslist.Add("N6220Y02011405");
  327. // poslist.Add("N6220Y02011946");
  328. // poslist.Add("N6220Y02172467");
  329. // poslist.Add("N6220Y02172563");
  330. // poslist.Add("N6220Y02172658");
  331. // poslist.Add("N6220Y02172658");
  332. // poslist.Add("N6220Y02007603");
  333. // foreach(string PosSn in poslist)
  334. // {
  335. // PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  336. // if(pos != null)
  337. // {
  338. // // SycnSpTradeService.Instance.LiShuaActPrize(db, pos, 50);
  339. // StatService.Instance.activePrizeWithoutDeposit6(pos.Id);
  340. // }
  341. // }
  342. // db.Dispose();
  343. return "ok";
  344. }
  345. //金控自备机,补商户信息
  346. public string jkmerinfo(string sn)
  347. {
  348. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  349. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  350. var Bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == sn && m.Field1 == "解绑");
  351. if (Bind != null)
  352. {
  353. PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.MerSnNo) ?? new PxcModels.MachineForSnNo();
  354. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  355. if (pos != null)
  356. {
  357. pos.BindingState = 1;
  358. pos.BindingTime = Bind.CreateTime;
  359. pos.Status = 0;
  360. PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo);
  361. if (merFor == null)
  362. {
  363. merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
  364. {
  365. MerNo = Bind.MerNo,
  366. SnId = pos.Id,
  367. }).Entity;
  368. }
  369. else
  370. {
  371. merFor.SnId = pos.Id;
  372. }
  373. db.SaveChanges();
  374. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  375. int TopUserId = 0;
  376. if (!string.IsNullOrEmpty(user.ParentNav))
  377. {
  378. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  379. }
  380. int BrandId = pos.BrandId;
  381. PxcModels.TradeRecord trade = db.TradeRecord.FirstOrDefault(m => m.SnNo == sn) ?? new PxcModels.TradeRecord();
  382. PxcModels.PosMerchantInfo add = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == Bind.MerNo);
  383. if (add == null)
  384. {
  385. if(trade.MerchantId > 0)
  386. {
  387. add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
  388. {
  389. CreateDate = Bind.CreateTime,
  390. KqMerNo = Bind.MerNo,
  391. MerchantNo = Bind.MerNo.Length > 16 ? Bind.MerNo.Substring(0, 16) : Bind.MerNo,
  392. Id = trade.MerchantId,
  393. }).Entity;
  394. db.SaveChanges();
  395. }
  396. else
  397. {
  398. add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
  399. {
  400. CreateDate = Bind.CreateTime,
  401. KqMerNo = Bind.MerNo,
  402. MerchantNo = Bind.MerNo.Length > 16 ? Bind.MerNo.Substring(0, 16) : Bind.MerNo,
  403. }).Entity;
  404. db.SaveChanges();
  405. }
  406. }
  407. add.UpdateDate = Bind.UpdateTime;
  408. add.TopUserId = TopUserId;
  409. add.BrandId = BrandId;
  410. add.SnStoreId = pos.StoreId;
  411. add.SnType = pos.PosSnType;
  412. add.UserId = pos.UserId;
  413. add.MerStatus = 1;
  414. add.KqSnNo = Bind.MerSnNo;
  415. add.MerIdcardNo = function.CheckNull(Bind.SeoKeyword).ToUpper();
  416. add.MerRealName = Bind.MerName;
  417. add.MerchantMobile = Bind.MerNewSnNo;
  418. add.MerchantName = Bind.MerName;
  419. pos.BindMerchantId = add.Id;
  420. pos.LastMerchantId = add.Id;
  421. db.SaveChanges();
  422. RedisDbconn.Instance.AddList("DepositReturnStatQueue", add.Id.ToString());
  423. PxcModels.Users buser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new PxcModels.Users();
  424. if(buser.BusinessFlag == 1)
  425. {
  426. bool checkMer = db.BusinessPartnerMerchant.Any(m => m.MerchantId == add.Id);
  427. if(!checkMer)
  428. {
  429. PxcModels.BusinessPartnerPos bpos = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id) ?? new PxcModels.BusinessPartnerPos();
  430. db.BusinessPartnerMerchant.Add(new PxcModels.BusinessPartnerMerchant()
  431. {
  432. CreateDate = DateTime.Now,
  433. MerNo = Bind.MerNo,
  434. MerchantId = add.Id,
  435. PartnerId = bpos.PartnerId,
  436. UserId = pos.BuyUserId,
  437. });
  438. db.SaveChanges();
  439. }
  440. }
  441. }
  442. }
  443. spdb.Dispose();
  444. db.Dispose();
  445. return "ok";
  446. }
  447. public string sycnTrade(int Id)
  448. {
  449. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  450. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id);
  451. if(merchant != null)
  452. {
  453. DepositReturnStatService.Instance.DoSomething(db, merchant);
  454. }
  455. return "ok";
  456. }
  457. }
  458. }