12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using MySystem.SpModels;
- using Library;
- using LitJson;
- using System.Threading;
- namespace MySystem
- {
- public class SycnSpTradeService
- {
- public readonly static SycnSpTradeService Instance = new SycnSpTradeService();
- private SycnSpTradeService()
- { }
- public void Start()
- {
- Thread th = new Thread(StartDo);
- th.IsBackground = true;
- th.Start();
- }
- public void StartDo()
- {
- while (true)
- {
- try
- {
- List<string> BrandIds = new List<string>();
- BrandIds.Add("14");
- BrandIds.Add("17");
- BrandIds.Add("23");
- BrandIds.Add("24");
- BrandIds.Add("25");
- BrandIds.Add("26");
- WebCMSEntities spdb = new WebCMSEntities();
- PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
- DateTime start = DateTime.Now.AddDays(-10);
- DateTime end = DateTime.Now.AddMinutes(-1);
- int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/TradeRecordId.txt")));
- 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);
- foreach (TradeRecord trade in trades.ToList())
- {
- bool op = true;
- bool isDeposit = false;
- if (trade.SerEntryMode == "N" && trade.ProductType == "1") //金控押金获取
- {
- if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900)
- {
- op = false;
- PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == trade.TradeSnNo) ?? new PxcModels.MachineForSnNo();
- PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
- if (pos != null)
- {
- if(string.IsNullOrEmpty(pos.SeoKeyword)) Utils.Instance.SendActData(pos);
- pos.SeoKeyword = trade.TradeAmount.ToString("f2");
- db.SaveChanges();
- isDeposit = true;
- function.WriteLog("押金监控:" + trade.MerNo, "服务费奖励发放日志");
- }
- TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
- if (edit != null)
- {
- edit.Status = 2;
- }
- spdb.SaveChanges();
- }
- }
- else if ((trade.ProductType == "4" || trade.ProductType == "8" || trade.ProductType == "9") && (trade.Field2 == "5200" || trade.Field2 == "5800")) //乐刷海科费率0.52,0.58的不入库
- {
- op = false;
- TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
- if (edit != null)
- {
- edit.Status = 2;
- }
- spdb.SaveChanges();
- }
- else if (trade.SerEntryMode == "1" && trade.ProductType == "10") //联动押金获取
- {
- if (trade.TradeAmount == 99 || trade.TradeAmount == 199 || trade.TradeAmount == 299)
- {
- op = false;
- PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == trade.TradeSnNo) ?? new PxcModels.MachineForSnNo();
- PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
- if (pos != null)
- {
- if(string.IsNullOrEmpty(pos.SeoKeyword)) Utils.Instance.SendActData(pos);
- pos.SeoKeyword = trade.TradeAmount.ToString("f2");
- db.SaveChanges();
- isDeposit = true;
- function.WriteLog("押金监控:" + trade.MerNo, "服务费奖励发放日志");
- }
- TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
- if (edit != null)
- {
- edit.Status = 2;
- }
- spdb.SaveChanges();
- }
- }
- else if (trade.SerEntryMode == "40" && trade.ProductType == "12") //盒易付押金获取
- {
- if (trade.TradeAmount == 99 || trade.TradeAmount == 199 || trade.TradeAmount == 299)
- {
- op = false;
- PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == trade.TradeSnNo) ?? new PxcModels.MachineForSnNo();
- PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
- if (pos != null)
- {
- if(string.IsNullOrEmpty(pos.SeoKeyword)) Utils.Instance.SendActData(pos);
- pos.SeoKeyword = trade.TradeAmount.ToString("f2");
- PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
- db.MerchantDepositRecord.Add(new PxcModels.MerchantDepositRecord()
- {
- CreateDate = DateTime.Now,
- SnNo = pos.PosSn,
- MerNo = function.CheckNull(merchant.KqMerNo),
- DepositAmount = trade.TradeAmount,
- UserId = pos.BuyUserId,
- AgentNo = function.CheckNull(merchant.MgrNo),
- OrderId = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
- });
- db.SaveChanges();
- isDeposit = true;
- function.WriteLog("押金监控:" + trade.MerNo, "服务费奖励发放日志");
- }
- TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
- if (edit != null)
- {
- edit.Status = 2;
- }
- spdb.SaveChanges();
- }
- }
- else if (trade.TradeType == "40" && trade.ProductType == "15") //联客宝押金获取
- {
- if (trade.TradeAmount == 99 || trade.TradeAmount == 199 || trade.TradeAmount == 299)
- {
- op = false;
- PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == trade.TradeSnNo) ?? new PxcModels.MachineForSnNo();
- PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
- if (pos != null)
- {
- if(string.IsNullOrEmpty(pos.SeoKeyword)) Utils.Instance.SendActData(pos);
- pos.SeoKeyword = trade.TradeAmount.ToString("f2");
- PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
- db.MerchantDepositRecord.Add(new PxcModels.MerchantDepositRecord()
- {
- CreateDate = DateTime.Now,
- SnNo = pos.PosSn,
- MerNo = merchant.KqMerNo,
- DepositAmount = trade.TradeAmount,
- UserId = pos.BuyUserId,
- AgentNo = function.CheckNull(merchant.MgrNo),
- OrderId = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
- });
- db.SaveChanges();
- isDeposit = true;
- function.WriteLog("押金监控:" + trade.MerNo, "服务费奖励发放日志");
- }
- TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
- if (edit != null)
- {
- edit.Status = 2;
- }
- spdb.SaveChanges();
- }
- }
- if (trade.DiscountRateFlag == "True")
- {
- op = false;
- TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
- if (edit != null)
- {
- edit.Status = 2;
- }
- spdb.SaveChanges();
- }
- if(trade.ProductType == "7" && trade.TradeStatus != "00")
- {
- op = false;
- TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
- if (edit != null)
- {
- edit.Status = 2;
- }
- spdb.SaveChanges();
- }
- if (op)
- {
- PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == trade.TradeSnNo);
- if (pos != null)
- {
- PxcModels.KqProducts brand = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new PxcModels.KqProducts();
- if (pos.BindMerchantId > 0)
- {
- PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(user.ParentNav))
- {
- TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
- }
- bool check = db.SpOrderNos.Any(m => m.OrderNo == trade.TradeSerialNo);
- if (!check)
- {
- decimal TradeAmount = trade.TradeAmount;
- int BankCardType = -1;
- int QrPayFlag = 0;
- int VipFlag = 0;
- int PayType = 0;
- if (pos.BrandId == 1 || pos.BrandId == 3)
- {
- TradeAmount = TradeAmount / 100;
- BankCardType = int.Parse(trade.BankCardType);
- if (trade.TradeType == "02") QrPayFlag = 1;
- else if (trade.TradeType == "NQ") PayType = 1;
- if (trade.SettleMethod == "E") VipFlag = 1;
- }
- else if (pos.BrandId == 2)
- {
- if (trade.TradeType == "CREDIT_BY_CARD")
- {
- BankCardType = 1;
- }
- else
- {
- BankCardType = 0;
- }
- if (trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
- }
- else if (pos.BrandId == 4 || pos.BrandId == 5)
- {
- TradeAmount = TradeAmount / 100;
- if (trade.BankCardType == "100")
- {
- BankCardType = 1;
- }
- else if (trade.BankCardType == "200")
- {
- BankCardType = 0;
- }
- if (trade.TradeType == "200") QrPayFlag = 1;
- if (trade.Field1 == "1") VipFlag = 1;
- }
- else if (pos.BrandId == 6 || pos.BrandId == 22)
- {
- TradeAmount = TradeAmount / 100;
- if (trade.BankCardType == "02" || trade.BankCardType == "12")
- {
- BankCardType = 1;
- }
- else
- {
- BankCardType = 0;
- }
- }
- else if (pos.BrandId == 7)
- {
- TradeAmount = TradeAmount / 100;
- if (trade.BankCardType == "OA" || trade.BankCardType == "CC" || trade.BankCardType == "SCC")
- {
- BankCardType = 1;
- }
- else
- {
- BankCardType = 0;
- }
- }
- else if (pos.BrandId == 8 || pos.BrandId == 9)
- {
- TradeAmount = TradeAmount / 100;
- if (trade.BankCardType == "100")
- {
- BankCardType = 1;
- }
- else if (trade.BankCardType == "200")
- {
- BankCardType = 0;
- }
- if (trade.TradeType == "200") QrPayFlag = 1;
- if (trade.Field1 == "1") VipFlag = 1;
- }
- else if (pos.BrandId == 10 || pos.BrandId == 11)
- {
- if (trade.BankCardType == "01")
- {
- BankCardType = 1;
- }
- else if (trade.BankCardType == "00")
- {
- BankCardType = 0;
- }
- if (trade.TradeType == "F010") QrPayFlag = 1;
- PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if(merchant != null)
- {
- bool flag = false;
- if(function.CheckNull(merchant.MerchantName).Contains("*")) merchant.MerchantName = trade.MerName;
- if(string.IsNullOrEmpty(merchant.MerIdcardNo) && !string.IsNullOrEmpty(trade.Field2))
- {
- merchant.MerIdcardNo = trade.Field2.ToUpper(); //商户身份证号
- flag = true;
- }
- if(!string.IsNullOrEmpty(trade.Field1))
- {
- merchant.MerchantMobile = trade.Field1; //商户手机号
- }
- if(flag)
- {
- string startNo = merchant.MerIdcardNo.Substring(0, 6);
- string endNo = merchant.MerIdcardNo.Substring(merchant.MerIdcardNo.Length - 4, 4).ToUpper();
- string Name = merchant.MerchantName;
- Name = Name.Replace("*", "");
- function.WriteLog(DateTime.Now.ToString() + "-----startNo:" + startNo + ",endNo:" + endNo + ",Name:" + Name, "监控机具是否互斥");
- PxcModels.PosMerchantInfo chk = db.PosMerchantInfo.FirstOrDefault(m => m.MerIdcardNo.StartsWith(startNo) && m.MerIdcardNo.EndsWith(endNo) && m.MerchantName.Contains(Name));
- if(chk != null)
- {
- function.WriteLog("互斥机具---sn:" + chk.KqSnNo + ",merno:" + chk.KqMerNo + ",name:" + chk.MerchantName, "监控机具是否互斥");
- pos.IsFirst = 0;
- }
- }
- db.SaveChanges();
- }
- }
- else if (pos.BrandId == 12 || pos.BrandId == 13) //盒易付
- {
- if (trade.BankCardType == "C")
- {
- BankCardType = 1;
- }
- else if (trade.BankCardType == "D")
- {
- BankCardType = 0;
- }
- if (trade.Field3 == "1") QrPayFlag = 1;
- }
- else if (pos.BrandId == 15 || pos.BrandId == 16) //联客宝
- {
- TradeAmount = TradeAmount / 100;
- // 支付类型
- // 01-内卡借记卡
- // 02-内卡贷记卡
- // 03-银联二维码
- // 11-外卡借记卡
- // 12-外卡贷记卡
- // 30-微信
- // 31-支付宝
- // M3-扫码(银联二维码、微信、支付宝)
- if (trade.BankCardType == "02")
- {
- BankCardType = 1;
- }
- else
- {
- BankCardType = 0;
- }
- // if (trade.SerEntryMode == "1") QrPayFlag = 1;
- }
- int BrandId = pos.BrandId;
- // int BrandId = int.Parse(trade.ProductType);
- // if (BrandId == 1 && trade.MerNo.StartsWith("M900"))
- // {
- // BrandId = 3;
- // }
- // if (BrandId == 4 && trade.DeviceType == "200")
- // {
- // BrandId = 5;
- // }
- decimal SourceTradeAmount = TradeAmount;
- if (pos.Sort == 0 && pos.BrandId == 7)
- {
- decimal deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
- if (deposit > 0)
- {
- int SftStartId = RedisDbconn.Instance.Get<int>("SftTradeChkId");
- PxcModels.TradeRecord chk = db.TradeRecord.FirstOrDefault(m => m.Id > SftStartId && m.SnNo == pos.PosSn);
- if(chk == null)
- {
- TradeAmount -= deposit;
- }
- else
- {
- chk.TradeAmount -= deposit;
- }
- pos.Sort = 1;
- }
- }
- decimal CheckMoney = brand.ActTradeAmount > 0 ? brand.ActTradeAmount : 1000;
- int CheckDays = 30;
- //联动
- if(BankCardType == 1 && trade.TradeType == "M015" && (pos.BrandId == 10 || pos.BrandId == 11))
- {
- pos.CreditTrade += SourceTradeAmount;
- }
- //盒易付
- else if(BankCardType == 1 && trade.TradeType == "0" && trade.SerEntryMode != "40" && (pos.BrandId == 12 || pos.BrandId == 13))
- {
- pos.CreditTrade += SourceTradeAmount;
- }
- //联客宝
- else if(BankCardType == 1 && trade.TradeType != "40" && (pos.BrandId == 15 || pos.BrandId == 16))
- {
- pos.CreditTrade += SourceTradeAmount;
- }
- //金控
- else if((BankCardType == 1 || BankCardType == 2) && (pos.BrandId == 1 || pos.BrandId == 3))
- {
- pos.CreditTrade += SourceTradeAmount;
- }
- //开店宝
- else if (BankCardType == 1 && pos.BrandId == 2)
- {
- pos.CreditTrade += SourceTradeAmount;
- }
- //乐刷or海科
- 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))
- {
- pos.CreditTrade += SourceTradeAmount;
- }
- //立刷
- else if(BankCardType == 1 && trade.Field2 == "0104" && (pos.BrandId == 6 || pos.BrandId == 22))
- {
- pos.CreditTrade += SourceTradeAmount;
- }
- //盛付通
- else if(BankCardType == 1 && pos.BrandId == 7)
- {
- pos.CreditTrade += SourceTradeAmount;
- }
- //广电卡
- else if(pos.BrandId == 14)
- {
- pos.CreditTrade += SourceTradeAmount;
- }
- else if (BankCardType == 0)
- {
- pos.DebitCardTrade += TradeAmount;
- }
- //判断激活条件并激活
- ActPos(db, pos, CheckMoney, CheckDays);
- if (TradeAmount > 0)
- {
- ulong MerHelpFlag = 0;
- decimal DepositAmt = decimal.Parse(function.CheckNum(pos.SeoKeyword));
- DateTime ChkTime = DateTime.Now;
- if(pos.BrandId == 7)
- {
- ChkTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 03:00:00");
- }
- if (pos.DownFeeFlag == 1 && pos.DownFeeDate <= ChkTime)
- {
- if (pos.DownFee == 0.6M)
- {
- MerHelpFlag = 3;
- }
- else
- {
- MerHelpFlag = 2;
- }
- }
- else if (pos.IsFirst == 1 || pos.BrandId == 14)
- {
- string DayString = RedisDbconn.Instance.Get<string>("pobjrule:1:HelpPolicy:Days");
- int Days = int.Parse(DayString); //天数
- if (pos.BindingTime != null)
- {
- DateTime CheckTime = pos.BindingTime.Value.AddDays(Days);
- if(pos.BrandId == 7)
- {
- CheckTime = DateTime.Parse(pos.BindingTime.Value.AddDays(Days + 1).ToString("yyyy-MM-dd") + " 03:00:00");
- }
- if (CheckTime > DateTime.Now)
- {
- MerHelpFlag = 1;
- }
- }
- }
- if((pos.BrandId == 12 || pos.BrandId == 13) && pos.UpFeeFlag == 1 && pos.DownFeeFlag == 0)
- {
- MerHelpFlag = 2;
- }
- if((pos.BrandId == 10 || pos.BrandId == 11) && trade.TradeType == "T015" && MerHelpFlag == 1)
- {
- MerHelpFlag = 0;
- }
- int CapFlag = 0;
- if(BankCardType == 0 && TradeAmount >= 1666.67M)
- {
- CapFlag = 1;
- }
- string HelpProfitFlag = "";
- bool checkHelpProfit = db.HelpProfitMerchantForUser.Any(m => m.MerchantId == pos.BindMerchantId);
- if(checkHelpProfit)
- {
- HelpProfitFlag = "HelpProfit";
- }
- int ActStatus = pos.ActivationState;
- // if(BrandId == 4 || BrandId == 5 || BrandId == 8 || BrandId == 9)
- // {
- // ActStatus = GetLeShuaHaiKe(pos.UserId, BrandId);
- // }
- int Version = 0;
- if(MerHelpFlag == 2) Version = 1;
- if(MerHelpFlag == 3) Version = 2;
- //盒易付和来客吧电签,稳定期自动转到稳定期A
- if((pos.BrandId == 12 || pos.BrandId == 13) && MerHelpFlag == 0 && Version == 0)
- {
- Version = 1;
- }
- if(pos.BrandId >= 23 && pos.BrandId <= 26)
- {
- MerHelpFlag = 1;
- Version = 0;
- }
- decimal SettleFee = trade.SettleFee * 100;
- PxcModels.TradeRecord add = db.TradeRecord.Add(new PxcModels.TradeRecord()
- {
- ParentNav = user.ParentNav,
- CreateDate = trade.CreateDate,
- UpdateDate = trade.UpdateDate,
- RecordNo = trade.TradeSerialNo, //单号
- UserId = pos.UserId, //创客
- MerchantId = pos.BindMerchantId, //商户
- MerNo = trade.MerNo, //渠道商户编号
- MerHelpFlag = MerHelpFlag >= 2 ? 1 : MerHelpFlag, //1扶持周,0稳定期,2盈利期
- HelpMonthCount = 0, //扶持第几个月
- MerBuddyType = user.MerchantType, //商户创客类型
- SnNo = trade.TradeSnNo, //渠道SN号
- TradeSerialNo = trade.ChannelSerial, //交易流水号
- TradeAmount = TradeAmount, //交易金额
- BankCardType = BankCardType, //银行卡类型
- QrPayFlag = QrPayFlag, //云闪付标识
- CapFlag = CapFlag, //借记卡是否封顶
- VipFlag = VipFlag, //会员标记
- PayType = PayType, //支付方式
- BrandId = BrandId, //品牌
- Remark = trade.Remark, //备注
- TopUserId = TopUserId, //顶级创客
- MerUserId = pos.UserId, //商户直属创客M
- SeoTitle = HelpProfitFlag,
- Version = Version,
- ActStatus = ActStatus,
- CreateMan = trade.AgentNo,
- UpdateMan = trade.BankCardType,
- SeoKeyword = trade.SerEntryMode,
- SeoDescription = trade.TradeType,
- Sort = (int)SettleFee,
- TradeDate = pos.BindingTime,
- }).Entity;
- db.SaveChanges();
- string TradeMonth = trade.CreateDate == null ? DateTime.Now.ToString("yyyyMM") : trade.CreateDate.Value.ToString("yyyyMM");
- PublicFunction.SplitTradeRecord(add, TradeMonth);
- //统计商户交易额
- string TradeDate = trade.CreateDate == null ? DateTime.Now.ToString("yyyyMMdd") : trade.CreateDate.Value.ToString("yyyyMMdd");
- RedisDbconn.Instance.AddList("StatMerTradeAmountQueue", "{\"TradeDate\":\"" + TradeDate + "\",\"TradeAmount\":\"" + TradeAmount + "\",\"MerchantId\":\"" + pos.BindMerchantId + "\",\"BrandId\":\"" + BrandId + "\"}");
- }
- db.SpOrderNos.Add(new PxcModels.SpOrderNos()
- {
- OrderNo = trade.TradeSerialNo
- });
- db.SaveChanges();
-
- // 推荐王逻辑(交易)
- // if(TradeAmount > 0)
- // {
- // string Send = "{\"Kind\":\"4\",\"Data\":{\"PosId\":\"" + pos.Id + "\",\"TradeMonth\":\"" + trade.CreateDate.Value.ToString("yyyyMM") + "\",\"TradeAmount\":\"" + TradeAmount + "\"}}";
- // RedisDbconn.Instance.AddList("RecommendActStatQueue", Send);
- // }
- }
- TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
- if (edit != null)
- {
- edit.Status = 2;
- }
- spdb.SaveChanges();
- }
- else
- {
- TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
- if (edit != null)
- {
- edit.Status = 0;
- }
- spdb.SaveChanges();
- }
- }
- else
- {
- TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
- if (edit != null)
- {
- edit.Status = 0;
- }
- spdb.SaveChanges();
- }
- }
- if(isDeposit)
- {
- // function.WriteLog("押金收到:" + trade.MerNo, "服务费奖励发放日志");
- // PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
- // function.WriteLog("MachineForMerNo:" + posFor.MerNo, "服务费奖励发放日志");
- PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == trade.TradeSnNo) ?? new PxcModels.PosMachinesTwo();
- function.WriteLog("PosMachinesTwo:" + pos.PosSn, "服务费奖励发放日志");
- PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
- function.WriteLog("PosMerchantInfo:" + merchant.KqMerNo, "服务费奖励发放日志");
- StatService.Instance.PreActPrize(db, pos, merchant, pos.SeoKeyword);
- }
- }
- spdb.Dispose();
- db.Dispose();
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP交易数据到MAIN异常");
- }
- Thread.Sleep(500);
- }
- }
- public void StartSim()
- {
- Thread th = new Thread(StartSimDo);
- th.IsBackground = true;
- th.Start();
- }
- public void StartSimDo()
- {
- while (true)
- {
- try
- {
- WebCMSEntities spdb = new WebCMSEntities();
- PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
- DateTime start = DateTime.Now.AddDays(-40);
- int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/TradeRecordId.txt")));
- 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);
- foreach (TradeRecord trade in trades.ToList())
- {
- bool op = true;
- if (op)
- {
- PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
- PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
- if (pos != null)
- {
- PxcModels.KqProducts brand = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new PxcModels.KqProducts();
- if (pos.BindMerchantId > 0)
- {
- PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(user.ParentNav))
- {
- TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
- }
- bool check = db.SpOrderNos.Any(m => m.OrderNo == trade.TradeSerialNo);
- if (!check)
- {
- decimal TradeAmount = trade.TradeAmount;
- int BankCardType = -1;
- int QrPayFlag = 0;
- int VipFlag = 0;
- int PayType = 0;
- BankCardType = int.Parse(trade.BankCardType);
- int BrandId = pos.BrandId;
- decimal SourceTradeAmount = TradeAmount;
- if (TradeAmount > 0)
- {
- ulong MerHelpFlag = 0;
- string DayString = RedisDbconn.Instance.Get<string>("pobjrule:" + pos.BrandId + ":HelpPolicy:Days");
- int Days = int.Parse(DayString); //天数
- if (pos.BindingTime != null)
- {
- if (pos.BindingTime.Value.AddDays(Days) > DateTime.Now)
- {
- MerHelpFlag = 1;
- }
- }
- int ActStatus = pos.ActivationState;
- decimal SettleFee = trade.SettleFee * 100;
- PxcModels.TradeRecord add = db.TradeRecord.Add(new PxcModels.TradeRecord()
- {
- ParentNav = user.ParentNav,
- CreateDate = trade.CreateDate,
- UpdateDate = trade.UpdateDate,
- RecordNo = trade.TradeSerialNo, //单号
- UserId = pos.UserId, //创客
- MerchantId = pos.BindMerchantId, //商户
- MerNo = trade.MerNo, //渠道商户编号
- MerHelpFlag = MerHelpFlag >= 2 ? 1 : MerHelpFlag, //1扶持周,0稳定期,2盈利期
- HelpMonthCount = 0, //扶持第几个月
- MerBuddyType = user.MerchantType, //商户创客类型
- SnNo = trade.TradeSnNo, //渠道SN号
- TradeSerialNo = trade.ChannelSerial, //交易流水号
- TradeAmount = TradeAmount, //交易金额
- BankCardType = BankCardType, //银行卡类型
- QrPayFlag = QrPayFlag, //云闪付标识
- VipFlag = VipFlag, //会员标记
- PayType = PayType, //支付方式
- BrandId = BrandId, //品牌
- Remark = trade.Remark, //备注
- TopUserId = TopUserId, //顶级创客
- MerUserId = pos.UserId, //商户直属创客
- ActStatus = ActStatus,
- CreateMan = trade.AgentNo,
- UpdateMan = trade.BankCardType,
- SeoKeyword = trade.SerEntryMode,
- SeoDescription = trade.TradeType,
- Sort = (int)SettleFee,
- TradeDate = pos.BindingTime,
- }).Entity;
- db.SaveChanges();
- string TradeMonth = trade.CreateDate == null ? DateTime.Now.ToString("yyyyMM") : trade.CreateDate.Value.ToString("yyyyMM");
- PublicFunction.SplitTradeRecord(add, TradeMonth);
- //统计商户交易额
- string TradeDate = trade.CreateDate == null ? DateTime.Now.ToString("yyyyMMdd") : trade.CreateDate.Value.ToString("yyyyMMdd");
- RedisDbconn.Instance.AddList("StatMerTradeAmountQueue", "{\"TradeDate\":\"" + TradeDate + "\",\"TradeAmount\":\"" + TradeAmount + "\",\"MerchantId\":\"" + pos.BindMerchantId + "\",\"BrandId\":\"" + BrandId + "\"}");
- }
- db.SpOrderNos.Add(new PxcModels.SpOrderNos()
- {
- OrderNo = trade.TradeSerialNo
- });
- db.SaveChanges();
- }
- TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
- if (edit != null)
- {
- edit.Status = 2;
- }
- spdb.SaveChanges();
- }
- else
- {
- TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
- if (edit != null)
- {
- edit.Status = 0;
- }
- spdb.SaveChanges();
- }
- }
- else
- {
- TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
- if (edit != null)
- {
- edit.Status = 0;
- }
- spdb.SaveChanges();
- }
- }
- }
- spdb.Dispose();
- db.Dispose();
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP交易数据到MAIN异常");
- }
- Thread.Sleep(500);
- }
- }
- public void StartTradeStatus()
- {
- Thread th = new Thread(StartTradeStatusDo);
- th.IsBackground = true;
- th.Start();
- }
- public void StartTradeStatusDo()
- {
- while (true)
- {
- try
- {
- PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
- WebCMSEntities spdb = new WebCMSEntities();
- DateTime start = DateTime.Now.AddDays(-10);
- DateTime end = DateTime.Now.AddMinutes(-10);
- int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/TradeRecordId.txt")));
- 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);
- foreach (TradeRecord trade in trades.ToList())
- {
- int Status = 1;
- bool op = db.PosMachinesTwo.Any(m => m.PosSn == trade.TradeSnNo);
- if(!op)
- {
- Status = -1;
- }
- else
- {
- op = db.PosMerchantInfo.Any(m => m.KqSnNo == trade.TradeSnNo);
- if(!op)
- {
- Status = -2;
- }
- }
- TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
- if (edit != null)
- {
- edit.Status = Status;
- spdb.SaveChanges();
- }
- }
- db.Dispose();
- spdb.Dispose();
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "恢复原始交易没有统计上的数据异常");
- }
- Thread.Sleep(10000);
- }
- }
- //机具激活逻辑
- public void ActPos(PxcModels.WebCMSEntities db, PxcModels.PosMachinesTwo pos, decimal CheckMoney, int CheckDays, bool PrizeFlag = true, string ActivationTime = "")
- {
- DateTime now = DateTime.Now;
- if(!string.IsNullOrEmpty(ActivationTime))
- {
- now = DateTime.Parse(ActivationTime);
- }
- DateTime TransferTime = pos.TransferTime == null ? DateTime.Parse("2050-01-01") : pos.TransferTime.Value;
- int minute = 30;
- if(pos.BrandId == 14 && pos.PosSn.StartsWith("CS"))
- {
- minute = 60 * 24 * 30;
- }
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:贷记卡是否刷满" + CheckMoney + ";贷记卡交易:" + pos.CreditTrade + "");
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:是否有机具所属人;机具所属人Id:" + pos.BuyUserId + "");
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:是否未激活;机具激活状态:" + pos.ActivationState + "");
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:划拨时间不能超过绑定时间" + minute + "分钟;划拨时间:" + TransferTime.ToString() + ",绑定时间:" + pos.BindingTime.Value.ToString());
- if (pos.CreditTrade >= CheckMoney && pos.BuyUserId > 0 && pos.ActivationState == 0 && TransferTime.AddMinutes(-minute) < pos.BindingTime)
- {
- Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件");
- pos.ActivationState = 1;
- pos.ActivationTime = now;
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:是否营训");
- if(pos.CardType == 101)
- {
- Utils.Instance.PrizeRecord(1, pos.PosSn, "是营训");
- pos.IsPurchase = 1;
- Utils.Instance.PrizeRecord(1, pos.PosSn, "取消循环资格");
- }
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:是否关联商户信息");
- PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (merchant != null)
- {
- merchant.ActiveStatus = 1;
- merchant.MerStandardDate = now;
- db.SaveChanges();
- Utils.Instance.PrizeRecord(1, pos.PosSn, "已关联");
- //发放开机奖励
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:绑定时间不超过" + CheckDays + "天;当前绑定时间:" + pos.BindingTime.ToString() + "");
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:非营训;当前类型:" + pos.CardType);
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:奖励开关;当前:" + PrizeFlag);
- if(pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100 && PrizeFlag)
- {
- Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放开机奖励");
- RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
- if(pos.BrandId == 14)
- {
- Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放运营中心奖励");
- RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:大盟主标记;当前大盟主Id:" + pos.LeaderUserId);
- PxcModels.Leaders leader = db.Leaders.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new PxcModels.Leaders();
- DateTime ExpiredDate = leader.ExpiredDate == null ? DateTime.Parse("1900-01-01") : leader.ExpiredDate.Value;
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:盟主是否过期;过期时间:" + pos.LeaderUserId);
- if(pos.LeaderUserId > 0 && ExpiredDate > now)
- {
- Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放大盟主奖励");
- RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
- }
- }
- }
- }
- //发放大盟主奖励
- decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
- if(pos.BrandId != 14)
- {
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:有押金;当前押金:" + Deposit);
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:大盟主标记;当前大盟主Id:" + pos.LeaderUserId);
- PxcModels.Leaders leader = db.Leaders.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new PxcModels.Leaders();
- DateTime ExpiredDate = leader.ExpiredDate == null ? DateTime.Parse("1900-01-01") : leader.ExpiredDate.Value;
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:盟主是否过期;过期时间:" + pos.LeaderUserId);
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:绑定时间不超过" + CheckDays + "天;绑定时间:" + pos.BindingTime.Value.ToString() + "");
- }
- 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)
- {
- Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放大盟主奖励");
- RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
- }
- //发放运营中心奖励
- if (Deposit > 0 && pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100 && PrizeFlag)
- {
- Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放运营中心奖励");
- RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
- }
- if(pos.CardType < 100)
- {
- //统计激活数
- RedisDbconn.Instance.AddList("StatActQueue", "{\"TradeDate\":\"" + now.ToString("yyyyMMdd") + "\",\"UserId\":\"" + pos.BuyUserId + "\",\"BrandId\":\"" + pos.BrandId + "\"}");
- //运营中心额度变更
- OpAmountItem item = new OpAmountItem()
- {
- UserId = pos.OpId,
- OperateType = 1,
- ChangeType = 9,
- Remark = "机具激活",
- UseAmount = pos.OpReserve1 + pos.OpReserve2 + pos.OpReserve3,
- UseValidForGetAmount = pos.OpReserve2,
- UseTotalAmt = pos.OpReserve1,
- UseValidAmount = pos.OpReserve3,
- DataType = 2,
- DataId = pos.Id,
- };
- RedisDbconn.Instance.AddList("OperateAmountRecordServiceQueue", item);
- }
- //清理预扣款
- RedisDbconn.Instance.AddList("PosWithholdQueue", "{\"UserId\":\"" + pos.BuyUserId + "\",\"SnNo\":\"" + pos.PosSn + "\"}");
- //推送激活数据
- if(Deposit == 0) Utils.Instance.SendActData(pos);
- }
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:已激活;当前状态:" + pos.ActivationState);
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:绑定后台30天到60天之间;绑定时间:" + pos.BindingTime.Value.ToString() + "");
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:贷记卡是否刷满10000;贷记卡交易:" + pos.CreditTrade + "");
- Utils.Instance.PrizeRecord(1, pos.PosSn, "条件:非营训;当前类型:" + pos.CardType);
- if(pos.ActivationState == 1 && pos.BindingTime.Value.AddDays(30) <= DateTime.Now && pos.BindingTime.Value.AddDays(60) > DateTime.Now && pos.CreditTrade >= 10000 && pos.CardType < 100)
- {
- Utils.Instance.PrizeRecord(1, pos.PosSn, "满足条件,发放盟主开机奖励");
- RedisDbconn.Instance.AddList("LeaderRewardQueue", pos.Id.ToString());
- }
- }
- //立刷格外奖励
- public void LiShuaActPrize(PxcModels.WebCMSEntities db, PxcModels.PosMachinesTwo pos, int prize)
- {
- PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if(merchant != null)
- {
- PxcModels.Users getUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new PxcModels.Users();
- int BuyTopUserId = 0;
- string ParentNav = getUser.ParentNav;
- if (!string.IsNullOrEmpty(ParentNav))
- {
- string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
- if (ParentNavList.Length > 1)
- {
- BuyTopUserId = int.Parse(ParentNavList[1]);
- }
- else if (ParentNavList.Length == 1)
- {
- BuyTopUserId = int.Parse(ParentNavList[0]);
- }
- }
- if(prize == 50)
- {
- StatService.Instance.doActiveReward(db, merchant, pos, getUser.Id, getUser.ParentNav, BuyTopUserId, prize);
- }
- if(prize == 40)
- {
- StatService.Instance.doActiveReward(db, merchant, pos, getUser.Id, getUser.ParentNav, BuyTopUserId, prize, 12);
- }
- if(prize == 30)
- {
- StatService.Instance.doActiveReward(db, merchant, pos, getUser.Id, getUser.ParentNav, BuyTopUserId, prize, 133);
- }
- }
- }
- private int GetLeShuaHaiKe(int UserId, int BrandId)
- {
- if(DateTime.Now >= DateTime.Parse("2023-08-01 00:00:00"))
- {
- return 0;
- }
- int ActStatus = 1;
- try
- {
- string Date = DateTime.Now.ToString("yyyyMMdd");
- int checkNum = 0;
- if(Date == "20230720") checkNum = 12;
- if(Date == "20230721") checkNum = 11;
- if(Date == "20230722") checkNum = 10;
- if(Date == "20230723") checkNum = 9;
- if(Date == "20230724") checkNum = 8;
- if(Date == "20230725") checkNum = 7;
- if(Date == "20230726") checkNum = 6;
- if(Date == "20230727") checkNum = 5;
- if(Date == "20230728") checkNum = 4;
- if(Date == "20230729") checkNum = 3;
- if(Date == "20230730") checkNum = 2;
- if(Date == "20230731") checkNum = 1;
- int check = int.Parse(function.CheckInt(RedisDbconn.Instance.Get<string>("lscut:" + UserId + ":" + BrandId + ":" + Date)));
- if(check <= checkNum)
- {
- check += 1;
- RedisDbconn.Instance.Set("lscut:" + UserId + ":" + BrandId + ":" + Date, check.ToString());
- }
- else
- {
- ActStatus = -1;
- RedisDbconn.Instance.Set("lscut:" + UserId + ":" + BrandId + ":" + Date, "0");
- }
- }
- catch(Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "乐刷海科计数异常");
- }
- return ActStatus;
- }
- }
- }
|