HomeController.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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. namespace MySystem.Controllers
  14. {
  15. public class HomeController : Controller
  16. {
  17. private readonly ILogger<HomeController> _logger;
  18. public HomeController(ILogger<HomeController> logger)
  19. {
  20. _logger = logger;
  21. }
  22. public IActionResult Index()
  23. {
  24. return View();
  25. }
  26. public IActionResult Error()
  27. {
  28. string isapi = Request.Headers["Api"].ToString();
  29. if (isapi != "1")
  30. {
  31. if (Response.StatusCode == 500)
  32. {
  33. return Redirect("/public/errpage/pc/500.html");
  34. }
  35. else if (Response.StatusCode == 502)
  36. {
  37. return Redirect("/public/errpage/pc/502.html");
  38. }
  39. else if (Response.StatusCode == 404)
  40. {
  41. return Redirect("/public/errpage/pc/404.html");
  42. }
  43. }
  44. return View();
  45. }
  46. private static object o = new object();
  47. public string addmer(string mid, int k = 0)
  48. {
  49. MerchantConfirmService.Instance.Start(mid, k);
  50. return "ok";
  51. }
  52. public string cleartrade()
  53. {
  54. StatService.Instance.clear();
  55. return "ok";
  56. }
  57. public string stattrade(string d)
  58. {
  59. StatService.Instance.dosomething2(d);
  60. return "ok";
  61. }
  62. public string setqrcode(int uid = 0)
  63. {
  64. return "ok";
  65. }
  66. public string userqrcode(int uid)
  67. {
  68. WebCMSEntities db = new WebCMSEntities();
  69. Users user = db.Users.FirstOrDefault(m => m.Id == uid);
  70. if (user != null)
  71. {
  72. MakeReferenceQrCodeService.Instance.Start(user.Id.ToString());
  73. return "ok";
  74. }
  75. db.Dispose();
  76. return "fail";
  77. }
  78. private void th1()
  79. {
  80. Thread th = new Thread(th1do);
  81. th.IsBackground = true;
  82. th.Start();
  83. }
  84. private void th1do()
  85. {
  86. WebCMSEntities db = new WebCMSEntities();
  87. Users user = db.Users.FirstOrDefault(m => m.Id == 2);
  88. if (user != null)
  89. {
  90. user.SeoTitle = "111111";
  91. Thread.Sleep(5000);
  92. user.SeoDescription = "222222";
  93. db.SaveChanges();
  94. }
  95. db.Dispose();
  96. }
  97. private void th2()
  98. {
  99. Thread th = new Thread(th2do);
  100. th.IsBackground = true;
  101. th.Start();
  102. }
  103. private void th2do()
  104. {
  105. Thread.Sleep(2000);
  106. WebCMSEntities db = new WebCMSEntities();
  107. Users user = db.Users.FirstOrDefault(m => m.Id == 2);
  108. if (user != null)
  109. {
  110. user.SeoKeyword = "看看有没有值写入";
  111. db.SaveChanges();
  112. }
  113. db.Dispose();
  114. }
  115. public string chkact(int Id = 0)
  116. {
  117. if (Id > 0)
  118. {
  119. SycnSpActiveService.Instance.Start(Id);
  120. }
  121. return "ok";
  122. }
  123. public string chktrade(int Id = 0)
  124. {
  125. if (Id > 0)
  126. {
  127. SycnSpTradeService.Instance.Start(Id);
  128. }
  129. return "ok";
  130. }
  131. // 补激活奖励
  132. public string setmeruser(string date)
  133. {
  134. StatService.Instance.dosomething1(date);
  135. return "ok";
  136. }
  137. public string chkactprize(int Id = 0)
  138. {
  139. if (Id > 0)
  140. {
  141. StatService.Instance.dosomething3(Id);
  142. }
  143. return "ok";
  144. }
  145. public string mutilactprize()
  146. {
  147. List<int> ids = new List<int>();
  148. WebCMSEntities db = new WebCMSEntities();
  149. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  150. foreach (int id in ids)
  151. {
  152. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == id);
  153. if (pos != null)
  154. {
  155. SpModels.ActivateRecord act = spdb.ActivateRecord.FirstOrDefault(m => m.SnNo == pos.PosSn && m.SeoTitle != "0" && !string.IsNullOrEmpty(m.SeoTitle));
  156. if (act != null)
  157. {
  158. pos.SeoKeyword = act.SeoTitle;
  159. db.SaveChanges();
  160. StatService.Instance.dosomething3(pos.Id);
  161. }
  162. }
  163. }
  164. db.Dispose();
  165. spdb.Dispose();
  166. return "ok";
  167. }
  168. public string checkOrder(int id)
  169. {
  170. AlipayPayBack2Service.Instance.checkOrder(id);
  171. return "ok";
  172. }
  173. public string scanBind()
  174. {
  175. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  176. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  177. var Binds = spdb.BindRecord.Select(m => new { m.Id, m.CreateTime, m.Status, m.MerNo, m.MerSnNo }).OrderBy(m => m.Id).ToList();
  178. foreach (var Bind in Binds)
  179. {
  180. var tran = db.Database.BeginTransaction();
  181. try
  182. {
  183. PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.MerSnNo) ?? new PxcModels.MachineForSnNo();
  184. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  185. if (pos != null)
  186. {
  187. if (pos.BindingState == 0)
  188. {
  189. pos.BindingState = 1;
  190. pos.BindingTime = Bind.CreateTime;
  191. PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo);
  192. if (merFor == null)
  193. {
  194. merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
  195. {
  196. MerNo = Bind.MerNo,
  197. SnId = pos.Id,
  198. }).Entity;
  199. }
  200. db.SaveChanges();
  201. tran.Commit();
  202. function.WriteLog(pos.PosSn, "补充绑定数据");
  203. }
  204. }
  205. }
  206. catch (Exception ex)
  207. {
  208. tran.Rollback();
  209. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Bind.Id, "同步SP绑定数据到MAIN异常");
  210. }
  211. tran.Dispose();
  212. }
  213. spdb.SaveChanges();
  214. spdb.Dispose();
  215. db.SaveChanges();
  216. db.Dispose();
  217. return "ok";
  218. }
  219. public string scanMerchant()
  220. {
  221. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  222. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  223. var Mers = spdb.Merchants.OrderBy(m => m.Id).ToList();
  224. foreach (var Mer in Mers)
  225. {
  226. var tran = db.Database.BeginTransaction();
  227. try
  228. {
  229. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo) ?? new PxcModels.MachineForMerNo();
  230. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId) ?? new PxcModels.PosMachinesTwo();
  231. if (pos.BindingState == 1)
  232. {
  233. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  234. int TopUserId = 0;
  235. if (!string.IsNullOrEmpty(user.ParentNav))
  236. {
  237. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  238. }
  239. int BrandId = int.Parse(Mer.ProductType);
  240. if (Mer.MerNo.StartsWith("M900"))
  241. {
  242. BrandId = 3;
  243. }
  244. bool check = db.PosMerchantInfo.Any(m => m.KqMerNo == Mer.MerNo);
  245. if (!check)
  246. {
  247. PxcModels.PosMerchantInfo add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
  248. {
  249. CreateDate = Mer.CreateTime,
  250. UpdateDate = Mer.UpdateTime,
  251. TopUserId = TopUserId,
  252. MerUserType = user.MerchantType,
  253. BrandId = BrandId,
  254. SnStoreId = pos.StoreId,
  255. SnType = pos.PosSnType,
  256. UserId = pos.UserId,
  257. MgrName = Mer.AgentName,
  258. MerStatus = 1,
  259. KqSnNo = Mer.SnNo,
  260. KqMerNo = Mer.MerNo,
  261. MerIdcardNo = Mer.MerIdcardNo,
  262. MerRealName = Mer.MerRealName,
  263. MerchantMobile = Mer.MerMobile,
  264. MerchantName = Mer.MerName,
  265. MerchantNo = Mer.MerNo.Length > 16 ? Mer.MerNo.Substring(0, 16) : Mer.MerNo,
  266. }).Entity;
  267. db.SaveChanges();
  268. pos.BindMerchantId = add.Id;
  269. db.SaveChanges();
  270. tran.Commit();
  271. function.WriteLog(Mer.MerNo, "补充商户数据");
  272. }
  273. }
  274. }
  275. catch (Exception ex)
  276. {
  277. tran.Rollback();
  278. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Mer.Id, "同步SP商户数据到MAIN异常");
  279. }
  280. tran.Dispose();
  281. }
  282. spdb.Dispose();
  283. db.Dispose();
  284. return "ok";
  285. }
  286. public string scanTrade()
  287. {
  288. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  289. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  290. IQueryable<SpModels.TradeRecord> trades = spdb.TradeRecord.OrderBy(m => m.Id);
  291. foreach (SpModels.TradeRecord trade in trades.ToList())
  292. {
  293. bool op = true;
  294. if (trade.SerEntryMode == "N")
  295. {
  296. if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900)
  297. {
  298. op = false;
  299. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
  300. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  301. if (pos != null)
  302. {
  303. if (trade.SerEntryMode == "N" && trade.ProductType == "1")
  304. {
  305. pos.SeoKeyword = trade.TradeAmount.ToString("f2");
  306. db.SaveChanges();
  307. }
  308. }
  309. }
  310. }
  311. if (op)
  312. {
  313. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
  314. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  315. if (pos != null)
  316. {
  317. if (pos.BindMerchantId > 0)
  318. {
  319. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  320. int TopUserId = 0;
  321. if (!string.IsNullOrEmpty(user.ParentNav))
  322. {
  323. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  324. }
  325. bool check = db.TradeRecord.Any(m => m.RecordNo == trade.TradeSerialNo);
  326. if (!check)
  327. {
  328. decimal TradeAmount = trade.TradeAmount;
  329. int BankCardType = -1;
  330. int QrPayFlag = 0;
  331. if (pos.BrandId == 1 || pos.BrandId == 3)
  332. {
  333. TradeAmount = TradeAmount / 100;
  334. BankCardType = int.Parse(trade.BankCardType);
  335. if(trade.TradeType == "02") QrPayFlag = 1;
  336. }
  337. else if (pos.BrandId == 2)
  338. {
  339. if (trade.TradeType == "CREDIT_BY_CARD")
  340. {
  341. BankCardType = 1;
  342. }
  343. else if (trade.TradeType == "DEBIT_BY_CARD")
  344. {
  345. BankCardType = 0;
  346. }
  347. if(trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
  348. }
  349. int BrandId = int.Parse(trade.ProductType);
  350. if (trade.MerNo.StartsWith("M900"))
  351. {
  352. BrandId = 3;
  353. }
  354. db.TradeRecord.Add(new PxcModels.TradeRecord()
  355. {
  356. CreateDate = trade.CreateDate,
  357. UpdateDate = trade.UpdateDate,
  358. RecordNo = trade.TradeSerialNo, //单号
  359. UserId = pos.UserId, //创客
  360. MerchantId = pos.BindMerchantId, //商户
  361. MerNo = trade.MerNo, //渠道商户编号
  362. MerHelpFlag = 0, //是否属于扶持周期内商户
  363. HelpMonthCount = 0, //扶持第几个月
  364. MerBuddyType = user.MerchantType, //商户创客类型
  365. SnNo = trade.TradeSnNo, //渠道SN号
  366. // TradeDate = DateTime.Parse(trade.TradeTime), //交易日期
  367. TradeSerialNo = trade.ChannelSerial, //交易流水号
  368. TradeAmount = TradeAmount, //交易金额
  369. BankCardType = BankCardType, //银行卡类型
  370. QrPayFlag = QrPayFlag, //云闪付标识
  371. BrandId = BrandId, //品牌
  372. Remark = trade.Remark, //备注
  373. TopUserId = TopUserId, //顶级创客
  374. MerUserId = pos.UserId, //商户直属创客
  375. });
  376. if (BankCardType == 1)
  377. {
  378. pos.CreditTrade += TradeAmount;
  379. }
  380. else if (BankCardType == 0)
  381. {
  382. pos.DebitCardTrade += TradeAmount;
  383. }
  384. if (pos.CreditTrade < 1000)
  385. {
  386. pos.IsPurchase = 99;
  387. }
  388. else if (pos.CreditTrade >= 1000 && pos.ActivationState == 0 && pos.BindingTime > DateTime.Now.AddDays(-20))
  389. {
  390. pos.IsPurchase = 0;
  391. pos.ActivationState = 1;
  392. pos.ActivationTime = DateTime.Now;
  393. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  394. if (merchant != null)
  395. {
  396. merchant.ActiveStatus = 1;
  397. merchant.MerStandardDate = DateTime.Now;
  398. db.SaveChanges();
  399. }
  400. }
  401. db.SaveChanges();
  402. function.WriteLog(trade.Id.ToString(), "补充交易数据");
  403. }
  404. }
  405. }
  406. }
  407. }
  408. spdb.Dispose();
  409. db.Dispose();
  410. return "ok";
  411. }
  412. // public string add100()
  413. // {
  414. // WebCMSEntities db = new WebCMSEntities();
  415. // List<int> uids = new List<int>();
  416. // uids.Add(1053);
  417. // foreach (int uid in uids)
  418. // {
  419. // int ParentUserId = uid;
  420. // int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台购买机
  421. // int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  422. // if (machineCount + ActiveCount >= 3)
  423. // {
  424. // UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == ParentUserId);
  425. // if (account == null)
  426. // {
  427. // account = db.UserAccount.Add(new UserAccount()
  428. // {
  429. // Id = ParentUserId,
  430. // UserId = ParentUserId,
  431. // }).Entity;
  432. // db.SaveChanges();
  433. // }
  434. // decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  435. // decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  436. // decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  437. // account.BalanceAmount += 100;
  438. // account.TotalAmount += 100;
  439. // decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  440. // decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  441. // decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  442. // UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  443. // {
  444. // CreateDate = DateTime.Now,
  445. // UpdateDate = DateTime.Now,
  446. // UserId = ParentUserId, //创客
  447. // ChangeType = 112, //变动类型
  448. // ChangeAmount = 100, //变更金额
  449. // BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  450. // AfterTotalAmount = AfterTotalAmount, //变更后总金额
  451. // BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  452. // AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  453. // BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  454. // AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  455. // }).Entity;
  456. // db.SaveChanges();
  457. // RedisDbconn.Instance.Set("UserAccount:" + ParentUserId, account);
  458. // //推荐下单上级获得30天的机具循环天数
  459. // var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.UserId, m.BindingState, m.RecycEndDate }).Where(m => m.UserId == ParentUserId && m.BindingState == 0 && m.RecycEndDate != null).ToList();
  460. // foreach (var subPos in posList)
  461. // {
  462. // PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  463. // if (pos != null)
  464. // {
  465. // pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  466. // }
  467. // }
  468. // db.SaveChanges();
  469. // }
  470. // }
  471. // db.Dispose();
  472. // return "finish";
  473. // }
  474. public string test()
  475. {
  476. StatService.Instance.testStatTrade("2022-04-04");
  477. return "ok";
  478. }
  479. }
  480. }