HomeController.cs 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  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. // 翻倍奖888
  729. public string prize888v2()
  730. {
  731. WebCMSEntities maindb = new WebCMSEntities();
  732. List<int> userIdList = new List<int>();
  733. string html = "<table>";
  734. DateTime StartDate = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 00:00:00");
  735. DateTime EndDate = StartDate.AddMonths(1);
  736. var orders = maindb.Orders.Select(m => new { m.UserId, m.TotalPrice, m.Status, m.PayDate }).Where(m => m.PayDate >= StartDate && m.PayDate < EndDate && m.TotalPrice == 88 && m.Status > 0).ToList();
  737. foreach (var order in orders)
  738. {
  739. userIdList.Add(order.UserId);
  740. }
  741. foreach (int UserId in userIdList)
  742. {
  743. Users myuser = maindb.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  744. var lastmonth = DateTime.Now.AddMonths(-2).ToString("yyyyMM");
  745. var thismonth = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
  746. DateTime start = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date;
  747. DateTime end = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.AddMonths(1).AddSeconds(-1);
  748. string UserIdString = "," + UserId + ",";
  749. List<Users> users = maindb.Users.Where(m => m.ParentNav.Contains(UserIdString) || m.Id == UserId).ToList();
  750. List<int> uids = new List<int>();
  751. List<int> uids2 = new List<int>();
  752. foreach (var user in users)
  753. {
  754. uids.Add(user.Id);
  755. }
  756. var suborders = orders.Where(m => uids.Contains(m.UserId)).ToList();
  757. foreach (var suborder in suborders)
  758. {
  759. uids2.Add(suborder.UserId);
  760. }
  761. users = users.Where(m => uids2.Contains(m.Id)).ToList();
  762. List<ProgressUserList> list = new List<ProgressUserList>();
  763. foreach (Users user in users)
  764. {
  765. int IsOk = 0;//是否达标(0-否 1-是)
  766. decimal lastMonthAmt = maindb.TradeDaySummary.Where(m => m.TradeMonth == lastmonth && m.SeoTitle == "team" && m.UserId == user.Id).Sum(m => m.HelpNonDirectTradeAmt + m.NotHelpNonDirectTradeAmt);
  767. decimal thisMonthAmt = maindb.TradeDaySummary.Where(m => m.TradeMonth == thismonth && m.SeoTitle == "team" && m.UserId == user.Id).Sum(m => m.HelpNonDirectTradeAmt + m.NotHelpNonDirectTradeAmt);
  768. if (thisMonthAmt >= lastMonthAmt * 2 && thisMonthAmt >= 2000000)
  769. {
  770. IsOk = 1;
  771. }
  772. ProgressUserList item = new ProgressUserList()
  773. {
  774. LastMonth = lastMonthAmt,
  775. ThisMonth = thisMonthAmt,
  776. UserId = user.Id,
  777. ParentNav = user.ParentNav,
  778. IsOk = IsOk,
  779. };
  780. list.Add(item);
  781. }
  782. list = list.OrderBy(m => m.ParentNav).ToList();
  783. int index = 0;
  784. decimal selfTrade = 0; // 自己的本月交易额
  785. decimal lastTrade = 0; // 自己的上月交易额
  786. decimal totalTrade = 0; // 自己的本月目标交易额
  787. string selfNav = ""; // 自己的ParentNav
  788. List<string> ParentNavs = new List<string>();
  789. if (list.Count > 0)
  790. {
  791. foreach (ProgressUserList sub in list)
  792. {
  793. index += 1;
  794. if (index == 1)
  795. {
  796. selfTrade = sub.ThisMonth;
  797. lastTrade = sub.LastMonth;
  798. totalTrade = lastTrade * 2;
  799. selfNav = sub.ParentNav + "," + sub.UserId + ",";
  800. }
  801. else
  802. {
  803. bool op = true; //是否满足条件
  804. string ParentNav = sub.ParentNav + "," + sub.UserId + ",";
  805. foreach (string subNav in ParentNavs)
  806. {
  807. if (ParentNavs.Contains(ParentNav) && ParentNav != subNav)
  808. {
  809. op = false;
  810. }
  811. }
  812. if (op)
  813. {
  814. if (sub.IsOk == 1)
  815. {
  816. selfTrade -= sub.ThisMonth;
  817. totalTrade -= sub.ThisMonth;
  818. }
  819. }
  820. ParentNavs.Add(ParentNav);
  821. }
  822. }
  823. }
  824. if (lastTrade * 2 < 2000000 || selfTrade == 0 || totalTrade < 2000000)
  825. {
  826. totalTrade = 2000000;
  827. }
  828. html += "<tr>";
  829. html += "<td>" + myuser.MakerCode + "</td>";
  830. html += "<td>" + myuser.RealName + "</td>";
  831. html += "<td>" + selfTrade + "</td>";
  832. html += "<td>" + lastTrade + "</td>";
  833. html += "<td>" + totalTrade + "</td>";
  834. if (selfTrade >= totalTrade)
  835. {
  836. html += "<td>满足条件</td>";
  837. }
  838. else
  839. {
  840. html += "<td>未满足条件</td>";
  841. }
  842. html += "</tr>";
  843. }
  844. html += "</table>";
  845. maindb.Dispose();
  846. return html;
  847. }
  848. // 大盟主标记扫描
  849. public string leaderflag()
  850. {
  851. WebCMSEntities db = new WebCMSEntities();
  852. List<int> ids = new List<int>();
  853. // List<PosCouponRecord> records = db.PosCouponRecord.Where(m => m.FromUserId == 597).ToList();
  854. // foreach(PosCouponRecord record in records)
  855. // {
  856. // ids.Add(record.PosCouponId);
  857. // }
  858. ids.Add(6843);
  859. List<PosCoupons> coupons = db.PosCoupons.Where(m => ids.Contains(m.Id) && m.IsUse == 1).ToList();
  860. foreach (PosCoupons coupon in coupons)
  861. {
  862. PosSns.Add(coupon.ExchangeCode);
  863. }
  864. foreach (PosCoupons coupon in coupons)
  865. {
  866. ChildNo(db, coupon.ExchangeCode, coupon.ExchangeCode, coupon.LeaderUserId);
  867. }
  868. // db.SaveChanges();
  869. db.Dispose();
  870. return "ok";
  871. }
  872. List<string> nos = new List<string>();
  873. private void ChildNo(WebCMSEntities db, string RootCheckNo, string CheckNo, int LeaderUserId)
  874. {
  875. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(CheckNo));
  876. if(apply != null)
  877. {
  878. int len = 0;
  879. string[] SnList = apply.SwapSnExpand.TrimEnd('\n').Split('\n');
  880. foreach(string sn in SnList)
  881. {
  882. if(PosSns.Contains(sn.Split(':')[0]) || nos.Contains(sn.Split(':')[0]))
  883. {
  884. len += 1;
  885. }
  886. }
  887. Orders order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount);
  888. if(order != null)
  889. {
  890. if(!string.IsNullOrEmpty(order.SnNos))
  891. {
  892. if(order.SnNos.Contains(","))
  893. {
  894. string[] SwapSnExpands = order.SnNos.TrimEnd(',').Split(',');
  895. int index = 0;
  896. foreach(string no in SwapSnExpands)
  897. {
  898. if(!nos.Contains(no) && index < len)
  899. {
  900. index += 1;
  901. nos.Add(no);
  902. ChildNo(db, RootCheckNo, no, LeaderUserId);
  903. }
  904. }
  905. }
  906. else
  907. {
  908. string[] SwapSnExpands = order.SnNos.TrimEnd('\n').Split('\n');
  909. int index = 0;
  910. foreach(string no in SwapSnExpands)
  911. {
  912. if(!nos.Contains(no) && index < len)
  913. {
  914. index += 1;
  915. nos.Add(no);
  916. ChildNo(db, RootCheckNo, no, LeaderUserId);
  917. }
  918. }
  919. }
  920. }
  921. else
  922. {
  923. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == CheckNo) ?? new MachineForSnNo();
  924. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  925. if(pos != null)
  926. {
  927. // pos.LeaderUserId = LeaderUserId;
  928. // Library.function.WriteLog(LeaderUserId + ":" + pos.PosSn + ":" + apply.SwapSnExpand.TrimEnd('\n').Split('\n').Length, "大盟主奖励标记机具");
  929. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  930. Library.function.WriteLog(pos.PosSn + ":" + RootCheckNo + ":" + user.MakerCode + ":" + user.RealName, "大盟主奖励标记机具");
  931. }
  932. }
  933. }
  934. }
  935. else
  936. {
  937. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == CheckNo) ?? new MachineForSnNo();
  938. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m=>m.Id == forSnNo.SnId);
  939. if(pos != null)
  940. {
  941. // pos.LeaderUserId = LeaderUserId;
  942. // Library.function.WriteLog(LeaderUserId + ":" + pos.PosSn, "大盟主奖励标记机具");
  943. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  944. Library.function.WriteLog(pos.PosSn + ":" + RootCheckNo + ":" + user.MakerCode + ":" + user.RealName, "大盟主奖励标记机具");
  945. }
  946. }
  947. }
  948. List<string> PosSns = new List<string>();
  949. public string ScanNos()
  950. {
  951. PosSns = new List<string>();
  952. PosSns.Add("00005002681889125851");
  953. WebCMSEntities db = new WebCMSEntities();
  954. foreach(string PosSn in PosSns)
  955. {
  956. ChildNo(db, PosSn, PosSn, 0);
  957. }
  958. db.Dispose();
  959. return "ok";
  960. }
  961. //补推荐奖励
  962. public string AddDirectPrice(int oid = 0)
  963. {
  964. WebCMSEntities db = new WebCMSEntities();
  965. List<int> uids = new List<int>(); //领取过的下单创客
  966. IQueryable<Orders> orders = db.Orders.Where(m => m.Status > 1 && m.UserId > 1 && m.TotalPrice % 600 == 0 && m.Sort == 0);
  967. if(oid > 0)
  968. {
  969. orders = orders.Where(m => m.Id == oid);
  970. }
  971. foreach (Orders order in orders.ToList())
  972. {
  973. if(!uids.Contains(order.UserId))
  974. {
  975. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == oid && m.ChangeType == 112);
  976. if(checkPrize)
  977. {
  978. uids.Add(order.UserId);
  979. }
  980. else
  981. {
  982. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == oid) ?? new OrderProduct();
  983. if (pro.ProductId == 10 || pro.ProductId == 11)
  984. {
  985. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  986. if (user != null)
  987. {
  988. bool directPrize = false; //直推奖标记
  989. int ParentUserId = user.ParentUserId;
  990. List<int> proids = new List<int>();
  991. proids.Add(10);
  992. proids.Add(11);
  993. while (ParentUserId > 0)
  994. {
  995. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  996. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
  997. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  998. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  999. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  1000. {
  1001. function.WriteLog("满足条件", "推荐下单奖励监控日志");
  1002. if (puser.LeaderLevel == 0) // 非盟主直推奖励,每个创客第一次下单,上级可得
  1003. {
  1004. List<int> oids = new List<int>();
  1005. var orderpros = db.OrderProduct.Select(m => new { m.OrderId, m.UserId, m.ProductId }).Where(m => m.UserId == order.UserId && proids.Contains(m.ProductId)).ToList();
  1006. foreach (var orderpro in orderpros)
  1007. {
  1008. oids.Add(orderpro.OrderId);
  1009. }
  1010. bool check = db.Orders.Any(m => oids.Contains(m.Id) && m.Status > 0);
  1011. if (check)
  1012. {
  1013. // AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  1014. function.WriteLog(order.Id + "," + ParentUserId + "," + pro.ProductCount, "没发的推荐奖励");
  1015. directPrize = true;
  1016. }
  1017. }
  1018. else
  1019. {
  1020. // 盟主直推奖励,可以每次下单获得
  1021. // AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  1022. function.WriteLog(order.Id + "," + ParentUserId + "," + pro.ProductCount + "--盟主", "没发的推荐奖励");
  1023. directPrize = true;
  1024. }
  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(directPrize)
  1038. {
  1039. ParentUserId = 0;
  1040. }
  1041. else
  1042. {
  1043. ParentUserId = puser.ParentUserId;
  1044. }
  1045. }
  1046. }
  1047. }
  1048. }
  1049. }
  1050. }
  1051. return "ok";
  1052. }
  1053. public string checkLeaderOrder(int OrderId)
  1054. {
  1055. WebCMSEntities db = new WebCMSEntities();
  1056. Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId);
  1057. if (order != null)
  1058. {
  1059. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == OrderId);
  1060. if (pro != null)
  1061. {
  1062. //推荐下单奖励
  1063. if (pro.ProductId == 10 || pro.ProductId == 11)
  1064. {
  1065. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  1066. function.WriteLog("OrderId:" + OrderId, "推荐下单奖励监控日志");
  1067. function.WriteLog("checkPrize:" + checkPrize, "推荐下单奖励监控日志");
  1068. if (!checkPrize)
  1069. {
  1070. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  1071. if (user != null)
  1072. {
  1073. bool directPrize = false; //直推奖标记
  1074. bool buyPrize = false; //返100购机奖励标记
  1075. int leaderFlag = 0; //返600备用金标记
  1076. if(user.LeaderLevel > 0)
  1077. {
  1078. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
  1079. if(acccount.LeaderReserve >= order.TotalPrice)
  1080. {
  1081. if(order.PayMode == 4)
  1082. {
  1083. //扣减备用金
  1084. AlipayPayBack2Service.Instance.OpReserve(db, order, order.UserId, order.TotalPrice, 2, 0, "商城购机");
  1085. //返回到余额
  1086. // OpAccount(db, order, order.UserId, order.TotalPrice / pro.ProductCount, pro.ProductCount);
  1087. }
  1088. }
  1089. //获得100元奖励
  1090. AlipayPayBack2Service.Instance.OpAccount(db, order, order.UserId, 100, pro.ProductCount);
  1091. //推荐奖励
  1092. AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, order.UserId, pro.ProductCount);
  1093. //推荐下单上级获得30天的机具循环天数
  1094. 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();
  1095. foreach (var subPos in posList)
  1096. {
  1097. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  1098. if (pos != null)
  1099. {
  1100. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  1101. }
  1102. }
  1103. db.SaveChanges();
  1104. if(user.LeaderLevel != 2)
  1105. {
  1106. int PUserId = user.ParentUserId;
  1107. while(PUserId > 0)
  1108. {
  1109. Users puser = db.Users.FirstOrDefault(m => m.Id == PUserId) ?? new Users();
  1110. if(puser.LeaderLevel == 2)
  1111. {
  1112. UserAccount acc = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  1113. if(acc.LeaderReserve >= order.TotalPrice)
  1114. {
  1115. //扣减备用金
  1116. AlipayPayBack2Service.Instance.OpReserve(db, order, puser.Id, order.TotalPrice, 2, order.UserId, "购机奖励");
  1117. //返回到余额
  1118. AlipayPayBack2Service.Instance.OpAccount(db, order, puser.Id, order.TotalPrice / pro.ProductCount, pro.ProductCount);
  1119. }
  1120. PUserId = 0;
  1121. }
  1122. else
  1123. {
  1124. PUserId = puser.ParentUserId;
  1125. }
  1126. }
  1127. }
  1128. return "自己就是盟主,发放成功";
  1129. }
  1130. int ParentUserId = user.ParentUserId;
  1131. // List<int> proids = new List<int>();
  1132. // proids.Add(10);
  1133. // proids.Add(11);
  1134. while(ParentUserId > 0)
  1135. {
  1136. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1137. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
  1138. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1139. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  1140. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  1141. {
  1142. // 盟主直推奖励,可以每次下单获得
  1143. AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  1144. directPrize = true;
  1145. //推荐下单上级获得30天的机具循环天数
  1146. 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();
  1147. foreach (var subPos in posList)
  1148. {
  1149. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  1150. if (pos != null)
  1151. {
  1152. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  1153. }
  1154. }
  1155. db.SaveChanges();
  1156. }
  1157. if(puser.LeaderLevel > 0)
  1158. {
  1159. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  1160. if(acccount.LeaderReserve >= order.TotalPrice && !buyPrize)
  1161. {
  1162. //购机奖励
  1163. AlipayPayBack2Service.Instance.OpAccount(db, order, puser.Id, 100, pro.ProductCount);
  1164. buyPrize = true;
  1165. }
  1166. if(acccount.LeaderReserve >= order.TotalPrice && puser.LeaderLevel > leaderFlag)
  1167. {
  1168. //扣减备用金
  1169. AlipayPayBack2Service.Instance.OpReserve(db, order, puser.Id, order.TotalPrice, 2, order.UserId, "购机奖励");
  1170. //返回到余额
  1171. AlipayPayBack2Service.Instance.OpAccount(db, order, puser.Id, order.TotalPrice / pro.ProductCount, pro.ProductCount);
  1172. leaderFlag = puser.LeaderLevel;
  1173. }
  1174. }
  1175. ParentUserId = puser.ParentUserId;
  1176. }
  1177. return "找到上级盟主,发放成功";
  1178. }
  1179. }
  1180. }
  1181. }
  1182. }
  1183. return "失败";
  1184. }
  1185. public string setdeposit()
  1186. {
  1187. // List<string> ordernos = new List<string>();
  1188. // ordernos.Add("17343379");
  1189. string content = "";
  1190. // foreach(string orderno in ordernos)
  1191. // {
  1192. // content += SetDepositPostService.Instance.QueryFee(orderno) + "\n";
  1193. // }
  1194. // List<string> snnos = new List<string>();
  1195. // foreach(string snno in snnos)
  1196. // {
  1197. // content += SetDepositPostService.Instance.ModifyFee(snno, 0.0006M) + "\n";
  1198. // }
  1199. // content = SetDepositPostService.Instance.SetFeeForSft("38888910", "0.63");
  1200. // content = SetDepositPostService.Instance.SetFeeForBrand("00003202D9625450004213", bzConfigId, yhConfigId, surfeeConfigId, "");
  1201. return content;
  1202. }
  1203. public string putdata()
  1204. {
  1205. WebCMSEntities db = new WebCMSEntities();
  1206. var list = db.PosMachinesFeeChangeRecord.Where(m => m.Sort == 2 && m.Status == 0).ToList();
  1207. foreach(var sub in list)
  1208. {
  1209. Users user = db.Users.FirstOrDefault(m => m.Id == sub.UserId) ?? new Users();
  1210. string info = "{\"RecordId\":\"" + sub.Id + "\",\"PosId\":\"" + sub.PosId + "\",\"Fee\": \"0.6\",\"Kind\": \"2\",\"OpMan\": \"" + user.MakerCode + "\"}";
  1211. RedisDbconn.Instance.AddList("SetDepositQueue", info);
  1212. }
  1213. db.Dispose();
  1214. return "ok";
  1215. }
  1216. public string test3(string sn)
  1217. {
  1218. WebCMSEntities db = new WebCMSEntities();
  1219. // StoreApplyHelper.Instance.DoSomething(db, 89);
  1220. // AlipayPayBack2Service.Instance.DoOrderV2(db, 94559);
  1221. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == sn);
  1222. if(pos != null)
  1223. {
  1224. //发放大盟主奖励
  1225. if(pos.LeaderUserId > 0)
  1226. {
  1227. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  1228. }
  1229. //发放运营中心奖励
  1230. if(pos.OpId > 0)
  1231. {
  1232. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  1233. AlipayPayBack2Service.Instance.ActReserveBack(pos.OpId, pos.OpReserve1, pos.OpReserve2, pos.OpReserve3);
  1234. }
  1235. }
  1236. db.Dispose();
  1237. return "ok";
  1238. }
  1239. }
  1240. }