HomeController.cs 31 KB

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