SycnSpTradeService.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.SpModels;
  5. using Library;
  6. using LitJson;
  7. using System.Threading;
  8. namespace MySystem
  9. {
  10. public class SycnSpTradeService
  11. {
  12. public readonly static SycnSpTradeService Instance = new SycnSpTradeService();
  13. private SycnSpTradeService()
  14. { }
  15. public void Start()
  16. {
  17. Thread th = new Thread(StartDo);
  18. th.IsBackground = true;
  19. th.Start();
  20. }
  21. public void StartDo()
  22. {
  23. while (true)
  24. {
  25. try
  26. {
  27. List<string> BrandIds = new List<string>();
  28. BrandIds.Add("14");
  29. BrandIds.Add("17");
  30. BrandIds.Add("23");
  31. BrandIds.Add("24");
  32. BrandIds.Add("25");
  33. BrandIds.Add("26");
  34. BrandIds.Add("32");
  35. List<string> SaveDataBindIds = Utils.Instance.SaveDataBindIds();
  36. WebCMSEntities spdb = new WebCMSEntities();
  37. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  38. JavaProductModels.WebCMSEntities pdb = new JavaProductModels.WebCMSEntities();
  39. DateTime start = DateTime.Now.AddDays(-60);
  40. DateTime end = DateTime.Now.AddMinutes(-3);
  41. int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/TradeRecordId.txt")));
  42. IQueryable<TradeRecord> trades = spdb.TradeRecord.Where(m => m.Id >= StartId && !BrandIds.Contains(m.ProductType) && SaveDataBindIds.Contains(m.ProductType) && m.CreateDate >= start && m.Status == 1).OrderBy(m => m.CreateDate).Take(20);
  43. foreach (TradeRecord trade in trades.ToList())
  44. {
  45. DoQueueTrade(db, pdb, trade);
  46. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  47. if (edit != null)
  48. {
  49. edit.Status = 2;
  50. }
  51. spdb.SaveChanges();
  52. }
  53. spdb.Dispose();
  54. db.Dispose();
  55. pdb.Dispose();
  56. }
  57. catch (Exception ex)
  58. {
  59. Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP交易数据到MAIN异常");
  60. }
  61. Thread.Sleep(500);
  62. }
  63. }
  64. public void DoQueueTrade(PxcModels.WebCMSEntities db, JavaProductModels.WebCMSEntities pdb, TradeRecord trade)
  65. {
  66. string TradeSnNo = trade.TradeSnNo;
  67. if(trade.ProductType == "30")
  68. {
  69. trade.MerNo = trade.Field2;
  70. }
  71. bool op = true;
  72. //判断盒易付吱码交易
  73. if(trade.ProductType == "12" && trade.TradeType == "2")
  74. {
  75. JavaProductModels.KxsMerchant merchant = pdb.KxsMerchant.FirstOrDefault(m => m.MerchantNo == trade.MerNo);
  76. if(merchant != null)
  77. {
  78. JavaProductModels.KxsMachine pos = pdb.KxsMachine.FirstOrDefault(m => m.Id == merchant.MachineId);
  79. if(pos != null)
  80. {
  81. trade.TradeSnNo = pos.PosSn;
  82. }
  83. }
  84. }
  85. if (trade.SerEntryMode == "N" && trade.ProductType == "1") //金控押金获取
  86. {
  87. if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900)
  88. {
  89. op = false;
  90. PosPushDataNewHelper.Deposit(trade);
  91. }
  92. }
  93. else if (trade.SerEntryMode == "1" && trade.ProductType == "27") //金控押金获取
  94. {
  95. if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900)
  96. {
  97. op = false;
  98. PosPushDataNewHelper.Deposit(trade);
  99. }
  100. }
  101. else if ((trade.ProductType == "4" || trade.ProductType == "8" || trade.ProductType == "9") && (trade.ErrorCode == "5200" || trade.ErrorCode == "5800")) //乐刷海科费率0.52,0.58的不入库
  102. {
  103. op = false;
  104. }
  105. else if (trade.SerEntryMode == "1" && trade.ProductType == "10") //联动押金获取
  106. {
  107. if (trade.TradeAmount == 99 || trade.TradeAmount == 199 || trade.TradeAmount == 299)
  108. {
  109. op = false;
  110. PosPushDataNewHelper.Deposit(trade);
  111. }
  112. }
  113. else if (trade.SerEntryMode == "40" && trade.ProductType == "12") //盒易付押金获取
  114. {
  115. if (trade.TradeAmount == 99 || trade.TradeAmount == 199 || trade.TradeAmount == 299)
  116. {
  117. op = false;
  118. PosPushDataNewHelper.Deposit(trade);
  119. //创业帮押金数据推送
  120. string conn = ConfigurationManager.AppSettings["PushSqlConnStr"].ToString();
  121. CustomerSqlConn.op("INSERT INTO `u_kxs_trade_info_" + trade.CreateDate.Value.ToString("yyyyMM") + "` (`user_id`, `cash_flag`, `merch_no`, `agent_id`, `pos_sn`, `order_id`, `amount`, `trans_time`, `card_type`, `pay_type`) VALUES (123005, 1, '" + trade.MerNo + "', '01', '" + trade.TradeSnNo + "', '" + trade.TradeSerialNo + "', " + trade.TradeAmount + ", '" + trade.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "', 1, 0);", conn);
  122. }
  123. }
  124. else if (trade.SettleFee == 0 && trade.ProductType == "15") //联客宝押金获取
  125. {
  126. if (trade.TradeAmount == 99 || trade.TradeAmount == 199 || trade.TradeAmount == 299)
  127. {
  128. op = false;
  129. }
  130. }
  131. else if (trade.Field2 == "1590" && trade.ProductType == "22") //立刷微智能押金获取
  132. {
  133. if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900)
  134. {
  135. op = false;
  136. }
  137. }
  138. else if (trade.SerEntryMode == "DEPOSIT" && trade.ProductType == "30") //拉卡拉押金获取
  139. {
  140. if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900)
  141. {
  142. op = false;
  143. if(trade.ProductType == "30")
  144. {
  145. PxcModels.LklMerNo mer = db.LklMerNo.FirstOrDefault(m => m.ExtMerNo == trade.MerNo);
  146. if(mer != null)
  147. {
  148. trade.MerNo = mer.MerNo;
  149. }
  150. }
  151. PosPushDataNewHelper.Deposit(trade);
  152. }
  153. }
  154. else if (trade.SerEntryMode == "MACHINE" && trade.ProductType == "34") //联动掌中宝押金获取
  155. {
  156. PosPushDataNewHelper.Deposit(trade);
  157. op = false;
  158. }
  159. if (trade.DiscountRateFlag == "True")
  160. {
  161. op = false;
  162. }
  163. if(trade.ProductType == "7" && trade.TradeStatus != "00")
  164. {
  165. op = false;
  166. }
  167. if(trade.ProductType == "34" && trade.TradeStatus != "SUCCESS")
  168. {
  169. op = false;
  170. }
  171. if (op)
  172. {
  173. bool check = db.SpOrderNos.Any(m => m.OrderNo == trade.TradeSerialNo);
  174. if (!check)
  175. {
  176. PosPushDataNewHelper.Trade(trade);
  177. //创业帮交易数据推送
  178. if(trade.ProductType == "12")
  179. {
  180. int BankCardType = 1;
  181. if (trade.BankCardType == "C")
  182. {
  183. BankCardType = 1;
  184. }
  185. else if (trade.BankCardType == "D")
  186. {
  187. BankCardType = 0;
  188. }
  189. string conn = ConfigurationManager.AppSettings["PushSqlConnStr"].ToString();
  190. CustomerSqlConn.op("INSERT INTO `u_kxs_trade_info_" + trade.CreateDate.Value.ToString("yyyyMM") + "` (`user_id`, `cash_flag`, `merch_no`, `agent_id`, `pos_sn`, `order_id`, `amount`, `trans_time`, `card_type`, `pay_type`) VALUES (123005, 0, '" + trade.MerNo + "', '01', '" + trade.TradeSnNo + "', '" + trade.TradeSerialNo + "', " + trade.TradeAmount + ", '" + trade.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "', " + BankCardType + ", 0);", conn);
  191. }
  192. }
  193. }
  194. }
  195. public void StartSim()
  196. {
  197. Thread th = new Thread(StartSimDo);
  198. th.IsBackground = true;
  199. th.Start();
  200. }
  201. public void StartSimDo()
  202. {
  203. while (true)
  204. {
  205. try
  206. {
  207. List<string> SaveDataBindIds = Utils.Instance.SaveDataBindIds();
  208. WebCMSEntities spdb = new WebCMSEntities();
  209. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  210. DateTime start = DateTime.Now.AddDays(-40);
  211. int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/TradeRecordId.txt")));
  212. IQueryable<TradeRecord> trades = spdb.TradeRecord.Where(m => m.Id >= StartId && m.ProductType == "14" && SaveDataBindIds.Contains(m.ProductType) && m.CreateDate >= start && m.Status == 1).OrderBy(m => m.CreateDate).Take(20);
  213. foreach (TradeRecord trade in trades.ToList())
  214. {
  215. PosPushDataNewHelper.Trade(trade);
  216. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  217. if (edit != null)
  218. {
  219. edit.Status = 2;
  220. }
  221. spdb.SaveChanges();
  222. }
  223. spdb.Dispose();
  224. db.Dispose();
  225. }
  226. catch (Exception ex)
  227. {
  228. Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP交易数据到MAIN异常");
  229. }
  230. Thread.Sleep(500);
  231. }
  232. }
  233. public void StartTradeStatus()
  234. {
  235. Thread th = new Thread(StartTradeStatusDo);
  236. th.IsBackground = true;
  237. th.Start();
  238. }
  239. public void StartTradeStatusDo()
  240. {
  241. while (true)
  242. {
  243. try
  244. {
  245. List<string> SaveDataBindIds = Utils.Instance.SaveDataBindIds();
  246. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  247. WebCMSEntities spdb = new WebCMSEntities();
  248. DateTime start = DateTime.Now.AddDays(-10);
  249. DateTime end = DateTime.Now.AddMinutes(-10);
  250. int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/TradeRecordId.txt")));
  251. IQueryable<TradeRecord> trades = spdb.TradeRecord.Where(m => m.Id >= StartId && m.CreateDate >= start && m.CreateDate < end && SaveDataBindIds.Contains(m.ProductType) && m.Status == 0).OrderBy(m => m.CreateDate).Take(20);
  252. foreach (TradeRecord trade in trades.ToList())
  253. {
  254. int Status = 1;
  255. bool op = db.PosMachinesTwo.Any(m => m.PosSn == trade.TradeSnNo);
  256. if(!op)
  257. {
  258. Status = -1;
  259. }
  260. else
  261. {
  262. op = db.PosMerchantInfo.Any(m => m.KqSnNo == trade.TradeSnNo);
  263. if(!op)
  264. {
  265. Status = -2;
  266. }
  267. }
  268. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  269. if (edit != null)
  270. {
  271. edit.Status = Status;
  272. spdb.SaveChanges();
  273. }
  274. }
  275. db.Dispose();
  276. spdb.Dispose();
  277. }
  278. catch (Exception ex)
  279. {
  280. Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "恢复原始交易没有统计上的数据异常");
  281. }
  282. Thread.Sleep(10000);
  283. }
  284. }
  285. //机具激活逻辑
  286. public void ActPos(PxcModels.WebCMSEntities db, PxcModels.PosMachinesTwo pos, decimal CheckMoney, int CheckDays, bool PrizeFlag = true, string ActivationTime = "")
  287. {
  288. DateTime now = DateTime.Now;
  289. if(!string.IsNullOrEmpty(ActivationTime))
  290. {
  291. now = DateTime.Parse(ActivationTime);
  292. }
  293. DateTime TransferTime = pos.TransferTime == null ? DateTime.Parse("2050-01-01") : pos.TransferTime.Value;
  294. int minute = 30;
  295. if(pos.BrandId == 14 && pos.PosSn.StartsWith("CS"))
  296. {
  297. minute = 60 * 24 * 30;
  298. }
  299. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:贷记卡是否刷满" + CheckMoney + ";贷记卡交易:" + pos.CreditTrade + "");
  300. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:是否有机具所属人;机具所属人Id:" + pos.BuyUserId + "");
  301. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:是否未激活;机具激活状态:" + pos.ActivationState + "");
  302. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:划拨时间不能超过绑定时间" + minute + "分钟;划拨时间:" + TransferTime.ToString() + ",绑定时间:" + pos.BindingTime.Value.ToString());
  303. if (pos.CreditTrade >= CheckMoney && pos.BuyUserId > 0 && pos.ActivationState == 0 && TransferTime.AddMinutes(-minute) < pos.BindingTime)
  304. {
  305. Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件");
  306. pos.ActivationState = 1;
  307. pos.ActivationTime = now;
  308. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:是否营训");
  309. if(pos.CardType == 101)
  310. {
  311. Utils.Instance.PrizeRecord(1, pos.PosSn, "是营训");
  312. pos.IsPurchase = 1;
  313. Utils.Instance.PrizeRecord(1, pos.PosSn, "取消循环资格");
  314. }
  315. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:是否关联商户信息");
  316. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  317. if (merchant != null)
  318. {
  319. merchant.ActiveStatus = 1;
  320. merchant.MerStandardDate = now;
  321. db.SaveChanges();
  322. if(pos.BrandId != 14)
  323. {
  324. //发放奖励MQ
  325. PrizeSetHelper.Do("1", pos.PosSn);
  326. }
  327. Utils.Instance.PrizeRecord(1, pos.PosSn, "已关联");
  328. //发放开机奖励
  329. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:绑定时间不超过" + CheckDays + "天;当前绑定时间:" + pos.BindingTime.ToString() + "");
  330. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:非营训;当前类型:" + pos.CardType);
  331. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:奖励开关;当前:" + PrizeFlag);
  332. if(pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100 && PrizeFlag)
  333. {
  334. Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放开机奖励");
  335. RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
  336. if(pos.BrandId == 14)
  337. {
  338. Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放运营中心奖励");
  339. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  340. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:大盟主标记;当前大盟主Id:" + pos.LeaderUserId);
  341. PxcModels.Leaders leader = db.Leaders.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new PxcModels.Leaders();
  342. DateTime ExpiredDate = leader.ExpiredDate == null ? DateTime.Parse("1900-01-01") : leader.ExpiredDate.Value;
  343. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:盟主是否过期;过期时间:" + pos.LeaderUserId);
  344. if(pos.LeaderUserId > 0 && ExpiredDate > now)
  345. {
  346. Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放大盟主奖励");
  347. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  348. }
  349. }
  350. }
  351. }
  352. //发放大盟主奖励
  353. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  354. if(pos.BrandId != 14)
  355. {
  356. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:有押金;当前押金:" + Deposit);
  357. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:大盟主标记;当前大盟主Id:" + pos.LeaderUserId);
  358. PxcModels.Leaders leader = db.Leaders.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new PxcModels.Leaders();
  359. DateTime ExpiredDate = leader.ExpiredDate == null ? DateTime.Parse("1900-01-01") : leader.ExpiredDate.Value;
  360. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:盟主是否过期;过期时间:" + pos.LeaderUserId);
  361. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:绑定时间不超过" + CheckDays + "天;绑定时间:" + pos.BindingTime.Value.ToString() + "");
  362. }
  363. if (Deposit > 0 && pos.LeaderUserId > 0 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now) && pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100 && PrizeFlag)
  364. {
  365. Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放大盟主奖励");
  366. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  367. }
  368. //发放运营中心奖励
  369. if (Deposit > 0 && pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100 && PrizeFlag)
  370. {
  371. Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放运营中心奖励");
  372. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  373. }
  374. if(pos.CardType < 100)
  375. {
  376. //统计激活数
  377. RedisDbconn.Instance.AddList("StatActQueue", "{\"TradeDate\":\"" + now.ToString("yyyyMMdd") + "\",\"UserId\":\"" + pos.BuyUserId + "\",\"BrandId\":\"" + pos.BrandId + "\"}");
  378. //运营中心额度变更
  379. OpAmountItem item = new OpAmountItem()
  380. {
  381. UserId = pos.OpId,
  382. OperateType = 1,
  383. ChangeType = 9,
  384. Remark = "机具激活",
  385. UseAmount = pos.OpReserve1 + pos.OpReserve2 + pos.OpReserve3,
  386. UseValidForGetAmount = pos.OpReserve2,
  387. UseTotalAmt = pos.OpReserve1,
  388. UseValidAmount = pos.OpReserve3,
  389. DataType = 2,
  390. DataId = pos.Id,
  391. };
  392. RedisDbconn.Instance.AddList("OperateAmountRecordServiceQueue", item);
  393. }
  394. //清理预扣款
  395. RedisDbconn.Instance.AddList("PosWithholdQueue", "{\"UserId\":\"" + pos.BuyUserId + "\",\"SnNo\":\"" + pos.PosSn + "\"}");
  396. //推送激活数据
  397. if(Deposit == 0) Utils.Instance.SendActData(pos);
  398. }
  399. else if (pos.ActivationState == 1 && pos.BrandId == 14)
  400. {
  401. if(pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100 && PrizeFlag)
  402. {
  403. RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
  404. if(pos.BrandId == 14)
  405. {
  406. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  407. PxcModels.Leaders leader = db.Leaders.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new PxcModels.Leaders();
  408. DateTime ExpiredDate = leader.ExpiredDate == null ? DateTime.Parse("1900-01-01") : leader.ExpiredDate.Value;
  409. if(pos.LeaderUserId > 0 && ExpiredDate > now)
  410. {
  411. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  412. }
  413. }
  414. }
  415. }
  416. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:已激活;当前状态:" + pos.ActivationState);
  417. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:绑定后台30天到60天之间;绑定时间:" + pos.BindingTime.Value.ToString() + "");
  418. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:贷记卡是否刷满10000;贷记卡交易:" + pos.CreditTrade + "");
  419. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:非营训;当前类型:" + pos.CardType);
  420. if(pos.ActivationState == 1 && pos.BindingTime.Value.AddDays(30) <= DateTime.Now && pos.BindingTime.Value.AddDays(60) > DateTime.Now && pos.CreditTrade >= 10000 && pos.CardType < 100)
  421. {
  422. Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放盟主开机奖励");
  423. RedisDbconn.Instance.AddList("LeaderRewardQueue", pos.Id.ToString());
  424. //发放奖励MQ
  425. PrizeSetHelper.Do("1", pos.PosSn);
  426. }
  427. }
  428. //立刷格外奖励
  429. public void LiShuaActPrize(PxcModels.WebCMSEntities db, PxcModels.PosMachinesTwo pos, int prize)
  430. {
  431. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  432. if(merchant != null)
  433. {
  434. PxcModels.Users getUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new PxcModels.Users();
  435. int BuyTopUserId = 0;
  436. string ParentNav = getUser.ParentNav;
  437. if (!string.IsNullOrEmpty(ParentNav))
  438. {
  439. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  440. if (ParentNavList.Length > 1)
  441. {
  442. BuyTopUserId = int.Parse(ParentNavList[1]);
  443. }
  444. else if (ParentNavList.Length == 1)
  445. {
  446. BuyTopUserId = int.Parse(ParentNavList[0]);
  447. }
  448. }
  449. if(prize == 50)
  450. {
  451. StatService.Instance.doActiveReward(db, merchant, pos, getUser.Id, getUser.ParentNav, BuyTopUserId, prize);
  452. }
  453. if(prize == 40)
  454. {
  455. StatService.Instance.doActiveReward(db, merchant, pos, getUser.Id, getUser.ParentNav, BuyTopUserId, prize, 12);
  456. }
  457. if(prize == 30)
  458. {
  459. StatService.Instance.doActiveReward(db, merchant, pos, getUser.Id, getUser.ParentNav, BuyTopUserId, prize, 133);
  460. }
  461. }
  462. }
  463. private int GetLeShuaHaiKe(int UserId, int BrandId)
  464. {
  465. if(DateTime.Now >= DateTime.Parse("2023-08-01 00:00:00"))
  466. {
  467. return 0;
  468. }
  469. int ActStatus = 1;
  470. try
  471. {
  472. string Date = DateTime.Now.ToString("yyyyMMdd");
  473. int checkNum = 0;
  474. if(Date == "20230720") checkNum = 12;
  475. if(Date == "20230721") checkNum = 11;
  476. if(Date == "20230722") checkNum = 10;
  477. if(Date == "20230723") checkNum = 9;
  478. if(Date == "20230724") checkNum = 8;
  479. if(Date == "20230725") checkNum = 7;
  480. if(Date == "20230726") checkNum = 6;
  481. if(Date == "20230727") checkNum = 5;
  482. if(Date == "20230728") checkNum = 4;
  483. if(Date == "20230729") checkNum = 3;
  484. if(Date == "20230730") checkNum = 2;
  485. if(Date == "20230731") checkNum = 1;
  486. int check = int.Parse(function.CheckInt(RedisDbconn.Instance.Get<string>("lscut:" + UserId + ":" + BrandId + ":" + Date)));
  487. if(check <= checkNum)
  488. {
  489. check += 1;
  490. RedisDbconn.Instance.Set("lscut:" + UserId + ":" + BrandId + ":" + Date, check.ToString());
  491. }
  492. else
  493. {
  494. ActStatus = -1;
  495. RedisDbconn.Instance.Set("lscut:" + UserId + ":" + BrandId + ":" + Date, "0");
  496. }
  497. }
  498. catch(Exception ex)
  499. {
  500. Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "乐刷海科计数异常");
  501. }
  502. return ActStatus;
  503. }
  504. }
  505. }