HomeController.cs 86 KB

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