HomeController.cs 33 KB

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