SycnSpTradeService.cs 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  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. WebCMSEntities spdb = new WebCMSEntities();
  35. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  36. DateTime start = DateTime.Now.AddDays(-10);
  37. DateTime end = DateTime.Now.AddMinutes(-1);
  38. int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/TradeRecordId.txt")));
  39. IQueryable<TradeRecord> trades = spdb.TradeRecord.Where(m => m.Id >= StartId && !BrandIds.Contains(m.ProductType) && m.CreateDate >= start && m.Status == 1).OrderBy(m => m.CreateDate).Take(20);
  40. foreach (TradeRecord trade in trades.ToList())
  41. {
  42. bool op = true;
  43. bool isDeposit = false;
  44. if (trade.SerEntryMode == "N" && trade.ProductType == "1") //金控押金获取
  45. {
  46. if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900)
  47. {
  48. op = false;
  49. PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == trade.TradeSnNo) ?? new PxcModels.MachineForSnNo();
  50. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  51. if (pos != null)
  52. {
  53. if(string.IsNullOrEmpty(pos.SeoKeyword)) Utils.Instance.SendActData(pos);
  54. pos.SeoKeyword = trade.TradeAmount.ToString("f2");
  55. db.SaveChanges();
  56. isDeposit = true;
  57. function.WriteLog("押金监控:" + trade.MerNo, "服务费奖励发放日志");
  58. }
  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. }
  67. else if ((trade.ProductType == "4" || trade.ProductType == "8" || trade.ProductType == "9") && (trade.Field2 == "5200" || trade.Field2 == "5800")) //乐刷海科费率0.52,0.58的不入库
  68. {
  69. op = false;
  70. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  71. if (edit != null)
  72. {
  73. edit.Status = 2;
  74. }
  75. spdb.SaveChanges();
  76. }
  77. else if (trade.SerEntryMode == "1" && trade.ProductType == "10") //联动押金获取
  78. {
  79. if (trade.TradeAmount == 99 || trade.TradeAmount == 199 || trade.TradeAmount == 299)
  80. {
  81. op = false;
  82. PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == trade.TradeSnNo) ?? new PxcModels.MachineForSnNo();
  83. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  84. if (pos != null)
  85. {
  86. if(string.IsNullOrEmpty(pos.SeoKeyword)) Utils.Instance.SendActData(pos);
  87. pos.SeoKeyword = trade.TradeAmount.ToString("f2");
  88. db.SaveChanges();
  89. isDeposit = true;
  90. function.WriteLog("押金监控:" + trade.MerNo, "服务费奖励发放日志");
  91. }
  92. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  93. if (edit != null)
  94. {
  95. edit.Status = 2;
  96. }
  97. spdb.SaveChanges();
  98. }
  99. }
  100. else if (trade.SerEntryMode == "40" && trade.ProductType == "12") //盒易付押金获取
  101. {
  102. if (trade.TradeAmount == 99 || trade.TradeAmount == 199 || trade.TradeAmount == 299)
  103. {
  104. op = false;
  105. PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == trade.TradeSnNo) ?? new PxcModels.MachineForSnNo();
  106. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  107. if (pos != null)
  108. {
  109. if(string.IsNullOrEmpty(pos.SeoKeyword)) Utils.Instance.SendActData(pos);
  110. pos.SeoKeyword = trade.TradeAmount.ToString("f2");
  111. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
  112. db.MerchantDepositRecord.Add(new PxcModels.MerchantDepositRecord()
  113. {
  114. CreateDate = DateTime.Now,
  115. SnNo = pos.PosSn,
  116. MerNo = function.CheckNull(merchant.KqMerNo),
  117. DepositAmount = trade.TradeAmount,
  118. UserId = pos.BuyUserId,
  119. AgentNo = function.CheckNull(merchant.MgrNo),
  120. OrderId = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  121. });
  122. db.SaveChanges();
  123. isDeposit = true;
  124. function.WriteLog("押金监控:" + trade.MerNo, "服务费奖励发放日志");
  125. }
  126. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  127. if (edit != null)
  128. {
  129. edit.Status = 2;
  130. }
  131. spdb.SaveChanges();
  132. }
  133. }
  134. else if (trade.TradeType == "40" && trade.ProductType == "15") //联客宝押金获取
  135. {
  136. if (trade.TradeAmount == 99 || trade.TradeAmount == 199 || trade.TradeAmount == 299)
  137. {
  138. op = false;
  139. PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == trade.TradeSnNo) ?? new PxcModels.MachineForSnNo();
  140. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  141. if (pos != null)
  142. {
  143. if(string.IsNullOrEmpty(pos.SeoKeyword)) Utils.Instance.SendActData(pos);
  144. pos.SeoKeyword = trade.TradeAmount.ToString("f2");
  145. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
  146. db.MerchantDepositRecord.Add(new PxcModels.MerchantDepositRecord()
  147. {
  148. CreateDate = DateTime.Now,
  149. SnNo = pos.PosSn,
  150. MerNo = merchant.KqMerNo,
  151. DepositAmount = trade.TradeAmount,
  152. UserId = pos.BuyUserId,
  153. AgentNo = function.CheckNull(merchant.MgrNo),
  154. OrderId = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  155. });
  156. db.SaveChanges();
  157. isDeposit = true;
  158. function.WriteLog("押金监控:" + trade.MerNo, "服务费奖励发放日志");
  159. }
  160. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  161. if (edit != null)
  162. {
  163. edit.Status = 2;
  164. }
  165. spdb.SaveChanges();
  166. }
  167. }
  168. if (trade.DiscountRateFlag == "True")
  169. {
  170. op = false;
  171. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  172. if (edit != null)
  173. {
  174. edit.Status = 2;
  175. }
  176. spdb.SaveChanges();
  177. }
  178. if(trade.ProductType == "7" && trade.TradeStatus != "00")
  179. {
  180. op = false;
  181. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  182. if (edit != null)
  183. {
  184. edit.Status = 2;
  185. }
  186. spdb.SaveChanges();
  187. }
  188. if (op)
  189. {
  190. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == trade.TradeSnNo);
  191. if (pos != null)
  192. {
  193. PxcModels.KqProducts brand = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new PxcModels.KqProducts();
  194. if (pos.BindMerchantId > 0)
  195. {
  196. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  197. int TopUserId = 0;
  198. if (!string.IsNullOrEmpty(user.ParentNav))
  199. {
  200. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  201. }
  202. bool check = db.SpOrderNos.Any(m => m.OrderNo == trade.TradeSerialNo);
  203. if (!check)
  204. {
  205. decimal TradeAmount = trade.TradeAmount;
  206. int BankCardType = -1;
  207. int QrPayFlag = 0;
  208. int VipFlag = 0;
  209. int PayType = 0;
  210. if (pos.BrandId == 1 || pos.BrandId == 3)
  211. {
  212. TradeAmount = TradeAmount / 100;
  213. BankCardType = int.Parse(trade.BankCardType);
  214. if (trade.TradeType == "02") QrPayFlag = 1;
  215. else if (trade.TradeType == "NQ") PayType = 1;
  216. if (trade.SettleMethod == "E") VipFlag = 1;
  217. }
  218. else if (pos.BrandId == 2)
  219. {
  220. if (trade.TradeType == "CREDIT_BY_CARD")
  221. {
  222. BankCardType = 1;
  223. }
  224. else
  225. {
  226. BankCardType = 0;
  227. }
  228. if (trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
  229. }
  230. else if (pos.BrandId == 4 || pos.BrandId == 5)
  231. {
  232. TradeAmount = TradeAmount / 100;
  233. if (trade.BankCardType == "100")
  234. {
  235. BankCardType = 1;
  236. }
  237. else if (trade.BankCardType == "200")
  238. {
  239. BankCardType = 0;
  240. }
  241. if (trade.TradeType == "200") QrPayFlag = 1;
  242. if (trade.Field1 == "1") VipFlag = 1;
  243. }
  244. else if (pos.BrandId == 6 || pos.BrandId == 22)
  245. {
  246. TradeAmount = TradeAmount / 100;
  247. if (trade.BankCardType == "02" || trade.BankCardType == "12")
  248. {
  249. BankCardType = 1;
  250. }
  251. else
  252. {
  253. BankCardType = 0;
  254. }
  255. }
  256. else if (pos.BrandId == 7)
  257. {
  258. TradeAmount = TradeAmount / 100;
  259. if (trade.BankCardType == "OA" || trade.BankCardType == "CC" || trade.BankCardType == "SCC")
  260. {
  261. BankCardType = 1;
  262. }
  263. else
  264. {
  265. BankCardType = 0;
  266. }
  267. }
  268. else if (pos.BrandId == 8 || pos.BrandId == 9)
  269. {
  270. TradeAmount = TradeAmount / 100;
  271. if (trade.BankCardType == "100")
  272. {
  273. BankCardType = 1;
  274. }
  275. else if (trade.BankCardType == "200")
  276. {
  277. BankCardType = 0;
  278. }
  279. if (trade.TradeType == "200") QrPayFlag = 1;
  280. if (trade.Field1 == "1") VipFlag = 1;
  281. }
  282. else if (pos.BrandId == 10 || pos.BrandId == 11)
  283. {
  284. if (trade.BankCardType == "01")
  285. {
  286. BankCardType = 1;
  287. }
  288. else if (trade.BankCardType == "00")
  289. {
  290. BankCardType = 0;
  291. }
  292. if (trade.TradeType == "F010") QrPayFlag = 1;
  293. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  294. if(merchant != null)
  295. {
  296. bool flag = false;
  297. if(function.CheckNull(merchant.MerchantName).Contains("*")) merchant.MerchantName = trade.MerName;
  298. if(string.IsNullOrEmpty(merchant.MerIdcardNo) && !string.IsNullOrEmpty(trade.Field2))
  299. {
  300. merchant.MerIdcardNo = trade.Field2.ToUpper(); //商户身份证号
  301. flag = true;
  302. }
  303. if(!string.IsNullOrEmpty(trade.Field1))
  304. {
  305. merchant.MerchantMobile = trade.Field1; //商户手机号
  306. }
  307. if(flag)
  308. {
  309. string startNo = merchant.MerIdcardNo.Substring(0, 6);
  310. string endNo = merchant.MerIdcardNo.Substring(merchant.MerIdcardNo.Length - 4, 4).ToUpper();
  311. string Name = merchant.MerchantName;
  312. Name = Name.Replace("*", "");
  313. function.WriteLog(DateTime.Now.ToString() + "-----startNo:" + startNo + ",endNo:" + endNo + ",Name:" + Name, "监控机具是否互斥");
  314. PxcModels.PosMerchantInfo chk = db.PosMerchantInfo.FirstOrDefault(m => m.MerIdcardNo.StartsWith(startNo) && m.MerIdcardNo.EndsWith(endNo) && m.MerchantName.Contains(Name));
  315. if(chk != null)
  316. {
  317. function.WriteLog("互斥机具---sn:" + chk.KqSnNo + ",merno:" + chk.KqMerNo + ",name:" + chk.MerchantName, "监控机具是否互斥");
  318. pos.IsFirst = 0;
  319. }
  320. }
  321. db.SaveChanges();
  322. }
  323. }
  324. else if (pos.BrandId == 12 || pos.BrandId == 13) //盒易付
  325. {
  326. if (trade.BankCardType == "C")
  327. {
  328. BankCardType = 1;
  329. }
  330. else if (trade.BankCardType == "D")
  331. {
  332. BankCardType = 0;
  333. }
  334. if (trade.Field3 == "1") QrPayFlag = 1;
  335. }
  336. else if (pos.BrandId == 15 || pos.BrandId == 16) //联客宝
  337. {
  338. TradeAmount = TradeAmount / 100;
  339. // 支付类型
  340. // 01-内卡借记卡
  341. // 02-内卡贷记卡
  342. // 03-银联二维码
  343. // 11-外卡借记卡
  344. // 12-外卡贷记卡
  345. // 30-微信
  346. // 31-支付宝
  347. // M3-扫码(银联二维码、微信、支付宝)
  348. if (trade.BankCardType == "02")
  349. {
  350. BankCardType = 1;
  351. }
  352. else
  353. {
  354. BankCardType = 0;
  355. }
  356. // if (trade.SerEntryMode == "1") QrPayFlag = 1;
  357. }
  358. int BrandId = pos.BrandId;
  359. // int BrandId = int.Parse(trade.ProductType);
  360. // if (BrandId == 1 && trade.MerNo.StartsWith("M900"))
  361. // {
  362. // BrandId = 3;
  363. // }
  364. // if (BrandId == 4 && trade.DeviceType == "200")
  365. // {
  366. // BrandId = 5;
  367. // }
  368. decimal SourceTradeAmount = TradeAmount;
  369. if (pos.Sort == 0 && pos.BrandId == 7)
  370. {
  371. decimal deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  372. if (deposit > 0)
  373. {
  374. int SftStartId = RedisDbconn.Instance.Get<int>("SftTradeChkId");
  375. PxcModels.TradeRecord chk = db.TradeRecord.FirstOrDefault(m => m.Id > SftStartId && m.SnNo == pos.PosSn);
  376. if(chk == null)
  377. {
  378. TradeAmount -= deposit;
  379. }
  380. else
  381. {
  382. chk.TradeAmount -= deposit;
  383. }
  384. pos.Sort = 1;
  385. }
  386. }
  387. decimal CheckMoney = brand.ActTradeAmount > 0 ? brand.ActTradeAmount : 1000;
  388. int CheckDays = 30;
  389. //联动
  390. if(BankCardType == 1 && trade.TradeType == "M015" && (pos.BrandId == 10 || pos.BrandId == 11))
  391. {
  392. pos.CreditTrade += SourceTradeAmount;
  393. }
  394. //盒易付
  395. else if(BankCardType == 1 && trade.TradeType == "0" && trade.SerEntryMode != "40" && (pos.BrandId == 12 || pos.BrandId == 13))
  396. {
  397. pos.CreditTrade += SourceTradeAmount;
  398. }
  399. //联客宝
  400. else if(BankCardType == 1 && trade.TradeType != "40" && (pos.BrandId == 15 || pos.BrandId == 16))
  401. {
  402. pos.CreditTrade += SourceTradeAmount;
  403. }
  404. //金控
  405. else if((BankCardType == 1 || BankCardType == 2) && (pos.BrandId == 1 || pos.BrandId == 3))
  406. {
  407. pos.CreditTrade += SourceTradeAmount;
  408. }
  409. //开店宝
  410. else if (BankCardType == 1 && pos.BrandId == 2)
  411. {
  412. pos.CreditTrade += SourceTradeAmount;
  413. }
  414. //乐刷or海科
  415. 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))
  416. {
  417. pos.CreditTrade += SourceTradeAmount;
  418. }
  419. //立刷
  420. else if(BankCardType == 1 && trade.Field2 == "0104" && (pos.BrandId == 6 || pos.BrandId == 22))
  421. {
  422. pos.CreditTrade += SourceTradeAmount;
  423. }
  424. //盛付通
  425. else if(BankCardType == 1 && pos.BrandId == 7)
  426. {
  427. pos.CreditTrade += SourceTradeAmount;
  428. }
  429. //广电卡
  430. else if(pos.BrandId == 14)
  431. {
  432. pos.CreditTrade += SourceTradeAmount;
  433. }
  434. else if (BankCardType == 0)
  435. {
  436. pos.DebitCardTrade += TradeAmount;
  437. }
  438. //判断激活条件并激活
  439. ActPos(db, pos, CheckMoney, CheckDays);
  440. if (TradeAmount > 0)
  441. {
  442. ulong MerHelpFlag = 0;
  443. decimal DepositAmt = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  444. DateTime ChkTime = DateTime.Now;
  445. if(pos.BrandId == 7)
  446. {
  447. ChkTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 03:00:00");
  448. }
  449. if (pos.DownFeeFlag == 1 && pos.DownFeeDate <= ChkTime)
  450. {
  451. if (pos.DownFee == 0.6M)
  452. {
  453. MerHelpFlag = 3;
  454. }
  455. else
  456. {
  457. MerHelpFlag = 2;
  458. }
  459. }
  460. else if (pos.IsFirst == 1 || pos.BrandId == 14)
  461. {
  462. string DayString = RedisDbconn.Instance.Get<string>("pobjrule:1:HelpPolicy:Days");
  463. int Days = int.Parse(DayString); //天数
  464. if (pos.BindingTime != null)
  465. {
  466. DateTime CheckTime = pos.BindingTime.Value.AddDays(Days);
  467. if(pos.BrandId == 7)
  468. {
  469. CheckTime = DateTime.Parse(pos.BindingTime.Value.AddDays(Days + 1).ToString("yyyy-MM-dd") + " 03:00:00");
  470. }
  471. if (CheckTime > DateTime.Now)
  472. {
  473. MerHelpFlag = 1;
  474. }
  475. }
  476. }
  477. if((pos.BrandId == 12 || pos.BrandId == 13) && pos.UpFeeFlag == 1 && pos.DownFeeFlag == 0)
  478. {
  479. MerHelpFlag = 2;
  480. }
  481. if((pos.BrandId == 10 || pos.BrandId == 11) && trade.TradeType == "T015" && MerHelpFlag == 1)
  482. {
  483. MerHelpFlag = 0;
  484. }
  485. int CapFlag = 0;
  486. if(BankCardType == 0 && TradeAmount >= 1666.67M)
  487. {
  488. CapFlag = 1;
  489. }
  490. string HelpProfitFlag = "";
  491. bool checkHelpProfit = db.HelpProfitMerchantForUser.Any(m => m.MerchantId == pos.BindMerchantId);
  492. if(checkHelpProfit)
  493. {
  494. HelpProfitFlag = "HelpProfit";
  495. }
  496. int ActStatus = pos.ActivationState;
  497. // if(BrandId == 4 || BrandId == 5 || BrandId == 8 || BrandId == 9)
  498. // {
  499. // ActStatus = GetLeShuaHaiKe(pos.UserId, BrandId);
  500. // }
  501. int Version = 0;
  502. if(MerHelpFlag == 2) Version = 1;
  503. if(MerHelpFlag == 3) Version = 2;
  504. //盒易付和来客吧电签,稳定期自动转到稳定期A
  505. if((pos.BrandId == 12 || pos.BrandId == 13) && MerHelpFlag == 0 && Version == 0)
  506. {
  507. Version = 1;
  508. }
  509. if(pos.BrandId >= 23 && pos.BrandId <= 26)
  510. {
  511. MerHelpFlag = 1;
  512. Version = 0;
  513. }
  514. decimal SettleFee = trade.SettleFee * 100;
  515. PxcModels.TradeRecord add = db.TradeRecord.Add(new PxcModels.TradeRecord()
  516. {
  517. ParentNav = user.ParentNav,
  518. CreateDate = trade.CreateDate,
  519. UpdateDate = trade.UpdateDate,
  520. RecordNo = trade.TradeSerialNo, //单号
  521. UserId = pos.UserId, //创客
  522. MerchantId = pos.BindMerchantId, //商户
  523. MerNo = trade.MerNo, //渠道商户编号
  524. MerHelpFlag = MerHelpFlag >= 2 ? 1 : MerHelpFlag, //1扶持周,0稳定期,2盈利期
  525. HelpMonthCount = 0, //扶持第几个月
  526. MerBuddyType = user.MerchantType, //商户创客类型
  527. SnNo = trade.TradeSnNo, //渠道SN号
  528. TradeSerialNo = trade.ChannelSerial, //交易流水号
  529. TradeAmount = TradeAmount, //交易金额
  530. BankCardType = BankCardType, //银行卡类型
  531. QrPayFlag = QrPayFlag, //云闪付标识
  532. CapFlag = CapFlag, //借记卡是否封顶
  533. VipFlag = VipFlag, //会员标记
  534. PayType = PayType, //支付方式
  535. BrandId = BrandId, //品牌
  536. Remark = trade.Remark, //备注
  537. TopUserId = TopUserId, //顶级创客
  538. MerUserId = pos.UserId, //商户直属创客M
  539. SeoTitle = HelpProfitFlag,
  540. Version = Version,
  541. ActStatus = ActStatus,
  542. CreateMan = trade.AgentNo,
  543. UpdateMan = trade.BankCardType,
  544. SeoKeyword = trade.SerEntryMode,
  545. SeoDescription = trade.TradeType,
  546. Sort = (int)SettleFee,
  547. TradeDate = pos.BindingTime,
  548. }).Entity;
  549. db.SaveChanges();
  550. string TradeMonth = trade.CreateDate == null ? DateTime.Now.ToString("yyyyMM") : trade.CreateDate.Value.ToString("yyyyMM");
  551. PublicFunction.SplitTradeRecord(add, TradeMonth);
  552. //统计商户交易额
  553. string TradeDate = trade.CreateDate == null ? DateTime.Now.ToString("yyyyMMdd") : trade.CreateDate.Value.ToString("yyyyMMdd");
  554. RedisDbconn.Instance.AddList("StatMerTradeAmountQueue", "{\"TradeDate\":\"" + TradeDate + "\",\"TradeAmount\":\"" + TradeAmount + "\",\"MerchantId\":\"" + pos.BindMerchantId + "\",\"BrandId\":\"" + BrandId + "\"}");
  555. }
  556. db.SpOrderNos.Add(new PxcModels.SpOrderNos()
  557. {
  558. OrderNo = trade.TradeSerialNo
  559. });
  560. db.SaveChanges();
  561. // 推荐王逻辑(交易)
  562. // if(TradeAmount > 0)
  563. // {
  564. // string Send = "{\"Kind\":\"4\",\"Data\":{\"PosId\":\"" + pos.Id + "\",\"TradeMonth\":\"" + trade.CreateDate.Value.ToString("yyyyMM") + "\",\"TradeAmount\":\"" + TradeAmount + "\"}}";
  565. // RedisDbconn.Instance.AddList("RecommendActStatQueue", Send);
  566. // }
  567. }
  568. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  569. if (edit != null)
  570. {
  571. edit.Status = 2;
  572. }
  573. spdb.SaveChanges();
  574. }
  575. else
  576. {
  577. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  578. if (edit != null)
  579. {
  580. edit.Status = 0;
  581. }
  582. spdb.SaveChanges();
  583. }
  584. }
  585. else
  586. {
  587. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  588. if (edit != null)
  589. {
  590. edit.Status = 0;
  591. }
  592. spdb.SaveChanges();
  593. }
  594. }
  595. if(isDeposit)
  596. {
  597. // function.WriteLog("押金收到:" + trade.MerNo, "服务费奖励发放日志");
  598. // PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
  599. // function.WriteLog("MachineForMerNo:" + posFor.MerNo, "服务费奖励发放日志");
  600. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == trade.TradeSnNo) ?? new PxcModels.PosMachinesTwo();
  601. function.WriteLog("PosMachinesTwo:" + pos.PosSn, "服务费奖励发放日志");
  602. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
  603. function.WriteLog("PosMerchantInfo:" + merchant.KqMerNo, "服务费奖励发放日志");
  604. StatService.Instance.PreActPrize(db, pos, merchant, pos.SeoKeyword);
  605. }
  606. }
  607. spdb.Dispose();
  608. db.Dispose();
  609. }
  610. catch (Exception ex)
  611. {
  612. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP交易数据到MAIN异常");
  613. }
  614. Thread.Sleep(500);
  615. }
  616. }
  617. public void StartSim()
  618. {
  619. Thread th = new Thread(StartSimDo);
  620. th.IsBackground = true;
  621. th.Start();
  622. }
  623. public void StartSimDo()
  624. {
  625. while (true)
  626. {
  627. try
  628. {
  629. WebCMSEntities spdb = new WebCMSEntities();
  630. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  631. DateTime start = DateTime.Now.AddDays(-40);
  632. int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/TradeRecordId.txt")));
  633. IQueryable<TradeRecord> trades = spdb.TradeRecord.Where(m => m.Id >= StartId && m.ProductType == "14" && m.CreateDate >= start && m.Status == 1).OrderBy(m => m.CreateDate).Take(20);
  634. foreach (TradeRecord trade in trades.ToList())
  635. {
  636. bool op = true;
  637. if (op)
  638. {
  639. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
  640. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
  641. if (pos != null)
  642. {
  643. PxcModels.KqProducts brand = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new PxcModels.KqProducts();
  644. if (pos.BindMerchantId > 0)
  645. {
  646. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  647. int TopUserId = 0;
  648. if (!string.IsNullOrEmpty(user.ParentNav))
  649. {
  650. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  651. }
  652. bool check = db.SpOrderNos.Any(m => m.OrderNo == trade.TradeSerialNo);
  653. if (!check)
  654. {
  655. decimal TradeAmount = trade.TradeAmount;
  656. int BankCardType = -1;
  657. int QrPayFlag = 0;
  658. int VipFlag = 0;
  659. int PayType = 0;
  660. BankCardType = int.Parse(trade.BankCardType);
  661. int BrandId = pos.BrandId;
  662. decimal SourceTradeAmount = TradeAmount;
  663. if (TradeAmount > 0)
  664. {
  665. ulong MerHelpFlag = 0;
  666. string DayString = RedisDbconn.Instance.Get<string>("pobjrule:" + pos.BrandId + ":HelpPolicy:Days");
  667. int Days = int.Parse(DayString); //天数
  668. if (pos.BindingTime != null)
  669. {
  670. if (pos.BindingTime.Value.AddDays(Days) > DateTime.Now)
  671. {
  672. MerHelpFlag = 1;
  673. }
  674. }
  675. int ActStatus = pos.ActivationState;
  676. decimal SettleFee = trade.SettleFee * 100;
  677. PxcModels.TradeRecord add = db.TradeRecord.Add(new PxcModels.TradeRecord()
  678. {
  679. ParentNav = user.ParentNav,
  680. CreateDate = trade.CreateDate,
  681. UpdateDate = trade.UpdateDate,
  682. RecordNo = trade.TradeSerialNo, //单号
  683. UserId = pos.UserId, //创客
  684. MerchantId = pos.BindMerchantId, //商户
  685. MerNo = trade.MerNo, //渠道商户编号
  686. MerHelpFlag = MerHelpFlag >= 2 ? 1 : MerHelpFlag, //1扶持周,0稳定期,2盈利期
  687. HelpMonthCount = 0, //扶持第几个月
  688. MerBuddyType = user.MerchantType, //商户创客类型
  689. SnNo = trade.TradeSnNo, //渠道SN号
  690. TradeSerialNo = trade.ChannelSerial, //交易流水号
  691. TradeAmount = TradeAmount, //交易金额
  692. BankCardType = BankCardType, //银行卡类型
  693. QrPayFlag = QrPayFlag, //云闪付标识
  694. VipFlag = VipFlag, //会员标记
  695. PayType = PayType, //支付方式
  696. BrandId = BrandId, //品牌
  697. Remark = trade.Remark, //备注
  698. TopUserId = TopUserId, //顶级创客
  699. MerUserId = pos.UserId, //商户直属创客
  700. ActStatus = ActStatus,
  701. CreateMan = trade.AgentNo,
  702. UpdateMan = trade.BankCardType,
  703. SeoKeyword = trade.SerEntryMode,
  704. SeoDescription = trade.TradeType,
  705. Sort = (int)SettleFee,
  706. TradeDate = pos.BindingTime,
  707. }).Entity;
  708. db.SaveChanges();
  709. string TradeMonth = trade.CreateDate == null ? DateTime.Now.ToString("yyyyMM") : trade.CreateDate.Value.ToString("yyyyMM");
  710. PublicFunction.SplitTradeRecord(add, TradeMonth);
  711. //统计商户交易额
  712. string TradeDate = trade.CreateDate == null ? DateTime.Now.ToString("yyyyMMdd") : trade.CreateDate.Value.ToString("yyyyMMdd");
  713. RedisDbconn.Instance.AddList("StatMerTradeAmountQueue", "{\"TradeDate\":\"" + TradeDate + "\",\"TradeAmount\":\"" + TradeAmount + "\",\"MerchantId\":\"" + pos.BindMerchantId + "\",\"BrandId\":\"" + BrandId + "\"}");
  714. }
  715. db.SpOrderNos.Add(new PxcModels.SpOrderNos()
  716. {
  717. OrderNo = trade.TradeSerialNo
  718. });
  719. db.SaveChanges();
  720. }
  721. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  722. if (edit != null)
  723. {
  724. edit.Status = 2;
  725. }
  726. spdb.SaveChanges();
  727. }
  728. else
  729. {
  730. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  731. if (edit != null)
  732. {
  733. edit.Status = 0;
  734. }
  735. spdb.SaveChanges();
  736. }
  737. }
  738. else
  739. {
  740. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  741. if (edit != null)
  742. {
  743. edit.Status = 0;
  744. }
  745. spdb.SaveChanges();
  746. }
  747. }
  748. }
  749. spdb.Dispose();
  750. db.Dispose();
  751. }
  752. catch (Exception ex)
  753. {
  754. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP交易数据到MAIN异常");
  755. }
  756. Thread.Sleep(500);
  757. }
  758. }
  759. public void StartTradeStatus()
  760. {
  761. Thread th = new Thread(StartTradeStatusDo);
  762. th.IsBackground = true;
  763. th.Start();
  764. }
  765. public void StartTradeStatusDo()
  766. {
  767. while (true)
  768. {
  769. try
  770. {
  771. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  772. WebCMSEntities spdb = new WebCMSEntities();
  773. DateTime start = DateTime.Now.AddDays(-10);
  774. DateTime end = DateTime.Now.AddMinutes(-10);
  775. int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/TradeRecordId.txt")));
  776. IQueryable<TradeRecord> trades = spdb.TradeRecord.Where(m => m.Id >= StartId && m.CreateDate >= start && m.CreateDate < end && m.Status == 0).OrderBy(m => m.CreateDate).Take(20);
  777. foreach (TradeRecord trade in trades.ToList())
  778. {
  779. int Status = 1;
  780. bool op = db.PosMachinesTwo.Any(m => m.PosSn == trade.TradeSnNo);
  781. if(!op)
  782. {
  783. Status = -1;
  784. }
  785. else
  786. {
  787. op = db.PosMerchantInfo.Any(m => m.KqSnNo == trade.TradeSnNo);
  788. if(!op)
  789. {
  790. Status = -2;
  791. }
  792. }
  793. TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
  794. if (edit != null)
  795. {
  796. edit.Status = Status;
  797. spdb.SaveChanges();
  798. }
  799. }
  800. db.Dispose();
  801. spdb.Dispose();
  802. }
  803. catch (Exception ex)
  804. {
  805. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "恢复原始交易没有统计上的数据异常");
  806. }
  807. Thread.Sleep(10000);
  808. }
  809. }
  810. //机具激活逻辑
  811. public void ActPos(PxcModels.WebCMSEntities db, PxcModels.PosMachinesTwo pos, decimal CheckMoney, int CheckDays, bool PrizeFlag = true, string ActivationTime = "")
  812. {
  813. DateTime now = DateTime.Now;
  814. if(!string.IsNullOrEmpty(ActivationTime))
  815. {
  816. now = DateTime.Parse(ActivationTime);
  817. }
  818. DateTime TransferTime = pos.TransferTime == null ? DateTime.Parse("2050-01-01") : pos.TransferTime.Value;
  819. int minute = 30;
  820. if(pos.BrandId == 14 && pos.PosSn.StartsWith("CS"))
  821. {
  822. minute = 60 * 24 * 30;
  823. }
  824. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:贷记卡是否刷满" + CheckMoney + ";贷记卡交易:" + pos.CreditTrade + "");
  825. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:是否有机具所属人;机具所属人Id:" + pos.BuyUserId + "");
  826. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:是否未激活;机具激活状态:" + pos.ActivationState + "");
  827. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:划拨时间不能超过绑定时间" + minute + "分钟;划拨时间:" + TransferTime.ToString() + ",绑定时间:" + pos.BindingTime.Value.ToString());
  828. if (pos.CreditTrade >= CheckMoney && pos.BuyUserId > 0 && pos.ActivationState == 0 && TransferTime.AddMinutes(-minute) < pos.BindingTime)
  829. {
  830. Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件");
  831. pos.ActivationState = 1;
  832. pos.ActivationTime = now;
  833. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:是否营训");
  834. if(pos.CardType == 101)
  835. {
  836. Utils.Instance.PrizeRecord(1, pos.PosSn, "是营训");
  837. pos.IsPurchase = 1;
  838. Utils.Instance.PrizeRecord(1, pos.PosSn, "取消循环资格");
  839. }
  840. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:是否关联商户信息");
  841. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  842. if (merchant != null)
  843. {
  844. merchant.ActiveStatus = 1;
  845. merchant.MerStandardDate = now;
  846. db.SaveChanges();
  847. Utils.Instance.PrizeRecord(1, pos.PosSn, "已关联");
  848. //发放开机奖励
  849. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:绑定时间不超过" + CheckDays + "天;当前绑定时间:" + pos.BindingTime.ToString() + "");
  850. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:非营训;当前类型:" + pos.CardType);
  851. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:奖励开关;当前:" + PrizeFlag);
  852. if(pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100 && PrizeFlag)
  853. {
  854. Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放开机奖励");
  855. RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
  856. if(pos.BrandId == 14)
  857. {
  858. Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放运营中心奖励");
  859. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  860. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:大盟主标记;当前大盟主Id:" + pos.LeaderUserId);
  861. PxcModels.Leaders leader = db.Leaders.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new PxcModels.Leaders();
  862. DateTime ExpiredDate = leader.ExpiredDate == null ? DateTime.Parse("1900-01-01") : leader.ExpiredDate.Value;
  863. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:盟主是否过期;过期时间:" + pos.LeaderUserId);
  864. if(pos.LeaderUserId > 0 && ExpiredDate > now)
  865. {
  866. Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放大盟主奖励");
  867. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  868. }
  869. }
  870. }
  871. }
  872. //发放大盟主奖励
  873. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  874. if(pos.BrandId != 14)
  875. {
  876. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:有押金;当前押金:" + Deposit);
  877. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:大盟主标记;当前大盟主Id:" + pos.LeaderUserId);
  878. PxcModels.Leaders leader = db.Leaders.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new PxcModels.Leaders();
  879. DateTime ExpiredDate = leader.ExpiredDate == null ? DateTime.Parse("1900-01-01") : leader.ExpiredDate.Value;
  880. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:盟主是否过期;过期时间:" + pos.LeaderUserId);
  881. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:绑定时间不超过" + CheckDays + "天;绑定时间:" + pos.BindingTime.Value.ToString() + "");
  882. }
  883. 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)
  884. {
  885. Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放大盟主奖励");
  886. RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
  887. }
  888. //发放运营中心奖励
  889. if (Deposit > 0 && pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100 && PrizeFlag)
  890. {
  891. Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放运营中心奖励");
  892. RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
  893. }
  894. if(pos.CardType < 100)
  895. {
  896. //统计激活数
  897. RedisDbconn.Instance.AddList("StatActQueue", "{\"TradeDate\":\"" + now.ToString("yyyyMMdd") + "\",\"UserId\":\"" + pos.BuyUserId + "\",\"BrandId\":\"" + pos.BrandId + "\"}");
  898. //运营中心额度变更
  899. OpAmountItem item = new OpAmountItem()
  900. {
  901. UserId = pos.OpId,
  902. OperateType = 1,
  903. ChangeType = 9,
  904. Remark = "机具激活",
  905. UseAmount = pos.OpReserve1 + pos.OpReserve2 + pos.OpReserve3,
  906. UseValidForGetAmount = pos.OpReserve2,
  907. UseTotalAmt = pos.OpReserve1,
  908. UseValidAmount = pos.OpReserve3,
  909. DataType = 2,
  910. DataId = pos.Id,
  911. };
  912. RedisDbconn.Instance.AddList("OperateAmountRecordServiceQueue", item);
  913. }
  914. //清理预扣款
  915. RedisDbconn.Instance.AddList("PosWithholdQueue", "{\"UserId\":\"" + pos.BuyUserId + "\",\"SnNo\":\"" + pos.PosSn + "\"}");
  916. //推送激活数据
  917. if(Deposit == 0) Utils.Instance.SendActData(pos);
  918. }
  919. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:已激活;当前状态:" + pos.ActivationState);
  920. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:绑定后台30天到60天之间;绑定时间:" + pos.BindingTime.Value.ToString() + "");
  921. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:贷记卡是否刷满10000;贷记卡交易:" + pos.CreditTrade + "");
  922. Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:非营训;当前类型:" + pos.CardType);
  923. if(pos.ActivationState == 1 && pos.BindingTime.Value.AddDays(30) <= DateTime.Now && pos.BindingTime.Value.AddDays(60) > DateTime.Now && pos.CreditTrade >= 10000 && pos.CardType < 100)
  924. {
  925. Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放盟主开机奖励");
  926. RedisDbconn.Instance.AddList("LeaderRewardQueue", pos.Id.ToString());
  927. }
  928. }
  929. //立刷格外奖励
  930. public void LiShuaActPrize(PxcModels.WebCMSEntities db, PxcModels.PosMachinesTwo pos, int prize)
  931. {
  932. PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  933. if(merchant != null)
  934. {
  935. PxcModels.Users getUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new PxcModels.Users();
  936. int BuyTopUserId = 0;
  937. string ParentNav = getUser.ParentNav;
  938. if (!string.IsNullOrEmpty(ParentNav))
  939. {
  940. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  941. if (ParentNavList.Length > 1)
  942. {
  943. BuyTopUserId = int.Parse(ParentNavList[1]);
  944. }
  945. else if (ParentNavList.Length == 1)
  946. {
  947. BuyTopUserId = int.Parse(ParentNavList[0]);
  948. }
  949. }
  950. if(prize == 50)
  951. {
  952. StatService.Instance.doActiveReward(db, merchant, pos, getUser.Id, getUser.ParentNav, BuyTopUserId, prize);
  953. }
  954. if(prize == 40)
  955. {
  956. StatService.Instance.doActiveReward(db, merchant, pos, getUser.Id, getUser.ParentNav, BuyTopUserId, prize, 12);
  957. }
  958. if(prize == 30)
  959. {
  960. StatService.Instance.doActiveReward(db, merchant, pos, getUser.Id, getUser.ParentNav, BuyTopUserId, prize, 133);
  961. }
  962. }
  963. }
  964. private int GetLeShuaHaiKe(int UserId, int BrandId)
  965. {
  966. if(DateTime.Now >= DateTime.Parse("2023-08-01 00:00:00"))
  967. {
  968. return 0;
  969. }
  970. int ActStatus = 1;
  971. try
  972. {
  973. string Date = DateTime.Now.ToString("yyyyMMdd");
  974. int checkNum = 0;
  975. if(Date == "20230720") checkNum = 12;
  976. if(Date == "20230721") checkNum = 11;
  977. if(Date == "20230722") checkNum = 10;
  978. if(Date == "20230723") checkNum = 9;
  979. if(Date == "20230724") checkNum = 8;
  980. if(Date == "20230725") checkNum = 7;
  981. if(Date == "20230726") checkNum = 6;
  982. if(Date == "20230727") checkNum = 5;
  983. if(Date == "20230728") checkNum = 4;
  984. if(Date == "20230729") checkNum = 3;
  985. if(Date == "20230730") checkNum = 2;
  986. if(Date == "20230731") checkNum = 1;
  987. int check = int.Parse(function.CheckInt(RedisDbconn.Instance.Get<string>("lscut:" + UserId + ":" + BrandId + ":" + Date)));
  988. if(check <= checkNum)
  989. {
  990. check += 1;
  991. RedisDbconn.Instance.Set("lscut:" + UserId + ":" + BrandId + ":" + Date, check.ToString());
  992. }
  993. else
  994. {
  995. ActStatus = -1;
  996. RedisDbconn.Instance.Set("lscut:" + UserId + ":" + BrandId + ":" + Date, "0");
  997. }
  998. }
  999. catch(Exception ex)
  1000. {
  1001. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "乐刷海科计数异常");
  1002. }
  1003. return ActStatus;
  1004. }
  1005. }
  1006. }