HomeController.cs 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  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. // 补流量费奖励
  123. public string addflux(string date)
  124. {
  125. StatService.Instance.doFluxRecord(date);
  126. return "ok";
  127. }
  128. public string chkactprize(int Id = 0)
  129. {
  130. if (Id > 0)
  131. {
  132. StatService.Instance.dosomething3(Id);
  133. }
  134. return "ok";
  135. }
  136. public string mutilactprize()
  137. {
  138. List<int> ids = new List<int>();
  139. WebCMSEntities db = new WebCMSEntities();
  140. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  141. foreach (int id in ids)
  142. {
  143. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == id);
  144. if (pos != null)
  145. {
  146. SpModels.ActivateRecord act = spdb.ActivateRecord.FirstOrDefault(m => m.SnNo == pos.PosSn && m.SeoTitle != "0" && !string.IsNullOrEmpty(m.SeoTitle));
  147. if (act != null)
  148. {
  149. pos.SeoKeyword = act.SeoTitle;
  150. db.SaveChanges();
  151. StatService.Instance.dosomething3(pos.Id);
  152. }
  153. }
  154. }
  155. db.Dispose();
  156. spdb.Dispose();
  157. return "ok";
  158. }
  159. public string scanBind()
  160. {
  161. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  162. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  163. var Binds = spdb.BindRecord.Select(m => new { m.Id, m.CreateTime, m.Status, m.MerNo, m.MerSnNo }).OrderBy(m => m.Id).ToList();
  164. foreach (var Bind in Binds)
  165. {
  166. var tran = db.Database.BeginTransaction();
  167. try
  168. {
  169. PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.MerSnNo) ?? new PxcModels.MachineForSnNo();
  170. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  171. if (pos != null)
  172. {
  173. if (pos.BindingState == 0)
  174. {
  175. pos.BindingState = 1;
  176. pos.BindingTime = Bind.CreateTime;
  177. PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo);
  178. if (merFor == null)
  179. {
  180. merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
  181. {
  182. MerNo = Bind.MerNo,
  183. SnId = pos.Id,
  184. }).Entity;
  185. }
  186. db.SaveChanges();
  187. tran.Commit();
  188. function.WriteLog(pos.PosSn, "补充绑定数据");
  189. }
  190. }
  191. }
  192. catch (Exception ex)
  193. {
  194. tran.Rollback();
  195. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Bind.Id, "同步SP绑定数据到MAIN异常");
  196. }
  197. tran.Dispose();
  198. }
  199. spdb.SaveChanges();
  200. spdb.Dispose();
  201. db.SaveChanges();
  202. db.Dispose();
  203. return "ok";
  204. }
  205. public string scanMerchant()
  206. {
  207. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  208. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  209. var Mers = spdb.Merchants.OrderBy(m => m.Id).ToList();
  210. foreach (var Mer in Mers)
  211. {
  212. var tran = db.Database.BeginTransaction();
  213. try
  214. {
  215. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo) ?? new PxcModels.MachineForMerNo();
  216. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId) ?? new PxcModels.PosMachinesTwo();
  217. if (pos.BindingState == 1)
  218. {
  219. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  220. int TopUserId = 0;
  221. if (!string.IsNullOrEmpty(user.ParentNav))
  222. {
  223. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  224. }
  225. int BrandId = int.Parse(Mer.ProductType);
  226. if (Mer.MerNo.StartsWith("M900"))
  227. {
  228. BrandId = 3;
  229. }
  230. bool check = db.PosMerchantInfo.Any(m => m.KqMerNo == Mer.MerNo);
  231. if (!check)
  232. {
  233. PxcModels.PosMerchantInfo add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
  234. {
  235. CreateDate = Mer.CreateTime,
  236. UpdateDate = Mer.UpdateTime,
  237. TopUserId = TopUserId,
  238. MerUserType = user.MerchantType,
  239. BrandId = BrandId,
  240. SnStoreId = pos.StoreId,
  241. SnType = pos.PosSnType,
  242. UserId = pos.UserId,
  243. MgrName = Mer.AgentName,
  244. MerStatus = 1,
  245. KqSnNo = Mer.SnNo,
  246. KqMerNo = Mer.MerNo,
  247. MerIdcardNo = Mer.MerIdcardNo,
  248. MerRealName = Mer.MerRealName,
  249. MerchantMobile = Mer.MerMobile,
  250. MerchantName = Mer.MerName,
  251. MerchantNo = Mer.MerNo.Length > 16 ? Mer.MerNo.Substring(0, 16) : Mer.MerNo,
  252. }).Entity;
  253. db.SaveChanges();
  254. pos.BindMerchantId = add.Id;
  255. db.SaveChanges();
  256. tran.Commit();
  257. function.WriteLog(Mer.MerNo, "补充商户数据");
  258. }
  259. }
  260. }
  261. catch (Exception ex)
  262. {
  263. tran.Rollback();
  264. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Mer.Id, "同步SP商户数据到MAIN异常");
  265. }
  266. tran.Dispose();
  267. }
  268. spdb.Dispose();
  269. db.Dispose();
  270. return "ok";
  271. }
  272. public string scanTrade()
  273. {
  274. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  275. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  276. IQueryable<SpModels.TradeRecord> trades = spdb.TradeRecord.OrderBy(m => m.Id);
  277. foreach (SpModels.TradeRecord trade in trades.ToList())
  278. {
  279. bool op = true;
  280. if (trade.SerEntryMode == "N")
  281. {
  282. if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900)
  283. {
  284. op = false;
  285. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
  286. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  287. if (pos != null)
  288. {
  289. if (trade.SerEntryMode == "N" && trade.ProductType == "1")
  290. {
  291. pos.SeoKeyword = trade.TradeAmount.ToString("f2");
  292. db.SaveChanges();
  293. }
  294. }
  295. }
  296. }
  297. if (op)
  298. {
  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 (pos.BindMerchantId > 0)
  304. {
  305. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  306. int TopUserId = 0;
  307. if (!string.IsNullOrEmpty(user.ParentNav))
  308. {
  309. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  310. }
  311. bool check = db.TradeRecord.Any(m => m.RecordNo == trade.TradeSerialNo);
  312. if (!check)
  313. {
  314. decimal TradeAmount = trade.TradeAmount;
  315. int BankCardType = -1;
  316. int QrPayFlag = 0;
  317. if (pos.BrandId == 1 || pos.BrandId == 3)
  318. {
  319. TradeAmount = TradeAmount / 100;
  320. BankCardType = int.Parse(trade.BankCardType);
  321. if (trade.TradeType == "02") QrPayFlag = 1;
  322. }
  323. else if (pos.BrandId == 2)
  324. {
  325. if (trade.TradeType == "CREDIT_BY_CARD")
  326. {
  327. BankCardType = 1;
  328. }
  329. else if (trade.TradeType == "DEBIT_BY_CARD")
  330. {
  331. BankCardType = 0;
  332. }
  333. if (trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
  334. }
  335. int BrandId = int.Parse(trade.ProductType);
  336. if (trade.MerNo.StartsWith("M900"))
  337. {
  338. BrandId = 3;
  339. }
  340. db.TradeRecord.Add(new PxcModels.TradeRecord()
  341. {
  342. CreateDate = trade.CreateDate,
  343. UpdateDate = trade.UpdateDate,
  344. RecordNo = trade.TradeSerialNo, //单号
  345. UserId = pos.UserId, //创客
  346. MerchantId = pos.BindMerchantId, //商户
  347. MerNo = trade.MerNo, //渠道商户编号
  348. MerHelpFlag = 0, //是否属于扶持周期内商户
  349. HelpMonthCount = 0, //扶持第几个月
  350. MerBuddyType = user.MerchantType, //商户创客类型
  351. SnNo = trade.TradeSnNo, //渠道SN号
  352. // TradeDate = DateTime.Parse(trade.TradeTime), //交易日期
  353. TradeSerialNo = trade.ChannelSerial, //交易流水号
  354. TradeAmount = TradeAmount, //交易金额
  355. BankCardType = BankCardType, //银行卡类型
  356. QrPayFlag = QrPayFlag, //云闪付标识
  357. BrandId = BrandId, //品牌
  358. Remark = trade.Remark, //备注
  359. TopUserId = TopUserId, //顶级创客
  360. MerUserId = pos.UserId, //商户直属创客
  361. ParentNav = user.ParentNav,
  362. });
  363. if (BankCardType == 1)
  364. {
  365. pos.CreditTrade += TradeAmount;
  366. }
  367. else if (BankCardType == 0)
  368. {
  369. pos.DebitCardTrade += TradeAmount;
  370. }
  371. else if (pos.CreditTrade >= 1000 && pos.ActivationState == 0 && pos.BindingTime > DateTime.Now.AddDays(-20))
  372. {
  373. // pos.IsPurchase = 0;
  374. pos.ActivationState = 1;
  375. pos.ActivationTime = DateTime.Now;
  376. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  377. if (merchant != null)
  378. {
  379. merchant.ActiveStatus = 1;
  380. merchant.MerStandardDate = DateTime.Now;
  381. db.SaveChanges();
  382. }
  383. }
  384. db.SaveChanges();
  385. function.WriteLog(trade.Id.ToString(), "补充交易数据");
  386. }
  387. }
  388. }
  389. }
  390. }
  391. spdb.Dispose();
  392. db.Dispose();
  393. return "ok";
  394. }
  395. // public string add100()
  396. // {
  397. // WebCMSEntities db = new WebCMSEntities();
  398. // List<int> uids = new List<int>();
  399. // uids.Add(1053);
  400. // foreach (int uid in uids)
  401. // {
  402. // int ParentUserId = uid;
  403. // int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台购买机
  404. // int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  405. // if (machineCount + ActiveCount >= 3)
  406. // {
  407. // UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == ParentUserId);
  408. // if (account == null)
  409. // {
  410. // account = db.UserAccount.Add(new UserAccount()
  411. // {
  412. // Id = ParentUserId,
  413. // UserId = ParentUserId,
  414. // }).Entity;
  415. // db.SaveChanges();
  416. // }
  417. // decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  418. // decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  419. // decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  420. // account.BalanceAmount += 100;
  421. // account.TotalAmount += 100;
  422. // decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  423. // decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  424. // decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  425. // UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  426. // {
  427. // CreateDate = DateTime.Now,
  428. // UpdateDate = DateTime.Now,
  429. // UserId = ParentUserId, //创客
  430. // ChangeType = 112, //变动类型
  431. // ChangeAmount = 100, //变更金额
  432. // BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  433. // AfterTotalAmount = AfterTotalAmount, //变更后总金额
  434. // BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  435. // AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  436. // BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  437. // AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  438. // }).Entity;
  439. // db.SaveChanges();
  440. // RedisDbconn.Instance.Set("UserAccount:" + ParentUserId, account);
  441. // //推荐下单上级获得30天的机具循环天数
  442. // 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();
  443. // foreach (var subPos in posList)
  444. // {
  445. // PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  446. // if (pos != null)
  447. // {
  448. // pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  449. // }
  450. // }
  451. // db.SaveChanges();
  452. // }
  453. // }
  454. // db.Dispose();
  455. // return "finish";
  456. // }
  457. //交易不到1000的机具,顶级姓名-代理姓名-客户姓名-客户电话-开机日期-SN // TODO:做到BS后台导出,按绑定时间查
  458. public IActionResult PosTable()
  459. {
  460. WebCMSEntities db = new WebCMSEntities();
  461. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  462. List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
  463. foreach (PosMachinesTwo pos in poses)
  464. {
  465. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  466. Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
  467. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  468. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  469. Dictionary<string, string> item = new Dictionary<string, string>();
  470. string TopRealName = "";
  471. string TopMakerCode = "";
  472. string TopMobile = "";
  473. string ParentNav = user.ParentNav;
  474. if (!string.IsNullOrEmpty(ParentNav))
  475. {
  476. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  477. if (navlist.Length > 1)
  478. {
  479. int TopId = int.Parse(function.CheckInt(navlist[1]));
  480. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  481. TopRealName = tuser.RealName;
  482. TopMakerCode = tuser.MakerCode;
  483. TopMobile = tuser.Mobile;
  484. }
  485. }
  486. item.Add("TopRealName", TopRealName); //顶级姓名
  487. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  488. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  489. item.Add("UpRealName", puser.RealName); //上级姓名
  490. item.Add("RealName", user.RealName); //代理姓名
  491. item.Add("MakerCode", user.MakerCode); //代理编号
  492. item.Add("Mobile", user.Mobile); //代理手机号
  493. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  494. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  495. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  496. item.Add("Sn", pos.PosSn); //SN
  497. list.Add(item);
  498. }
  499. db.Dispose();
  500. ViewBag.list = list;
  501. return View();
  502. }
  503. public string resetall(int k = 0, int b = 1)
  504. {
  505. DataTable dt = dbconn.dtable("select Id from Users where AuthFlag=1");
  506. foreach (DataRow dr in dt.Rows)
  507. {
  508. if (k == 1)
  509. {
  510. reset(int.Parse(dr["Id"].ToString()));
  511. }
  512. else if (k == 2)
  513. {
  514. resetpos(int.Parse(dr["Id"].ToString()), b);
  515. }
  516. }
  517. return "ok";
  518. }
  519. public string reset(int uid)
  520. {
  521. WebCMSEntities db = new WebCMSEntities();
  522. List<Users> users = db.Users.Where(m => m.ParentUserId == uid).OrderByDescending(m => m.AuthDate).ToList();
  523. RedisDbconn.Instance.Clear("MyMakerList:" + uid);
  524. RedisDbconn.Instance.Clear("MyMakerForNotAuth:" + uid);
  525. RedisDbconn.Instance.Clear("TotalUser:" + uid + "*");
  526. RedisDbconn.Instance.Clear("TotalUser:Auth:" + uid);
  527. foreach (Users user in users)
  528. {
  529. RedisDbconn.Instance.AddInt("TotalUser:" + uid);
  530. RedisDbconn.Instance.AddInt("TotalUser:" + uid + ":" + user.CreateDate.Value.ToString("yyyyMM"));
  531. RedisDbconn.Instance.AddInt("TotalUser:" + uid + ":" + user.CreateDate.Value.ToString("yyyyMMdd"));
  532. if (user.AuthFlag == 1)
  533. {
  534. RedisDbconn.Instance.AddList("MyMakerList:" + uid, new MyMakerItem()
  535. {
  536. UserId = user.Id,
  537. RealName = user.RealName,
  538. UserLevel = user.UserLevel,
  539. });
  540. RedisDbconn.Instance.AddInt("TotalUser:Auth:" + uid);
  541. }
  542. else
  543. {
  544. RedisDbconn.Instance.AddList("MyMakerForNotAuth:" + uid, new MyMakerItem()
  545. {
  546. UserId = user.Id,
  547. RealName = user.RealName,
  548. UserLevel = user.UserLevel,
  549. });
  550. RedisDbconn.Instance.AddInt("TotalUser:NoAuth:" + uid);
  551. }
  552. RedisDbconn.Instance.Set("Users:" + user.Id, user);
  553. }
  554. db.Dispose();
  555. return "finish";
  556. }
  557. public string resetpos(int uid, int kind)
  558. {
  559. WebCMSEntities db = new WebCMSEntities();
  560. string IdBrand = uid + "_" + kind;
  561. UserMachineData machineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  562. if (machineData == null)
  563. {
  564. machineData = db.UserMachineData.Add(new UserMachineData()
  565. {
  566. IdBrand = IdBrand
  567. }).Entity;
  568. db.SaveChanges();
  569. }
  570. machineData.BindCount = db.PosMachinesTwo.Count(m => m.Status > -1 && m.BuyUserId == uid && m.BrandId == kind && m.BindingState == 1);
  571. machineData.UnBindCount = db.PosMachinesTwo.Count(m => m.Status > -1 && m.BuyUserId == uid && m.BrandId == kind && m.BindingState == 0);
  572. machineData.TotalMachineCount = machineData.BindCount + machineData.UnBindCount;
  573. db.SaveChanges();
  574. RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, machineData);
  575. RedisDbconn.Instance.SetExpire("UserMachineData:" + IdBrand, function.get_Random(1800, 5400));
  576. db.Dispose();
  577. return "finish";
  578. }
  579. // 更新分仓库存
  580. public string resetstorestock()
  581. {
  582. WebCMSEntities db = new WebCMSEntities();
  583. 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)");
  584. foreach (DataRow dr in dt.Rows)
  585. {
  586. int Id = int.Parse(function.CheckInt(dr["Id"].ToString()));
  587. int CurLaveNum = int.Parse(function.CheckInt(dr["CurLaveNum"].ToString()));
  588. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  589. if (store != null)
  590. {
  591. store.LaveNum = CurLaveNum;
  592. db.SaveChanges();
  593. RedisDbconn.Instance.Set("StoreHouse:" + Id, store);
  594. }
  595. }
  596. db.Dispose();
  597. return "ok";
  598. }
  599. public string resetstorestock2(int id)
  600. {
  601. WebCMSEntities db = new WebCMSEntities();
  602. 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);
  603. foreach (DataRow dr in dt.Rows)
  604. {
  605. int Id = int.Parse(function.CheckInt(dr["Id"].ToString()));
  606. int CurLaveNum = int.Parse(function.CheckInt(dr["CurLaveNum"].ToString()));
  607. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  608. if (store != null)
  609. {
  610. store.LaveNum = CurLaveNum;
  611. db.SaveChanges();
  612. RedisDbconn.Instance.Set("StoreHouse:" + Id, store);
  613. }
  614. }
  615. db.Dispose();
  616. return "ok";
  617. }
  618. public string chkpwd(string pwd)
  619. {
  620. return function.MD532(pwd);
  621. }
  622. //重置本月团队交易额
  623. public string resetMonthTrade()
  624. {
  625. return "";
  626. }
  627. public string traderecord(int kind, int id = 0)
  628. {
  629. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  630. if (kind == 1)
  631. {
  632. 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;");
  633. }
  634. else if (kind == 2)
  635. {
  636. 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;");
  637. }
  638. // OtherMySqlConn.connstr = ;
  639. return "ok";
  640. }
  641. public string test()
  642. {
  643. string result = "ok";
  644. OtherMySqlConn.connstr = "server=47.109.31.237;port=3306;user=KxsMainServer;password=Rw2imhXQQt5ODWIF;database=KxsMainServer;charset=utf8;";
  645. DataTable dt = OtherMySqlConn.dtable("select * from ProfitSubsidyDetail where TradeMonth='202204'");
  646. WebCMSEntities db = new WebCMSEntities();
  647. foreach (DataRow dr in dt.Rows)
  648. {
  649. int BrandId = int.Parse(function.CheckInt(dr["BrandId"].ToString()));
  650. int MerchantId = int.Parse(function.CheckInt(dr["MerchantId"].ToString()));
  651. int SubsidyUserId = int.Parse(function.CheckInt(dr["SubsidyUserId"].ToString()));
  652. int SubsidyType = int.Parse(function.CheckInt(dr["SubsidyType"].ToString()));
  653. ulong MerHelpFlag = ulong.Parse(function.CheckInt(dr["MerHelpFlag"].ToString()));
  654. decimal SubsidyProfitRate = decimal.Parse(function.CheckNum(dr["SubsidyProfitRate"].ToString()));
  655. decimal CreditTradeAmt = decimal.Parse(function.CheckNum(dr["CreditTradeAmt"].ToString()));
  656. decimal QrCreditTradeAmt = decimal.Parse(function.CheckNum(dr["QrCreditTradeAmt"].ToString()));
  657. decimal NonQrCreditTradeAmt = decimal.Parse(function.CheckNum(dr["NonQrCreditTradeAmt"].ToString()));
  658. decimal CreditProfitRate = decimal.Parse(function.CheckNum(dr["CreditProfitRate"].ToString()));
  659. decimal SubsidyProfit = decimal.Parse(function.CheckNum(dr["SubsidyProfit"].ToString()));
  660. string TradeMonth = dr["TradeMonth"].ToString();
  661. string SnNo = dr["SnNo"].ToString();
  662. string MerNo = dr["MerNo"].ToString();
  663. string RecordNo = dr["RecordNo"].ToString();
  664. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
  665. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId) ?? new PosMachinesTwo();
  666. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == MerchantId) ?? new PosMerchantInfo();
  667. ProfitSubsidyDetail item = db.ProfitSubsidyDetail.FirstOrDefault(m => m.SubsidyUserId == SubsidyUserId && m.TradeMonth == TradeMonth && m.MerchantId == MerchantId && m.SnNo == SnNo);
  668. if (item == null)
  669. {
  670. db.ProfitSubsidyDetail.Add(new ProfitSubsidyDetail()
  671. {
  672. CreateDate = DateTime.Now,
  673. UpdateDate = DateTime.Now,
  674. RecordNo = RecordNo, //流水号
  675. BrandId = BrandId, //品牌
  676. ProductName = RelationClass.GetKqProductBrandInfo(BrandId), //产品名称
  677. TradeMonth = TradeMonth, //交易月份
  678. MerchantId = MerchantId, //商户
  679. MerNo = MerNo, //渠道商户编号
  680. SnNo = SnNo, //渠道SN号
  681. MerRegTime = pos.BindingTime, //渠道注册时间
  682. MerStandardDate = merchant.MerStandardDate, //商户激活时间
  683. BelongUserId = merchant.UserId, //商户归属人
  684. MerHelpFlag = MerHelpFlag, //是否属于扶持周期内商户
  685. SubsidyUserId = SubsidyUserId, //补贴人
  686. SubsidyType = SubsidyType, //分润补贴类型
  687. SubsidyProfitRate = SubsidyProfitRate, //创客活动期内直营商户分润万分之十
  688. CreditTradeAmt = CreditTradeAmt, //商户贷记卡交易总金额
  689. QrCreditTradeAmt = QrCreditTradeAmt, //商户(云闪付)贷记卡交易总金额
  690. NonQrCreditTradeAmt = NonQrCreditTradeAmt, //商户(非云闪付)贷记卡交易总金额
  691. CreditProfitRate = CreditProfitRate, //(非云闪付)贷记卡交易分润比例
  692. SubsidyProfit = SubsidyProfit, //商户(非云闪付)贷记卡交易分润补贴金额
  693. });
  694. // db.SaveChanges();
  695. result += "增加--SubsidyUserId:" + SubsidyUserId + ";SnNo" + SnNo + ";SubsidyProfit" + SubsidyProfit + ";";
  696. }
  697. else
  698. {
  699. if (item.SubsidyProfit < SubsidyProfit)
  700. {
  701. item.SubsidyProfitRate = SubsidyProfitRate; //创客活动期内直营商户分润万分之十
  702. item.SubsidyProfit = SubsidyProfit; //商户(非云闪付)贷记卡交易分润补贴金额
  703. result += "更新--SubsidyUserId:" + SubsidyUserId + ";SnNo" + SnNo + ";SubsidyProfit" + SubsidyProfit + ";";
  704. // db.SaveChanges();
  705. }
  706. }
  707. }
  708. // OtherMySqlConn.connstr = ;
  709. db.Dispose();
  710. return result;
  711. }
  712. public string test2()
  713. {
  714. string result = "ok";
  715. OtherMySqlConn.connstr = "server=47.108.231.170;port=3306;user=KxsMainServer;password=Rw2imhXQQt5ODWIF;database=KxsMainServer;charset=utf8;";
  716. DataTable dt = OtherMySqlConn.dtable("select SubsidyUserId,BrandId,sum(SubsidyProfitRate) as SubsidyProfit from ProfitSubsidyDetail where TradeMonth='202204' and SubsidyUserId>0 GROUP BY SubsidyUserId,BrandId");
  717. WebCMSEntities db = new WebCMSEntities();
  718. DateTime checkDate = DateTime.Parse("2022-05-20 00:00:00");
  719. foreach (DataRow dr in dt.Rows)
  720. {
  721. int BrandId = int.Parse(function.CheckInt(dr["BrandId"].ToString()));
  722. int SubsidyUserId = int.Parse(function.CheckInt(dr["SubsidyUserId"].ToString()));
  723. decimal SubsidyProfit = decimal.Parse(function.CheckNum(dr["SubsidyProfit"].ToString()));
  724. UserAccountRecord userAccountRecord = db.UserAccountRecord.FirstOrDefault(m => m.Id > 86538 && m.CreateDate > checkDate && m.UserId == SubsidyUserId && m.ProductType == BrandId && m.ChangeType == 111);
  725. if (userAccountRecord == null)
  726. {
  727. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == SubsidyUserId);
  728. if (account == null)
  729. {
  730. account = db.UserAccount.Add(new UserAccount()
  731. {
  732. Id = SubsidyUserId,
  733. UserId = SubsidyUserId,
  734. }).Entity;
  735. db.SaveChanges();
  736. }
  737. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  738. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  739. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  740. // account.BalanceAmount += SubsidyProfit;
  741. // account.TotalAmount += SubsidyProfit;
  742. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  743. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  744. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  745. userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  746. {
  747. CreateDate = DateTime.Now,
  748. UpdateDate = DateTime.Now,
  749. UserId = SubsidyUserId, //创客
  750. ProductType = BrandId,
  751. ChangeType = 111, //变动类型
  752. ChangeAmount = SubsidyProfit, //变更金额
  753. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  754. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  755. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  756. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  757. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  758. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  759. Remark = "直拓商户补贴",
  760. }).Entity;
  761. db.SaveChanges();
  762. }
  763. else
  764. {
  765. userAccountRecord.ChangeAmount = SubsidyProfit;
  766. db.SaveChanges();
  767. }
  768. }
  769. // OtherMySqlConn.connstr = ;
  770. db.Dispose();
  771. return result;
  772. }
  773. public string prize888v2()
  774. {
  775. WebCMSEntities maindb = new WebCMSEntities();
  776. List<int> userIdList = new List<int>();
  777. string html = "<table>";
  778. DateTime StartDate = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 00:00:00");
  779. DateTime EndDate = StartDate.AddMonths(1);
  780. var orders = maindb.Orders.Select(m => new { m.UserId, m.TotalPrice, m.Status, m.PayDate }).Where(m => m.PayDate >= StartDate && m.PayDate < EndDate && m.TotalPrice == 88 && m.Status > 0).ToList();
  781. foreach (var order in orders)
  782. {
  783. userIdList.Add(order.UserId);
  784. }
  785. foreach (int UserId in userIdList)
  786. {
  787. Users myuser = maindb.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  788. var lastmonth = DateTime.Now.AddMonths(-2).ToString("yyyyMM");
  789. var thismonth = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
  790. DateTime start = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date;
  791. DateTime end = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.AddMonths(1).AddSeconds(-1);
  792. string UserIdString = "," + UserId + ",";
  793. List<Users> users = maindb.Users.Where(m => m.ParentNav.Contains(UserIdString) || m.Id == UserId).ToList();
  794. List<int> uids = new List<int>();
  795. List<int> uids2 = new List<int>();
  796. foreach (var user in users)
  797. {
  798. uids.Add(user.Id);
  799. }
  800. var suborders = orders.Where(m => uids.Contains(m.UserId)).ToList();
  801. foreach (var suborder in suborders)
  802. {
  803. uids2.Add(suborder.UserId);
  804. }
  805. users = users.Where(m => uids2.Contains(m.Id)).ToList();
  806. List<ProgressUserList> list = new List<ProgressUserList>();
  807. foreach (Users user in users)
  808. {
  809. int IsOk = 0;//是否达标(0-否 1-是)
  810. decimal lastMonthAmt = maindb.TradeDaySummary.Where(m => m.TradeMonth == lastmonth && m.SeoTitle == "team" && m.UserId == user.Id).Sum(m => m.HelpNonDirectTradeAmt + m.NotHelpNonDirectTradeAmt);
  811. decimal thisMonthAmt = maindb.TradeDaySummary.Where(m => m.TradeMonth == thismonth && m.SeoTitle == "team" && m.UserId == user.Id).Sum(m => m.HelpNonDirectTradeAmt + m.NotHelpNonDirectTradeAmt);
  812. if (thisMonthAmt >= lastMonthAmt * 2 && thisMonthAmt >= 2000000)
  813. {
  814. IsOk = 1;
  815. }
  816. ProgressUserList item = new ProgressUserList()
  817. {
  818. LastMonth = lastMonthAmt,
  819. ThisMonth = thisMonthAmt,
  820. UserId = user.Id,
  821. ParentNav = user.ParentNav,
  822. IsOk = IsOk,
  823. };
  824. list.Add(item);
  825. }
  826. list = list.OrderBy(m => m.ParentNav).ToList();
  827. int index = 0;
  828. decimal selfTrade = 0; // 自己的本月交易额
  829. decimal lastTrade = 0; // 自己的上月交易额
  830. decimal totalTrade = 0; // 自己的本月目标交易额
  831. string selfNav = ""; // 自己的ParentNav
  832. List<string> ParentNavs = new List<string>();
  833. if (list.Count > 0)
  834. {
  835. foreach (ProgressUserList sub in list)
  836. {
  837. index += 1;
  838. if (index == 1)
  839. {
  840. selfTrade = sub.ThisMonth;
  841. lastTrade = sub.LastMonth;
  842. totalTrade = lastTrade * 2;
  843. selfNav = sub.ParentNav + "," + sub.UserId + ",";
  844. }
  845. else
  846. {
  847. bool op = true; //是否满足条件
  848. string ParentNav = sub.ParentNav + "," + sub.UserId + ",";
  849. foreach (string subNav in ParentNavs)
  850. {
  851. if (ParentNavs.Contains(ParentNav) && ParentNav != subNav)
  852. {
  853. op = false;
  854. }
  855. }
  856. if (op)
  857. {
  858. if (sub.IsOk == 1)
  859. {
  860. selfTrade -= sub.ThisMonth;
  861. totalTrade -= sub.ThisMonth;
  862. }
  863. }
  864. ParentNavs.Add(ParentNav);
  865. }
  866. }
  867. }
  868. if (lastTrade * 2 < 2000000 || selfTrade == 0 || totalTrade < 2000000)
  869. {
  870. totalTrade = 2000000;
  871. }
  872. html += "<tr>";
  873. html += "<td>" + myuser.MakerCode + "</td>";
  874. html += "<td>" + myuser.RealName + "</td>";
  875. html += "<td>" + selfTrade + "</td>";
  876. html += "<td>" + lastTrade + "</td>";
  877. html += "<td>" + totalTrade + "</td>";
  878. if (selfTrade >= totalTrade)
  879. {
  880. html += "<td>满足条件</td>";
  881. }
  882. else
  883. {
  884. html += "<td>未满足条件</td>";
  885. }
  886. html += "</tr>";
  887. }
  888. html += "</table>";
  889. maindb.Dispose();
  890. return html;
  891. }
  892. // 大盟主标记扫描
  893. public string leaderflag()
  894. {
  895. WebCMSEntities db = new WebCMSEntities();
  896. List<int> ids = new List<int>();
  897. List<PosCouponRecord> records = db.PosCouponRecord.Where(m => m.FromUserId == 123354).ToList();
  898. foreach(PosCouponRecord record in records)
  899. {
  900. ids.Add(record.PosCouponId);
  901. }
  902. List<PosCoupons> coupons = db.PosCoupons.Where(m => ids.Contains(m.Id) && m.IsUse == 1).ToList();
  903. foreach (PosCoupons coupon in coupons)
  904. {
  905. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(coupon.ExchangeCode));
  906. if(apply != null)
  907. {
  908. Orders order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount);
  909. if(order != null)
  910. {
  911. if(!string.IsNullOrEmpty(order.SnNos))
  912. {
  913. string[] SwapSnExpands = order.SnNos.TrimEnd('\n').Split('\n');
  914. foreach(string no in SwapSnExpands)
  915. {
  916. ChildNo(db, no, coupon.LeaderUserId);
  917. }
  918. }
  919. }
  920. }
  921. }
  922. // db.SaveChanges();
  923. db.Dispose();
  924. return "ok";
  925. }
  926. List<string> nos = new List<string>();
  927. private void ChildNo(WebCMSEntities db, string CheckNo, int LeaderUserId)
  928. {
  929. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(CheckNo));
  930. if(apply != null)
  931. {
  932. Orders order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount);
  933. if(order != null)
  934. {
  935. if(!string.IsNullOrEmpty(order.SnNos))
  936. {
  937. string[] SwapSnExpands = order.SnNos.TrimEnd('\n').Split('\n');
  938. foreach(string no in SwapSnExpands)
  939. {
  940. ChildNo(db, no, LeaderUserId);
  941. }
  942. }
  943. else
  944. {
  945. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == CheckNo) ?? new MachineForSnNo();
  946. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m=>m.Id == forSnNo.SnId);
  947. if(pos != null)
  948. {
  949. // pos.LeaderUserId = LeaderUserId;
  950. // Library.function.WriteLog(LeaderUserId + ":" + pos.PosSn + ":" + apply.SwapSnExpand.TrimEnd('\n').Split('\n').Length, "大盟主奖励标记机具");
  951. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  952. Library.function.WriteLog(pos.PosSn + ":" + user.MakerCode + ":" + user.RealName, "大盟主奖励标记机具");
  953. }
  954. }
  955. }
  956. }
  957. else
  958. {
  959. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == CheckNo) ?? new MachineForSnNo();
  960. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m=>m.Id == forSnNo.SnId);
  961. if(pos != null)
  962. {
  963. // pos.LeaderUserId = LeaderUserId;
  964. // Library.function.WriteLog(LeaderUserId + ":" + pos.PosSn, "大盟主奖励标记机具");
  965. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  966. Library.function.WriteLog(pos.PosSn + ":" + user.MakerCode + ":" + user.RealName, "大盟主奖励标记机具");
  967. }
  968. }
  969. }
  970. //补推荐奖励
  971. public string AddDirectPrice(int oid = 0)
  972. {
  973. WebCMSEntities db = new WebCMSEntities();
  974. List<int> uids = new List<int>(); //领取过的下单创客
  975. IQueryable<Orders> orders = db.Orders.Where(m => m.Status > 1 && m.UserId > 1 && m.TotalPrice % 600 == 0 && m.Sort == 0);
  976. if(oid > 0)
  977. {
  978. orders = orders.Where(m => m.Id == oid);
  979. }
  980. foreach (Orders order in orders.ToList())
  981. {
  982. if(!uids.Contains(order.UserId))
  983. {
  984. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == oid && m.ChangeType == 112);
  985. if(checkPrize)
  986. {
  987. uids.Add(order.UserId);
  988. }
  989. else
  990. {
  991. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == oid) ?? new OrderProduct();
  992. if (pro.ProductId == 10 || pro.ProductId == 11)
  993. {
  994. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  995. if (user != null)
  996. {
  997. bool directPrize = false; //直推奖标记
  998. int ParentUserId = user.ParentUserId;
  999. List<int> proids = new List<int>();
  1000. proids.Add(10);
  1001. proids.Add(11);
  1002. while (ParentUserId > 0)
  1003. {
  1004. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1005. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
  1006. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1007. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  1008. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  1009. {
  1010. function.WriteLog("满足条件", "推荐下单奖励监控日志");
  1011. if (puser.LeaderLevel == 0) // 非盟主直推奖励,每个创客第一次下单,上级可得
  1012. {
  1013. List<int> oids = new List<int>();
  1014. var orderpros = db.OrderProduct.Select(m => new { m.OrderId, m.UserId, m.ProductId }).Where(m => m.UserId == order.UserId && proids.Contains(m.ProductId)).ToList();
  1015. foreach (var orderpro in orderpros)
  1016. {
  1017. oids.Add(orderpro.OrderId);
  1018. }
  1019. bool check = db.Orders.Any(m => oids.Contains(m.Id) && m.Status > 0);
  1020. if (check)
  1021. {
  1022. // AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  1023. function.WriteLog(order.Id + "," + ParentUserId + "," + pro.ProductCount, "没发的推荐奖励");
  1024. directPrize = true;
  1025. }
  1026. }
  1027. else
  1028. {
  1029. // 盟主直推奖励,可以每次下单获得
  1030. // AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  1031. function.WriteLog(order.Id + "," + ParentUserId + "," + pro.ProductCount + "--盟主", "没发的推荐奖励");
  1032. directPrize = true;
  1033. }
  1034. //推荐下单上级获得30天的机具循环天数
  1035. 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();
  1036. foreach (var subPos in posList)
  1037. {
  1038. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  1039. if (pos != null)
  1040. {
  1041. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  1042. }
  1043. }
  1044. db.SaveChanges();
  1045. }
  1046. if(directPrize)
  1047. {
  1048. ParentUserId = 0;
  1049. }
  1050. else
  1051. {
  1052. ParentUserId = puser.ParentUserId;
  1053. }
  1054. }
  1055. }
  1056. }
  1057. }
  1058. }
  1059. }
  1060. return "ok";
  1061. }
  1062. }
  1063. }