PosCouponPrizeService.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using System.Threading;
  6. using MySystem.PxcModels;
  7. using Library;
  8. using LitJson;
  9. namespace MySystem
  10. {
  11. public class PosCouponPrizeService
  12. {
  13. public readonly static PosCouponPrizeService Instance = new PosCouponPrizeService();
  14. private PosCouponPrizeService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(ready);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. private void ready()
  23. {
  24. bool op = true;
  25. while (op)
  26. {
  27. string content = RedisDbconn.Instance.RPop<string>("PosCouponPrizeQueue");
  28. if (!string.IsNullOrEmpty(content))
  29. {
  30. try
  31. {
  32. dosomething(int.Parse(function.CheckInt(content)));
  33. }
  34. catch(Exception ex)
  35. {
  36. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "商城下单机具券发奖异常");
  37. }
  38. }
  39. else
  40. {
  41. Thread.Sleep(2000);
  42. }
  43. }
  44. }
  45. public void dosomething(int OrderId)
  46. {
  47. WebCMSEntities db = new WebCMSEntities();
  48. OpModels.WebCMSEntities opdb = new OpModels.WebCMSEntities();
  49. Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId);
  50. if(order != null)
  51. {
  52. List<int> ChkIds = new List<int>(); //机具券商品Id集合
  53. ChkIds.Add(10);
  54. ChkIds.Add(11);
  55. ChkIds.Add(77);
  56. ChkIds.Add(78);
  57. ChkIds.Add(79);
  58. //判断是否是指定商品
  59. if(ChkIds.Contains(order.ProductId))
  60. {
  61. int Kind = 0;
  62. if (order.ProductId == 10)
  63. {
  64. Kind = 1;
  65. }
  66. else if (order.ProductId == 11)
  67. {
  68. Kind = 2;
  69. }
  70. int CouponCount = 0;
  71. if(Kind == 1)
  72. {
  73. CouponCount = 3 * order.BuyCount;
  74. }
  75. else if(Kind == 2)
  76. {
  77. CouponCount = 2 * order.BuyCount;
  78. }
  79. UserRankItem orderUser = GetUserLevel(db, order.UserId);
  80. if(orderUser.UserLevel == 0)
  81. {
  82. PreUserLevel(db, order.UserId, 1, DateTime.Parse("2025-01-01 00:00:00"));
  83. }
  84. string ParentNav = orderUser.ParentNav + "," + orderUser.Id + ",";
  85. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  86. Array.Reverse(ParentNavList);
  87. int index = 0;
  88. bool DirectPrizeFlag = false; //推荐奖励发放标识
  89. bool BackAccountFlag = false; //备用金返余额标识
  90. bool BigLeaderFlag = false; //大盟主标记
  91. decimal BuyPrize = 0; //购机奖励
  92. foreach(string ParentId in ParentNavList)
  93. {
  94. UserRankItem parentUser = GetUserLevel(db, int.Parse(ParentId));
  95. index += 1;
  96. if(index == 1 && (orderUser.LeaderLevel > 0 || orderUser.OperateLevel > 0) && !DirectPrizeFlag)
  97. {
  98. DirectPrize(db, order.Id, order.UserId, order.BuyCount);
  99. DirectPrizeFlag = true;
  100. }
  101. if(index > 1)
  102. {
  103. if(Utils.Instance.IsStandardUser(parentUser.Id) && !DirectPrizeFlag)
  104. {
  105. DirectPrize(db, order.Id, parentUser.Id, order.BuyCount);
  106. DirectPrizeFlag = true;
  107. }
  108. }
  109. if(parentUser.AgoLeaderLevel > 0 && CheckLeaderReserve(db, order.BuyCount, parentUser.Id))
  110. {
  111. //购机奖
  112. if(parentUser.LeaderLevel > 0)
  113. {
  114. decimal CurBuyPrize = GetBuyPrize(parentUser);
  115. decimal GetPrize = CurBuyPrize - BuyPrize;
  116. if(GetPrize > 0)
  117. {
  118. int ChangeType = 118;
  119. if(parentUser.OperateLevel == 1)
  120. {
  121. ChangeType = 120;
  122. }
  123. if(parentUser.OperateLevel > 1)
  124. {
  125. ChangeType = 128;
  126. }
  127. OpAccount(db, order.Id, parentUser.Id, CurBuyPrize - BuyPrize, order.BuyCount, ChangeType);
  128. BuyPrize = CurBuyPrize;
  129. }
  130. }
  131. if(!BackAccountFlag)
  132. {
  133. BackAccountFlag = true;
  134. //扣减备用金
  135. OpReserve(db, order.Id, parentUser.Id, GetWithdrawMoney(parentUser) * order.BuyCount, 2, order.UserId, "购机奖励");
  136. //返回到余额
  137. OpLeaderAccount(db, order, parentUser.Id, GetWithdrawMoney(parentUser), order.BuyCount);
  138. }
  139. //给券打大盟主标记
  140. if(parentUser.LeaderLevel == 2 && !BigLeaderFlag)
  141. {
  142. BigLeaderFlag = true;
  143. if(!string.IsNullOrEmpty(order.SnNos))
  144. {
  145. List<string> codes = order.SnNos.Split(',').ToList();
  146. List<int> couponIds = db.PosCoupons.Where(m => codes.Contains(m.ExchangeCode)).OrderBy(m => m.Id).Take(CouponCount).ToList().Select(m => m.Id).ToList();
  147. SetPosCouponLeaderFlag(db, parentUser.Id, order.BuyCount, couponIds);
  148. }
  149. }
  150. }
  151. else if(parentUser.OperateLevel > 0 && CheckOpReserve(opdb, order.BuyCount, parentUser.Id))
  152. {
  153. //购机奖
  154. decimal CurBuyPrize = GetBuyPrize(parentUser);
  155. decimal GetPrize = CurBuyPrize - BuyPrize;
  156. if(GetPrize > 0)
  157. {
  158. int ChangeType = 120;
  159. if(parentUser.OperateLevel > 1)
  160. {
  161. ChangeType = 128;
  162. }
  163. OpAccount(db, order.Id, parentUser.Id, GetPrize, order.BuyCount, ChangeType);
  164. BuyPrize = CurBuyPrize;
  165. }
  166. if(!BackAccountFlag)
  167. {
  168. BackAccountFlag = true;
  169. //扣减备用金
  170. OperateAmountChange(opdb, parentUser.Id, GetWithdrawMoney(parentUser) * order.BuyCount, 2, 1, "商城购机", true);
  171. //返回到余额
  172. OperateAmountChange(opdb, parentUser.Id, GetWithdrawMoney(parentUser) * order.BuyCount, 1, 2, "商城购机", true);
  173. }
  174. }
  175. }
  176. }
  177. }
  178. db.Dispose();
  179. opdb.Dispose();
  180. }
  181. /// <summary>
  182. /// 获取创客各种等级
  183. /// </summary>
  184. /// <param name="db"></param>
  185. /// <param name="UserId"></param>
  186. /// <returns></returns>
  187. public UserRankItem GetUserLevel(WebCMSEntities db, int UserId)
  188. {
  189. UserRankItem dic = new UserRankItem();
  190. DateTime now = DateTime.Now;
  191. Users user = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1 && m.Status > -1) ?? new Users();
  192. UserRankWhite userWhite = db.UserRankWhite.FirstOrDefault(m => m.Id == UserId && m.UpdateDate > now) ?? new UserRankWhite();
  193. Leaders leader = db.Leaders.FirstOrDefault(m => m.Id == UserId) ?? new Leaders();
  194. dic.UserLevel = userWhite.Rank > user.UserLevel ? userWhite.Rank : user.UserLevel;
  195. if(leader.ExpiredDate > now)
  196. {
  197. dic.LeaderLevel = leader.LeaderLevel;
  198. }
  199. dic.AgoLeaderLevel = leader.LeaderLevel;
  200. dic.OperateLevel = user.UserType;
  201. dic.UserType = user.UserType;
  202. dic.MerchantType = user.MerchantType;
  203. dic.Id = user.Id;
  204. dic.MakerCode = user.MakerCode;
  205. dic.RealName = user.RealName;
  206. dic.ParentUserId = user.ParentUserId;
  207. dic.ParentNav = user.ParentNav;
  208. return dic;
  209. }
  210. /// <summary>
  211. /// 直推奖励
  212. /// </summary>
  213. /// <param name="db"></param>
  214. /// <param name="OrderId"></param>
  215. /// <param name="UserId"></param>
  216. /// <param name="Count"></param>
  217. public void DirectPrize(WebCMSEntities db, int OrderId, int UserId, int Count = 1)
  218. {
  219. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  220. if (account == null)
  221. {
  222. account = db.UserAccount.Add(new UserAccount()
  223. {
  224. Id = UserId,
  225. UserId = UserId,
  226. }).Entity;
  227. db.SaveChanges();
  228. }
  229. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  230. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  231. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  232. account.BalanceAmount += 100 * Count;
  233. account.TotalAmount += 100 * Count;
  234. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  235. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  236. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  237. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  238. {
  239. CreateDate = DateTime.Now,
  240. UpdateDate = DateTime.Now,
  241. UserId = UserId, //创客
  242. ChangeType = 112, //变动类型
  243. ChangeAmount = 100 * Count, //变更金额
  244. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  245. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  246. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  247. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  248. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  249. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  250. QueryCount = OrderId,
  251. }).Entity;
  252. db.SaveChanges();
  253. }
  254. /// <summary>
  255. /// 判断盟主储蓄金足够
  256. /// </summary>
  257. /// <param name="db"></param>
  258. /// <param name="Count"></param>
  259. /// <param name="UserId"></param>
  260. /// <returns></returns>
  261. public bool CheckLeaderReserve(WebCMSEntities db, int Count, int UserId)
  262. {
  263. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new UserAccount();
  264. if(acccount.LeaderReserve >= 400 * Count)
  265. {
  266. return true;
  267. }
  268. return false;
  269. }
  270. /// <summary>
  271. /// 判断运营中心/合伙人额度足够
  272. /// </summary>
  273. /// <param name="db"></param>
  274. /// <param name="Count"></param>
  275. /// <param name="UserId"></param>
  276. /// <returns></returns>
  277. public bool CheckOpReserve(OpModels.WebCMSEntities db, int Count, int UserId)
  278. {
  279. OpModels.UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new OpModels.UserAccount();
  280. if(account.TotalAmt >= 400 * Count)
  281. {
  282. return true;
  283. }
  284. return false;
  285. }
  286. public bool CheckOpReserve(OpModels.WebCMSEntities db, decimal Amt, int UserId)
  287. {
  288. OpModels.UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new OpModels.UserAccount();
  289. if(account.TotalAmt >= Amt)
  290. {
  291. return true;
  292. }
  293. return false;
  294. }
  295. /// <summary>
  296. /// 扣减/增加盟主储蓄金
  297. /// </summary>
  298. /// <param name="db"></param>
  299. /// <param name="OrderId"></param>
  300. /// <param name="UserId"></param>
  301. /// <param name="Money"></param>
  302. /// <param name="ChangeType"></param>
  303. /// <param name="SourceUserId"></param>
  304. /// <param name="Remark"></param>
  305. public void OpReserve(WebCMSEntities db, int OrderId, int UserId, decimal Money, int ChangeType, int SourceUserId = 0, string Remark = "储备金购买")
  306. {
  307. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  308. if (account == null)
  309. {
  310. account = db.UserAccount.Add(new UserAccount()
  311. {
  312. Id = UserId,
  313. UserId = UserId,
  314. }).Entity;
  315. db.SaveChanges();
  316. }
  317. decimal BeforeAmount = account.LeaderReserve; //变更前总金额
  318. if(ChangeType == 1)
  319. {
  320. account.LeaderReserve += Money;
  321. }
  322. else
  323. {
  324. account.LeaderReserve -= Money;
  325. }
  326. decimal AfterAmount = account.LeaderReserve; //变更后总金额
  327. LeaderReserveRecord add = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  328. {
  329. CreateDate = DateTime.Now,
  330. ChangeType = ChangeType,
  331. OrderId = OrderId,
  332. Remark = Remark,
  333. AfterAmt = AfterAmount,
  334. BeforeAmt = BeforeAmount,
  335. ChangeAmt = Money,
  336. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  337. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  338. UserId = UserId,
  339. SourceUserId = SourceUserId,
  340. Sort = GetLeaderReserveRecordType(Remark),
  341. }).Entity;
  342. db.SaveChanges();
  343. }
  344. private int GetLeaderReserveRecordType(string Remark)
  345. {
  346. Dictionary<int, string> data = new Dictionary<int, string>();
  347. data.Add(11, "兑换机具券,机具券兑换,系统增加(盟主储蓄金),系统扣减(盟主储蓄金),储备金购买");
  348. data.Add(12, "系统增加(可提现余额),系统扣减(可提现余额)");
  349. data.Add(13, "推荐大盟主,推荐小盟主,商城购机,购机奖励");
  350. var item = data.FirstOrDefault(m => m.Value.Contains(Remark));
  351. if(item.Key > 0)
  352. {
  353. return item.Key;
  354. }
  355. return 0;
  356. }
  357. /// <summary>
  358. /// 操作盟主可提现余额
  359. /// </summary>
  360. /// <param name="db"></param>
  361. /// <param name="order"></param>
  362. /// <param name="UserId"></param>
  363. /// <param name="Money"></param>
  364. /// <param name="Count"></param>
  365. /// <param name="Kind"></param>
  366. public void OpLeaderAccount(WebCMSEntities db, Orders order, int UserId, decimal Money, int Count = 1)
  367. {
  368. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  369. if (account == null)
  370. {
  371. account = db.UserAccount.Add(new UserAccount()
  372. {
  373. Id = UserId,
  374. UserId = UserId,
  375. }).Entity;
  376. db.SaveChanges();
  377. }
  378. int ChangeType = 0;
  379. if(Money == 400)
  380. {
  381. ChangeType = 117;
  382. }
  383. decimal BeforeLeaderBalanceAmount = account.LeaderBalanceAmount; //变更前余额
  384. account.LeaderBalanceAmount += Money * Count;
  385. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后余额
  386. LeaderAccountRecord leaderAccountRecord = db.LeaderAccountRecord.Add(new LeaderAccountRecord()
  387. {
  388. CreateDate = DateTime.Now,
  389. UpdateDate = DateTime.Now,
  390. UserId = UserId, //创客
  391. ChangeType = ChangeType, //变动类型
  392. ChangeAmount = Money * Count, //变更金额
  393. BeforeBalanceAmount = BeforeLeaderBalanceAmount, //变更前余额
  394. AfterBalanceAmount = AfterLeaderBalanceAmount, //变更后余额
  395. QueryCount = order.Id,
  396. Sort = order.UserId,
  397. }).Entity;
  398. db.SaveChanges();
  399. }
  400. /// <summary>
  401. /// 操作余额
  402. /// </summary>
  403. /// <param name="db"></param>
  404. /// <param name="order"></param>
  405. /// <param name="UserId"></param>
  406. /// <param name="Money"></param>
  407. /// <param name="Count"></param>
  408. public void OpAccount(WebCMSEntities db, int OrderId, int UserId, decimal Money, int Count = 1, int ChangeType = 0, int Kind = 0)
  409. {
  410. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  411. if (account == null)
  412. {
  413. account = db.UserAccount.Add(new UserAccount()
  414. {
  415. Id = UserId,
  416. UserId = UserId,
  417. }).Entity;
  418. db.SaveChanges();
  419. }
  420. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  421. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  422. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  423. account.BalanceAmount += Money * Count;
  424. account.TotalAmount += Money * Count;
  425. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  426. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  427. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  428. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  429. {
  430. CreateDate = DateTime.Now,
  431. UpdateDate = DateTime.Now,
  432. UserId = UserId, //创客
  433. ChangeType = ChangeType, //变动类型
  434. ChangeAmount = Money * Count, //变更金额
  435. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  436. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  437. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  438. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  439. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  440. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  441. QueryCount = OrderId,
  442. Kind = Kind,
  443. }).Entity;
  444. db.SaveChanges();
  445. }
  446. /// <summary>
  447. /// 操作运营中心/合伙人额度(TotalAmt未使用额度,ValidForGetAmount可提现额度)
  448. /// </summary>
  449. /// <param name="db"></param>
  450. /// <param name="UserId"></param>
  451. /// <param name="Money"></param>
  452. /// <param name="OperateType">(1增加,2减少)</param>
  453. /// <param name="AmountType">(1未使用额度,2可提现额度)</param>
  454. /// <param name="Remark"></param>
  455. /// <param name="record"></param>
  456. public void OperateAmountChange(OpModels.WebCMSEntities db, int UserId, decimal Money, int OperateType, int AmountType, string Remark = "", bool record = false)
  457. {
  458. OpModels.UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  459. if (account == null)
  460. {
  461. account = db.UserAccount.Add(new OpModels.UserAccount()
  462. {
  463. Id = UserId,
  464. UserId = UserId,
  465. }).Entity;
  466. db.SaveChanges();
  467. }
  468. decimal BeforeAmount = account.ValidAmount + account.TotalAmt + account.ValidForGetAmount; //变更前总金额
  469. if(OperateType == 1)
  470. {
  471. if(AmountType == 1)
  472. {
  473. account.TotalAmt += Money;
  474. }
  475. else if(AmountType == 2)
  476. {
  477. account.ValidForGetAmount += Money;
  478. }
  479. else
  480. {
  481. account.ValidAmount += Money;
  482. }
  483. }
  484. else
  485. {
  486. if(AmountType == 1)
  487. {
  488. account.TotalAmt -= Money;
  489. }
  490. else if(AmountType == 2)
  491. {
  492. account.ValidForGetAmount -= Money;
  493. }
  494. else
  495. {
  496. account.ValidAmount -= Money;
  497. }
  498. }
  499. decimal AfterAmount = account.ValidAmount + account.TotalAmt + account.ValidForGetAmount; //变更后总金额
  500. if(record)
  501. {
  502. OpModels.AmountRecord add = db.AmountRecord.Add(new OpModels.AmountRecord()
  503. {
  504. CreateDate = DateTime.Now,
  505. UpdateDate = DateTime.Now,
  506. OperateType = OperateType,
  507. AfterAmount = AfterAmount,
  508. AfterValidForGetAmount = account.ValidForGetAmount,
  509. AfterTotalAmt = account.TotalAmt,
  510. AfterValidAmount = account.ValidAmount,
  511. BeforeAmount = BeforeAmount,
  512. UseAmount = Money,
  513. UserId = UserId,
  514. SeoDescription = Remark,
  515. Version = AmountType,
  516. }).Entity;
  517. }
  518. db.SaveChanges();
  519. }
  520. /// <summary>
  521. /// 给券设置大盟主标记
  522. /// </summary>
  523. /// <param name="db"></param>
  524. /// <param name="LeaderUserId"></param>
  525. /// <param name="Count"></param>
  526. /// <param name="couponIds"></param>
  527. public int SetPosCouponLeaderFlag(WebCMSEntities db, int LeaderUserId, int Count, List<int> couponIds)
  528. {
  529. int SetCount = 0;
  530. UserAccount pacccount = db.UserAccount.FirstOrDefault(m => m.Id == LeaderUserId) ?? new UserAccount();
  531. foreach(int couponId in couponIds)
  532. {
  533. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  534. if(coupon != null && pacccount.LeaderReserve >= 400 * Count)
  535. {
  536. coupon.LeaderUserId = LeaderUserId;
  537. SetCount += 1;
  538. }
  539. }
  540. db.SaveChanges();
  541. return SetCount;
  542. }
  543. /// <summary>
  544. /// 获取购机奖金额
  545. /// </summary>
  546. /// <param name="user"></param>
  547. /// <returns></returns>
  548. public decimal GetBuyPrize(UserRankItem user)
  549. {
  550. if(user.OperateLevel == 1) return 100;
  551. if(user.OperateLevel == 2) return 160;
  552. if(user.OperateLevel == 3) return 180;
  553. if(user.OperateLevel == 4) return 200;
  554. if(user.LeaderLevel > 0) return 100;
  555. return 0;
  556. }
  557. /// <summary>
  558. /// 获取可提现金额
  559. /// </summary>
  560. /// <param name="user"></param>
  561. /// <returns></returns>
  562. public decimal GetWithdrawMoney(UserRankItem user)
  563. {
  564. if(user.OperateLevel == 1) return 400;
  565. // if(user.OperateLevel == 2) return 340;
  566. // if(user.OperateLevel == 3) return 320;
  567. // if(user.OperateLevel == 4) return 300;
  568. if(user.OperateLevel == 2) return 400;
  569. if(user.OperateLevel == 3) return 400;
  570. if(user.OperateLevel == 4) return 400;
  571. if(user.AgoLeaderLevel > 0) return 400;
  572. return 0;
  573. }
  574. /// <summary>
  575. /// 预设职级
  576. /// </summary>
  577. /// <param name="db"></param>
  578. /// <param name="UserId">创客Id</param>
  579. /// <param name="Rank">职级</param>
  580. /// <param name="ExpiredDate">过期时间</param>
  581. public void PreUserLevel(WebCMSEntities db, int UserId, int Rank, DateTime ExpiredDate)
  582. {
  583. UserRankWhite rank = db.UserRankWhite.FirstOrDefault(m => m.Id == UserId);
  584. if(rank == null)
  585. {
  586. rank = db.UserRankWhite.Add(new UserRankWhite()
  587. {
  588. CreateDate = DateTime.Now, //设置时间
  589. UserId = UserId, //用户
  590. Id = UserId,
  591. }).Entity;
  592. db.SaveChanges();
  593. }
  594. rank.Rank = Rank;
  595. rank.UpdateDate = ExpiredDate;
  596. db.SaveChanges();
  597. }
  598. }
  599. }