HomeController.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. //交易不到1000的机具,顶级姓名-代理姓名-客户姓名-客户电话-开机日期-SN // TODO:做到BS后台导出,按绑定时间查
  475. public IActionResult PosTable()
  476. {
  477. WebCMSEntities db = new WebCMSEntities();
  478. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  479. List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
  480. foreach (PosMachinesTwo pos in poses)
  481. {
  482. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  483. Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
  484. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  485. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  486. Dictionary<string, string> item = new Dictionary<string, string>();
  487. string TopRealName = "";
  488. string TopMakerCode = "";
  489. string TopMobile = "";
  490. string ParentNav = user.ParentNav;
  491. if (!string.IsNullOrEmpty(ParentNav))
  492. {
  493. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  494. if (navlist.Length > 1)
  495. {
  496. int TopId = int.Parse(function.CheckInt(navlist[1]));
  497. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  498. TopRealName = tuser.RealName;
  499. TopMakerCode = tuser.MakerCode;
  500. TopMobile = tuser.Mobile;
  501. }
  502. }
  503. item.Add("TopRealName", TopRealName); //顶级姓名
  504. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  505. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  506. item.Add("UpRealName", puser.RealName); //上级姓名
  507. item.Add("RealName", user.RealName); //代理姓名
  508. item.Add("MakerCode", user.MakerCode); //代理编号
  509. item.Add("Mobile", user.Mobile); //代理手机号
  510. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  511. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  512. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  513. item.Add("Sn", pos.PosSn); //SN
  514. list.Add(item);
  515. }
  516. db.Dispose();
  517. ViewBag.list = list;
  518. return View();
  519. }
  520. public string resetall(int k = 0, int b = 1)
  521. {
  522. DataTable dt = dbconn.dtable("select Id from Users where AuthFlag=1");
  523. foreach (DataRow dr in dt.Rows)
  524. {
  525. if (k == 1)
  526. {
  527. reset(int.Parse(dr["Id"].ToString()));
  528. }
  529. else if (k == 2)
  530. {
  531. resetpos(int.Parse(dr["Id"].ToString()), b);
  532. }
  533. }
  534. return "ok";
  535. }
  536. public string reset(int uid)
  537. {
  538. WebCMSEntities db = new WebCMSEntities();
  539. List<Users> users = db.Users.Where(m => m.ParentUserId == uid).OrderByDescending(m => m.AuthDate).ToList();
  540. RedisDbconn.Instance.Clear("MyMakerList:" + uid);
  541. RedisDbconn.Instance.Clear("MyMakerForNotAuth:" + uid);
  542. RedisDbconn.Instance.Clear("TotalUser:" + uid + "*");
  543. RedisDbconn.Instance.Clear("TotalUser:Auth:" + uid);
  544. foreach (Users user in users)
  545. {
  546. RedisDbconn.Instance.AddInt("TotalUser:" + uid);
  547. RedisDbconn.Instance.AddInt("TotalUser:" + uid + ":" + user.CreateDate.Value.ToString("yyyyMM"));
  548. RedisDbconn.Instance.AddInt("TotalUser:" + uid + ":" + user.CreateDate.Value.ToString("yyyyMMdd"));
  549. if (user.AuthFlag == 1)
  550. {
  551. RedisDbconn.Instance.AddList("MyMakerList:" + uid, new MyMakerItem()
  552. {
  553. UserId = user.Id,
  554. RealName = user.RealName,
  555. UserLevel = user.UserLevel,
  556. });
  557. RedisDbconn.Instance.AddInt("TotalUser:Auth:" + uid);
  558. }
  559. else
  560. {
  561. RedisDbconn.Instance.AddList("MyMakerForNotAuth:" + uid, new MyMakerItem()
  562. {
  563. UserId = user.Id,
  564. RealName = user.RealName,
  565. UserLevel = user.UserLevel,
  566. });
  567. RedisDbconn.Instance.AddInt("TotalUser:NoAuth:" + uid);
  568. }
  569. RedisDbconn.Instance.Set("Users:" + user.Id, user);
  570. }
  571. db.Dispose();
  572. return "finish";
  573. }
  574. public string resetpos(int uid, int kind)
  575. {
  576. WebCMSEntities db = new WebCMSEntities();
  577. string IdBrand = uid + "_" + kind;
  578. UserMachineData machineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  579. if (machineData == null)
  580. {
  581. machineData = db.UserMachineData.Add(new UserMachineData()
  582. {
  583. IdBrand = IdBrand
  584. }).Entity;
  585. db.SaveChanges();
  586. }
  587. machineData.BindCount = db.PosMachinesTwo.Count(m => m.UserId == uid && m.BrandId == kind && m.BindingState == 1);
  588. machineData.UnBindCount = db.PosMachinesTwo.Count(m => m.UserId == uid && m.BrandId == kind && m.BindingState == 0);
  589. machineData.TotalMachineCount = machineData.BindCount + machineData.UnBindCount;
  590. db.SaveChanges();
  591. RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, machineData);
  592. RedisDbconn.Instance.SetExpire("UserMachineData:" + IdBrand, function.get_Random(1800, 5400));
  593. db.Dispose();
  594. return "finish";
  595. }
  596. // 更新分仓库存
  597. public string resetstorestock()
  598. {
  599. WebCMSEntities db = new WebCMSEntities();
  600. DataTable dt = dbconn.dtable("select s.Id,LaveNum,count(p.Id) as CurLaveNum from StoreHouse s left join PosMachinesTwo p on s.Id=p.StoreId and s.BrandId=p.BrandId and p.UserId=0 group by s.Id HAVING LaveNum!=count(p.Id)");
  601. foreach (DataRow dr in dt.Rows)
  602. {
  603. int Id = int.Parse(function.CheckInt(dr["Id"].ToString()));
  604. int CurLaveNum = int.Parse(function.CheckInt(dr["CurLaveNum"].ToString()));
  605. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  606. if (store != null)
  607. {
  608. store.LaveNum = CurLaveNum;
  609. db.SaveChanges();
  610. RedisDbconn.Instance.Set("StoreHouse:" + Id, store);
  611. }
  612. }
  613. db.Dispose();
  614. return "ok";
  615. }
  616. public string resetstorestock2(int id)
  617. {
  618. WebCMSEntities db = new WebCMSEntities();
  619. DataTable dt = dbconn.dtable("select Id,LaveNum,(select count(Id) from PosMachinesTwo where StoreId=s.Id and UserId=0) as CurLaveNum from StoreHouse s where Id=" + id);
  620. foreach (DataRow dr in dt.Rows)
  621. {
  622. int Id = int.Parse(function.CheckInt(dr["Id"].ToString()));
  623. int CurLaveNum = int.Parse(function.CheckInt(dr["CurLaveNum"].ToString()));
  624. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  625. if (store != null)
  626. {
  627. store.LaveNum = CurLaveNum;
  628. db.SaveChanges();
  629. RedisDbconn.Instance.Set("StoreHouse:" + Id, store);
  630. }
  631. }
  632. db.Dispose();
  633. return "ok";
  634. }
  635. public string chkpwd(string pwd)
  636. {
  637. return function.MD532(pwd);
  638. }
  639. public string test()
  640. {
  641. StatService.Instance.testStatTrade("2022-04-04");
  642. return "ok";
  643. }
  644. }
  645. }