AlipayPayBack2Service.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using MySystem.PxcModels;
  6. using Library;
  7. using LitJson;
  8. namespace MySystem
  9. {
  10. public class AlipayPayBack2Service
  11. {
  12. public readonly static AlipayPayBack2Service Instance = new AlipayPayBack2Service();
  13. private AlipayPayBack2Service()
  14. { }
  15. public void Start(JobMqMsg jobInfo)
  16. {
  17. string content = "";
  18. try
  19. {
  20. dosomething();
  21. string Msg = "success";
  22. jobInfo.Status = Msg == "success" ? 1 : 0;
  23. jobInfo.Msg = Msg == "success" ? "执行完成" : Msg;
  24. RabbitMQClient.Instance.SendMsg(Newtonsoft.Json.JsonConvert.SerializeObject(jobInfo), "PublicBack");
  25. }
  26. catch (Exception ex)
  27. {
  28. if (!string.IsNullOrEmpty(content))
  29. {
  30. Dictionary<string, string> data = new Dictionary<string, string>();
  31. data.Add("ErrTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  32. data.Add("ErrMsg", ex.ToString());
  33. function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(data), "public_err");
  34. }
  35. else
  36. {
  37. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "商城订单支付回调异常");
  38. }
  39. }
  40. }
  41. private void dosomething()
  42. {
  43. bool op = true;
  44. while (op)
  45. {
  46. string content = RedisDbconn.Instance.RPop<string>("PayCallBack2");
  47. if (!string.IsNullOrEmpty(content))
  48. {
  49. sloveAlipayCallBack(content);
  50. }
  51. else
  52. {
  53. op = false;
  54. }
  55. }
  56. }
  57. public void sloveAlipayCallBack(string content)
  58. {
  59. JsonData jsonObj = JsonMapper.ToObject(content);
  60. string OrderNo = jsonObj["out_trade_no"].ToString();
  61. string TradeNo = jsonObj["transaction_id"].ToString();
  62. decimal TotalFee = decimal.Parse(function.CheckNum(jsonObj["total_fee"].ToString()));
  63. WebCMSEntities db = new WebCMSEntities();
  64. OrderForNo forNo = db.OrderForNo.FirstOrDefault(m => m.OrderNo == OrderNo);
  65. if (forNo != null)
  66. {
  67. string[] ids = forNo.OrderIds.Split(',');
  68. foreach (string idString in ids)
  69. {
  70. int OrderId = int.Parse(idString);
  71. DoOrderV2(db, OrderId);
  72. }
  73. }
  74. db.Dispose();
  75. }
  76. #region 新订单流程
  77. public void DoOrderV2(WebCMSEntities db, int OrderId)
  78. {
  79. Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId && m.Status == 0);
  80. if (order != null)
  81. {
  82. order.Status = 1;
  83. order.PayDate = DateTime.Now;
  84. order.PayStatus = 1;
  85. if(order.ParentOrderId > 0)
  86. {
  87. int total = db.Orders.Count(m => m.ParentOrderId == order.ParentOrderId);
  88. int paycount = db.Orders.Count(m => m.ParentOrderId == order.ParentOrderId && m.Status > 0);
  89. if(paycount + 1 >= total)
  90. {
  91. order = db.Orders.FirstOrDefault(m => m.Id == order.ParentOrderId && m.Status == 0);
  92. if (order != null)
  93. {
  94. order.Status = 2;
  95. order.PayDate = DateTime.Now;
  96. order.PayStatus = 1;
  97. OrderId = order.Id;
  98. }
  99. }
  100. }
  101. db.SaveChanges();
  102. if(order.ParentOrderId > 0)
  103. {
  104. return;
  105. }
  106. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == OrderId);
  107. if (pro != null)
  108. {
  109. if(order.ErpMode > 0)
  110. {
  111. pro.ProductId = order.ProductId;
  112. }
  113. List<int> couponIds = new List<int>();
  114. if (pro.ProductId == 10 || pro.ProductId == 11 || pro.ProductId == 27 || pro.ProductId == 28 || pro.ProductId == 34 || pro.ProductId == -2)
  115. {
  116. order.Status = 2;
  117. int BuyCount = pro.ProductCount;
  118. int Kind = 0;
  119. if (pro.ProductId == 10 || pro.ProductId == 34)
  120. {
  121. Kind = 1;
  122. }
  123. else if (pro.ProductId == 11 || pro.ProductId == -2)
  124. {
  125. Kind = 2;
  126. }
  127. else if (pro.ProductId == 28)
  128. {
  129. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId && m.LeaderLevel == 0);
  130. if(user != null)
  131. {
  132. user.LeaderLevel = 1;
  133. }
  134. }
  135. else if (pro.ProductId == 27)
  136. {
  137. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId && m.LeaderLevel < 2);
  138. if(user != null)
  139. {
  140. user.LeaderLevel = 2;
  141. }
  142. }
  143. if(Kind <= 2 && (pro.ProductId == 10 || pro.ProductId == 11 || pro.ProductId == 34 || pro.ProductId == -2))
  144. {
  145. // 购买600一组机具券,返券
  146. int CouponCount = 0;
  147. if(Kind == 1)
  148. {
  149. CouponCount = 3 * pro.ProductCount;
  150. }
  151. else if(Kind == 2)
  152. {
  153. CouponCount = 2 * pro.ProductCount;
  154. }
  155. string Codes = "";
  156. var coupons = db.PosCoupons.Where(m => m.IsLock == 0 && m.IsUse == 0 && m.UserId == 0 && m.QueryCount == Kind).OrderBy(m => m.Id).Take(CouponCount).ToList();
  157. int RecordId = 0;
  158. if(coupons.Count > 0 && (pro.ProductId == 34 || pro.ProductId == -2))
  159. {
  160. var adds = db.HelpProfitExchange.Add(new HelpProfitExchange()
  161. {
  162. CreateDate = DateTime.Now, //创建时间
  163. UserId = order.UserId,
  164. ExchangeCount = coupons.Count,
  165. }).Entity;
  166. db.SaveChanges();
  167. RecordId = adds.Id;
  168. }
  169. foreach (var coupon in coupons) // TODO: 数量多的话,会慢
  170. {
  171. PosCoupons item = db.PosCoupons.FirstOrDefault(m => m.Id == coupon.Id);
  172. if (item != null)
  173. {
  174. item.CreateDate = DateTime.Now;
  175. item.UserId = order.UserId;
  176. item.UpdateDate = DateTime.Now.AddDays(180);
  177. if(pro.ProductId == 34 || pro.ProductId == -2)
  178. {
  179. item.HelpProfitFlag = 1;
  180. db.HelpProfitExchangeDetail.Add(new HelpProfitExchangeDetail()
  181. {
  182. CreateDate = DateTime.Now, //创建时间
  183. UserId = order.UserId,
  184. PosCouponId = item.Id,
  185. ExchangeCode = item.ExchangeCode,
  186. RecordId = RecordId,
  187. });
  188. }
  189. Codes += item.ExchangeCode + ",";
  190. couponIds.Add(coupon.Id);
  191. }
  192. }
  193. order.SnNos = Codes.TrimEnd(',');
  194. }
  195. db.SaveChanges();
  196. if (pro.ProductId == 27 || pro.ProductId == 28)
  197. {
  198. //充值盟主储备金
  199. OpReserve(db, order, order.UserId, order.TotalPrice, 1);
  200. }
  201. if (pro.ProductId == 28) //购买小盟主,给上级大盟主返储备金
  202. {
  203. int LeaderUserId = order.UserId;
  204. int level = 0;
  205. while(LeaderUserId > 0)
  206. {
  207. level += 1;
  208. Users user = db.Users.FirstOrDefault(m => m.Id == LeaderUserId);
  209. if(user != null)
  210. {
  211. if(user.LeaderLevel == 2 && level > 1)
  212. {
  213. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == LeaderUserId);
  214. if(account != null)
  215. {
  216. if(account.LeaderReserve >= order.TotalPrice)
  217. {
  218. OpReserve(db, order, LeaderUserId, order.TotalPrice, 2, 0, "推荐小盟主");
  219. OpLeaderAccount(db, order, LeaderUserId, order.TotalPrice);
  220. }
  221. else
  222. {
  223. decimal LeaderReserve = account.LeaderReserve;
  224. OpReserve(db, order, LeaderUserId, LeaderReserve, 2, 0, "推荐小盟主");
  225. OpLeaderAccount(db, order, LeaderUserId, LeaderReserve);
  226. }
  227. }
  228. LeaderUserId = 0;
  229. }
  230. else
  231. {
  232. LeaderUserId = user.ParentUserId;
  233. }
  234. }
  235. else
  236. {
  237. LeaderUserId = 0;
  238. }
  239. }
  240. }
  241. }
  242. //推荐下单奖励
  243. if (pro.ProductId == 10 || pro.ProductId == 11)
  244. {
  245. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  246. function.WriteLog("OrderId:" + OrderId, "推荐下单奖励监控日志");
  247. function.WriteLog("checkPrize:" + checkPrize, "推荐下单奖励监控日志");
  248. if (!checkPrize)
  249. {
  250. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  251. if (user != null)
  252. {
  253. bool directPrize = false; //直推奖标记
  254. bool bigLeaderPrize = false; //大盟主券标记
  255. bool buyPrize = false; //返100购机奖励标记
  256. int leaderFlag = 0; //返600备用金标记
  257. if(user.LeaderLevel > 0)
  258. {
  259. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
  260. if(acccount.LeaderReserve >= order.TotalPrice)
  261. {
  262. if(order.PayMode == 4)
  263. {
  264. //扣减备用金
  265. OpReserve(db, order, order.UserId, order.TotalPrice, 2, 0, "商城购机");
  266. //返回到余额
  267. // OpAccount(db, order, order.UserId, order.TotalPrice / pro.ProductCount, pro.ProductCount);
  268. }
  269. else
  270. {
  271. //扣减备用金
  272. OpReserve(db, order, order.UserId, order.TotalPrice, 2, 0, "商城购机");
  273. //返回到余额
  274. OpLeaderAccount(db, order, order.UserId, order.TotalPrice / pro.ProductCount, pro.ProductCount);
  275. }
  276. }
  277. //获得100元奖励
  278. OpAccount(db, order, order.UserId, 100, pro.ProductCount);
  279. //推荐奖励
  280. DirectPrize(db, order.Id, order.UserId, pro.ProductCount);
  281. //推荐下单上级获得30天的机具循环天数(盟主自己得)
  282. 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();
  283. foreach (var subPos in posList)
  284. {
  285. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  286. if (pos != null)
  287. {
  288. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  289. }
  290. }
  291. db.SaveChanges();
  292. if(user.LeaderLevel == 2)
  293. {
  294. if(couponIds.Count > 0)
  295. {
  296. foreach(int couponId in couponIds)
  297. {
  298. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  299. if(coupon != null)
  300. {
  301. coupon.LeaderUserId = user.Id;
  302. }
  303. }
  304. db.SaveChanges();
  305. }
  306. }
  307. // else
  308. // {
  309. // int PUserId = user.ParentUserId;
  310. // while(PUserId > 0)
  311. // {
  312. // Users puser = db.Users.FirstOrDefault(m => m.Id == PUserId) ?? new Users();
  313. // if(puser.LeaderLevel == 2)
  314. // {
  315. // UserAccount acc = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  316. // if(acc.LeaderReserve >= order.TotalPrice)
  317. // {
  318. // //扣减备用金
  319. // OpReserve(db, order, puser.Id, order.TotalPrice, 2, order.UserId, "购机奖励");
  320. // //返回到余额
  321. // OpLeaderAccount(db, order, puser.Id, order.TotalPrice / pro.ProductCount, pro.ProductCount);
  322. // }
  323. // PUserId = 0;
  324. // }
  325. // else
  326. // {
  327. // PUserId = puser.ParentUserId;
  328. // }
  329. // }
  330. // }
  331. return;
  332. }
  333. int ParentUserId = user.ParentUserId;
  334. // List<int> proids = new List<int>();
  335. // proids.Add(10);
  336. // proids.Add(11);
  337. while(ParentUserId > 0)
  338. {
  339. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  340. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
  341. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  342. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  343. function.WriteLog("MakerCode:" + puser.MakerCode, "推荐下单奖励监控日志");
  344. function.WriteLog("machineCount:" + machineCount, "推荐下单奖励监控日志");
  345. function.WriteLog("ActiveCount:" + ActiveCount, "推荐下单奖励监控日志");
  346. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  347. {
  348. // function.WriteLog("满足条件", "推荐下单奖励监控日志");
  349. // if(puser.LeaderLevel == 0) // 非盟主直推奖励,每个创客第一次下单,上级可得
  350. // {
  351. // List<int> oids = new List<int>();
  352. // var orderpros = db.OrderProduct.Select(m => new { m.OrderId,m.UserId,m.ProductId }).Where(m => m.UserId == order.UserId && proids.Contains(m.ProductId)).ToList();
  353. // foreach(var orderpro in orderpros)
  354. // {
  355. // oids.Add(orderpro.OrderId);
  356. // }
  357. // bool check = db.Orders.Any(m => oids.Contains(m.Id) && m.Status > 0);
  358. // if(!check)
  359. // {
  360. // DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  361. // directPrize = true;
  362. // }
  363. // }
  364. // else
  365. // {
  366. // 盟主直推奖励,可以每次下单获得
  367. DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  368. directPrize = true;
  369. // }
  370. //推荐下单上级获得30天的机具循环天数
  371. 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();
  372. foreach (var subPos in posList)
  373. {
  374. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  375. if (pos != null)
  376. {
  377. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  378. }
  379. }
  380. db.SaveChanges();
  381. }
  382. if(puser.LeaderLevel > 0)
  383. {
  384. UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
  385. if(acccount.LeaderReserve >= order.TotalPrice && !buyPrize)
  386. {
  387. //购机奖励
  388. OpAccount(db, order, puser.Id, 100, pro.ProductCount);
  389. buyPrize = true;
  390. }
  391. if(acccount.LeaderReserve >= order.TotalPrice && leaderFlag == 0)
  392. {
  393. //扣减备用金
  394. OpReserve(db, order, puser.Id, order.TotalPrice, 2, order.UserId, "购机奖励");
  395. //返回到余额
  396. OpLeaderAccount(db, order, puser.Id, order.TotalPrice / pro.ProductCount, pro.ProductCount);
  397. leaderFlag = puser.LeaderLevel;
  398. }
  399. //如果是大盟主,则标记大盟主标签
  400. if(couponIds.Count > 0 && puser.LeaderLevel == 2 && acccount.LeaderReserve >= order.TotalPrice && !bigLeaderPrize)
  401. {
  402. foreach(int couponId in couponIds)
  403. {
  404. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
  405. if(coupon != null)
  406. {
  407. coupon.LeaderUserId = puser.Id;
  408. }
  409. }
  410. db.SaveChanges();
  411. bigLeaderPrize = true;
  412. }
  413. }
  414. ParentUserId = puser.ParentUserId;
  415. }
  416. }
  417. }
  418. function.WriteLog("\r\n\r\n", "推荐下单奖励监控日志");
  419. }
  420. //推荐王
  421. if(pro.ProductId == 29)
  422. {
  423. RecommendMethod(order.UserId, order.CreateDate.Value.ToString("yyyyMM"));
  424. }
  425. //分仓向总仓申请机具额度
  426. if(pro.ProductId == 30 || pro.ProductId == 31 || pro.ProductId == 32)
  427. {
  428. string SendData = "{\"Kind\":\"1\",\"Data\":{\"OrderId\":\"" + order.Id + "\"}}";
  429. RedisDbconn.Instance.AddList("StoreApplyQueue", SendData);
  430. }
  431. }
  432. else
  433. {
  434. if(order.ProductId > 0 && order.ErpMode > 0)
  435. {
  436. //盟主储备金-升级/购买 ErpMode:1-升级,2-购买
  437. if(order.ErpMode > 0)
  438. {
  439. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  440. if(user != null)
  441. {
  442. if(order.ErpMode == 1)
  443. {
  444. user.LeaderLevel = 2;
  445. db.SaveChanges();
  446. }
  447. OpReserve(db, order, order.UserId, order.TotalPrice, 1);
  448. }
  449. }
  450. }
  451. }
  452. }
  453. }
  454. //操作储备金
  455. public void OpReserve(WebCMSEntities db, Orders order, int UserId, decimal Money, int ChangeType, int SourceUserId = 0, string Remark = "储备金购买")
  456. {
  457. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  458. if (account == null)
  459. {
  460. account = db.UserAccount.Add(new UserAccount()
  461. {
  462. Id = UserId,
  463. UserId = UserId,
  464. }).Entity;
  465. db.SaveChanges();
  466. }
  467. decimal BeforeAmount = account.LeaderReserve; //变更前总金额
  468. if(ChangeType == 1)
  469. {
  470. account.LeaderReserve += Money;
  471. }
  472. else
  473. {
  474. account.LeaderReserve -= Money;
  475. }
  476. decimal AfterAmount = account.LeaderReserve; //变更后总金额
  477. LeaderReserveRecord add = db.LeaderReserveRecord.Add(new LeaderReserveRecord()
  478. {
  479. CreateDate = DateTime.Now,
  480. ChangeType = ChangeType,
  481. OrderId = order.Id,
  482. Remark = Remark,
  483. AfterAmt = AfterAmount,
  484. BeforeAmt = BeforeAmount,
  485. ChangeAmt = Money,
  486. TradeDate = DateTime.Now.ToString("yyyyMMdd"),
  487. TradeMonth = DateTime.Now.ToString("yyyyMM"),
  488. UserId = UserId,
  489. SourceUserId = SourceUserId,
  490. }).Entity;
  491. db.SaveChanges();
  492. }
  493. //操作余额
  494. public void OpAccount(WebCMSEntities db, Orders order, int UserId, decimal Money, int Count = 1)
  495. {
  496. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  497. if (account == null)
  498. {
  499. account = db.UserAccount.Add(new UserAccount()
  500. {
  501. Id = UserId,
  502. UserId = UserId,
  503. }).Entity;
  504. db.SaveChanges();
  505. }
  506. int ChangeType = 0;
  507. if(Money == 600)
  508. {
  509. ChangeType = 117;
  510. }
  511. else if(Money == 100)
  512. {
  513. ChangeType = 118;
  514. }
  515. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  516. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  517. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  518. account.BalanceAmount += Money * Count;
  519. account.TotalAmount += Money * Count;
  520. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  521. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  522. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  523. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  524. {
  525. CreateDate = DateTime.Now,
  526. UpdateDate = DateTime.Now,
  527. UserId = UserId, //创客
  528. ChangeType = ChangeType, //变动类型
  529. ChangeAmount = Money * Count, //变更金额
  530. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  531. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  532. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  533. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  534. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  535. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  536. QueryCount = order.Id,
  537. }).Entity;
  538. db.SaveChanges();
  539. }
  540. //操作盟主可提现余额
  541. public void OpLeaderAccount(WebCMSEntities db, Orders order, int UserId, decimal Money, int Count = 1)
  542. {
  543. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  544. if (account == null)
  545. {
  546. account = db.UserAccount.Add(new UserAccount()
  547. {
  548. Id = UserId,
  549. UserId = UserId,
  550. }).Entity;
  551. db.SaveChanges();
  552. }
  553. int ChangeType = 0;
  554. if(Money == 600)
  555. {
  556. ChangeType = 117;
  557. }
  558. decimal BeforeLeaderBalanceAmount = account.LeaderBalanceAmount; //变更前余额
  559. account.LeaderBalanceAmount += Money * Count;
  560. decimal AfterLeaderBalanceAmount = account.LeaderBalanceAmount; //变更后余额
  561. LeaderAccountRecord leaderAccountRecord = db.LeaderAccountRecord.Add(new LeaderAccountRecord()
  562. {
  563. CreateDate = DateTime.Now,
  564. UpdateDate = DateTime.Now,
  565. UserId = UserId, //创客
  566. ChangeType = ChangeType, //变动类型
  567. ChangeAmount = Money * Count, //变更金额
  568. BeforeBalanceAmount = BeforeLeaderBalanceAmount, //变更前余额
  569. AfterBalanceAmount = AfterLeaderBalanceAmount, //变更后余额
  570. QueryCount = order.Id,
  571. }).Entity;
  572. db.SaveChanges();
  573. }
  574. public void DirectPrize(WebCMSEntities db, int OrderId, int UserId, int Count = 1)
  575. {
  576. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  577. if (account == null)
  578. {
  579. account = db.UserAccount.Add(new UserAccount()
  580. {
  581. Id = UserId,
  582. UserId = UserId,
  583. }).Entity;
  584. db.SaveChanges();
  585. }
  586. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  587. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  588. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  589. account.BalanceAmount += 100 * Count;
  590. account.TotalAmount += 100 * Count;
  591. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  592. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  593. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  594. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  595. {
  596. CreateDate = DateTime.Now,
  597. UpdateDate = DateTime.Now,
  598. UserId = UserId, //创客
  599. ChangeType = 112, //变动类型
  600. ChangeAmount = 100 * Count, //变更金额
  601. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  602. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  603. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  604. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  605. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  606. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  607. QueryCount = OrderId,
  608. }).Entity;
  609. db.SaveChanges();
  610. }
  611. // 推荐王逻辑(下单)
  612. public void RecommendMethod(int UserId, string TradeMonth)
  613. {
  614. string SendData = "{\"Kind\":\"1\",\"Data\":{\"UserId\":\"" + UserId + "\",\"TradeMonth\":\"" + TradeMonth + "\"}}";
  615. RedisDbconn.Instance.AddList("RecommendActStatQueue", SendData);
  616. }
  617. #endregion
  618. }
  619. }