HomeController.cs 64 KB

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