SycnSpTradeService.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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. WebCMSEntities spdb = new WebCMSEntities();
  28. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  29. DateTime start = DateTime.Now.AddDays(-10);
  30. int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/TradeRecordId.txt")));
  31. IQueryable<TradeRecord> trades = spdb.TradeRecord.Where(m => m.Id >= StartId && m.CreateDate >= start && m.Status == 1).OrderBy(m => m.CreateDate).Take(20);
  32. foreach (TradeRecord trade in trades.ToList())
  33. {
  34. bool op = true;
  35. if (trade.SerEntryMode == "N" && trade.ProductType == "1") //金控押金获取
  36. {
  37. if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900)
  38. {
  39. op = false;
  40. PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == trade.TradeSnNo) ?? new PxcModels.MachineForSnNo();
  41. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  42. if (pos != null)
  43. {
  44. pos.SeoKeyword = trade.TradeAmount.ToString("f2");
  45. // pos.IsPurchase = 0;
  46. db.SaveChanges();
  47. }
  48. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  49. if (edit != null)
  50. {
  51. edit.Status = 2;
  52. }
  53. spdb.SaveChanges();
  54. }
  55. }
  56. else if ((trade.ProductType == "4" || trade.ProductType == "8" || trade.ProductType == "9") && trade.Field2 == "5200" && trade.Field3 == "300") //乐刷海科费率0.52的不入库
  57. {
  58. op = false;
  59. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  60. if (edit != null)
  61. {
  62. edit.Status = 2;
  63. }
  64. spdb.SaveChanges();
  65. }
  66. else if (trade.SerEntryMode == "1" && trade.ProductType == "10") //联动押金获取
  67. {
  68. if (trade.TradeAmount == 99 || trade.TradeAmount == 199 || trade.TradeAmount == 299)
  69. {
  70. op = false;
  71. PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == trade.TradeSnNo) ?? new PxcModels.MachineForSnNo();
  72. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  73. if (pos != null)
  74. {
  75. pos.SeoKeyword = trade.TradeAmount.ToString("f2");
  76. db.SaveChanges();
  77. }
  78. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  79. if (edit != null)
  80. {
  81. edit.Status = 2;
  82. }
  83. spdb.SaveChanges();
  84. }
  85. }
  86. else if (trade.SerEntryMode == "40" && trade.ProductType == "12") //盒易付押金获取
  87. {
  88. if (trade.TradeAmount == 99 || trade.TradeAmount == 199 || trade.TradeAmount == 299)
  89. {
  90. op = false;
  91. PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == trade.TradeSnNo) ?? new PxcModels.MachineForSnNo();
  92. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  93. if (pos != null)
  94. {
  95. pos.SeoKeyword = trade.TradeAmount.ToString("f2");
  96. db.SaveChanges();
  97. }
  98. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  99. if (edit != null)
  100. {
  101. edit.Status = 2;
  102. }
  103. spdb.SaveChanges();
  104. }
  105. }
  106. if (trade.DiscountRateFlag == "True")
  107. {
  108. op = false;
  109. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  110. if (edit != null)
  111. {
  112. edit.Status = 2;
  113. }
  114. spdb.SaveChanges();
  115. }
  116. if(trade.ProductType == "7" && trade.TradeStatus != "00")
  117. {
  118. op = false;
  119. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  120. if (edit != null)
  121. {
  122. edit.Status = 2;
  123. }
  124. spdb.SaveChanges();
  125. }
  126. if (op)
  127. {
  128. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
  129. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  130. if (pos != null)
  131. {
  132. PxcModels.KqProducts brand = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new PxcModels.KqProducts();
  133. if (pos.BindMerchantId > 0)
  134. {
  135. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  136. int TopUserId = 0;
  137. if (!string.IsNullOrEmpty(user.ParentNav))
  138. {
  139. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  140. }
  141. bool check = db.SpOrderNos.Any(m => m.OrderNo == trade.TradeSerialNo);
  142. if (!check)
  143. {
  144. decimal TradeAmount = trade.TradeAmount;
  145. int BankCardType = -1;
  146. int QrPayFlag = 0;
  147. int VipFlag = 0;
  148. int PayType = 0;
  149. if (pos.BrandId == 1 || pos.BrandId == 3)
  150. {
  151. TradeAmount = TradeAmount / 100;
  152. BankCardType = int.Parse(trade.BankCardType);
  153. if (trade.TradeType == "02") QrPayFlag = 1;
  154. else if (trade.TradeType == "NQ") PayType = 1;
  155. if (trade.SettleMethod == "E") VipFlag = 1;
  156. }
  157. else if (pos.BrandId == 2)
  158. {
  159. if (trade.TradeType == "CREDIT_BY_CARD")
  160. {
  161. BankCardType = 1;
  162. }
  163. else
  164. {
  165. BankCardType = 0;
  166. }
  167. if (trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
  168. }
  169. else if (pos.BrandId == 4 || pos.BrandId == 5)
  170. {
  171. TradeAmount = TradeAmount / 100;
  172. if (trade.BankCardType == "100")
  173. {
  174. BankCardType = 1;
  175. }
  176. else if (trade.BankCardType == "200")
  177. {
  178. BankCardType = 0;
  179. }
  180. if (trade.TradeType == "200") QrPayFlag = 1;
  181. if (trade.Field1 == "1") VipFlag = 1;
  182. }
  183. else if (pos.BrandId == 6)
  184. {
  185. TradeAmount = TradeAmount / 100;
  186. if (trade.BankCardType == "02" || trade.BankCardType == "12")
  187. {
  188. BankCardType = 1;
  189. }
  190. else
  191. {
  192. BankCardType = 0;
  193. }
  194. }
  195. else if (pos.BrandId == 7)
  196. {
  197. TradeAmount = TradeAmount / 100;
  198. if (trade.BankCardType == "OA" || trade.BankCardType == "CC" || trade.BankCardType == "SCC")
  199. {
  200. BankCardType = 1;
  201. }
  202. else
  203. {
  204. BankCardType = 0;
  205. }
  206. }
  207. else if (pos.BrandId == 8 || pos.BrandId == 9)
  208. {
  209. TradeAmount = TradeAmount / 100;
  210. if (trade.BankCardType == "100")
  211. {
  212. BankCardType = 1;
  213. }
  214. else if (trade.BankCardType == "200")
  215. {
  216. BankCardType = 0;
  217. }
  218. if (trade.TradeType == "200") QrPayFlag = 1;
  219. if (trade.Field1 == "1") VipFlag = 1;
  220. }
  221. else if (pos.BrandId == 10 || pos.BrandId == 11)
  222. {
  223. if (trade.BankCardType == "01")
  224. {
  225. BankCardType = 1;
  226. }
  227. else if (trade.BankCardType == "00")
  228. {
  229. BankCardType = 0;
  230. }
  231. if (trade.TradeType == "F010") QrPayFlag = 1;
  232. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  233. if(merchant != null)
  234. {
  235. bool flag = false;
  236. if(function.CheckNull(merchant.MerchantName).Contains("*")) merchant.MerchantName = trade.MerName;
  237. if(string.IsNullOrEmpty(merchant.MerIdcardNo) && !string.IsNullOrEmpty(trade.Field2))
  238. {
  239. merchant.MerIdcardNo = trade.Field2.ToUpper(); //商户身份证号
  240. flag = true;
  241. }
  242. if(!string.IsNullOrEmpty(trade.Field1))
  243. {
  244. merchant.MerchantMobile = trade.Field1; //商户手机号
  245. }
  246. if(flag)
  247. {
  248. string startNo = merchant.MerIdcardNo.Substring(0, 6);
  249. string endNo = merchant.MerIdcardNo.Substring(merchant.MerIdcardNo.Length - 4, 4).ToUpper();
  250. string Name = merchant.MerchantName;
  251. Name = Name.Replace("*", "");
  252. function.WriteLog(DateTime.Now.ToString() + "-----startNo:" + startNo + ",endNo:" + endNo + ",Name:" + Name, "监控机具是否互斥");
  253. PxcModels.PosMerchantInfo chk = db.PosMerchantInfo.FirstOrDefault(m => m.MerIdcardNo.StartsWith(startNo) && m.MerIdcardNo.EndsWith(endNo) && m.MerchantName.Contains(Name));
  254. if(chk != null)
  255. {
  256. function.WriteLog("互斥机具---sn:" + chk.KqSnNo + ",merno:" + chk.KqMerNo + ",name:" + chk.MerchantName, "监控机具是否互斥");
  257. pos.IsFirst = 0;
  258. }
  259. }
  260. db.SaveChanges();
  261. }
  262. }
  263. else if (pos.BrandId == 12 || pos.BrandId == 13) //盒易付
  264. {
  265. if (trade.BankCardType == "C")
  266. {
  267. BankCardType = 1;
  268. }
  269. else if (trade.BankCardType == "D")
  270. {
  271. BankCardType = 0;
  272. }
  273. if (trade.Field3 == "1") QrPayFlag = 1;
  274. }
  275. int BrandId = pos.BrandId;
  276. // int BrandId = int.Parse(trade.ProductType);
  277. // if (BrandId == 1 && trade.MerNo.StartsWith("M900"))
  278. // {
  279. // BrandId = 3;
  280. // }
  281. // if (BrandId == 4 && trade.DeviceType == "200")
  282. // {
  283. // BrandId = 5;
  284. // }
  285. decimal SourceTradeAmount = TradeAmount;
  286. if (pos.Sort == 0 && pos.BrandId == 7)
  287. {
  288. decimal deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  289. if (deposit > 0)
  290. {
  291. TradeAmount -= deposit;
  292. pos.Sort = 1;
  293. }
  294. }
  295. decimal CheckMoney = brand.ActTradeAmount > 0 ? brand.ActTradeAmount : 1000;
  296. int CheckDays = 30;
  297. //联动
  298. if(BankCardType == 1 && trade.TradeType == "M015" && (pos.BrandId == 10 || pos.BrandId == 11))
  299. {
  300. pos.CreditTrade += SourceTradeAmount;
  301. }
  302. //盒易付
  303. else if(BankCardType == 1 && trade.TradeType == "0" && trade.SerEntryMode != "40" && (pos.BrandId == 12 || pos.BrandId == 13))
  304. {
  305. pos.CreditTrade += SourceTradeAmount;
  306. }
  307. //金控
  308. else if((BankCardType == 1 || BankCardType == 2) && (pos.BrandId == 1 || pos.BrandId == 3))
  309. {
  310. pos.CreditTrade += SourceTradeAmount;
  311. }
  312. //开店宝
  313. else if (BankCardType == 1 && pos.BrandId == 2)
  314. {
  315. pos.CreditTrade += SourceTradeAmount;
  316. }
  317. //乐刷or海科
  318. else if (BankCardType == 1 && (trade.TradeType == "100" || trade.TradeType == "200" || trade.TradeType == "300" || trade.TradeType == "400" || trade.TradeType == "500" || trade.TradeType == "600") && (pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 8 || pos.BrandId == 9))
  319. {
  320. pos.CreditTrade += SourceTradeAmount;
  321. }
  322. //立刷
  323. else if(BankCardType == 1 && trade.Field2 == "0104" && pos.BrandId == 6)
  324. {
  325. pos.CreditTrade += SourceTradeAmount;
  326. }
  327. //盛付通
  328. else if(BankCardType == 1 && pos.BrandId == 7)
  329. {
  330. pos.CreditTrade += SourceTradeAmount;
  331. }
  332. //广电卡
  333. else if(pos.BrandId == 14)
  334. {
  335. pos.CreditTrade += SourceTradeAmount;
  336. }
  337. else if (BankCardType == 0)
  338. {
  339. pos.DebitCardTrade += TradeAmount;
  340. }
  341. //判断激活条件并激活
  342. ActPos(db, pos, CheckMoney, CheckDays);
  343. if (TradeAmount > 0)
  344. {
  345. ulong MerHelpFlag = 0;
  346. decimal DepositAmt = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  347. if (pos.DownFeeFlag == 1)
  348. {
  349. if(pos.BrandId == 12 || pos.BrandId == 13)
  350. {
  351. MerHelpFlag = 3;
  352. }
  353. else
  354. {
  355. if (pos.DownFee == 0.6M)
  356. {
  357. MerHelpFlag = 3;
  358. }
  359. else
  360. {
  361. MerHelpFlag = 2;
  362. }
  363. }
  364. }
  365. else if ((DepositAmt > 0 && pos.IsFirst == 1) || pos.BrandId == 14)
  366. {
  367. string DayString = RedisDbconn.Instance.Get<string>("pobjrule:" + pos.BrandId + ":HelpPolicy:Days");
  368. int Days = int.Parse(DayString); //天数
  369. if (pos.BindingTime != null)
  370. {
  371. if (pos.BindingTime.Value.AddDays(Days) > DateTime.Now)
  372. {
  373. MerHelpFlag = 1;
  374. }
  375. }
  376. }
  377. if((pos.BrandId == 12 || pos.BrandId == 13) && pos.UpFeeFlag == 1 && pos.DownFeeFlag == 0)
  378. {
  379. MerHelpFlag = 2;
  380. }
  381. if((pos.BrandId == 10 || pos.BrandId == 11) && trade.TradeType == "T015" && MerHelpFlag == 1)
  382. {
  383. MerHelpFlag = 0;
  384. }
  385. int CapFlag = 0;
  386. if(BankCardType == 0 && TradeAmount >= 1666.67M)
  387. {
  388. CapFlag = 1;
  389. }
  390. string HelpProfitFlag = "";
  391. bool checkHelpProfit = db.HelpProfitMerchantForUser.Any(m => m.MerchantId == pos.BindMerchantId);
  392. if(checkHelpProfit)
  393. {
  394. HelpProfitFlag = "HelpProfit";
  395. }
  396. int ActStatus = pos.ActivationState;
  397. // if(BrandId == 4 || BrandId == 5 || BrandId == 8 || BrandId == 9)
  398. // {
  399. // ActStatus = GetLeShuaHaiKe(pos.UserId, BrandId);
  400. // }
  401. int Version = 0;
  402. if(MerHelpFlag == 2) Version = 1;
  403. if(MerHelpFlag == 3) Version = 2;
  404. PxcModels.TradeRecord add = db.TradeRecord.Add(new PxcModels.TradeRecord()
  405. {
  406. ParentNav = user.ParentNav,
  407. CreateDate = trade.CreateDate,
  408. UpdateDate = trade.UpdateDate,
  409. RecordNo = trade.TradeSerialNo, //单号
  410. UserId = pos.UserId, //创客
  411. MerchantId = pos.BindMerchantId, //商户
  412. MerNo = trade.MerNo, //渠道商户编号
  413. MerHelpFlag = MerHelpFlag >= 2 ? 1 : MerHelpFlag, //1扶持周,0稳定期,2盈利期
  414. HelpMonthCount = 0, //扶持第几个月
  415. MerBuddyType = user.MerchantType, //商户创客类型
  416. SnNo = trade.TradeSnNo, //渠道SN号
  417. TradeSerialNo = trade.ChannelSerial, //交易流水号
  418. TradeAmount = TradeAmount, //交易金额
  419. BankCardType = BankCardType, //银行卡类型
  420. QrPayFlag = QrPayFlag, //云闪付标识
  421. CapFlag = CapFlag, //借记卡是否封顶
  422. VipFlag = VipFlag, //会员标记
  423. PayType = PayType, //支付方式
  424. BrandId = BrandId, //品牌
  425. Remark = trade.Remark, //备注
  426. TopUserId = TopUserId, //顶级创客
  427. MerUserId = pos.UserId, //商户直属创客
  428. SeoTitle = HelpProfitFlag,
  429. Version = Version,
  430. ActStatus = ActStatus,
  431. }).Entity;
  432. db.SaveChanges();
  433. string TradeMonth = trade.CreateDate == null ? DateTime.Now.ToString("yyyyMM") : trade.CreateDate.Value.ToString("yyyyMM");
  434. PublicFunction.SplitTradeRecord(add, TradeMonth);
  435. //统计商户交易额
  436. string TradeDate = trade.CreateDate == null ? DateTime.Now.ToString("yyyyMMdd") : trade.CreateDate.Value.ToString("yyyyMMdd");
  437. RedisDbconn.Instance.AddList("StatMerTradeAmountQueue", "{\"TradeDate\":\"" + TradeDate + "\",\"TradeAmount\":\"" + TradeAmount + "\",\"MerchantId\":\"" + pos.BindMerchantId + "\",\"BrandId\":\"" + BrandId + "\"}");
  438. }
  439. // 立刷60天内刷满10000,再返40
  440. // if (pos.BrandId == 6 && decimal.Parse(function.CheckNum(pos.SeoKeyword)) > 0&& pos.CreditTrade >= 10000 && pos.ActivationState == 1 && pos.BindingTime > DateTime.Now.AddDays(-60))
  441. // {
  442. // LiShuaActPrize(db, pos, 40);
  443. // }
  444. //9月1日-9月30日立刷机具刷5000激活时额外奖励30元立刷活动奖
  445. // if(pos.BrandId == 6 && pos.CreditTrade >= 5000M && pos.ActivationTime >= DateTime.Parse("2023-08-31 00:00:00") && pos.ActivationTime < DateTime.Parse("2023-11-01 00:00:00"))
  446. // {
  447. // LiShuaActPrize(db, pos, 30);
  448. // }
  449. db.SpOrderNos.Add(new PxcModels.SpOrderNos()
  450. {
  451. OrderNo = trade.TradeSerialNo
  452. });
  453. db.SaveChanges();
  454. // 推荐王逻辑(交易)
  455. // if(TradeAmount > 0)
  456. // {
  457. // string Send = "{\"Kind\":\"4\",\"Data\":{\"PosId\":\"" + pos.Id + "\",\"TradeMonth\":\"" + trade.CreateDate.Value.ToString("yyyyMM") + "\",\"TradeAmount\":\"" + TradeAmount + "\"}}";
  458. // RedisDbconn.Instance.AddList("RecommendActStatQueue", Send);
  459. // }
  460. }
  461. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  462. if (edit != null)
  463. {
  464. edit.Status = 2;
  465. }
  466. spdb.SaveChanges();
  467. }
  468. else
  469. {
  470. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  471. if (edit != null)
  472. {
  473. edit.Status = 0;
  474. }
  475. spdb.SaveChanges();
  476. }
  477. }
  478. else
  479. {
  480. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  481. if (edit != null)
  482. {
  483. edit.Status = 0;
  484. }
  485. spdb.SaveChanges();
  486. }
  487. }
  488. }
  489. spdb.Dispose();
  490. db.Dispose();
  491. }
  492. catch (Exception ex)
  493. {
  494. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP交易数据到MAIN异常");
  495. }
  496. Thread.Sleep(500);
  497. }
  498. }
  499. //机具激活逻辑
  500. public void ActPos(PxcModels.WebCMSEntities db, PxcModels.PosMachinesTwo pos, decimal CheckMoney, int CheckDays, bool PrizeFlag = true, string ActivationTime = "")
  501. {
  502. DateTime now = DateTime.Now;
  503. if(!string.IsNullOrEmpty(ActivationTime))
  504. {
  505. now = DateTime.Parse(ActivationTime);
  506. }
  507. DateTime TransferTime = pos.TransferTime == null ? DateTime.Now : pos.TransferTime.Value;
  508. int minute = 30;
  509. if(pos.BrandId == 14)
  510. {
  511. minute = 0;
  512. }
  513. if (pos.CreditTrade >= CheckMoney && pos.BuyUserId > 0 && pos.ActivationState == 0 && TransferTime.AddMinutes(-minute) < pos.BindingTime)
  514. {
  515. pos.ActivationState = 1;
  516. pos.ActivationTime = now;
  517. function.WriteLog("机具" + pos.PosSn, "开机奖励在激活中监控");
  518. function.WriteLog("PrizeFlag:" + PrizeFlag, "开机奖励在激活中监控");
  519. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  520. if (merchant != null)
  521. {
  522. function.WriteLog("查询到商户", "开机奖励在激活中监控");
  523. merchant.ActiveStatus = 1;
  524. merchant.MerStandardDate = now;
  525. db.SaveChanges();
  526. function.WriteLog("商户" + merchant.KqMerNo, "开机奖励在激活中监控");
  527. //发放开机奖励
  528. function.WriteLog("首台" + pos.IsFirst, "开机奖励在激活中监控");
  529. if(pos.IsFirst == 1 && pos.BindingTime > now.AddDays(-CheckDays) && PrizeFlag)
  530. {
  531. function.WriteLog("开机奖发放", "开机奖励在激活中监控");
  532. RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
  533. }
  534. }
  535. else if(pos.BrandId == 14 && pos.IsFirst == 1 && pos.BindingTime > now.AddDays(-CheckDays) && PrizeFlag)
  536. {
  537. function.WriteLog("开机奖发放", "开机奖励在激活中监控");
  538. RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
  539. }
  540. //发放大盟主奖励
  541. function.WriteLog("大盟主---PrizeFlag:" + PrizeFlag + ";LeaderUserId:" + pos.LeaderUserId + ";pos.IsFirst:" + pos.IsFirst + ";pos.BindingTime:" + pos.BindingTime + ";now.AddDays(-CheckDays):" + now.AddDays(-CheckDays) + ";", "开机奖励在激活中监控");
  542. if (pos.LeaderUserId > 0 && pos.IsFirst == 1 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now) && pos.BindingTime > now.AddDays(-CheckDays) && PrizeFlag)
  543. {
  544. function.WriteLog("大盟主奖发放", "开机奖励在激活中监控");
  545. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  546. }
  547. //发放运营中心奖励
  548. if (pos.IsFirst == 1 && pos.BindingTime > now.AddDays(-CheckDays) && PrizeFlag)
  549. {
  550. function.WriteLog("运营中心奖发放", "开机奖励在激活中监控");
  551. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  552. }
  553. AlipayPayBack2Service.Instance.ActReserveBack(pos.OpId, pos.OpReserve1, pos.OpReserve2, pos.OpReserve3);
  554. //统计激活数
  555. RedisDbconn.Instance.AddList("StatActQueue", "{\"TradeDate\":\"" + now.ToString("yyyyMMdd") + "\",\"UserId\":\"" + pos.BuyUserId + "\",\"BrandId\":\"" + pos.BrandId + "\"}");
  556. }
  557. }
  558. //立刷格外奖励
  559. public void LiShuaActPrize(PxcModels.WebCMSEntities db, PxcModels.PosMachinesTwo pos, int prize)
  560. {
  561. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  562. if(merchant != null)
  563. {
  564. PxcModels.Users getUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new PxcModels.Users();
  565. int BuyTopUserId = 0;
  566. string ParentNav = getUser.ParentNav;
  567. if (!string.IsNullOrEmpty(ParentNav))
  568. {
  569. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  570. if (ParentNavList.Length > 1)
  571. {
  572. BuyTopUserId = int.Parse(ParentNavList[1]);
  573. }
  574. else if (ParentNavList.Length == 1)
  575. {
  576. BuyTopUserId = int.Parse(ParentNavList[0]);
  577. }
  578. }
  579. if(prize == 50)
  580. {
  581. StatService.Instance.doActiveReward(db, merchant, pos, getUser.Id, getUser.ParentNav, BuyTopUserId, prize);
  582. }
  583. if(prize == 40)
  584. {
  585. StatService.Instance.doActiveReward(db, merchant, pos, getUser.Id, getUser.ParentNav, BuyTopUserId, prize, 12);
  586. }
  587. if(prize == 30)
  588. {
  589. StatService.Instance.doActiveReward(db, merchant, pos, getUser.Id, getUser.ParentNav, BuyTopUserId, prize, 133);
  590. }
  591. }
  592. }
  593. private int GetLeShuaHaiKe(int UserId, int BrandId)
  594. {
  595. if(DateTime.Now >= DateTime.Parse("2023-08-01 00:00:00"))
  596. {
  597. return 0;
  598. }
  599. int ActStatus = 1;
  600. try
  601. {
  602. string Date = DateTime.Now.ToString("yyyyMMdd");
  603. int checkNum = 0;
  604. if(Date == "20230720") checkNum = 12;
  605. if(Date == "20230721") checkNum = 11;
  606. if(Date == "20230722") checkNum = 10;
  607. if(Date == "20230723") checkNum = 9;
  608. if(Date == "20230724") checkNum = 8;
  609. if(Date == "20230725") checkNum = 7;
  610. if(Date == "20230726") checkNum = 6;
  611. if(Date == "20230727") checkNum = 5;
  612. if(Date == "20230728") checkNum = 4;
  613. if(Date == "20230729") checkNum = 3;
  614. if(Date == "20230730") checkNum = 2;
  615. if(Date == "20230731") checkNum = 1;
  616. int check = int.Parse(function.CheckInt(RedisDbconn.Instance.Get<string>("lscut:" + UserId + ":" + BrandId + ":" + Date)));
  617. if(check <= checkNum)
  618. {
  619. check += 1;
  620. RedisDbconn.Instance.Set("lscut:" + UserId + ":" + BrandId + ":" + Date, check.ToString());
  621. }
  622. else
  623. {
  624. ActStatus = -1;
  625. RedisDbconn.Instance.Set("lscut:" + UserId + ":" + BrandId + ":" + Date, "0");
  626. }
  627. }
  628. catch(Exception ex)
  629. {
  630. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "乐刷海科计数异常");
  631. }
  632. return ActStatus;
  633. }
  634. }
  635. }