12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Data;
- using MySystem.PxcModels;
- using Library;
- using System.Threading;
- using Microsoft.Extensions.Hosting;
- using System.Threading.Tasks;
- namespace MySystem
- {
- public class ProfitHelperV2
- {
- public readonly static ProfitHelperV2 Instance = new ProfitHelperV2();
- private ProfitHelperV2()
- {
- }
-
- #region 获取分润规则Id
- public int GetLevelKindId(int BrandId, int Help, int BankCardType)
- {
- return RedisDbconn.Instance.Get<int>("pobjlv:kid:" + BrandId + ":" + Help + ":" + BankCardType);
- }
- #endregion
-
- #region POS分润算法
- public void StatProfit()
- {
- Thread th = new Thread(StatProfitDo);
- th.IsBackground = true;
- th.Start();
- }
- public void StatProfitDo()
- {
- while (true)
- {
- string content = RedisDbconn.Instance.RPop<string>("DoProfitQueue");
- if(!string.IsNullOrEmpty(content) && DateTime.Now.Day < 14)
- {
- StatProfiting();
- }
- else
- {
- Thread.Sleep(60000);
- }
- }
- }
- public void StatProfiting()
- {
- string Month = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
- string check = function.ReadInstance("/ProfitStat/" + Month + "-1.txt");
- if (!string.IsNullOrEmpty(check))
- {
- return;
- }
- function.WritePage("/ProfitStat/", Month + "-1.txt", DateTime.Now.ToString());
- try
- {
- WebCMSEntities db = new WebCMSEntities();
- List<int> BrandIds = db.KqProducts.OrderBy(m => m.Id).ToList().Select(m => m.Id).ToList();
- foreach (int i in BrandIds)
- {
- for (int j = 0; j <= 1; j++)
- {
- int PageNum = 1;
- bool op = true;
- while(op)
- {
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + "BrandId:" + i + ",BankCardType:" + j + ",Month:" + Month + ",PageNum:" + PageNum, "分润监控日志");
- List<ProfitResult> result = new List<ProfitResult>();
- if(i == 14)
- {
- result = StartProftForSimByDate(Month, i, PageNum);
- }
- else
- {
- result = StartProftForPosByDate(i, j, Month, PageNum);
- }
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + "result:" + result.Count, "分润监控日志");
- function.WriteLog("\r\n", "分润监控日志");
- if(result.Count > 0)
- {
- foreach (ProfitResult sub in result)
- {
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(sub.UserNav))
- {
- string[] UserNavList = sub.UserNav.Trim(',').Replace(",,", ",").Split(',');
- if (UserNavList.Length > 1)
- {
- TopUserId = int.Parse(UserNavList[1]);
- }
- else
- {
- TopUserId = int.Parse(UserNavList[0]);
- }
- }
- string RecordNo = "P" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
- decimal ProfitAmt = sub.Money;
- decimal TradeAmt = sub.TradeAmount;
- decimal ProfitRate = sub.ProfitRate;
- if (sub.IsSubsidy == 1 && j == 1)
- {
- }
- else
- {
- decimal CreditTradeAmt = 0;
- decimal CreditTradeProfit = 0;
- decimal QrCreditTradeAmt = 0;
- decimal QrCreditProfitRate = 0;
- decimal QrCreditProfitStandardRate = 0;
- decimal QrCreditAddOrSubRate = 0;
- decimal QrCreditTradeProfit = 0;
- decimal NonQrCreditTradeAmt = 0;
- decimal NotHelpCreditTradeAmt = 0;
- decimal NotHelpCreditTradeProfit = 0;
- decimal NotHelpCreditProfitRate = 0;
- decimal NotHelpCreditProfitStandardRate = 0;
- decimal NotHelpCreditAddOrSubRate = 0;
- decimal HelpCreditTradeAmt = 0;
- decimal NonQrCreditTradeProfit = 0;
- decimal HelpCreditTradeProfit = 0;
- decimal HelpCreditProfitRate = 0;
- decimal HelpCreditProfitStandardRate = 0;
- decimal HelpCreditAddOrSubRate = 0;
- decimal DebitNonCapTradeAmt = 0;
- decimal DebitCapTradeAmt = 0;
- decimal QrDebitNotCapTradeAmt = 0;
- decimal NonQrDebitNotCapTradeAmt = 0;
- decimal NotHelpDebitNonCapTradeAmt = 0;
- decimal HelpDebitNonCapTradeAmt = 0;
- decimal DebitNonTradeCapProfit = 0;
- decimal QrDebitNonTradeCapProfit = 0;
- decimal NonQrDebitNonTradeCapProfit = 0;
- decimal NotHelpDebitNonTradeCapProfit = 0;
- decimal HelpDebitNonTradeCapProfit = 0;
- decimal DebitTradeCapProfit = 0;
- decimal NotHelpDebitProfitRate = 0;
- decimal NotHelpDebitProfitStandardRate = 0;
- decimal NotHelpDebitAddOrSubRate = 0;
- decimal HelpDebitProfitRate = 0;
- decimal HelpDebitProfitStandardRate = 0;
- decimal HelpDebitAddOrSubRate = 0;
- decimal DebitCapSingleReward = 0;
- decimal QrDebitProfitRate = 0;
- decimal QrDebitProfitStandardRate = 0;
- decimal QrDebitAddOrSubRate = 0;
- decimal ProfitCreditTradeProfit = 0;
- decimal ProfitCreditProfitRate = 0;
- decimal ProfitCreditTradeAmt = 0;
- decimal ProfitCreditTradeProfit2 = 0;
- decimal ProfitCreditProfitRate2 = 0;
- decimal ProfitCreditTradeAmt2 = 0;
- decimal ProfitDebitNonCapTradeAmt = 0;
- decimal ProfitDebitNonTradeCapProfit = 0;
- decimal ProfitDebitProfitRate = 0;
- if (j == 1)
- {
- CreditTradeAmt = TradeAmt;
- CreditTradeProfit = ProfitAmt;
- if (sub.QrPayFlag == 1)
- {
- QrCreditTradeAmt = TradeAmt;
- QrCreditProfitRate = ProfitRate;
- QrCreditTradeProfit = ProfitAmt;
- }
- else
- {
- NonQrCreditTradeAmt = TradeAmt;
- NonQrCreditTradeProfit = ProfitAmt;
- if(sub.HelpFlag == 1)
- {
- HelpCreditTradeProfit = ProfitAmt;
- HelpCreditProfitRate = ProfitRate;
- HelpCreditTradeAmt = TradeAmt;
- }
- else if(sub.HelpFlag == 2)
- {
- ProfitCreditTradeProfit = ProfitAmt;
- ProfitCreditProfitRate = ProfitRate;
- ProfitCreditTradeAmt = TradeAmt;
- }
- else if(sub.HelpFlag == 3)
- {
- ProfitCreditTradeProfit2 = ProfitAmt;
- ProfitCreditProfitRate2 = ProfitRate;
- ProfitCreditTradeAmt2 = TradeAmt;
- }
- else
- {
- NotHelpCreditTradeAmt = TradeAmt;
- NotHelpCreditTradeProfit = ProfitAmt;
- NotHelpCreditProfitRate = ProfitRate;
- }
- }
- }
- if (j == 0)
- {
- if (sub.Money < 1)
- {
- DebitNonCapTradeAmt = TradeAmt;
- DebitNonTradeCapProfit = ProfitAmt;
- }
- else
- {
- DebitCapTradeAmt = TradeAmt;
- DebitCapSingleReward = ProfitAmt;
- DebitTradeCapProfit = ProfitAmt;
- }
- if (sub.QrPayFlag == 1)
- {
- if (sub.Money < 1)
- {
- QrDebitNotCapTradeAmt = TradeAmt;
- QrDebitProfitRate = ProfitRate;
- QrDebitNonTradeCapProfit = ProfitAmt;
- }
- }
- else
- {
- if (sub.Money < 1)
- {
- NonQrDebitNonTradeCapProfit = ProfitAmt;
- NonQrDebitNotCapTradeAmt = TradeAmt;
- }
- if (sub.HelpFlag == 1)
- {
- if (sub.Money < 1)
- {
- HelpDebitNonCapTradeAmt = TradeAmt;
- HelpDebitNonTradeCapProfit = ProfitAmt;
- }
- HelpDebitProfitRate = ProfitRate;
- }
- else if (sub.HelpFlag >= 2)
- {
- if (sub.Money < 1)
- {
- ProfitDebitNonCapTradeAmt = TradeAmt;
- ProfitDebitNonTradeCapProfit = ProfitAmt;
- }
- ProfitDebitProfitRate = ProfitRate;
- }
- else
- {
- if (sub.Money < 1)
- {
- NotHelpDebitNonCapTradeAmt = TradeAmt;
- NotHelpDebitNonTradeCapProfit = ProfitAmt;
- }
- NotHelpDebitProfitRate = ProfitRate;
- }
- }
- }
- db.ProfitRewardRecord.Add(new ProfitRewardRecord()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- UserId = sub.UserId,
- MerchantId = sub.MerchantId,
- BrandId = sub.BrandId,
- ProfitType = sub.DirectFlag,
- TradeAmt = sub.TradeAmount,
- TradeProfit = sub.Money,
- TradeMonth = Month,
- RecordNo = RecordNo,
- TopUserId = TopUserId,
- CreditTradeAmt = CreditTradeAmt,
- QrCreditTradeAmt = QrCreditTradeAmt,
- NonQrCreditTradeAmt = NonQrCreditTradeAmt,
- NotHelpCreditTradeAmt = NotHelpCreditTradeAmt,
- HelpCreditTradeAmt = HelpCreditTradeAmt,
- DebitNonCapTradeAmt = DebitNonCapTradeAmt,
- QrDebitNotCapTradeAmt = QrDebitNotCapTradeAmt,
- NonQrDebitNotCapTradeAmt = NonQrDebitNotCapTradeAmt,
- NotHelpDebitNonCapTradeAmt = NotHelpDebitNonCapTradeAmt,
- HelpDebitNonCapTradeAmt = HelpDebitNonCapTradeAmt,
- DebitCapTradeAmt = DebitCapTradeAmt,
- CreditTradeProfit = CreditTradeProfit,
- QrCreditTradeProfit = QrCreditTradeProfit,
- NonQrCreditTradeProfit = NonQrCreditTradeProfit,
- NotHelpCreditTradeProfit = NotHelpCreditTradeProfit,
- HelpCreditTradeProfit = HelpCreditTradeProfit,
- DebitNonTradeCapProfit = DebitNonTradeCapProfit,
- QrDebitNonTradeCapProfit = QrDebitNonTradeCapProfit,
- NonQrDebitNonTradeCapProfit = NonQrDebitNonTradeCapProfit,
- NotHelpDebitNonTradeCapProfit = NotHelpDebitNonTradeCapProfit,
- HelpDebitNonTradeCapProfit = HelpDebitNonTradeCapProfit,
- DebitTradeCapProfit = DebitTradeCapProfit,
- NotHelpCreditProfitRate = NotHelpCreditProfitRate,
- NotHelpCreditProfitStandardRate = NotHelpCreditProfitStandardRate,
- NotHelpCreditAddOrSubRate = NotHelpCreditAddOrSubRate,
- HelpCreditProfitRate = HelpCreditProfitRate,
- HelpCreditProfitStandardRate = HelpCreditProfitStandardRate,
- HelpCreditAddOrSubRate = HelpCreditAddOrSubRate,
- NotHelpDebitProfitRate = NotHelpDebitProfitRate,
- NotHelpDebitProfitStandardRate = NotHelpDebitProfitStandardRate,
- NotHelpDebitAddOrSubRate = NotHelpDebitAddOrSubRate,
- HelpDebitProfitRate = HelpDebitProfitRate,
- HelpDebitProfitStandardRate = HelpDebitProfitStandardRate,
- HelpDebitAddOrSubRate = HelpDebitAddOrSubRate,
- DebitCapSingleReward = DebitCapSingleReward,
- QrCreditProfitRate = QrCreditProfitRate,
- QrCreditProfitStandardRate = QrCreditProfitStandardRate,
- QrCreditAddOrSubRate = QrCreditAddOrSubRate,
- QrDebitProfitRate = QrDebitProfitRate,
- QrDebitProfitStandardRate = QrDebitProfitStandardRate,
- QrDebitAddOrSubRate = QrDebitAddOrSubRate,
- ProfitCreditTradeProfit = ProfitCreditTradeProfit,
- ProfitCreditProfitRate = ProfitCreditProfitRate,
- ProfitCreditTradeAmt = ProfitCreditTradeAmt,
- ProfitCreditTradeProfit2 = ProfitCreditTradeProfit2,
- ProfitCreditProfitRate2 = ProfitCreditProfitRate2,
- ProfitCreditTradeAmt2 = ProfitCreditTradeAmt2,
- ProfitDebitNonCapTradeAmt = ProfitDebitNonCapTradeAmt,
- ProfitDebitNonTradeCapProfit = ProfitDebitNonTradeCapProfit,
- ProfitDebitProfitRate = ProfitDebitProfitRate,
- });
-
- }
- }
- db.SaveChanges();
- PageNum += 1;
- }
- else
- {
- op = false;
- }
- }
- }
- }
- db.Dispose();
- }
- catch(Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "分润监控异常");
- }
- ProfitHelper.Instance.StatProfit();
- }
- public List<ProfitResult> StartProftForPosByDate(int BrandId, int BankCardType, string Month, int PageNum = 1)
- {
-
-
- int PageSize = 200;
- int SkipNum = (PageNum - 1) * PageSize;
- string LimitString = " limit " + PageSize;
- if(PageNum > 1)
- {
- LimitString = " limit " + SkipNum + "," + PageSize;
- }
- List<ProfitResult> result = new List<ProfitResult>();
- ProfitObjects obj = RedisDbconn.Instance.Get<ProfitObjects>("pobj" + BrandId);
- if (obj.Status == 1)
- {
- string sqlstr = "";
- if (BankCardType == 1)
- {
- sqlstr = "select UserId,QrPayFlag,HelpDirectTradeAmt,NotHelpDirectTradeAmt,ProfitDirectTradeAmt from CreditTradeDaySummary" + Month + " where BrandId=" + BrandId + LimitString;
- }
- if (BankCardType == 0)
- {
- sqlstr = "select UserId,QrPayFlag,HelpDirectDebitTradeAmt,NotHelpDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpDirectDebitCapNum,ProfitDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum from DebitTradeDaySummary" + Month + " where BrandId=" + BrandId + LimitString;
- }
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + sqlstr, "分润监控日志");
- DataTable dt = GetDataTable(sqlstr);
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + dt.Rows.Count.ToString(), "分润监控日志");
- if(dt.Rows.Count > 0)
- {
- foreach (DataRow dr in dt.Rows)
- {
- WebCMSEntities dbnew = new WebCMSEntities();
- try
- {
- int UserId = int.Parse(dr["UserId"].ToString());
- int QrPayFlag = int.Parse(dr["QrPayFlag"].ToString());
- List<UserLevelSet> levels = dbnew.UserLevelSet.ToList();
- SubUser selfUser = GetUser(UserId, Month) ?? new SubUser();
- int Days = int.Parse(RedisDbconn.Instance.Get<string>("pobjrule:" + BrandId + ":HelpPolicy:Days"));
- if (BankCardType == 0)
- {
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":借记卡", "分润监控日志");
- decimal HelpDirectDebitTradeAmt = decimal.Parse(dr[2].ToString());
- decimal NotHelpDirectDebitTradeAmt = decimal.Parse(dr[3].ToString());
- decimal ProfitDirectDebitTradeAmt = decimal.Parse(dr[8].ToString());
- decimal HelpDirectDebitCapTradeAmt = decimal.Parse(dr[4].ToString());
- decimal NotHelpDirectDebitCapTradeAmt = decimal.Parse(dr[5].ToString());
- decimal ProfitDirectDebitCapTradeAmt = decimal.Parse(dr[9].ToString());
- int HelpDirectDebitCapNum = int.Parse(dr[6].ToString().Split('.')[0]);
- int NotHelpDirectDebitCapNum = int.Parse(dr[7].ToString().Split('.')[0]);
- int ProfitDirectDebitCapNum = int.Parse(dr[10].ToString().Split('.')[0]);
- int UserLevel = selfUser.UserLevel;
- decimal getLevelProfit = (HelpDirectDebitTradeAmt + NotHelpDirectDebitTradeAmt + ProfitDirectDebitTradeAmt - HelpDirectDebitCapTradeAmt - NotHelpDirectDebitCapTradeAmt - ProfitDirectDebitCapTradeAmt) * 0.0006M + HelpDirectDebitCapNum + NotHelpDirectDebitCapNum + ProfitDirectDebitCapNum;
- result.Add(new ProfitResult()
- {
- UserId = selfUser.Id,
- UserNav = selfUser.ParentNav,
- Money = PublicFunction.NumberFormat(getLevelProfit),
- ProfitRate = 0.0006M,
- Message = "储蓄卡分润",
- BankCardType = BankCardType,
- QrPayFlag = QrPayFlag,
- BrandId = BrandId,
- DirectFlag = 1,
- IsSubsidy = 0,
- TradeAmount = HelpDirectDebitTradeAmt + NotHelpDirectDebitTradeAmt + ProfitDirectDebitTradeAmt,
- });
- }
- else
- {
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":贷记卡", "分润监控日志");
- decimal HelpDirectTradeAmt = decimal.Parse(dr[2].ToString());
- decimal NotHelpDirectTradeAmt = decimal.Parse(dr[3].ToString());
- decimal ProfitDirectTradeAmt = decimal.Parse(dr[4].ToString());
- int maxLevel = obj.MaxLevel;
- decimal diffLevelProfit = 0;
- int curLevel = 0;
- string ParentNav = selfUser.ParentNav;
- if (string.IsNullOrEmpty(ParentNav))
- {
- ParentNav = ",0,";
- }
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + ParentNav, "分润监控日志");
- if (!string.IsNullOrEmpty(ParentNav))
- {
- ParentNav += "," + UserId + ",";
- string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
- Array.Reverse(ParentNavList);
- int level = 0;
- DateTime now = DateTime.Now;
- DateTime ThisMonth = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":扶持期:" + HelpDirectTradeAmt, "分润监控日志");
- if (HelpDirectTradeAmt > 0)
- {
- level = 0;
- curLevel = 0;
- diffLevelProfit = 0;
- decimal checkProfit = HelpDirectTradeAmt * 0.0012M;
- decimal curProfit = 0;
- foreach (string UserIdString in ParentNavList)
- {
- level += 1;
- int uid = int.Parse(UserIdString);
- SubUser user = GetUser(uid, Month) ?? new SubUser();
- int UserLevel = user.PreUserLevel > user.UserLevel ? user.PreUserLevel : user.UserLevel;
- if (curLevel == maxLevel)
- {
- break;
- }
- if (UserLevel <= maxLevel && UserLevel > curLevel)
- {
- int LevelKindId = GetLevelKindId(BrandId, 1, 1);
- ProfitObjectLevels objlevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + UserLevel);
- if (objlevel != null)
- {
- decimal getLevelProfit = 0;
- if (objlevel.Percents > 0)
- {
-
- getLevelProfit += HelpDirectTradeAmt * objlevel.Percents;
- }
- if (objlevel.AddProfitVal > 0)
- {
- getLevelProfit += objlevel.AddProfitVal;
- }
- decimal money = getLevelProfit;
- getLevelProfit -= diffLevelProfit;
- if (objlevel.LevelDiff == 1)
- {
- diffLevelProfit = money;
- }
- if (getLevelProfit >= obj.MinProfitVal)
- {
- int DirectFlag = selfUser.Id == user.Id ? 1 : 0;
- result.Add(new ProfitResult()
- {
- UserId = user.Id,
- UserNav = user.ParentNav,
- Money = PublicFunction.NumberFormat(getLevelProfit),
- ProfitRate = objlevel.Percents,
- Message = "交易分润",
- BankCardType = BankCardType,
- QrPayFlag = QrPayFlag,
- DirectFlag = DirectFlag,
- BrandId = BrandId,
- IsSubsidy = 0,
- TradeAmount = HelpDirectTradeAmt,
- HelpFlag = 1,
- });
- curProfit += getLevelProfit;
- function.WriteLog(user.Id + "-" + UserLevel + "-" + HelpDirectTradeAmt + "-" + DirectFlag + "-扶持期分润:" + getLevelProfit, "分润监控日志");
- }
- }
- }
- if(curLevel < UserLevel)
- {
- curLevel = UserLevel;
- }
- }
- if(curProfit > checkProfit)
- {
- decimal more = curProfit - checkProfit;
- function.WriteLog("超标了:" + more, "分润监控日志");
- }
- }
- function.WriteLog("------------------------", "分润监控日志");
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":稳定期:" + NotHelpDirectTradeAmt, "分润监控日志");
- if (NotHelpDirectTradeAmt > 0)
- {
- level = 0;
- curLevel = 0;
- diffLevelProfit = 0;
- foreach (string UserIdString in ParentNavList)
- {
- level += 1;
- int uid = int.Parse(UserIdString);
- SubUser user = GetUser(uid, Month) ?? new SubUser();
- int UserLevel = user.PreUserLevel > user.UserLevel ? user.PreUserLevel : user.UserLevel;
- if (curLevel == maxLevel)
- {
- break;
- }
- if (UserLevel <= maxLevel && UserLevel > curLevel)
- {
- int LevelKindId = GetLevelKindId(BrandId, 0, 1);
- ProfitObjectLevels objlevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + UserLevel);
- if (objlevel != null)
- {
- decimal getLevelProfit = 0;
- if (objlevel.Percents > 0)
- {
-
- getLevelProfit += NotHelpDirectTradeAmt * objlevel.Percents;
- }
- if (objlevel.AddProfitVal > 0)
- {
- getLevelProfit += objlevel.AddProfitVal;
- }
- decimal money = getLevelProfit;
- getLevelProfit -= diffLevelProfit;
- if (objlevel.LevelDiff == 1)
- {
- diffLevelProfit = money;
- }
- if (getLevelProfit >= obj.MinProfitVal)
- {
- result.Add(new ProfitResult()
- {
- UserId = user.Id,
- UserNav = user.ParentNav,
- Money = PublicFunction.NumberFormat(getLevelProfit),
- ProfitRate = objlevel.Percents,
- Message = "交易分润",
- BankCardType = BankCardType,
- QrPayFlag = QrPayFlag,
- BrandId = BrandId,
- DirectFlag = selfUser.Id == user.Id ? 1 : 0,
- IsSubsidy = 0,
- TradeAmount = NotHelpDirectTradeAmt,
- HelpFlag = 0,
- });
- }
- }
- }
- if(curLevel < UserLevel)
- {
- curLevel = UserLevel;
- }
- }
- }
- function.WriteLog("------------------------", "分润监控日志");
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":盈利期:" + ProfitDirectTradeAmt, "分润监控日志");
- if (ProfitDirectTradeAmt > 0)
- {
- level = 0;
- curLevel = 0;
- diffLevelProfit = 0;
- foreach (string UserIdString in ParentNavList)
- {
- level += 1;
- int uid = int.Parse(UserIdString);
- SubUser user = GetUser(uid, Month) ?? new SubUser();
- int UserLevel = user.PreUserLevel > user.UserLevel ? user.PreUserLevel : user.UserLevel;
- if (curLevel == maxLevel)
- {
- break;
- }
- if (UserLevel <= maxLevel && UserLevel > curLevel)
- {
- int LevelKindId = GetLevelKindId(BrandId, 2, 1);
- ProfitObjectLevels objlevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + UserLevel);
- if (objlevel != null)
- {
- decimal getLevelProfit = 0;
- if (objlevel.Percents > 0)
- {
- getLevelProfit += ProfitDirectTradeAmt * objlevel.Percents;
- }
- if (objlevel.AddProfitVal > 0)
- {
- getLevelProfit += objlevel.AddProfitVal;
- }
- decimal money = getLevelProfit;
- getLevelProfit -= diffLevelProfit;
- if (objlevel.LevelDiff == 1)
- {
- diffLevelProfit = money;
- }
- if (getLevelProfit >= obj.MinProfitVal)
- {
- result.Add(new ProfitResult()
- {
- UserId = user.Id,
- UserNav = user.ParentNav,
- Money = PublicFunction.NumberFormat(getLevelProfit),
- ProfitRate = objlevel.Percents,
- Message = "交易分润",
- BankCardType = BankCardType,
- QrPayFlag = QrPayFlag,
- BrandId = BrandId,
- DirectFlag = selfUser.Id == user.Id ? 1 : 0,
- IsSubsidy = 0,
- TradeAmount = ProfitDirectTradeAmt,
- HelpFlag = 2,
- });
- }
- }
- }
- if(curLevel < UserLevel)
- {
- curLevel = UserLevel;
- }
- }
- }
- }
- }
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":over", "分润监控日志");
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "每月统计分润异常");
- }
- dbnew.Dispose();
- }
- }
- sqlstr = "";
- if (BankCardType == 1)
- {
- sqlstr = "select UserId,QrPayFlag,ProfitDirectTradeAmt from CreditTradeDaySummary2" + Month + " where BrandId=" + BrandId + LimitString;
- }
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + sqlstr, "分润监控日志");
- dt = GetDataTable(sqlstr);
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + dt.Rows.Count.ToString(), "分润监控日志");
- if(dt.Rows.Count > 0)
- {
- foreach (DataRow dr in dt.Rows)
- {
- WebCMSEntities dbnew = new WebCMSEntities();
- try
- {
- int UserId = int.Parse(dr["UserId"].ToString());
- int QrPayFlag = int.Parse(dr["QrPayFlag"].ToString());
- List<UserLevelSet> levels = dbnew.UserLevelSet.ToList();
- SubUser selfUser = GetUser(UserId, Month) ?? new SubUser();
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":贷记卡", "分润监控日志");
- decimal ProfitDirectTradeAmt = decimal.Parse(dr[2].ToString());
- int maxLevel = obj.MaxLevel;
- decimal diffLevelProfit = 0;
- int curLevel = 0;
- string ParentNav = selfUser.ParentNav;
- if (string.IsNullOrEmpty(ParentNav))
- {
- ParentNav = ",0,";
- }
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + ParentNav, "分润监控日志");
- if (!string.IsNullOrEmpty(ParentNav))
- {
- ParentNav += "," + UserId + ",";
- string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
- Array.Reverse(ParentNavList);
- int level = 0;
- DateTime now = DateTime.Now;
- DateTime ThisMonth = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
- function.WriteLog("------------------------", "分润监控日志");
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":盈利期2:" + ProfitDirectTradeAmt, "分润监控日志");
- if (ProfitDirectTradeAmt > 0)
- {
- level = 0;
- curLevel = 0;
- diffLevelProfit = 0;
- foreach (string UserIdString in ParentNavList)
- {
- level += 1;
- int uid = int.Parse(UserIdString);
- SubUser user = GetUser(uid, Month) ?? new SubUser();
- int UserLevel = user.PreUserLevel > user.UserLevel ? user.PreUserLevel : user.UserLevel;
- if (curLevel == maxLevel)
- {
- break;
- }
- if (UserLevel <= maxLevel && UserLevel > curLevel)
- {
- int LevelKindId = GetLevelKindId(BrandId, 3, 1);
- ProfitObjectLevels objlevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + UserLevel);
- if (objlevel != null)
- {
- decimal getLevelProfit = 0;
- if (objlevel.Percents > 0)
- {
- getLevelProfit += ProfitDirectTradeAmt * objlevel.Percents;
- }
- if (objlevel.AddProfitVal > 0)
- {
- getLevelProfit += objlevel.AddProfitVal;
- }
- decimal money = getLevelProfit;
- getLevelProfit -= diffLevelProfit;
- if (objlevel.LevelDiff == 1)
- {
- diffLevelProfit = money;
- }
- if (getLevelProfit >= obj.MinProfitVal)
- {
- result.Add(new ProfitResult()
- {
- UserId = user.Id,
- UserNav = user.ParentNav,
- Money = PublicFunction.NumberFormat(getLevelProfit),
- ProfitRate = objlevel.Percents,
- Message = "交易分润",
- BankCardType = BankCardType,
- QrPayFlag = QrPayFlag,
- BrandId = BrandId,
- DirectFlag = selfUser.Id == user.Id ? 1 : 0,
- IsSubsidy = 0,
- TradeAmount = ProfitDirectTradeAmt,
- HelpFlag = 3,
- });
- }
- }
- }
- if(curLevel < UserLevel)
- {
- curLevel = UserLevel;
- }
- }
- }
- }
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":over", "分润监控日志");
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "每月统计分润异常");
- }
- dbnew.Dispose();
- }
- }
- }
- return result;
- }
- public List<ProfitResult> StartProftForSimByDate(string Month, int BrandId = 14, int PageNum = 1)
- {
- int PageSize = 200;
- int SkipNum = (PageNum - 1) * PageSize;
- string LimitString = " limit " + PageSize;
- if(PageNum > 1)
- {
- LimitString = " limit " + SkipNum + "," + PageSize;
- }
- List<ProfitResult> result = new List<ProfitResult>();
- ProfitObjects obj = RedisDbconn.Instance.Get<ProfitObjects>("pobj" + BrandId);
- if (obj.Status == 1)
- {
- string sqlstr = "select UserId,sum(HelpTradeAmount),sum(NotHelpTradeAmount) from SimCardDaySummary where TradeMonth='" + Month + "' and SeoTitle='self'" + LimitString;
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + sqlstr, "广电卡分润监控日志");
- DataTable dt = GetDataTable(sqlstr);
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + dt.Rows.Count.ToString(), "广电卡分润监控日志");
- if(dt.Rows.Count > 0)
- {
- foreach (DataRow dr in dt.Rows)
- {
- WebCMSEntities dbnew = new WebCMSEntities();
- try
- {
- int UserId = int.Parse(dr["UserId"].ToString());
- List<UserLevelSet> levels = dbnew.UserLevelSet.ToList();
- SubUser selfUser = GetUser(UserId, Month) ?? new SubUser();
- int Days = int.Parse(RedisDbconn.Instance.Get<string>("pobjrule:" + BrandId + ":HelpPolicy:Days"));
-
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "", "广电卡分润监控日志");
- decimal HelpDirectTradeAmt = decimal.Parse(dr[1].ToString());
- decimal NotHelpDirectTradeAmt = decimal.Parse(dr[2].ToString());
- int maxLevel = obj.MaxLevel;
- decimal diffLevelProfit = 0;
- int curLevel = 0;
- string ParentNav = selfUser.ParentNav;
- if (string.IsNullOrEmpty(ParentNav))
- {
- ParentNav = ",0,";
- }
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + ParentNav, "广电卡分润监控日志");
- if (!string.IsNullOrEmpty(ParentNav))
- {
- ParentNav += "," + UserId + ",";
- string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
- Array.Reverse(ParentNavList);
- int level = 0;
- DateTime now = DateTime.Now;
- DateTime ThisMonth = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":扶持期:" + HelpDirectTradeAmt, "广电卡分润监控日志");
- if (HelpDirectTradeAmt > 0)
- {
- level = 0;
- curLevel = 0;
- diffLevelProfit = 0;
- decimal curProfit = 0;
- foreach (string UserIdString in ParentNavList)
- {
- level += 1;
- int uid = int.Parse(UserIdString);
- SubUser user = GetUser(uid, Month) ?? new SubUser();
- int UserLevel = user.PreUserLevel > user.UserLevel ? user.PreUserLevel : user.UserLevel;
- if (curLevel == maxLevel)
- {
- break;
- }
- if (UserLevel <= maxLevel && UserLevel > curLevel)
- {
- int LevelKindId = GetLevelKindId(BrandId, 1, 1);
- ProfitObjectLevels objlevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + UserLevel);
- if (objlevel != null)
- {
- decimal getLevelProfit = 0;
- if (objlevel.Percents > 0)
- {
-
- getLevelProfit += HelpDirectTradeAmt * objlevel.Percents;
- }
- if (objlevel.AddProfitVal > 0)
- {
- getLevelProfit += objlevel.AddProfitVal;
- }
- decimal money = getLevelProfit;
- getLevelProfit -= diffLevelProfit;
- if (objlevel.LevelDiff == 1)
- {
- diffLevelProfit = money;
- }
- if (getLevelProfit >= obj.MinProfitVal)
- {
- int DirectFlag = selfUser.Id == user.Id ? 1 : 0;
- result.Add(new ProfitResult()
- {
- UserId = user.Id,
- UserNav = user.ParentNav,
- Money = PublicFunction.NumberFormat(getLevelProfit),
- ProfitRate = objlevel.Percents,
- Message = "交易分润",
- BankCardType = 0,
- QrPayFlag = 0,
- DirectFlag = DirectFlag,
- BrandId = BrandId,
- IsSubsidy = 0,
- TradeAmount = HelpDirectTradeAmt,
- HelpFlag = 1,
- });
- curProfit += getLevelProfit;
- function.WriteLog(user.Id + "-" + UserLevel + "-" + HelpDirectTradeAmt + "-" + DirectFlag + "-扶持期分润:" + getLevelProfit, "广电卡分润监控日志");
- }
- }
- }
- if(curLevel < UserLevel)
- {
- curLevel = UserLevel;
- }
- }
- }
- function.WriteLog("------------------------", "广电卡分润监控日志");
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":稳定期:" + NotHelpDirectTradeAmt, "广电卡分润监控日志");
- if (NotHelpDirectTradeAmt > 0)
- {
- level = 0;
- curLevel = 0;
- diffLevelProfit = 0;
- foreach (string UserIdString in ParentNavList)
- {
- level += 1;
- int uid = int.Parse(UserIdString);
- SubUser user = GetUser(uid, Month) ?? new SubUser();
- int UserLevel = user.PreUserLevel > user.UserLevel ? user.PreUserLevel : user.UserLevel;
- if (curLevel == maxLevel)
- {
- break;
- }
- if (UserLevel <= maxLevel && UserLevel > curLevel)
- {
- int LevelKindId = GetLevelKindId(BrandId, 0, 1);
- ProfitObjectLevels objlevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + UserLevel);
- if (objlevel != null)
- {
- decimal getLevelProfit = 0;
- if (objlevel.Percents > 0)
- {
-
- getLevelProfit += NotHelpDirectTradeAmt * objlevel.Percents;
- }
- if (objlevel.AddProfitVal > 0)
- {
- getLevelProfit += objlevel.AddProfitVal;
- }
- decimal money = getLevelProfit;
- getLevelProfit -= diffLevelProfit;
- if (objlevel.LevelDiff == 1)
- {
- diffLevelProfit = money;
- }
- if (getLevelProfit >= obj.MinProfitVal)
- {
- result.Add(new ProfitResult()
- {
- UserId = user.Id,
- UserNav = user.ParentNav,
- Money = PublicFunction.NumberFormat(getLevelProfit),
- ProfitRate = objlevel.Percents,
- Message = "交易分润",
- BankCardType = 0,
- QrPayFlag = 0,
- BrandId = BrandId,
- DirectFlag = selfUser.Id == user.Id ? 1 : 0,
- IsSubsidy = 0,
- TradeAmount = NotHelpDirectTradeAmt,
- HelpFlag = 0,
- });
- }
- }
- }
- if(curLevel < UserLevel)
- {
- curLevel = UserLevel;
- }
- }
- }
- function.WriteLog("------------------------", "广电卡分润监控日志");
- }
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":over", "广电卡分润监控日志");
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "广电卡分润异常");
- }
- dbnew.Dispose();
- }
- }
- }
- return result;
- }
- #endregion
- public SubUser GetUser(int UserId, string Month)
- {
- SubUser user = new SubUser();
- DataTable dt = GetDataTable("select * from Users" + Month + " where Id=" + UserId);
- if(dt.Rows.Count > 0)
- {
- user.Id = int.Parse(dt.Rows[0]["Id"].ToString());
- user.ParentUserId = int.Parse(dt.Rows[0]["ParentUserId"].ToString());
- user.ParentNav = dt.Rows[0]["ParentNav"].ToString();
- user.UserLevel = int.Parse(dt.Rows[0]["UserLevel"].ToString());
- user.PreUserLevel = int.Parse(dt.Rows[0]["PreUserLevel"].ToString());
- }
- return user;
- }
- public DataTable GetDataTable(string sqlstr)
- {
- DataTable dt = CustomerSqlConn.dtable(sqlstr, Library.ConfigurationManager.AppSettings["MainSqlConnStr"].ToString());
- return dt;
- }
- }
- }
|