HomeController.cs 66 KB

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