HomeController.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  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. // 补激活奖励
  116. public string setmeruser(string date)
  117. {
  118. StatService.Instance.dosomething1(date);
  119. return "ok";
  120. }
  121. public string chkactprize(int Id = 0)
  122. {
  123. if (Id > 0)
  124. {
  125. StatService.Instance.dosomething3(Id);
  126. }
  127. return "ok";
  128. }
  129. public string mutilactprize()
  130. {
  131. List<int> ids = new List<int>();
  132. WebCMSEntities db = new WebCMSEntities();
  133. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  134. foreach (int id in ids)
  135. {
  136. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == id);
  137. if (pos != null)
  138. {
  139. SpModels.ActivateRecord act = spdb.ActivateRecord.FirstOrDefault(m => m.SnNo == pos.PosSn && m.SeoTitle != "0" && !string.IsNullOrEmpty(m.SeoTitle));
  140. if (act != null)
  141. {
  142. pos.SeoKeyword = act.SeoTitle;
  143. db.SaveChanges();
  144. StatService.Instance.dosomething3(pos.Id);
  145. }
  146. }
  147. }
  148. db.Dispose();
  149. spdb.Dispose();
  150. return "ok";
  151. }
  152. public string checkOrder(int id)
  153. {
  154. AlipayPayBack2Service.Instance.checkOrder(id);
  155. return "ok";
  156. }
  157. public string scanBind()
  158. {
  159. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  160. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  161. var Binds = spdb.BindRecord.Select(m => new { m.Id, m.CreateTime, m.Status, m.MerNo, m.MerSnNo }).OrderBy(m => m.Id).ToList();
  162. foreach (var Bind in Binds)
  163. {
  164. var tran = db.Database.BeginTransaction();
  165. try
  166. {
  167. PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.MerSnNo) ?? new PxcModels.MachineForSnNo();
  168. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  169. if (pos != null)
  170. {
  171. if (pos.BindingState == 0)
  172. {
  173. pos.BindingState = 1;
  174. pos.BindingTime = Bind.CreateTime;
  175. PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo);
  176. if (merFor == null)
  177. {
  178. merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
  179. {
  180. MerNo = Bind.MerNo,
  181. SnId = pos.Id,
  182. }).Entity;
  183. }
  184. db.SaveChanges();
  185. tran.Commit();
  186. function.WriteLog(pos.PosSn, "补充绑定数据");
  187. }
  188. }
  189. }
  190. catch (Exception ex)
  191. {
  192. tran.Rollback();
  193. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Bind.Id, "同步SP绑定数据到MAIN异常");
  194. }
  195. tran.Dispose();
  196. }
  197. spdb.SaveChanges();
  198. spdb.Dispose();
  199. db.SaveChanges();
  200. db.Dispose();
  201. return "ok";
  202. }
  203. public string scanMerchant()
  204. {
  205. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  206. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  207. var Mers = spdb.Merchants.OrderBy(m => m.Id).ToList();
  208. foreach (var Mer in Mers)
  209. {
  210. var tran = db.Database.BeginTransaction();
  211. try
  212. {
  213. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo) ?? new PxcModels.MachineForMerNo();
  214. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId) ?? new PxcModels.PosMachinesTwo();
  215. if (pos.BindingState == 1)
  216. {
  217. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  218. int TopUserId = 0;
  219. if (!string.IsNullOrEmpty(user.ParentNav))
  220. {
  221. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  222. }
  223. int BrandId = int.Parse(Mer.ProductType);
  224. if (Mer.MerNo.StartsWith("M900"))
  225. {
  226. BrandId = 3;
  227. }
  228. bool check = db.PosMerchantInfo.Any(m => m.KqMerNo == Mer.MerNo);
  229. if (!check)
  230. {
  231. PxcModels.PosMerchantInfo add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
  232. {
  233. CreateDate = Mer.CreateTime,
  234. UpdateDate = Mer.UpdateTime,
  235. TopUserId = TopUserId,
  236. MerUserType = user.MerchantType,
  237. BrandId = BrandId,
  238. SnStoreId = pos.StoreId,
  239. SnType = pos.PosSnType,
  240. UserId = pos.UserId,
  241. MgrName = Mer.AgentName,
  242. MerStatus = 1,
  243. KqSnNo = Mer.SnNo,
  244. KqMerNo = Mer.MerNo,
  245. MerIdcardNo = Mer.MerIdcardNo,
  246. MerRealName = Mer.MerRealName,
  247. MerchantMobile = Mer.MerMobile,
  248. MerchantName = Mer.MerName,
  249. MerchantNo = Mer.MerNo.Length > 16 ? Mer.MerNo.Substring(0, 16) : Mer.MerNo,
  250. }).Entity;
  251. db.SaveChanges();
  252. pos.BindMerchantId = add.Id;
  253. db.SaveChanges();
  254. tran.Commit();
  255. function.WriteLog(Mer.MerNo, "补充商户数据");
  256. }
  257. }
  258. }
  259. catch (Exception ex)
  260. {
  261. tran.Rollback();
  262. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Mer.Id, "同步SP商户数据到MAIN异常");
  263. }
  264. tran.Dispose();
  265. }
  266. spdb.Dispose();
  267. db.Dispose();
  268. return "ok";
  269. }
  270. public string scanTrade()
  271. {
  272. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  273. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  274. IQueryable<SpModels.TradeRecord> trades = spdb.TradeRecord.OrderBy(m => m.Id);
  275. foreach (SpModels.TradeRecord trade in trades.ToList())
  276. {
  277. bool op = true;
  278. if (trade.SerEntryMode == "N")
  279. {
  280. if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900)
  281. {
  282. op = false;
  283. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
  284. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  285. if (pos != null)
  286. {
  287. if (trade.SerEntryMode == "N" && trade.ProductType == "1")
  288. {
  289. pos.SeoKeyword = trade.TradeAmount.ToString("f2");
  290. db.SaveChanges();
  291. }
  292. }
  293. }
  294. }
  295. if (op)
  296. {
  297. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
  298. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  299. if (pos != null)
  300. {
  301. if (pos.BindMerchantId > 0)
  302. {
  303. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  304. int TopUserId = 0;
  305. if (!string.IsNullOrEmpty(user.ParentNav))
  306. {
  307. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  308. }
  309. bool check = db.TradeRecord.Any(m => m.RecordNo == trade.TradeSerialNo);
  310. if (!check)
  311. {
  312. decimal TradeAmount = trade.TradeAmount;
  313. int BankCardType = -1;
  314. int QrPayFlag = 0;
  315. if (pos.BrandId == 1 || pos.BrandId == 3)
  316. {
  317. TradeAmount = TradeAmount / 100;
  318. BankCardType = int.Parse(trade.BankCardType);
  319. if(trade.TradeType == "02") QrPayFlag = 1;
  320. }
  321. else if (pos.BrandId == 2)
  322. {
  323. if (trade.TradeType == "CREDIT_BY_CARD")
  324. {
  325. BankCardType = 1;
  326. }
  327. else if (trade.TradeType == "DEBIT_BY_CARD")
  328. {
  329. BankCardType = 0;
  330. }
  331. if(trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
  332. }
  333. int BrandId = int.Parse(trade.ProductType);
  334. if (trade.MerNo.StartsWith("M900"))
  335. {
  336. BrandId = 3;
  337. }
  338. db.TradeRecord.Add(new PxcModels.TradeRecord()
  339. {
  340. CreateDate = trade.CreateDate,
  341. UpdateDate = trade.UpdateDate,
  342. RecordNo = trade.TradeSerialNo, //单号
  343. UserId = pos.UserId, //创客
  344. MerchantId = pos.BindMerchantId, //商户
  345. MerNo = trade.MerNo, //渠道商户编号
  346. MerHelpFlag = 0, //是否属于扶持周期内商户
  347. HelpMonthCount = 0, //扶持第几个月
  348. MerBuddyType = user.MerchantType, //商户创客类型
  349. SnNo = trade.TradeSnNo, //渠道SN号
  350. // TradeDate = DateTime.Parse(trade.TradeTime), //交易日期
  351. TradeSerialNo = trade.ChannelSerial, //交易流水号
  352. TradeAmount = TradeAmount, //交易金额
  353. BankCardType = BankCardType, //银行卡类型
  354. QrPayFlag = QrPayFlag, //云闪付标识
  355. BrandId = BrandId, //品牌
  356. Remark = trade.Remark, //备注
  357. TopUserId = TopUserId, //顶级创客
  358. MerUserId = pos.UserId, //商户直属创客
  359. });
  360. if (BankCardType == 1)
  361. {
  362. pos.CreditTrade += TradeAmount;
  363. }
  364. else if (BankCardType == 0)
  365. {
  366. pos.DebitCardTrade += TradeAmount;
  367. }
  368. if (pos.CreditTrade < 1000)
  369. {
  370. pos.IsPurchase = 99;
  371. }
  372. else if (pos.CreditTrade >= 1000 && pos.ActivationState == 0 && pos.BindingTime > DateTime.Now.AddDays(-20))
  373. {
  374. pos.IsPurchase = 0;
  375. pos.ActivationState = 1;
  376. pos.ActivationTime = DateTime.Now;
  377. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  378. if (merchant != null)
  379. {
  380. merchant.ActiveStatus = 1;
  381. merchant.MerStandardDate = DateTime.Now;
  382. db.SaveChanges();
  383. }
  384. }
  385. db.SaveChanges();
  386. function.WriteLog(trade.Id.ToString(), "补充交易数据");
  387. }
  388. }
  389. }
  390. }
  391. }
  392. spdb.Dispose();
  393. db.Dispose();
  394. return "ok";
  395. }
  396. // public string add100()
  397. // {
  398. // WebCMSEntities db = new WebCMSEntities();
  399. // List<int> uids = new List<int>();
  400. // uids.Add(1053);
  401. // foreach (int uid in uids)
  402. // {
  403. // int ParentUserId = uid;
  404. // int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台购买机
  405. // int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  406. // if (machineCount + ActiveCount >= 3)
  407. // {
  408. // UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == ParentUserId);
  409. // if (account == null)
  410. // {
  411. // account = db.UserAccount.Add(new UserAccount()
  412. // {
  413. // Id = ParentUserId,
  414. // UserId = ParentUserId,
  415. // }).Entity;
  416. // db.SaveChanges();
  417. // }
  418. // decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  419. // decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  420. // decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  421. // account.BalanceAmount += 100;
  422. // account.TotalAmount += 100;
  423. // decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  424. // decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  425. // decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  426. // UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  427. // {
  428. // CreateDate = DateTime.Now,
  429. // UpdateDate = DateTime.Now,
  430. // UserId = ParentUserId, //创客
  431. // ChangeType = 112, //变动类型
  432. // ChangeAmount = 100, //变更金额
  433. // BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  434. // AfterTotalAmount = AfterTotalAmount, //变更后总金额
  435. // BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  436. // AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  437. // BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  438. // AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  439. // }).Entity;
  440. // db.SaveChanges();
  441. // RedisDbconn.Instance.Set("UserAccount:" + ParentUserId, account);
  442. // //推荐下单上级获得30天的机具循环天数
  443. // 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();
  444. // foreach (var subPos in posList)
  445. // {
  446. // PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  447. // if (pos != null)
  448. // {
  449. // pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  450. // }
  451. // }
  452. // db.SaveChanges();
  453. // }
  454. // }
  455. // db.Dispose();
  456. // return "finish";
  457. // }
  458. //交易不到1000的机具,顶级姓名-代理姓名-客户姓名-客户电话-开机日期-SN // TODO:做到BS后台导出,按绑定时间查
  459. public IActionResult PosTable()
  460. {
  461. WebCMSEntities db = new WebCMSEntities();
  462. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  463. List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
  464. foreach (PosMachinesTwo pos in poses)
  465. {
  466. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  467. Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
  468. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  469. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  470. Dictionary<string, string> item = new Dictionary<string, string>();
  471. string TopRealName = "";
  472. string TopMakerCode = "";
  473. string TopMobile = "";
  474. string ParentNav = user.ParentNav;
  475. if (!string.IsNullOrEmpty(ParentNav))
  476. {
  477. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  478. if (navlist.Length > 1)
  479. {
  480. int TopId = int.Parse(function.CheckInt(navlist[1]));
  481. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  482. TopRealName = tuser.RealName;
  483. TopMakerCode = tuser.MakerCode;
  484. TopMobile = tuser.Mobile;
  485. }
  486. }
  487. item.Add("TopRealName", TopRealName); //顶级姓名
  488. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  489. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  490. item.Add("UpRealName", puser.RealName); //上级姓名
  491. item.Add("RealName", user.RealName); //代理姓名
  492. item.Add("MakerCode", user.MakerCode); //代理编号
  493. item.Add("Mobile", user.Mobile); //代理手机号
  494. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  495. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  496. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  497. item.Add("Sn", pos.PosSn); //SN
  498. list.Add(item);
  499. }
  500. db.Dispose();
  501. ViewBag.list = list;
  502. return View();
  503. }
  504. public string resetall(int k = 0, int b = 1)
  505. {
  506. DataTable dt = dbconn.dtable("select Id from Users where AuthFlag=1");
  507. foreach (DataRow dr in dt.Rows)
  508. {
  509. if (k == 1)
  510. {
  511. reset(int.Parse(dr["Id"].ToString()));
  512. }
  513. else if (k == 2)
  514. {
  515. resetpos(int.Parse(dr["Id"].ToString()), b);
  516. }
  517. }
  518. return "ok";
  519. }
  520. public string reset(int uid)
  521. {
  522. WebCMSEntities db = new WebCMSEntities();
  523. List<Users> users = db.Users.Where(m => m.ParentUserId == uid).OrderByDescending(m => m.AuthDate).ToList();
  524. RedisDbconn.Instance.Clear("MyMakerList:" + uid);
  525. RedisDbconn.Instance.Clear("MyMakerForNotAuth:" + uid);
  526. RedisDbconn.Instance.Clear("TotalUser:" + uid + "*");
  527. RedisDbconn.Instance.Clear("TotalUser:Auth:" + uid);
  528. foreach (Users user in users)
  529. {
  530. RedisDbconn.Instance.AddInt("TotalUser:" + uid);
  531. RedisDbconn.Instance.AddInt("TotalUser:" + uid + ":" + user.CreateDate.Value.ToString("yyyyMM"));
  532. RedisDbconn.Instance.AddInt("TotalUser:" + uid + ":" + user.CreateDate.Value.ToString("yyyyMMdd"));
  533. if (user.AuthFlag == 1)
  534. {
  535. RedisDbconn.Instance.AddList("MyMakerList:" + uid, new MyMakerItem()
  536. {
  537. UserId = user.Id,
  538. RealName = user.RealName,
  539. UserLevel = user.UserLevel,
  540. });
  541. RedisDbconn.Instance.AddInt("TotalUser:Auth:" + uid);
  542. }
  543. else
  544. {
  545. RedisDbconn.Instance.AddList("MyMakerForNotAuth:" + uid, new MyMakerItem()
  546. {
  547. UserId = user.Id,
  548. RealName = user.RealName,
  549. UserLevel = user.UserLevel,
  550. });
  551. RedisDbconn.Instance.AddInt("TotalUser:NoAuth:" + uid);
  552. }
  553. RedisDbconn.Instance.Set("Users:" + user.Id, user);
  554. }
  555. db.Dispose();
  556. return "finish";
  557. }
  558. public string resetpos(int uid, int kind)
  559. {
  560. WebCMSEntities db = new WebCMSEntities();
  561. string IdBrand = uid + "_" + kind;
  562. UserMachineData machineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  563. if (machineData == null)
  564. {
  565. machineData = db.UserMachineData.Add(new UserMachineData()
  566. {
  567. IdBrand = IdBrand
  568. }).Entity;
  569. db.SaveChanges();
  570. }
  571. machineData.BindCount = db.PosMachinesTwo.Count(m => (m.UserId == uid && m.BuyUserId == uid) && m.BrandId == kind && m.BindingState == 1);
  572. machineData.UnBindCount = db.PosMachinesTwo.Count(m => (m.UserId == uid && m.BuyUserId == uid) && m.BrandId == kind && m.BindingState == 0);
  573. machineData.TotalMachineCount = machineData.BindCount + machineData.UnBindCount;
  574. db.SaveChanges();
  575. RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, machineData);
  576. RedisDbconn.Instance.SetExpire("UserMachineData:" + IdBrand, function.get_Random(1800, 5400));
  577. db.Dispose();
  578. return "finish";
  579. }
  580. // 更新分仓库存
  581. public string resetstorestock()
  582. {
  583. WebCMSEntities db = new WebCMSEntities();
  584. 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)");
  585. foreach (DataRow dr in dt.Rows)
  586. {
  587. int Id = int.Parse(function.CheckInt(dr["Id"].ToString()));
  588. int CurLaveNum = int.Parse(function.CheckInt(dr["CurLaveNum"].ToString()));
  589. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  590. if (store != null)
  591. {
  592. store.LaveNum = CurLaveNum;
  593. db.SaveChanges();
  594. RedisDbconn.Instance.Set("StoreHouse:" + Id, store);
  595. }
  596. }
  597. db.Dispose();
  598. return "ok";
  599. }
  600. public string resetstorestock2(int id)
  601. {
  602. WebCMSEntities db = new WebCMSEntities();
  603. 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);
  604. foreach (DataRow dr in dt.Rows)
  605. {
  606. int Id = int.Parse(function.CheckInt(dr["Id"].ToString()));
  607. int CurLaveNum = int.Parse(function.CheckInt(dr["CurLaveNum"].ToString()));
  608. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  609. if (store != null)
  610. {
  611. store.LaveNum = CurLaveNum;
  612. db.SaveChanges();
  613. RedisDbconn.Instance.Set("StoreHouse:" + Id, store);
  614. }
  615. }
  616. db.Dispose();
  617. return "ok";
  618. }
  619. public string chkpwd(string pwd)
  620. {
  621. return function.MD532(pwd);
  622. }
  623. //重置本月团队交易额
  624. public string resetMonthTrade()
  625. {
  626. return "";
  627. }
  628. public string traderecord(int kind, int id = 0)
  629. {
  630. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  631. if (kind == 1)
  632. {
  633. OtherMySqlConn.op("delete from TradeRecordTest;insert into TradeRecordTest (Sort,QueryCount,Status,Version,CreateDate,UpdateDate,CreateMan,UpdateMan,SeoTitle,SeoKeyword,SeoDescription,MerUserId,TopUserId,Remark,BrandId,DirectFlag,CapFlag,QrPayFlag,BankCardType,TradeAmount,TradeSerialNo,ClearDate,TradeDate,SnNo,MerBuddyType,HelpMonthCount,MerHelpFlag,MerNo,MerchantId,UserId,RecordNo) select Sort,QueryCount,Status,Version,CreateDate,UpdateDate,CreateMan,UpdateMan,SeoTitle,SeoKeyword,SeoDescription,MerUserId,TopUserId,Remark,BrandId,DirectFlag,CapFlag,QrPayFlag,BankCardType,TradeAmount,TradeSerialNo,ClearDate,TradeDate,SnNo,MerBuddyType,HelpMonthCount,MerHelpFlag,MerNo,MerchantId,UserId,RecordNo from TradeRecord order by CreateDate;");
  634. }
  635. else if (kind == 2)
  636. {
  637. OtherMySqlConn.op("delete from TradeRecord where Id<" + id + ";insert into TradeRecord (Id,Sort,QueryCount,Status,Version,CreateDate,UpdateDate,CreateMan,UpdateMan,SeoTitle,SeoKeyword,SeoDescription,MerUserId,TopUserId,Remark,BrandId,DirectFlag,CapFlag,QrPayFlag,BankCardType,TradeAmount,TradeSerialNo,ClearDate,TradeDate,SnNo,MerBuddyType,HelpMonthCount,MerHelpFlag,MerNo,MerchantId,UserId,RecordNo) select Id,Sort,QueryCount,Status,Version,CreateDate,UpdateDate,CreateMan,UpdateMan,SeoTitle,SeoKeyword,SeoDescription,MerUserId,TopUserId,Remark,BrandId,DirectFlag,CapFlag,QrPayFlag,BankCardType,TradeAmount,TradeSerialNo,ClearDate,TradeDate,SnNo,MerBuddyType,HelpMonthCount,MerHelpFlag,MerNo,MerchantId,UserId,RecordNo from TradeRecordTest order by Id;");
  638. }
  639. OtherMySqlConn.connstr = "";
  640. return "ok";
  641. }
  642. public string test()
  643. {
  644. string result = "";
  645. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  646. DataTable dt = OtherMySqlConn.dtable("select PosSn,UserId from PosMachinesTwo where UserId in (select Id from Users where MerchantType=1);");
  647. foreach (DataRow dr in dt.Rows)
  648. {
  649. string PosSn = dr["PosSn"].ToString();
  650. string UserId = dr["UserId"].ToString();
  651. DataTable subdt = OtherMySqlConn.dtable("select Id from TradeRecord where SnNo='" + PosSn + "' and CreateDate>='2022-04-01 00:00:00'");
  652. foreach (DataRow subdr in subdt.Rows)
  653. {
  654. result += "update TradeRecord set UserId=" + UserId + " where Id=" + subdr["Id"].ToString() + ";\n";
  655. }
  656. }
  657. OtherMySqlConn.connstr = "";
  658. return result;
  659. }
  660. }
  661. }