HomeController.cs 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591
  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. // 补发小盟主15000返现
  123. public string LeaderBack(int oid)
  124. {
  125. WebCMSEntities db = new WebCMSEntities();
  126. Orders order = db.Orders.FirstOrDefault(m => m.Id == oid);
  127. if(order != null)
  128. {
  129. AlipayPayBack2Service.Instance.LeaderBack(db, order);
  130. }
  131. db.Dispose();
  132. return "ok";
  133. }
  134. public string chkactprize(int Id = 0)
  135. {
  136. if (Id > 0)
  137. {
  138. StatService.Instance.dosomething3(Id);
  139. }
  140. return "ok";
  141. }
  142. public string chkactprize2(int Id = 0)
  143. {
  144. if (Id > 0)
  145. {
  146. StatService.Instance.activePrizeWithoutDeposit(Id);
  147. }
  148. return "ok";
  149. }
  150. public string mutilactprize()
  151. {
  152. List<int> ids = new List<int>();
  153. WebCMSEntities db = new WebCMSEntities();
  154. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  155. foreach (int id in ids)
  156. {
  157. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == id);
  158. if (pos != null)
  159. {
  160. SpModels.ActivateRecord act = spdb.ActivateRecord.FirstOrDefault(m => m.SnNo == pos.PosSn && m.SeoTitle != "0" && !string.IsNullOrEmpty(m.SeoTitle));
  161. if (act != null)
  162. {
  163. pos.SeoKeyword = act.SeoTitle;
  164. db.SaveChanges();
  165. StatService.Instance.dosomething3(pos.Id);
  166. }
  167. }
  168. }
  169. db.Dispose();
  170. spdb.Dispose();
  171. return "ok";
  172. }
  173. public string scanBind()
  174. {
  175. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  176. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  177. var Binds = spdb.BindRecord.Select(m => new { m.Id, m.CreateTime, m.Status, m.MerNo, m.MerSnNo }).OrderBy(m => m.Id).ToList();
  178. foreach (var Bind in Binds)
  179. {
  180. var tran = db.Database.BeginTransaction();
  181. try
  182. {
  183. PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.MerSnNo) ?? new PxcModels.MachineForSnNo();
  184. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  185. if (pos != null)
  186. {
  187. if (pos.BindingState == 0)
  188. {
  189. pos.BindingState = 1;
  190. pos.BindingTime = Bind.CreateTime;
  191. PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo);
  192. if (merFor == null)
  193. {
  194. merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
  195. {
  196. MerNo = Bind.MerNo,
  197. SnId = pos.Id,
  198. }).Entity;
  199. }
  200. db.SaveChanges();
  201. tran.Commit();
  202. function.WriteLog(pos.PosSn, "补充绑定数据");
  203. }
  204. }
  205. }
  206. catch (Exception ex)
  207. {
  208. tran.Rollback();
  209. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Bind.Id, "同步SP绑定数据到MAIN异常");
  210. }
  211. tran.Dispose();
  212. }
  213. spdb.SaveChanges();
  214. spdb.Dispose();
  215. db.SaveChanges();
  216. db.Dispose();
  217. return "ok";
  218. }
  219. public string scanMerchant()
  220. {
  221. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  222. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  223. var Mers = spdb.Merchants.OrderBy(m => m.Id).ToList();
  224. foreach (var Mer in Mers)
  225. {
  226. var tran = db.Database.BeginTransaction();
  227. try
  228. {
  229. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo) ?? new PxcModels.MachineForMerNo();
  230. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId) ?? new PxcModels.PosMachinesTwo();
  231. if (pos.BindingState == 1)
  232. {
  233. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  234. int TopUserId = 0;
  235. if (!string.IsNullOrEmpty(user.ParentNav))
  236. {
  237. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  238. }
  239. int BrandId = int.Parse(Mer.ProductType);
  240. if (Mer.MerNo.StartsWith("M900"))
  241. {
  242. BrandId = 3;
  243. }
  244. bool check = db.PosMerchantInfo.Any(m => m.KqMerNo == Mer.MerNo);
  245. if (!check)
  246. {
  247. PxcModels.PosMerchantInfo add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
  248. {
  249. CreateDate = Mer.CreateTime,
  250. UpdateDate = Mer.UpdateTime,
  251. TopUserId = TopUserId,
  252. MerUserType = user.MerchantType,
  253. BrandId = BrandId,
  254. SnStoreId = pos.StoreId,
  255. SnType = pos.PosSnType,
  256. UserId = pos.UserId,
  257. MgrName = Mer.AgentName,
  258. MerStatus = 1,
  259. KqSnNo = Mer.SnNo,
  260. KqMerNo = Mer.MerNo,
  261. MerIdcardNo = Mer.MerIdcardNo,
  262. MerRealName = Mer.MerRealName,
  263. MerchantMobile = Mer.MerMobile,
  264. MerchantName = Mer.MerName,
  265. MerchantNo = Mer.MerNo.Length > 16 ? Mer.MerNo.Substring(0, 16) : Mer.MerNo,
  266. }).Entity;
  267. db.SaveChanges();
  268. pos.BindMerchantId = add.Id;
  269. db.SaveChanges();
  270. tran.Commit();
  271. function.WriteLog(Mer.MerNo, "补充商户数据");
  272. }
  273. }
  274. }
  275. catch (Exception ex)
  276. {
  277. tran.Rollback();
  278. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Mer.Id, "同步SP商户数据到MAIN异常");
  279. }
  280. tran.Dispose();
  281. }
  282. spdb.Dispose();
  283. db.Dispose();
  284. return "ok";
  285. }
  286. public string scanTrade()
  287. {
  288. SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
  289. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  290. IQueryable<SpModels.TradeRecord> trades = spdb.TradeRecord.OrderBy(m => m.Id);
  291. foreach (SpModels.TradeRecord trade in trades.ToList())
  292. {
  293. bool op = true;
  294. if (trade.SerEntryMode == "N")
  295. {
  296. if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900)
  297. {
  298. op = false;
  299. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
  300. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  301. if (pos != null)
  302. {
  303. if (trade.SerEntryMode == "N" && trade.ProductType == "1")
  304. {
  305. pos.SeoKeyword = trade.TradeAmount.ToString("f2");
  306. db.SaveChanges();
  307. }
  308. }
  309. }
  310. }
  311. if (op)
  312. {
  313. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
  314. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  315. if (pos != null)
  316. {
  317. if (pos.BindMerchantId > 0)
  318. {
  319. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  320. int TopUserId = 0;
  321. if (!string.IsNullOrEmpty(user.ParentNav))
  322. {
  323. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  324. }
  325. bool check = db.TradeRecord.Any(m => m.RecordNo == trade.TradeSerialNo);
  326. if (!check)
  327. {
  328. decimal TradeAmount = trade.TradeAmount;
  329. int BankCardType = -1;
  330. int QrPayFlag = 0;
  331. if (pos.BrandId == 1 || pos.BrandId == 3)
  332. {
  333. TradeAmount = TradeAmount / 100;
  334. BankCardType = int.Parse(trade.BankCardType);
  335. if (trade.TradeType == "02") QrPayFlag = 1;
  336. }
  337. else if (pos.BrandId == 2)
  338. {
  339. if (trade.TradeType == "CREDIT_BY_CARD")
  340. {
  341. BankCardType = 1;
  342. }
  343. else if (trade.TradeType == "DEBIT_BY_CARD")
  344. {
  345. BankCardType = 0;
  346. }
  347. if (trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
  348. }
  349. int BrandId = int.Parse(trade.ProductType);
  350. if (trade.MerNo.StartsWith("M900"))
  351. {
  352. BrandId = 3;
  353. }
  354. db.TradeRecord.Add(new PxcModels.TradeRecord()
  355. {
  356. CreateDate = trade.CreateDate,
  357. UpdateDate = trade.UpdateDate,
  358. RecordNo = trade.TradeSerialNo, //单号
  359. UserId = pos.UserId, //创客
  360. MerchantId = pos.BindMerchantId, //商户
  361. MerNo = trade.MerNo, //渠道商户编号
  362. MerHelpFlag = 0, //是否属于扶持周期内商户
  363. HelpMonthCount = 0, //扶持第几个月
  364. MerBuddyType = user.MerchantType, //商户创客类型
  365. SnNo = trade.TradeSnNo, //渠道SN号
  366. // TradeDate = DateTime.Parse(trade.TradeTime), //交易日期
  367. TradeSerialNo = trade.ChannelSerial, //交易流水号
  368. TradeAmount = TradeAmount, //交易金额
  369. BankCardType = BankCardType, //银行卡类型
  370. QrPayFlag = QrPayFlag, //云闪付标识
  371. BrandId = BrandId, //品牌
  372. Remark = trade.Remark, //备注
  373. TopUserId = TopUserId, //顶级创客
  374. MerUserId = pos.UserId, //商户直属创客
  375. ParentNav = user.ParentNav,
  376. });
  377. if (BankCardType == 1)
  378. {
  379. pos.CreditTrade += TradeAmount;
  380. }
  381. else if (BankCardType == 0)
  382. {
  383. pos.DebitCardTrade += TradeAmount;
  384. }
  385. else if (pos.CreditTrade >= 1000 && pos.ActivationState == 0 && pos.BindingTime > DateTime.Now.AddDays(-20))
  386. {
  387. // pos.IsPurchase = 0;
  388. pos.ActivationState = 1;
  389. pos.ActivationTime = DateTime.Now;
  390. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  391. if (merchant != null)
  392. {
  393. merchant.ActiveStatus = 1;
  394. merchant.MerStandardDate = DateTime.Now;
  395. db.SaveChanges();
  396. }
  397. }
  398. db.SaveChanges();
  399. function.WriteLog(trade.Id.ToString(), "补充交易数据");
  400. }
  401. }
  402. }
  403. }
  404. }
  405. spdb.Dispose();
  406. db.Dispose();
  407. return "ok";
  408. }
  409. // public string add100()
  410. // {
  411. // WebCMSEntities db = new WebCMSEntities();
  412. // List<int> uids = new List<int>();
  413. // uids.Add(1053);
  414. // foreach (int uid in uids)
  415. // {
  416. // int ParentUserId = uid;
  417. // int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台购买机
  418. // int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  419. // if (machineCount + ActiveCount >= 3)
  420. // {
  421. // UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == ParentUserId);
  422. // if (account == null)
  423. // {
  424. // account = db.UserAccount.Add(new UserAccount()
  425. // {
  426. // Id = ParentUserId,
  427. // UserId = ParentUserId,
  428. // }).Entity;
  429. // db.SaveChanges();
  430. // }
  431. // decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  432. // decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  433. // decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  434. // account.BalanceAmount += 100;
  435. // account.TotalAmount += 100;
  436. // decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  437. // decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  438. // decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  439. // UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  440. // {
  441. // CreateDate = DateTime.Now,
  442. // UpdateDate = DateTime.Now,
  443. // UserId = ParentUserId, //创客
  444. // ChangeType = 112, //变动类型
  445. // ChangeAmount = 100, //变更金额
  446. // BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  447. // AfterTotalAmount = AfterTotalAmount, //变更后总金额
  448. // BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  449. // AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  450. // BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  451. // AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  452. // }).Entity;
  453. // db.SaveChanges();
  454. // //推荐下单上级获得30天的机具循环天数
  455. // 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();
  456. // foreach (var subPos in posList)
  457. // {
  458. // PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  459. // if (pos != null)
  460. // {
  461. // pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  462. // }
  463. // }
  464. // db.SaveChanges();
  465. // }
  466. // }
  467. // db.Dispose();
  468. // return "finish";
  469. // }
  470. //交易不到1000的机具,顶级姓名-代理姓名-客户姓名-客户电话-开机日期-SN // TODO:做到BS后台导出,按绑定时间查
  471. public IActionResult PosTable()
  472. {
  473. WebCMSEntities db = new WebCMSEntities();
  474. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  475. List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
  476. foreach (PosMachinesTwo pos in poses)
  477. {
  478. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  479. Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
  480. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  481. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  482. Dictionary<string, string> item = new Dictionary<string, string>();
  483. string TopRealName = "";
  484. string TopMakerCode = "";
  485. string TopMobile = "";
  486. string ParentNav = user.ParentNav;
  487. if (!string.IsNullOrEmpty(ParentNav))
  488. {
  489. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  490. if (navlist.Length > 1)
  491. {
  492. int TopId = int.Parse(function.CheckInt(navlist[1]));
  493. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  494. TopRealName = tuser.RealName;
  495. TopMakerCode = tuser.MakerCode;
  496. TopMobile = tuser.Mobile;
  497. }
  498. }
  499. item.Add("TopRealName", TopRealName); //顶级姓名
  500. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  501. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  502. item.Add("UpRealName", puser.RealName); //上级姓名
  503. item.Add("RealName", user.RealName); //代理姓名
  504. item.Add("MakerCode", user.MakerCode); //代理编号
  505. item.Add("Mobile", user.Mobile); //代理手机号
  506. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  507. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  508. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  509. item.Add("Sn", pos.PosSn); //SN
  510. list.Add(item);
  511. }
  512. db.Dispose();
  513. ViewBag.list = list;
  514. return View();
  515. }
  516. public string resetpos(int uid, int kind)
  517. {
  518. WebCMSEntities db = new WebCMSEntities();
  519. string IdBrand = uid + "_" + kind;
  520. UserMachineData machineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  521. if (machineData == null)
  522. {
  523. machineData = db.UserMachineData.Add(new UserMachineData()
  524. {
  525. IdBrand = IdBrand
  526. }).Entity;
  527. db.SaveChanges();
  528. }
  529. machineData.BindCount = db.PosMachinesTwo.Count(m => m.Status > -1 && m.BuyUserId == uid && m.BrandId == kind && m.BindingState == 1);
  530. machineData.UnBindCount = db.PosMachinesTwo.Count(m => m.Status > -1 && m.BuyUserId == uid && m.BrandId == kind && m.BindingState == 0);
  531. machineData.TotalMachineCount = machineData.BindCount + machineData.UnBindCount;
  532. db.SaveChanges();
  533. db.Dispose();
  534. return "finish";
  535. }
  536. // 更新分仓库存
  537. public string resetstorestock()
  538. {
  539. WebCMSEntities db = new WebCMSEntities();
  540. 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)");
  541. foreach (DataRow dr in dt.Rows)
  542. {
  543. int Id = int.Parse(function.CheckInt(dr["Id"].ToString()));
  544. int CurLaveNum = int.Parse(function.CheckInt(dr["CurLaveNum"].ToString()));
  545. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  546. if (store != null)
  547. {
  548. store.LaveNum = CurLaveNum;
  549. db.SaveChanges();
  550. }
  551. }
  552. db.Dispose();
  553. return "ok";
  554. }
  555. public string resetstorestock2(int id)
  556. {
  557. WebCMSEntities db = new WebCMSEntities();
  558. 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);
  559. foreach (DataRow dr in dt.Rows)
  560. {
  561. int Id = int.Parse(function.CheckInt(dr["Id"].ToString()));
  562. int CurLaveNum = int.Parse(function.CheckInt(dr["CurLaveNum"].ToString()));
  563. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  564. if (store != null)
  565. {
  566. store.LaveNum = CurLaveNum;
  567. db.SaveChanges();
  568. }
  569. }
  570. db.Dispose();
  571. return "ok";
  572. }
  573. public string chkpwd(string pwd)
  574. {
  575. return function.MD532(pwd);
  576. }
  577. //重置本月团队交易额
  578. public string resetMonthTrade()
  579. {
  580. return "";
  581. }
  582. public string traderecord(int kind, int id = 0)
  583. {
  584. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  585. if (kind == 1)
  586. {
  587. 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;");
  588. }
  589. else if (kind == 2)
  590. {
  591. 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;");
  592. }
  593. // OtherMySqlConn.connstr = ;
  594. return "ok";
  595. }
  596. public string test()
  597. {
  598. string result = "ok";
  599. OtherMySqlConn.connstr = "server=47.109.31.237;port=3306;user=KxsMainServer;password=Rw2imhXQQt5ODWIF;database=KxsMainServer;charset=utf8;";
  600. DataTable dt = OtherMySqlConn.dtable("select * from ProfitSubsidyDetail where TradeMonth='202204'");
  601. WebCMSEntities db = new WebCMSEntities();
  602. foreach (DataRow dr in dt.Rows)
  603. {
  604. int BrandId = int.Parse(function.CheckInt(dr["BrandId"].ToString()));
  605. int MerchantId = int.Parse(function.CheckInt(dr["MerchantId"].ToString()));
  606. int SubsidyUserId = int.Parse(function.CheckInt(dr["SubsidyUserId"].ToString()));
  607. int SubsidyType = int.Parse(function.CheckInt(dr["SubsidyType"].ToString()));
  608. ulong MerHelpFlag = ulong.Parse(function.CheckInt(dr["MerHelpFlag"].ToString()));
  609. decimal SubsidyProfitRate = decimal.Parse(function.CheckNum(dr["SubsidyProfitRate"].ToString()));
  610. decimal CreditTradeAmt = decimal.Parse(function.CheckNum(dr["CreditTradeAmt"].ToString()));
  611. decimal QrCreditTradeAmt = decimal.Parse(function.CheckNum(dr["QrCreditTradeAmt"].ToString()));
  612. decimal NonQrCreditTradeAmt = decimal.Parse(function.CheckNum(dr["NonQrCreditTradeAmt"].ToString()));
  613. decimal CreditProfitRate = decimal.Parse(function.CheckNum(dr["CreditProfitRate"].ToString()));
  614. decimal SubsidyProfit = decimal.Parse(function.CheckNum(dr["SubsidyProfit"].ToString()));
  615. string TradeMonth = dr["TradeMonth"].ToString();
  616. string SnNo = dr["SnNo"].ToString();
  617. string MerNo = dr["MerNo"].ToString();
  618. string RecordNo = dr["RecordNo"].ToString();
  619. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
  620. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId) ?? new PosMachinesTwo();
  621. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == MerchantId) ?? new PosMerchantInfo();
  622. ProfitSubsidyDetail item = db.ProfitSubsidyDetail.FirstOrDefault(m => m.SubsidyUserId == SubsidyUserId && m.TradeMonth == TradeMonth && m.MerchantId == MerchantId && m.SnNo == SnNo);
  623. if (item == null)
  624. {
  625. db.ProfitSubsidyDetail.Add(new ProfitSubsidyDetail()
  626. {
  627. CreateDate = DateTime.Now,
  628. UpdateDate = DateTime.Now,
  629. RecordNo = RecordNo, //流水号
  630. BrandId = BrandId, //品牌
  631. ProductName = RelationClass.GetKqProductBrandInfo(BrandId), //产品名称
  632. TradeMonth = TradeMonth, //交易月份
  633. MerchantId = MerchantId, //商户
  634. MerNo = MerNo, //渠道商户编号
  635. SnNo = SnNo, //渠道SN号
  636. MerRegTime = pos.BindingTime, //渠道注册时间
  637. MerStandardDate = merchant.MerStandardDate, //商户激活时间
  638. BelongUserId = merchant.UserId, //商户归属人
  639. MerHelpFlag = MerHelpFlag, //是否属于扶持周期内商户
  640. SubsidyUserId = SubsidyUserId, //补贴人
  641. SubsidyType = SubsidyType, //分润补贴类型
  642. SubsidyProfitRate = SubsidyProfitRate, //创客活动期内直营商户分润万分之十
  643. CreditTradeAmt = CreditTradeAmt, //商户贷记卡交易总金额
  644. QrCreditTradeAmt = QrCreditTradeAmt, //商户(云闪付)贷记卡交易总金额
  645. NonQrCreditTradeAmt = NonQrCreditTradeAmt, //商户(非云闪付)贷记卡交易总金额
  646. CreditProfitRate = CreditProfitRate, //(非云闪付)贷记卡交易分润比例
  647. SubsidyProfit = SubsidyProfit, //商户(非云闪付)贷记卡交易分润补贴金额
  648. });
  649. // db.SaveChanges();
  650. result += "增加--SubsidyUserId:" + SubsidyUserId + ";SnNo" + SnNo + ";SubsidyProfit" + SubsidyProfit + ";";
  651. }
  652. else
  653. {
  654. if (item.SubsidyProfit < SubsidyProfit)
  655. {
  656. item.SubsidyProfitRate = SubsidyProfitRate; //创客活动期内直营商户分润万分之十
  657. item.SubsidyProfit = SubsidyProfit; //商户(非云闪付)贷记卡交易分润补贴金额
  658. result += "更新--SubsidyUserId:" + SubsidyUserId + ";SnNo" + SnNo + ";SubsidyProfit" + SubsidyProfit + ";";
  659. // db.SaveChanges();
  660. }
  661. }
  662. }
  663. // OtherMySqlConn.connstr = ;
  664. db.Dispose();
  665. return result;
  666. }
  667. public string test2()
  668. {
  669. string result = "ok";
  670. OtherMySqlConn.connstr = "server=47.108.231.170;port=3306;user=KxsMainServer;password=Rw2imhXQQt5ODWIF;database=KxsMainServer;charset=utf8;";
  671. DataTable dt = OtherMySqlConn.dtable("select SubsidyUserId,BrandId,sum(SubsidyProfitRate) as SubsidyProfit from ProfitSubsidyDetail where TradeMonth='202204' and SubsidyUserId>0 GROUP BY SubsidyUserId,BrandId");
  672. WebCMSEntities db = new WebCMSEntities();
  673. DateTime checkDate = DateTime.Parse("2022-05-20 00:00:00");
  674. foreach (DataRow dr in dt.Rows)
  675. {
  676. int BrandId = int.Parse(function.CheckInt(dr["BrandId"].ToString()));
  677. int SubsidyUserId = int.Parse(function.CheckInt(dr["SubsidyUserId"].ToString()));
  678. decimal SubsidyProfit = decimal.Parse(function.CheckNum(dr["SubsidyProfit"].ToString()));
  679. UserAccountRecord userAccountRecord = db.UserAccountRecord.FirstOrDefault(m => m.Id > 86538 && m.CreateDate > checkDate && m.UserId == SubsidyUserId && m.ProductType == BrandId && m.ChangeType == 111);
  680. if (userAccountRecord == null)
  681. {
  682. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == SubsidyUserId);
  683. if (account == null)
  684. {
  685. account = db.UserAccount.Add(new UserAccount()
  686. {
  687. Id = SubsidyUserId,
  688. UserId = SubsidyUserId,
  689. }).Entity;
  690. db.SaveChanges();
  691. }
  692. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  693. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  694. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  695. // account.BalanceAmount += SubsidyProfit;
  696. // account.TotalAmount += SubsidyProfit;
  697. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  698. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  699. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  700. userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  701. {
  702. CreateDate = DateTime.Now,
  703. UpdateDate = DateTime.Now,
  704. UserId = SubsidyUserId, //创客
  705. ProductType = BrandId,
  706. ChangeType = 111, //变动类型
  707. ChangeAmount = SubsidyProfit, //变更金额
  708. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  709. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  710. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  711. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  712. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  713. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  714. Remark = "直拓商户补贴",
  715. }).Entity;
  716. db.SaveChanges();
  717. }
  718. else
  719. {
  720. userAccountRecord.ChangeAmount = SubsidyProfit;
  721. db.SaveChanges();
  722. }
  723. }
  724. // OtherMySqlConn.connstr = ;
  725. db.Dispose();
  726. return result;
  727. }
  728. // 大盟主标记扫描
  729. public string leaderflag()
  730. {
  731. WebCMSEntities db = new WebCMSEntities();
  732. List<int> ids = new List<int>();
  733. // List<PosCouponRecord> records = db.PosCouponRecord.Where(m => m.FromUserId == 597).ToList();
  734. // foreach(PosCouponRecord record in records)
  735. // {
  736. // ids.Add(record.PosCouponId);
  737. // }
  738. ids.Add(6843);
  739. List<PosCoupons> coupons = db.PosCoupons.Where(m => ids.Contains(m.Id) && m.IsUse == 1).ToList();
  740. foreach (PosCoupons coupon in coupons)
  741. {
  742. PosSns.Add(coupon.ExchangeCode);
  743. }
  744. foreach (PosCoupons coupon in coupons)
  745. {
  746. ChildNo(db, coupon.ExchangeCode, coupon.ExchangeCode, coupon.LeaderUserId);
  747. }
  748. // db.SaveChanges();
  749. db.Dispose();
  750. return "ok";
  751. }
  752. List<string> nos = new List<string>();
  753. private void ChildNo(WebCMSEntities db, string RootCheckNo, string CheckNo, int LeaderUserId)
  754. {
  755. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(CheckNo));
  756. if(apply != null)
  757. {
  758. int len = 0;
  759. string[] SnList = apply.SwapSnExpand.TrimEnd('\n').Split('\n');
  760. foreach(string sn in SnList)
  761. {
  762. if(PosSns.Contains(sn.Split(':')[0]) || nos.Contains(sn.Split(':')[0]))
  763. {
  764. len += 1;
  765. }
  766. }
  767. Orders order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount);
  768. if(order != null)
  769. {
  770. if(!string.IsNullOrEmpty(order.SnNos))
  771. {
  772. if(order.SnNos.Contains(","))
  773. {
  774. string[] SwapSnExpands = order.SnNos.TrimEnd(',').Split(',');
  775. int index = 0;
  776. foreach(string no in SwapSnExpands)
  777. {
  778. if(!nos.Contains(no) && index < len)
  779. {
  780. index += 1;
  781. nos.Add(no);
  782. ChildNo(db, RootCheckNo, no, LeaderUserId);
  783. }
  784. }
  785. }
  786. else
  787. {
  788. string[] SwapSnExpands = order.SnNos.TrimEnd('\n').Split('\n');
  789. int index = 0;
  790. foreach(string no in SwapSnExpands)
  791. {
  792. if(!nos.Contains(no) && index < len)
  793. {
  794. index += 1;
  795. nos.Add(no);
  796. ChildNo(db, RootCheckNo, no, LeaderUserId);
  797. }
  798. }
  799. }
  800. }
  801. else
  802. {
  803. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == CheckNo) ?? new MachineForSnNo();
  804. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  805. if(pos != null)
  806. {
  807. // pos.LeaderUserId = LeaderUserId;
  808. // Library.function.WriteLog(LeaderUserId + ":" + pos.PosSn + ":" + apply.SwapSnExpand.TrimEnd('\n').Split('\n').Length, "大盟主奖励标记机具");
  809. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  810. Library.function.WriteLog(pos.PosSn + ":" + RootCheckNo + ":" + user.MakerCode + ":" + user.RealName, "大盟主奖励标记机具");
  811. }
  812. }
  813. }
  814. }
  815. else
  816. {
  817. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == CheckNo) ?? new MachineForSnNo();
  818. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m=>m.Id == forSnNo.SnId);
  819. if(pos != null)
  820. {
  821. // pos.LeaderUserId = LeaderUserId;
  822. // Library.function.WriteLog(LeaderUserId + ":" + pos.PosSn, "大盟主奖励标记机具");
  823. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  824. Library.function.WriteLog(pos.PosSn + ":" + RootCheckNo + ":" + user.MakerCode + ":" + user.RealName, "大盟主奖励标记机具");
  825. }
  826. }
  827. }
  828. List<string> PosSns = new List<string>();
  829. public string ScanNos()
  830. {
  831. PosSns = new List<string>();
  832. PosSns.Add("00005002681889125851");
  833. WebCMSEntities db = new WebCMSEntities();
  834. foreach(string PosSn in PosSns)
  835. {
  836. ChildNo(db, PosSn, PosSn, 0);
  837. }
  838. db.Dispose();
  839. return "ok";
  840. }
  841. //补推荐奖励
  842. public string AddDirectPrice(int oid = 0)
  843. {
  844. WebCMSEntities db = new WebCMSEntities();
  845. List<int> uids = new List<int>(); //领取过的下单创客
  846. IQueryable<Orders> orders = db.Orders.Where(m => m.Status > 1 && m.UserId > 1 && m.TotalPrice % 600 == 0 && m.Sort == 0);
  847. if(oid > 0)
  848. {
  849. orders = orders.Where(m => m.Id == oid);
  850. }
  851. foreach (Orders order in orders.ToList())
  852. {
  853. if(!uids.Contains(order.UserId))
  854. {
  855. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == oid && m.ChangeType == 112);
  856. if(checkPrize)
  857. {
  858. uids.Add(order.UserId);
  859. }
  860. else
  861. {
  862. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == oid) ?? new OrderProduct();
  863. if (pro.ProductId == 10 || pro.ProductId == 11)
  864. {
  865. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  866. if (user != null)
  867. {
  868. bool directPrize = false; //直推奖标记
  869. int ParentUserId = user.ParentUserId;
  870. List<int> proids = new List<int>();
  871. proids.Add(10);
  872. proids.Add(11);
  873. while (ParentUserId > 0)
  874. {
  875. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  876. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
  877. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  878. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  879. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  880. {
  881. function.WriteLog("满足条件", "推荐下单奖励监控日志");
  882. if (puser.LeaderLevel == 0) // 非盟主直推奖励,每个创客第一次下单,上级可得
  883. {
  884. List<int> oids = new List<int>();
  885. var orderpros = db.OrderProduct.Select(m => new { m.OrderId, m.UserId, m.ProductId }).Where(m => m.UserId == order.UserId && proids.Contains(m.ProductId)).ToList();
  886. foreach (var orderpro in orderpros)
  887. {
  888. oids.Add(orderpro.OrderId);
  889. }
  890. bool check = db.Orders.Any(m => oids.Contains(m.Id) && m.Status > 0);
  891. if (check)
  892. {
  893. // AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  894. function.WriteLog(order.Id + "," + ParentUserId + "," + pro.ProductCount, "没发的推荐奖励");
  895. directPrize = true;
  896. }
  897. }
  898. else
  899. {
  900. // 盟主直推奖励,可以每次下单获得
  901. // AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  902. function.WriteLog(order.Id + "," + ParentUserId + "," + pro.ProductCount + "--盟主", "没发的推荐奖励");
  903. directPrize = true;
  904. }
  905. //推荐下单上级获得30天的机具循环天数
  906. 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();
  907. foreach (var subPos in posList)
  908. {
  909. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  910. if (pos != null)
  911. {
  912. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  913. }
  914. }
  915. db.SaveChanges();
  916. }
  917. if(directPrize)
  918. {
  919. ParentUserId = 0;
  920. }
  921. else
  922. {
  923. ParentUserId = puser.ParentUserId;
  924. }
  925. }
  926. }
  927. }
  928. }
  929. }
  930. }
  931. return "ok";
  932. }
  933. public string checkLeaderOrder(int OrderId)
  934. {
  935. WebCMSEntities db = new WebCMSEntities();
  936. Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId);
  937. if (order != null)
  938. {
  939. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == OrderId);
  940. if (pro != null)
  941. {
  942. //推荐下单奖励
  943. if (pro.ProductId == 10 || pro.ProductId == 11)
  944. {
  945. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  946. function.WriteLog("OrderId:" + OrderId, "推荐下单奖励监控日志");
  947. function.WriteLog("checkPrize:" + checkPrize, "推荐下单奖励监控日志");
  948. if (!checkPrize)
  949. {
  950. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  951. if (user != null)
  952. {
  953. bool directPrize = false; //直推奖标记
  954. bool buyPrize = false; //返100购机奖励标记
  955. int leaderFlag = 0; //返600备用金标记
  956. if(user.LeaderLevel > 0)
  957. {
  958. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
  959. if(acccount.LeaderReserve >= order.TotalPrice)
  960. {
  961. if(order.PayMode == 4)
  962. {
  963. //扣减备用金
  964. AlipayPayBack2Service.Instance.OpReserve(db, order, order.UserId, order.TotalPrice, 2, 0, "商城购机");
  965. //返回到余额
  966. // OpAccount(db, order, order.UserId, order.TotalPrice / pro.ProductCount, pro.ProductCount);
  967. }
  968. }
  969. //获得100元奖励
  970. AlipayPayBack2Service.Instance.OpAccount(db, order, order.UserId, 100, pro.ProductCount);
  971. //推荐奖励
  972. AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, order.UserId, pro.ProductCount);
  973. //推荐下单上级获得30天的机具循环天数
  974. 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();
  975. foreach (var subPos in posList)
  976. {
  977. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  978. if (pos != null)
  979. {
  980. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  981. }
  982. }
  983. db.SaveChanges();
  984. if(user.LeaderLevel != 2)
  985. {
  986. int PUserId = user.ParentUserId;
  987. while(PUserId > 0)
  988. {
  989. Users puser = db.Users.FirstOrDefault(m => m.Id == PUserId) ?? new Users();
  990. if(puser.LeaderLevel == 2)
  991. {
  992. UserAccount acc = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  993. if(acc.LeaderReserve >= order.TotalPrice)
  994. {
  995. //扣减备用金
  996. AlipayPayBack2Service.Instance.OpReserve(db, order, puser.Id, order.TotalPrice, 2, order.UserId, "购机奖励");
  997. //返回到余额
  998. AlipayPayBack2Service.Instance.OpAccount(db, order, puser.Id, order.TotalPrice / pro.ProductCount, pro.ProductCount);
  999. }
  1000. PUserId = 0;
  1001. }
  1002. else
  1003. {
  1004. PUserId = puser.ParentUserId;
  1005. }
  1006. }
  1007. }
  1008. return "自己就是盟主,发放成功";
  1009. }
  1010. int ParentUserId = user.ParentUserId;
  1011. // List<int> proids = new List<int>();
  1012. // proids.Add(10);
  1013. // proids.Add(11);
  1014. while(ParentUserId > 0)
  1015. {
  1016. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1017. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
  1018. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1019. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  1020. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  1021. {
  1022. // 盟主直推奖励,可以每次下单获得
  1023. AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  1024. directPrize = true;
  1025. //推荐下单上级获得30天的机具循环天数
  1026. 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();
  1027. foreach (var subPos in posList)
  1028. {
  1029. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  1030. if (pos != null)
  1031. {
  1032. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  1033. }
  1034. }
  1035. db.SaveChanges();
  1036. }
  1037. if(puser.LeaderLevel > 0)
  1038. {
  1039. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  1040. if(acccount.LeaderReserve >= order.TotalPrice && !buyPrize)
  1041. {
  1042. //购机奖励
  1043. AlipayPayBack2Service.Instance.OpAccount(db, order, puser.Id, 100, pro.ProductCount);
  1044. buyPrize = true;
  1045. }
  1046. if(acccount.LeaderReserve >= order.TotalPrice && puser.LeaderLevel > leaderFlag)
  1047. {
  1048. //扣减备用金
  1049. AlipayPayBack2Service.Instance.OpReserve(db, order, puser.Id, order.TotalPrice, 2, order.UserId, "购机奖励");
  1050. //返回到余额
  1051. AlipayPayBack2Service.Instance.OpAccount(db, order, puser.Id, order.TotalPrice / pro.ProductCount, pro.ProductCount);
  1052. leaderFlag = puser.LeaderLevel;
  1053. }
  1054. }
  1055. ParentUserId = puser.ParentUserId;
  1056. }
  1057. return "找到上级盟主,发放成功";
  1058. }
  1059. }
  1060. }
  1061. }
  1062. }
  1063. return "失败";
  1064. }
  1065. public string setdeposit()
  1066. {
  1067. // List<string> ordernos = new List<string>();
  1068. // ordernos.Add("17343379");
  1069. string content = "";
  1070. // foreach(string orderno in ordernos)
  1071. // {
  1072. // content += SetDepositPostService.Instance.QueryFee(orderno) + "\n";
  1073. // }
  1074. // List<string> snnos = new List<string>();
  1075. // foreach(string snno in snnos)
  1076. // {
  1077. // content += SetDepositPostService.Instance.ModifyFee(snno, 0.0006M) + "\n";
  1078. // }
  1079. // content = SetDepositPostService.Instance.SetFeeForSft("38888910", "0.63");
  1080. // content = SetDepositPostService.Instance.SetFeeForBrand("00003202D9625450004213", bzConfigId, yhConfigId, surfeeConfigId, "");
  1081. return content;
  1082. }
  1083. public string putdata()
  1084. {
  1085. WebCMSEntities db = new WebCMSEntities();
  1086. var list = db.PosMachinesFeeChangeRecord.Where(m => m.Sort == 2 && m.Status == 0).ToList();
  1087. foreach(var sub in list)
  1088. {
  1089. Users user = db.Users.FirstOrDefault(m => m.Id == sub.UserId) ?? new Users();
  1090. string info = "{\"RecordId\":\"" + sub.Id + "\",\"PosId\":\"" + sub.PosId + "\",\"Fee\": \"0.6\",\"Kind\": \"2\",\"OpMan\": \"" + user.MakerCode + "\"}";
  1091. RedisDbconn.Instance.AddList("SetDepositQueue", info);
  1092. }
  1093. db.Dispose();
  1094. return "ok";
  1095. }
  1096. public string test3()
  1097. {
  1098. WebCMSEntities db = new WebCMSEntities();
  1099. StoreApplyHelper.Instance.DoSomething(db, 152335);
  1100. // AlipayPayBack2Service.Instance.DoOrderV2(db, 139620);
  1101. // PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == sn);
  1102. // if(pos != null)
  1103. // {
  1104. // //发放大盟主奖励
  1105. // if(pos.LeaderUserId > 0)
  1106. // {
  1107. // RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  1108. // }
  1109. // //发放运营中心奖励
  1110. // if(pos.OpId > 0)
  1111. // {
  1112. // RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  1113. // AlipayPayBack2Service.Instance.ActReserveBack(pos.OpId, pos.OpReserve1, pos.OpReserve2, pos.OpReserve3);
  1114. // }
  1115. // }
  1116. // db.Dispose();
  1117. return "ok";
  1118. }
  1119. public string test5()
  1120. {
  1121. WebCMSEntities db = new WebCMSEntities();
  1122. string Month = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
  1123. string PreMonth = DateTime.Now.AddMonths(-2).ToString("yyyyMM");
  1124. string minId = "0";
  1125. string connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  1126. DataTable minIdDt = CustomerSqlConn.dtable("select min(Id) from ProfitRewardRecord where TradeMonth='" + PreMonth + "'", connstr);
  1127. if(minIdDt.Rows.Count > 0)
  1128. {
  1129. minId = minIdDt.Rows[0][0].ToString();
  1130. }
  1131. ResetSmallStoreHelper.Instance.DoMethod(db, PreMonth, minId, "10115");
  1132. db.Dispose();
  1133. return "ok";
  1134. }
  1135. public string test6()
  1136. {
  1137. // string result = SetDepositPostService.Instance.LDServiceFee("0000320226636450126740", 99, 11);
  1138. string result = SetDepositPostService.Instance.LDFeeRate("91635559596276314112", "0.0060", 11);
  1139. // string content = "IARp4zPEPPcsJJiFrflSJn2dC+K8M1Aig1ch+39tCejtYfIZf62+0963QDhK6DDr9gh0V817KifLVEaMJwKeoXhH1ez58HvGeQz0xahzhUz8nLnQ1Uf5uw98/fHJabW3kZ0tdEN/2w/0m9g6hLsyQ5TQOoF9a//Pu1jbgQRro9w9GtsEi+IHd3Vlkf/B5vwu1ITAUycopfc27g8JwVC4Q+q+lKz6N00LDxUfBUWbZeidEHeq5rNtffZnSp5rrJ7ZUKqC/OlNYbLICPA/XcbgV7xKRxYAIcqa/mumlF9KyIQO4iYvf65sj5LVP9vh0YaWcEhBYyczwHvTxRni9VV4RCMHiQ9fTOMiPnTn0RyPcOMKzNYyxraDuEmla2c/lKRzZvHNwxIrUzpaTaXs+VmEtpEU/T8BBYxowE5gMt+bm5riJ6qbHmZfrBnqXRsRdk3/STZqZ3Goz9nE7bV0kyqYnpK/sg/qrhLGtAjpu9WvTBo7IrF00rahV4IpVXXKLFvjh+0ghKVglQ7ahUU3jx8RsoK8PTSm9LvKEoEDdmOdK7m2atzm6rG/EB67Rs/Mp1yxZTvjlMBuBMnna3LmLFfCkMRBQlIpha2GZKcc1NyH5z2EMOtxTfrt8rYlMRbYRhviDWk96N2Ha169/jzhye495pFJbbIkWssn9XwbvoB2z0Vmsuk7A+IvQ2paogmgeZGpaguWD5YBRTw5zMKlKMHN/Ph5JLaOvjYaHlYOCRPCrFt7WrAKj/Gobrs3MeMT+Bp1z8TpUWL/PqmGP8q/T+rZ7bX9d6F0QO2wKo631eXe0Z6EOXYaAEd/OAfn2NsSyw6BP5DtHxzLMCLJmMoi3E4llA==";
  1140. // string result = SetDepositPostService.Instance.LDDecrypt(content);
  1141. //{"mercId":"91635559596276314112","mercName":"刘**","posSn":"0000320226636450126740","bindTime":"2023-03-14 16:32:55","id":"e514cba6ff19466bb9a062a1153175db"}
  1142. return result;
  1143. }
  1144. public string sethkfee()
  1145. {
  1146. string bzConfigId = "", yhConfigId = "", surfeeConfigId = "";
  1147. int Kind = 2;
  1148. WebCMSEntities db = new WebCMSEntities();
  1149. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == "00005702832513011041") ?? new PosMachinesTwo();
  1150. if(pos.BrandId == 8)
  1151. {
  1152. if(Kind == 1)
  1153. {
  1154. bzConfigId = "684753829778436096";
  1155. yhConfigId = "684754046342934528";
  1156. surfeeConfigId = "570331704834170880";
  1157. }
  1158. else
  1159. {
  1160. bzConfigId = "585167132691009536";
  1161. yhConfigId = "579355312831074304";
  1162. surfeeConfigId = "570331704834170880";
  1163. }
  1164. }
  1165. else
  1166. {
  1167. if(Kind == 1)
  1168. {
  1169. bzConfigId = "691739824478494720";
  1170. yhConfigId = "691740128238383104";
  1171. surfeeConfigId = "574600660289888256";
  1172. }
  1173. else
  1174. {
  1175. bzConfigId = "584068951081226240";
  1176. yhConfigId = "584070145207963648";
  1177. surfeeConfigId = "574600660289888256";
  1178. }
  1179. }
  1180. string content = SetDepositPostService.Instance.HKSetFeeForBrand(pos.PosSn, bzConfigId, yhConfigId, surfeeConfigId, pos.BrandId);
  1181. return content;
  1182. }
  1183. public string add600(int OrderId = 0)
  1184. {
  1185. WebCMSEntities db = new WebCMSEntities();
  1186. List<int> couponIds = new List<int>();
  1187. couponIds.Add(74648);
  1188. couponIds.Add(74649);
  1189. couponIds.Add(74650);
  1190. Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId) ?? new Orders();
  1191. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == OrderId) ?? new OrderProduct();
  1192. if (pro.ProductId == 10 || pro.ProductId == 11)
  1193. {
  1194. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  1195. function.WriteLog("OrderId:" + OrderId, "推荐下单奖励监控日志");
  1196. function.WriteLog("checkPrize:" + checkPrize, "推荐下单奖励监控日志");
  1197. if (checkPrize)
  1198. {
  1199. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  1200. if (user != null)
  1201. {
  1202. if(user.LeaderLevel > 0 || user.UserType == 1) //盟主或运营中心
  1203. {
  1204. //获得100元奖励
  1205. AlipayPayBack2Service.Instance.OpAccount(db, order, order.UserId, 100, pro.ProductCount);
  1206. }
  1207. }
  1208. }
  1209. else
  1210. {
  1211. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  1212. if (user != null)
  1213. {
  1214. bool directPrize = false; //直推奖标记
  1215. bool bigLeaderPrize = false; //大盟主券标记
  1216. bool operateFlag = false; //运营中心标记
  1217. bool buyPrize = false; //返100购机奖励标记或返100购机奖励标记-运营中心
  1218. int leaderFlag = 0; //返600备用金标记
  1219. if(user.LeaderLevel > 0 || user.UserType == 1) //盟主或运营中心
  1220. {
  1221. if(user.LeaderLevel > 0)
  1222. {
  1223. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
  1224. if(acccount.LeaderReserve >= order.TotalPrice)
  1225. {
  1226. if(order.PayMode == 4)
  1227. {
  1228. //扣减备用金
  1229. AlipayPayBack2Service.Instance.OpReserve(db, order, order.UserId, order.TotalPrice, 0, 0, "商城购机(储备金支付)");
  1230. }
  1231. }
  1232. }
  1233. //获得100元奖励
  1234. AlipayPayBack2Service.Instance.OpAccount(db, order, order.UserId, 100, pro.ProductCount);
  1235. //推荐奖励
  1236. AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, order.UserId, pro.ProductCount);
  1237. //推荐下单上级获得30天的机具循环天数(盟主自己得)
  1238. 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();
  1239. foreach (var subPos in posList)
  1240. {
  1241. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  1242. if (pos != null)
  1243. {
  1244. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  1245. }
  1246. }
  1247. db.SaveChanges();
  1248. if(order.PayMode == 4 && user.LeaderLevel > 0) //使用盟主储蓄金,并且是盟主
  1249. {
  1250. if(user.UserType == 1)
  1251. {
  1252. if(couponIds.Count > 0)
  1253. {
  1254. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == user.Id) ?? new UserAccount();
  1255. foreach(int couponId in couponIds)
  1256. {
  1257. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1258. if(coupon != null)
  1259. {
  1260. if(acccount.LeaderReserve >= 400 * pro.ProductCount)
  1261. {
  1262. coupon.LeaderUserId = user.Id;
  1263. }
  1264. coupon.OpId = user.Id;
  1265. }
  1266. }
  1267. }
  1268. db.SaveChanges();
  1269. }
  1270. else
  1271. {
  1272. //寻找最近运营中心额度大于0的运营中心
  1273. int PUserId = user.Id;
  1274. bool OperateFlag = true;
  1275. bool OncePrizeFlag1 = true;
  1276. while(PUserId > 0)
  1277. {
  1278. Users puser = db.Users.FirstOrDefault(m => m.Id == PUserId);
  1279. if(puser != null)
  1280. {
  1281. if(puser.UserType == 1 && OperateFlag == true) //运营中心
  1282. {
  1283. if(couponIds.Count > 0)
  1284. {
  1285. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
  1286. foreach(int couponId in couponIds)
  1287. {
  1288. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1289. if(coupon != null)
  1290. {
  1291. if(acccount.LeaderReserve >= 400 * pro.ProductCount)
  1292. {
  1293. coupon.LeaderUserId = user.Id;
  1294. }
  1295. coupon.OpId = puser.Id;
  1296. }
  1297. }
  1298. db.SaveChanges();
  1299. if(acccount.LeaderReserve >= 400 * pro.ProductCount && OncePrizeFlag1)
  1300. {
  1301. //扣减备用金
  1302. AlipayPayBack2Service.Instance.OpReserve(db, order, order.UserId, 400 * pro.ProductCount, 2, 0, "商城购机");
  1303. //返回到余额
  1304. AlipayPayBack2Service.Instance.OpLeaderAccount(db, order, order.UserId, 400, pro.ProductCount);
  1305. OncePrizeFlag1 = false;
  1306. }
  1307. OperateFlag = false;
  1308. }
  1309. }
  1310. PUserId = puser.ParentUserId;
  1311. }
  1312. else
  1313. {
  1314. PUserId = 0;
  1315. }
  1316. }
  1317. }
  1318. }
  1319. else if(order.PayMode == 4 && user.UserType == 1) //使用盟主储蓄金,并且是运营中心
  1320. {
  1321. if(couponIds.Count > 0)
  1322. {
  1323. foreach(int couponId in couponIds)
  1324. {
  1325. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1326. if(coupon != null)
  1327. {
  1328. coupon.OpId = user.Id;
  1329. }
  1330. }
  1331. }
  1332. db.SaveChanges();
  1333. //寻找最近储蓄金充足的大盟主
  1334. int PUserId = user.Id;
  1335. bool LeaderFlag = true;
  1336. bool OncePrizeFlag2 = true;
  1337. while(PUserId > 0)
  1338. {
  1339. Users puser = db.Users.FirstOrDefault(m => m.Id == PUserId);
  1340. if(puser != null)
  1341. {
  1342. if(puser.LeaderLevel == 2 && LeaderFlag == true) //大盟主
  1343. {
  1344. if(couponIds.Count > 0)
  1345. {
  1346. UserAccount pacccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  1347. foreach(int couponId in couponIds)
  1348. {
  1349. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1350. if(coupon != null && pacccount.LeaderReserve >= 400 * pro.ProductCount)
  1351. {
  1352. coupon.LeaderUserId = puser.Id;
  1353. }
  1354. }
  1355. db.SaveChanges();
  1356. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
  1357. if(acccount.LeaderReserve >= 400 * pro.ProductCount && OncePrizeFlag2)
  1358. {
  1359. //扣减备用金
  1360. AlipayPayBack2Service.Instance.OpReserve(db, order, order.UserId, 400 * pro.ProductCount, 2, 0, "商城购机");
  1361. //返回到余额
  1362. AlipayPayBack2Service.Instance.OpLeaderAccount(db, order, order.UserId, 400, pro.ProductCount);
  1363. OncePrizeFlag2 = false;
  1364. }
  1365. LeaderFlag = false;
  1366. }
  1367. }
  1368. PUserId = puser.ParentUserId;
  1369. }
  1370. else
  1371. {
  1372. PUserId = 0;
  1373. }
  1374. }
  1375. }
  1376. else
  1377. {
  1378. //寻找最近储蓄金充足的大盟主及最近运营中心额度大于0的运营中心(含自身)
  1379. int PUserId = user.Id;
  1380. int LeaderFlag = 0;
  1381. bool OperateFlag = true;
  1382. bool OncePrizeFlag3 = true;
  1383. while(PUserId > 0)
  1384. {
  1385. Users puser = db.Users.FirstOrDefault(m => m.Id == PUserId);
  1386. if(puser != null)
  1387. {
  1388. if(puser.LeaderLevel > 0 && puser.LeaderLevel > LeaderFlag && LeaderFlag < 2) //大盟主
  1389. {
  1390. if(couponIds.Count > 0)
  1391. {
  1392. if(puser.LeaderLevel == 2)
  1393. {
  1394. UserAccount pacccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  1395. foreach(int couponId in couponIds)
  1396. {
  1397. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1398. if(coupon != null && pacccount.LeaderReserve >= 400 * pro.ProductCount)
  1399. {
  1400. coupon.LeaderUserId = puser.Id;
  1401. }
  1402. }
  1403. db.SaveChanges();
  1404. }
  1405. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  1406. if(acccount.LeaderReserve >= 400 * pro.ProductCount && OncePrizeFlag3)
  1407. {
  1408. //扣减备用金
  1409. AlipayPayBack2Service.Instance.OpReserve(db, order, puser.Id, 400 * pro.ProductCount, 2, 0, "商城购机");
  1410. //返回到余额
  1411. AlipayPayBack2Service.Instance.OpLeaderAccount(db, order, puser.Id, 400, pro.ProductCount);
  1412. LeaderFlag = puser.LeaderLevel;
  1413. OncePrizeFlag3 = false;
  1414. }
  1415. }
  1416. }
  1417. if(puser.UserType == 1 && OperateFlag == true) //运营中心
  1418. {
  1419. if(couponIds.Count > 0)
  1420. {
  1421. foreach(int couponId in couponIds)
  1422. {
  1423. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1424. if(coupon != null)
  1425. {
  1426. coupon.OpId = puser.Id;
  1427. }
  1428. }
  1429. db.SaveChanges();
  1430. OperateFlag = false;
  1431. }
  1432. }
  1433. PUserId = puser.ParentUserId;
  1434. }
  1435. else
  1436. {
  1437. PUserId = 0;
  1438. }
  1439. }
  1440. }
  1441. return "ok";
  1442. }
  1443. int ParentUserId = user.ParentUserId;
  1444. // List<int> proids = new List<int>();
  1445. // proids.Add(10);
  1446. // proids.Add(11);
  1447. // 普通创客购买600一组的机具券
  1448. bool OncePrizeFlag4 = true;
  1449. while(ParentUserId > 0)
  1450. {
  1451. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1452. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
  1453. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1454. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  1455. function.WriteLog("MakerCode:" + puser.MakerCode, "推荐下单奖励监控日志");
  1456. function.WriteLog("machineCount:" + machineCount, "推荐下单奖励监控日志");
  1457. function.WriteLog("ActiveCount:" + ActiveCount, "推荐下单奖励监控日志");
  1458. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  1459. {
  1460. AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  1461. directPrize = true;
  1462. //推荐下单上级获得30天的机具循环天数
  1463. 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();
  1464. foreach (var subPos in posList)
  1465. {
  1466. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  1467. if (pos != null)
  1468. {
  1469. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  1470. }
  1471. }
  1472. db.SaveChanges();
  1473. }
  1474. if(puser.LeaderLevel > 0)
  1475. {
  1476. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  1477. if(acccount.LeaderReserve >= order.TotalPrice && !buyPrize)
  1478. {
  1479. //购机奖励
  1480. AlipayPayBack2Service.Instance.OpAccount(db, order, puser.Id, 100, pro.ProductCount);
  1481. buyPrize = true;
  1482. }
  1483. if(acccount.LeaderReserve >= 400 * pro.ProductCount && puser.LeaderLevel > leaderFlag && leaderFlag < 2 && OncePrizeFlag4)
  1484. {
  1485. //扣减备用金
  1486. AlipayPayBack2Service.Instance.OpReserve(db, order, puser.Id, 400 * pro.ProductCount, 2, order.UserId, "购机奖励");
  1487. //返回到余额
  1488. AlipayPayBack2Service.Instance.OpLeaderAccount(db, order, puser.Id, 400, pro.ProductCount);
  1489. leaderFlag = puser.LeaderLevel;
  1490. OncePrizeFlag4 = false;
  1491. }
  1492. //如果是大盟主,则标记大盟主标签
  1493. if(couponIds.Count > 0 && puser.LeaderLevel == 2 && acccount.LeaderReserve >= order.TotalPrice && !bigLeaderPrize)
  1494. {
  1495. foreach(int couponId in couponIds)
  1496. {
  1497. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1498. if(coupon != null)
  1499. {
  1500. coupon.LeaderUserId = puser.Id;
  1501. }
  1502. }
  1503. db.SaveChanges();
  1504. bigLeaderPrize = true;
  1505. }
  1506. }
  1507. if(puser.UserType == 1)
  1508. {
  1509. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  1510. if(!buyPrize)
  1511. {
  1512. //购机奖励
  1513. AlipayPayBack2Service.Instance.ChangeAccount(db, order, puser.Id, 100 * pro.ProductCount, 120);
  1514. buyPrize = true;
  1515. }
  1516. //标记标签
  1517. if(couponIds.Count > 0 && !operateFlag)
  1518. {
  1519. foreach(int couponId in couponIds)
  1520. {
  1521. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1522. if(coupon != null)
  1523. {
  1524. coupon.OpId= puser.Id;
  1525. }
  1526. }
  1527. db.SaveChanges();
  1528. operateFlag = true;
  1529. }
  1530. }
  1531. ParentUserId = puser.ParentUserId;
  1532. }
  1533. }
  1534. }
  1535. function.WriteLog("\r\n\r\n", "推荐下单奖励监控日志");
  1536. }
  1537. db.Dispose();
  1538. return "ok";
  1539. }
  1540. }
  1541. }