HomeController.cs 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587
  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("33150000002", 299, 8);
  1138. return result;
  1139. }
  1140. public string sethkfee()
  1141. {
  1142. string bzConfigId = "", yhConfigId = "", surfeeConfigId = "";
  1143. int Kind = 2;
  1144. WebCMSEntities db = new WebCMSEntities();
  1145. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == "00005702832513011041") ?? new PosMachinesTwo();
  1146. if(pos.BrandId == 8)
  1147. {
  1148. if(Kind == 1)
  1149. {
  1150. bzConfigId = "684753829778436096";
  1151. yhConfigId = "684754046342934528";
  1152. surfeeConfigId = "570331704834170880";
  1153. }
  1154. else
  1155. {
  1156. bzConfigId = "585167132691009536";
  1157. yhConfigId = "579355312831074304";
  1158. surfeeConfigId = "570331704834170880";
  1159. }
  1160. }
  1161. else
  1162. {
  1163. if(Kind == 1)
  1164. {
  1165. bzConfigId = "691739824478494720";
  1166. yhConfigId = "691740128238383104";
  1167. surfeeConfigId = "574600660289888256";
  1168. }
  1169. else
  1170. {
  1171. bzConfigId = "584068951081226240";
  1172. yhConfigId = "584070145207963648";
  1173. surfeeConfigId = "574600660289888256";
  1174. }
  1175. }
  1176. string content = SetDepositPostService.Instance.HKSetFeeForBrand(pos.PosSn, bzConfigId, yhConfigId, surfeeConfigId, pos.BrandId);
  1177. return content;
  1178. }
  1179. public string add600(int OrderId = 0)
  1180. {
  1181. WebCMSEntities db = new WebCMSEntities();
  1182. List<int> couponIds = new List<int>();
  1183. couponIds.Add(74648);
  1184. couponIds.Add(74649);
  1185. couponIds.Add(74650);
  1186. Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId) ?? new Orders();
  1187. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == OrderId) ?? new OrderProduct();
  1188. if (pro.ProductId == 10 || pro.ProductId == 11)
  1189. {
  1190. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  1191. function.WriteLog("OrderId:" + OrderId, "推荐下单奖励监控日志");
  1192. function.WriteLog("checkPrize:" + checkPrize, "推荐下单奖励监控日志");
  1193. if (checkPrize)
  1194. {
  1195. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  1196. if (user != null)
  1197. {
  1198. if(user.LeaderLevel > 0 || user.UserType == 1) //盟主或运营中心
  1199. {
  1200. //获得100元奖励
  1201. AlipayPayBack2Service.Instance.OpAccount(db, order, order.UserId, 100, pro.ProductCount);
  1202. }
  1203. }
  1204. }
  1205. else
  1206. {
  1207. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  1208. if (user != null)
  1209. {
  1210. bool directPrize = false; //直推奖标记
  1211. bool bigLeaderPrize = false; //大盟主券标记
  1212. bool operateFlag = false; //运营中心标记
  1213. bool buyPrize = false; //返100购机奖励标记或返100购机奖励标记-运营中心
  1214. int leaderFlag = 0; //返600备用金标记
  1215. if(user.LeaderLevel > 0 || user.UserType == 1) //盟主或运营中心
  1216. {
  1217. if(user.LeaderLevel > 0)
  1218. {
  1219. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
  1220. if(acccount.LeaderReserve >= order.TotalPrice)
  1221. {
  1222. if(order.PayMode == 4)
  1223. {
  1224. //扣减备用金
  1225. AlipayPayBack2Service.Instance.OpReserve(db, order, order.UserId, order.TotalPrice, 0, 0, "商城购机(储备金支付)");
  1226. }
  1227. }
  1228. }
  1229. //获得100元奖励
  1230. AlipayPayBack2Service.Instance.OpAccount(db, order, order.UserId, 100, pro.ProductCount);
  1231. //推荐奖励
  1232. AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, order.UserId, pro.ProductCount);
  1233. //推荐下单上级获得30天的机具循环天数(盟主自己得)
  1234. 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();
  1235. foreach (var subPos in posList)
  1236. {
  1237. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  1238. if (pos != null)
  1239. {
  1240. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  1241. }
  1242. }
  1243. db.SaveChanges();
  1244. if(order.PayMode == 4 && user.LeaderLevel > 0) //使用盟主储蓄金,并且是盟主
  1245. {
  1246. if(user.UserType == 1)
  1247. {
  1248. if(couponIds.Count > 0)
  1249. {
  1250. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == user.Id) ?? new UserAccount();
  1251. foreach(int couponId in couponIds)
  1252. {
  1253. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1254. if(coupon != null)
  1255. {
  1256. if(acccount.LeaderReserve >= 400 * pro.ProductCount)
  1257. {
  1258. coupon.LeaderUserId = user.Id;
  1259. }
  1260. coupon.OpId = user.Id;
  1261. }
  1262. }
  1263. }
  1264. db.SaveChanges();
  1265. }
  1266. else
  1267. {
  1268. //寻找最近运营中心额度大于0的运营中心
  1269. int PUserId = user.Id;
  1270. bool OperateFlag = true;
  1271. bool OncePrizeFlag1 = true;
  1272. while(PUserId > 0)
  1273. {
  1274. Users puser = db.Users.FirstOrDefault(m => m.Id == PUserId);
  1275. if(puser != null)
  1276. {
  1277. if(puser.UserType == 1 && OperateFlag == true) //运营中心
  1278. {
  1279. if(couponIds.Count > 0)
  1280. {
  1281. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
  1282. foreach(int couponId in couponIds)
  1283. {
  1284. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1285. if(coupon != null)
  1286. {
  1287. if(acccount.LeaderReserve >= 400 * pro.ProductCount)
  1288. {
  1289. coupon.LeaderUserId = user.Id;
  1290. }
  1291. coupon.OpId = puser.Id;
  1292. }
  1293. }
  1294. db.SaveChanges();
  1295. if(acccount.LeaderReserve >= 400 * pro.ProductCount && OncePrizeFlag1)
  1296. {
  1297. //扣减备用金
  1298. AlipayPayBack2Service.Instance.OpReserve(db, order, order.UserId, 400 * pro.ProductCount, 2, 0, "商城购机");
  1299. //返回到余额
  1300. AlipayPayBack2Service.Instance.OpLeaderAccount(db, order, order.UserId, 400, pro.ProductCount);
  1301. OncePrizeFlag1 = false;
  1302. }
  1303. OperateFlag = false;
  1304. }
  1305. }
  1306. PUserId = puser.ParentUserId;
  1307. }
  1308. else
  1309. {
  1310. PUserId = 0;
  1311. }
  1312. }
  1313. }
  1314. }
  1315. else if(order.PayMode == 4 && user.UserType == 1) //使用盟主储蓄金,并且是运营中心
  1316. {
  1317. if(couponIds.Count > 0)
  1318. {
  1319. foreach(int couponId in couponIds)
  1320. {
  1321. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1322. if(coupon != null)
  1323. {
  1324. coupon.OpId = user.Id;
  1325. }
  1326. }
  1327. }
  1328. db.SaveChanges();
  1329. //寻找最近储蓄金充足的大盟主
  1330. int PUserId = user.Id;
  1331. bool LeaderFlag = true;
  1332. bool OncePrizeFlag2 = true;
  1333. while(PUserId > 0)
  1334. {
  1335. Users puser = db.Users.FirstOrDefault(m => m.Id == PUserId);
  1336. if(puser != null)
  1337. {
  1338. if(puser.LeaderLevel == 2 && LeaderFlag == true) //大盟主
  1339. {
  1340. if(couponIds.Count > 0)
  1341. {
  1342. UserAccount pacccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  1343. foreach(int couponId in couponIds)
  1344. {
  1345. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1346. if(coupon != null && pacccount.LeaderReserve >= 400 * pro.ProductCount)
  1347. {
  1348. coupon.LeaderUserId = puser.Id;
  1349. }
  1350. }
  1351. db.SaveChanges();
  1352. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
  1353. if(acccount.LeaderReserve >= 400 * pro.ProductCount && OncePrizeFlag2)
  1354. {
  1355. //扣减备用金
  1356. AlipayPayBack2Service.Instance.OpReserve(db, order, order.UserId, 400 * pro.ProductCount, 2, 0, "商城购机");
  1357. //返回到余额
  1358. AlipayPayBack2Service.Instance.OpLeaderAccount(db, order, order.UserId, 400, pro.ProductCount);
  1359. OncePrizeFlag2 = false;
  1360. }
  1361. LeaderFlag = false;
  1362. }
  1363. }
  1364. PUserId = puser.ParentUserId;
  1365. }
  1366. else
  1367. {
  1368. PUserId = 0;
  1369. }
  1370. }
  1371. }
  1372. else
  1373. {
  1374. //寻找最近储蓄金充足的大盟主及最近运营中心额度大于0的运营中心(含自身)
  1375. int PUserId = user.Id;
  1376. int LeaderFlag = 0;
  1377. bool OperateFlag = true;
  1378. bool OncePrizeFlag3 = true;
  1379. while(PUserId > 0)
  1380. {
  1381. Users puser = db.Users.FirstOrDefault(m => m.Id == PUserId);
  1382. if(puser != null)
  1383. {
  1384. if(puser.LeaderLevel > 0 && puser.LeaderLevel > LeaderFlag && LeaderFlag < 2) //大盟主
  1385. {
  1386. if(couponIds.Count > 0)
  1387. {
  1388. if(puser.LeaderLevel == 2)
  1389. {
  1390. UserAccount pacccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  1391. foreach(int couponId in couponIds)
  1392. {
  1393. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1394. if(coupon != null && pacccount.LeaderReserve >= 400 * pro.ProductCount)
  1395. {
  1396. coupon.LeaderUserId = puser.Id;
  1397. }
  1398. }
  1399. db.SaveChanges();
  1400. }
  1401. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  1402. if(acccount.LeaderReserve >= 400 * pro.ProductCount && OncePrizeFlag3)
  1403. {
  1404. //扣减备用金
  1405. AlipayPayBack2Service.Instance.OpReserve(db, order, puser.Id, 400 * pro.ProductCount, 2, 0, "商城购机");
  1406. //返回到余额
  1407. AlipayPayBack2Service.Instance.OpLeaderAccount(db, order, puser.Id, 400, pro.ProductCount);
  1408. LeaderFlag = puser.LeaderLevel;
  1409. OncePrizeFlag3 = false;
  1410. }
  1411. }
  1412. }
  1413. if(puser.UserType == 1 && OperateFlag == true) //运营中心
  1414. {
  1415. if(couponIds.Count > 0)
  1416. {
  1417. foreach(int couponId in couponIds)
  1418. {
  1419. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1420. if(coupon != null)
  1421. {
  1422. coupon.OpId = puser.Id;
  1423. }
  1424. }
  1425. db.SaveChanges();
  1426. OperateFlag = false;
  1427. }
  1428. }
  1429. PUserId = puser.ParentUserId;
  1430. }
  1431. else
  1432. {
  1433. PUserId = 0;
  1434. }
  1435. }
  1436. }
  1437. return "ok";
  1438. }
  1439. int ParentUserId = user.ParentUserId;
  1440. // List<int> proids = new List<int>();
  1441. // proids.Add(10);
  1442. // proids.Add(11);
  1443. // 普通创客购买600一组的机具券
  1444. bool OncePrizeFlag4 = true;
  1445. while(ParentUserId > 0)
  1446. {
  1447. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1448. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
  1449. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1450. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  1451. function.WriteLog("MakerCode:" + puser.MakerCode, "推荐下单奖励监控日志");
  1452. function.WriteLog("machineCount:" + machineCount, "推荐下单奖励监控日志");
  1453. function.WriteLog("ActiveCount:" + ActiveCount, "推荐下单奖励监控日志");
  1454. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  1455. {
  1456. AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  1457. directPrize = true;
  1458. //推荐下单上级获得30天的机具循环天数
  1459. 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();
  1460. foreach (var subPos in posList)
  1461. {
  1462. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  1463. if (pos != null)
  1464. {
  1465. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  1466. }
  1467. }
  1468. db.SaveChanges();
  1469. }
  1470. if(puser.LeaderLevel > 0)
  1471. {
  1472. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  1473. if(acccount.LeaderReserve >= order.TotalPrice && !buyPrize)
  1474. {
  1475. //购机奖励
  1476. AlipayPayBack2Service.Instance.OpAccount(db, order, puser.Id, 100, pro.ProductCount);
  1477. buyPrize = true;
  1478. }
  1479. if(acccount.LeaderReserve >= 400 * pro.ProductCount && puser.LeaderLevel > leaderFlag && leaderFlag < 2 && OncePrizeFlag4)
  1480. {
  1481. //扣减备用金
  1482. AlipayPayBack2Service.Instance.OpReserve(db, order, puser.Id, 400 * pro.ProductCount, 2, order.UserId, "购机奖励");
  1483. //返回到余额
  1484. AlipayPayBack2Service.Instance.OpLeaderAccount(db, order, puser.Id, 400, pro.ProductCount);
  1485. leaderFlag = puser.LeaderLevel;
  1486. OncePrizeFlag4 = false;
  1487. }
  1488. //如果是大盟主,则标记大盟主标签
  1489. if(couponIds.Count > 0 && puser.LeaderLevel == 2 && acccount.LeaderReserve >= order.TotalPrice && !bigLeaderPrize)
  1490. {
  1491. foreach(int couponId in couponIds)
  1492. {
  1493. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1494. if(coupon != null)
  1495. {
  1496. coupon.LeaderUserId = puser.Id;
  1497. }
  1498. }
  1499. db.SaveChanges();
  1500. bigLeaderPrize = true;
  1501. }
  1502. }
  1503. if(puser.UserType == 1)
  1504. {
  1505. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  1506. if(!buyPrize)
  1507. {
  1508. //购机奖励
  1509. AlipayPayBack2Service.Instance.ChangeAccount(db, order, puser.Id, 100 * pro.ProductCount, 120);
  1510. buyPrize = true;
  1511. }
  1512. //标记标签
  1513. if(couponIds.Count > 0 && !operateFlag)
  1514. {
  1515. foreach(int couponId in couponIds)
  1516. {
  1517. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  1518. if(coupon != null)
  1519. {
  1520. coupon.OpId= puser.Id;
  1521. }
  1522. }
  1523. db.SaveChanges();
  1524. operateFlag = true;
  1525. }
  1526. }
  1527. ParentUserId = puser.ParentUserId;
  1528. }
  1529. }
  1530. }
  1531. function.WriteLog("\r\n\r\n", "推荐下单奖励监控日志");
  1532. }
  1533. db.Dispose();
  1534. return "ok";
  1535. }
  1536. }
  1537. }