HomeController.cs 86 KB

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