Sfoglia il codice sorgente

大盟主订单匹配调整,主要是文字改动

lichunlei 2 anni fa
parent
commit
cf5e0b47ac

+ 2 - 2
AppStart/Helper/AlipayPayBack2Service.cs

@@ -120,11 +120,11 @@ namespace MySystem
                         }
                         else if (pro.ProductId == 13)
                         {
-                            if (pro.NormDetail == "电签POS")
+                            if (pro.NormDetail == "300电签POS")
                             {
                                 Kind = 1;
                             }
-                            else if (pro.NormDetail == "大POS")
+                            else if (pro.NormDetail == "200大POS")
                             {
                                 Kind = 2;
                             }

+ 450 - 412
AppStart/Helper/Profit/ProfitHelperV2.cs

@@ -35,7 +35,7 @@ namespace MySystem
         }
         public void StatProfitDo()
         {
-            DateTime end = DateTime.Parse("2022-06-25 00:00:00");
+            DateTime end = DateTime.Parse("2022-06-30 00:00:00");
             DateTime check = DateTime.Parse("2022-06-01");
             while (check <= end)
             {
@@ -58,257 +58,273 @@ namespace MySystem
             {
                 for (int j = 0; j <= 1; j++) //卡类型
                 {
-                    List<ProfitResult> result = StartProftForPosByDate(i, j, Date);
-                    foreach (ProfitResult sub in result)
+                    int PageNum = 1;
+                    bool op = true;
+                    while(op)
                     {
-                        int TopUserId = 0;
-                        if (!string.IsNullOrEmpty(sub.UserNav))
+                        function.WriteLog("BrandId:" + i + ",BankCardType:" + j + ",Date:" + Date + ",PageNum:" + PageNum, "分润监控日志");
+                        List<ProfitResult> result = StartProftForPosByDate(i, j, Date, PageNum);
+                        function.WriteLog("result:" + result.Count, "分润监控日志");
+                        function.WriteLog("\r\n", "分润监控日志");
+                        if(result.Count > 0)
                         {
-                            string[] UserNavList = sub.UserNav.Trim(',').Replace(",,", ",").Split(',');
-                            if (UserNavList.Length > 1)
+                            foreach (ProfitResult sub in result)
                             {
-                                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)
-                        {
-                            decimal CreditTradeAmt = TradeAmt; //商户贷记卡交易总金额
-                            decimal QrCreditTradeAmt = 0; //商户(云闪付)贷记卡交易总金额
-                            decimal NonQrCreditTradeAmt = 0; //商户(非云闪付)贷记卡交易总金额
-                            decimal CreditProfitRate = 0; //(非云闪付)贷记卡交易分润比例
-                            decimal SubsidyProfit = 0; //商户(非云闪付)贷记卡交易分润补贴金额
-                            if (sub.QrPayFlag == 1)
-                            {
-                                QrCreditTradeAmt = TradeAmt; //商户(云闪付)贷记卡交易总金额
-                            }
-                            else
-                            { 
-                                NonQrCreditTradeAmt = TradeAmt; //商户(非云闪付)贷记卡交易总金额
-                                CreditProfitRate = ProfitRate; //(非云闪付)贷记卡交易分润比例
-                                SubsidyProfit = ProfitAmt; //商户(非云闪付)贷记卡交易分润补贴金额
-                            }
-                            MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == sub.PosSn) ?? new MachineForSnNo();
-                            PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId) ?? new PosMachinesTwo(); 
-                            PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == sub.MerchantId) ?? new PosMerchantInfo();
-                            db.ProfitSubsidyDetail.Add(new ProfitSubsidyDetail()
-                            {
-                                CreateDate = DateTime.Now,
-                                UpdateDate = DateTime.Now,
-                                RecordNo = RecordNo, //流水号
-                                BrandId = sub.BrandId, //品牌
-                                ProductName = RelationClass.GetKqProductBrandInfo(sub.BrandId), //产品名称
-                                TradeMonth = Month, //交易月份
-                                SeoTitle = Date,
-                                MerchantId = sub.MerchantId, //商户
-                                MerNo = merchant.KqMerNo, //渠道商户编号
-                                SnNo = sub.PosSn, //渠道SN号
-                                MerRegTime = pos.BindingTime, //渠道注册时间
-                                MerStandardDate = merchant.MerStandardDate, //商户激活时间
-                                BelongUserId = merchant.UserId, //商户归属人
-                                MerHelpFlag = sub.HelpFlag == 1 ? 1u : 0u, //是否属于扶持周期内商户
-                                SubsidyUserId = sub.UserId, //补贴人
-                                SubsidyType = sub.DirectFlag, //分润补贴类型
-                                SubsidyProfitRate = sub.Money, //创客活动期内直营商户分润万分之十
-                                CreditTradeAmt = CreditTradeAmt, //商户贷记卡交易总金额
-                                QrCreditTradeAmt = QrCreditTradeAmt, //商户(云闪付)贷记卡交易总金额
-                                NonQrCreditTradeAmt = NonQrCreditTradeAmt, //商户(非云闪付)贷记卡交易总金额
-                                CreditProfitRate = CreditProfitRate, //(非云闪付)贷记卡交易分润比例
-                                SubsidyProfit = SubsidyProfit, //商户(非云闪付)贷记卡交易分润补贴金额
-                            });
-                            db.SaveChanges();
-                        }
-                        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;
-                            if (j == 1)
-                            {
-                                CreditTradeAmt = TradeAmt; //贷记卡交易总金额
-                                CreditTradeProfit = ProfitAmt; //贷记卡分润总金额
-                                if (sub.QrPayFlag == 1)
+                                int TopUserId = 0;
+                                if (!string.IsNullOrEmpty(sub.UserNav))
                                 {
-                                    QrCreditTradeAmt = TradeAmt; //(云闪付)贷记卡交易总金额
-                                    QrCreditProfitRate = ProfitRate; //(云闪付)贷记卡交易分润比例
-                                    QrCreditTradeProfit = ProfitAmt; //(云闪付)贷记卡交易分润
-                                }
-                                else
-                                {
-                                    NonQrCreditTradeAmt = TradeAmt; //(非云闪付)贷记卡交易总金额
-                                    NonQrCreditTradeProfit = ProfitAmt; //(非云闪付)贷记卡交易分润
-                                    if(sub.HelpFlag == 1)
+                                    string[] UserNavList = sub.UserNav.Trim(',').Replace(",,", ",").Split(',');
+                                    if (UserNavList.Length > 1)
                                     {
-                                        HelpCreditTradeProfit = ProfitAmt; //(扶持期)(非云闪付)贷记卡分润总金额
-                                        HelpCreditProfitRate = ProfitRate; //(扶持期)(非云闪付)贷记卡商户交易对应分润比例
-                                        HelpCreditTradeAmt = TradeAmt; //(扶持期)(非云闪付)贷记卡交易总金额
+                                        TopUserId = int.Parse(UserNavList[1]);
                                     }
                                     else
                                     {
-                                        NotHelpCreditTradeAmt = TradeAmt; //(非扶持期)(非云闪付)贷记卡交易总金额
-                                        NotHelpCreditTradeProfit = ProfitAmt; //(非扶持期)(非云闪付)贷记卡分润总金额
-                                        NotHelpCreditProfitRate = ProfitRate; //(非扶持期)(非云闪付)贷记卡商户交易对应分润比例
+                                        TopUserId = int.Parse(UserNavList[0]);
                                     }
                                 }
-                            }
-                            if (j == 0)
-                            {
-                                if (sub.Money < 1)
-                                {
-                                    DebitNonCapTradeAmt = TradeAmt; //商户非封顶借记卡交易总额
-                                    DebitNonTradeCapProfit = ProfitAmt; //借记卡非封顶交易分润总金额
-                                }
-                                else
+                                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)
                                 {
-                                    DebitCapTradeAmt = TradeAmt; //商户借记卡封顶交易总额
-                                    DebitCapSingleReward = ProfitAmt; //借记卡合伙人直营封顶交易奖励金额
-                                    DebitTradeCapProfit = ProfitAmt; //借记卡封顶交易分润总金额
-                                }
-                                if (sub.QrPayFlag == 1)
-                                {
-                                    if (sub.Money < 1)
+                                    decimal CreditTradeAmt = TradeAmt; //商户贷记卡交易总金额
+                                    decimal QrCreditTradeAmt = 0; //商户(云闪付)贷记卡交易总金额
+                                    decimal NonQrCreditTradeAmt = 0; //商户(非云闪付)贷记卡交易总金额
+                                    decimal CreditProfitRate = 0; //(非云闪付)贷记卡交易分润比例
+                                    decimal SubsidyProfit = 0; //商户(非云闪付)贷记卡交易分润补贴金额
+                                    if (sub.QrPayFlag == 1)
                                     {
-                                        QrDebitNotCapTradeAmt = TradeAmt; //(云闪付)商户非封顶借记卡交易总额
-                                        QrDebitProfitRate = ProfitRate; //(云闪付)借记卡非封顶交易分润比例
-                                        QrDebitNonTradeCapProfit = ProfitAmt; //(云闪付)借记卡非封顶交易分润总金额
+                                        QrCreditTradeAmt = TradeAmt; //商户(云闪付)贷记卡交易总金额
+                                    }
+                                    else
+                                    { 
+                                        NonQrCreditTradeAmt = TradeAmt; //商户(非云闪付)贷记卡交易总金额
+                                        CreditProfitRate = ProfitRate; //(非云闪付)贷记卡交易分润比例
+                                        SubsidyProfit = ProfitAmt; //商户(非云闪付)贷记卡交易分润补贴金额
                                     }
+                                    MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == sub.PosSn) ?? new MachineForSnNo();
+                                    PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId) ?? new PosMachinesTwo(); 
+                                    PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == sub.MerchantId) ?? new PosMerchantInfo();
+                                    db.ProfitSubsidyDetail.Add(new ProfitSubsidyDetail()
+                                    {
+                                        CreateDate = DateTime.Now,
+                                        UpdateDate = DateTime.Now,
+                                        RecordNo = RecordNo, //流水号
+                                        BrandId = sub.BrandId, //品牌
+                                        ProductName = RelationClass.GetKqProductBrandInfo(sub.BrandId), //产品名称
+                                        TradeMonth = Month, //交易月份
+                                        SeoTitle = Date,
+                                        MerchantId = sub.MerchantId, //商户
+                                        MerNo = merchant.KqMerNo, //渠道商户编号
+                                        SnNo = sub.PosSn, //渠道SN号
+                                        MerRegTime = pos.BindingTime, //渠道注册时间
+                                        MerStandardDate = merchant.MerStandardDate, //商户激活时间
+                                        BelongUserId = merchant.UserId, //商户归属人
+                                        MerHelpFlag = sub.HelpFlag == 1 ? 1u : 0u, //是否属于扶持周期内商户
+                                        SubsidyUserId = sub.UserId, //补贴人
+                                        SubsidyType = sub.DirectFlag, //分润补贴类型
+                                        SubsidyProfitRate = sub.Money, //创客活动期内直营商户分润万分之十
+                                        CreditTradeAmt = CreditTradeAmt, //商户贷记卡交易总金额
+                                        QrCreditTradeAmt = QrCreditTradeAmt, //商户(云闪付)贷记卡交易总金额
+                                        NonQrCreditTradeAmt = NonQrCreditTradeAmt, //商户(非云闪付)贷记卡交易总金额
+                                        CreditProfitRate = CreditProfitRate, //(非云闪付)贷记卡交易分润比例
+                                        SubsidyProfit = SubsidyProfit, //商户(非云闪付)贷记卡交易分润补贴金额
+                                    });
+                                    db.SaveChanges();
                                 }
                                 else
                                 {
-                                    if (sub.Money < 1)
+                                    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;
+                                    if (j == 1)
                                     {
-                                        NonQrDebitNonTradeCapProfit = ProfitAmt; //(非云闪付)借记卡非封顶交易分润总金额
-                                        NonQrDebitNotCapTradeAmt = TradeAmt; //(非云闪付)商户非封顶借记卡交易总额
-                                    }
-                                    if (sub.HelpFlag == 1)
-                                    {
-                                        if (sub.Money < 1)
+                                        CreditTradeAmt = TradeAmt; //贷记卡交易总金额
+                                        CreditTradeProfit = ProfitAmt; //贷记卡分润总金额
+                                        if (sub.QrPayFlag == 1)
                                         {
-                                            HelpDebitNonCapTradeAmt = TradeAmt; //(扶持期)(非云闪付)借记卡非封顶交易总金额
-                                            HelpDebitNonTradeCapProfit = ProfitAmt; //(扶持期)(非云闪付)借记卡非封顶交易分润总金额
+                                            QrCreditTradeAmt = TradeAmt; //(云闪付)贷记卡交易总金额
+                                            QrCreditProfitRate = ProfitRate; //(云闪付)贷记卡交易分润比例
+                                            QrCreditTradeProfit = ProfitAmt; //(云闪付)贷记卡交易分润
+                                        }
+                                        else
+                                        {
+                                            NonQrCreditTradeAmt = TradeAmt; //(非云闪付)贷记卡交易总金额
+                                            NonQrCreditTradeProfit = ProfitAmt; //(非云闪付)贷记卡交易分润
+                                            if(sub.HelpFlag == 1)
+                                            {
+                                                HelpCreditTradeProfit = ProfitAmt; //(扶持期)(非云闪付)贷记卡分润总金额
+                                                HelpCreditProfitRate = ProfitRate; //(扶持期)(非云闪付)贷记卡商户交易对应分润比例
+                                                HelpCreditTradeAmt = TradeAmt; //(扶持期)(非云闪付)贷记卡交易总金额
+                                            }
+                                            else
+                                            {
+                                                NotHelpCreditTradeAmt = TradeAmt; //(非扶持期)(非云闪付)贷记卡交易总金额
+                                                NotHelpCreditTradeProfit = ProfitAmt; //(非扶持期)(非云闪付)贷记卡分润总金额
+                                                NotHelpCreditProfitRate = ProfitRate; //(非扶持期)(非云闪付)贷记卡商户交易对应分润比例
+                                            }
                                         }
-                                        HelpDebitProfitRate = ProfitRate; //(扶持期)(非云闪付)借记卡商户交易对应分润比例
                                     }
-                                    else
+                                    if (j == 0)
                                     {
                                         if (sub.Money < 1)
                                         {
-                                            NotHelpDebitNonCapTradeAmt = TradeAmt; //(非扶持期)(非云闪付)借记卡非封顶交易总金额
-                                            NotHelpDebitNonTradeCapProfit = ProfitAmt; //(非扶持期)(非云闪付)借记卡非封顶交易分润总金额
+                                            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.Money < 1)
+                                                {
+                                                    NotHelpDebitNonCapTradeAmt = TradeAmt; //(非扶持期)(非云闪付)借记卡非封顶交易总金额
+                                                    NotHelpDebitNonTradeCapProfit = ProfitAmt; //(非扶持期)(非云闪付)借记卡非封顶交易分润总金额
+                                                }
+                                                NotHelpDebitProfitRate = ProfitRate; //(非扶持期)(非云闪付)借记卡商户交易对应分润比例
+                                            }
                                         }
-                                        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, //交易月
+                                        SeoTitle = Date,
+                                        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, //(云闪付)借记卡非封顶交易分润比例或增或减
+                                    });
+                                    db.SaveChanges();
                                 }
                             }
-                            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, //交易月
-                                SeoTitle = Date,
-                                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, //(云闪付)借记卡非封顶交易分润比例或增或减
-                            });
-                            db.SaveChanges();
+                            PageNum += 1;
+                        }
+                        else
+                        {
+                            op = false;
                         }
                     }
                 }
             }
             db.Dispose();
         }
-        public List<ProfitResult> StartProftForPosByDate(int BrandId, int BankCardType, string Date)
+        public List<ProfitResult> StartProftForPosByDate(int BrandId, int BankCardType, string Date, int PageNum = 1)
         {
             // 级差
             /*   
@@ -375,253 +391,275 @@ namespace MySystem
 
             */
 
-
+            int PageSize = 20;
+            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) //判断分润是否开启
             {
-                DataTable dt = new DataTable();
+                string sqlstr = "";
                 if (BankCardType == 1)
                 {
-                    dt = dbconn.dtable("select UserId,QueryCount,sum(HelpDirectTradeAmt),sum(NotHelpDirectTradeAmt) from TradeDaySummary where TradeDate='" + Date + "' and BrandId=" + BrandId + " group by UserId,QueryCount having sum(HelpDirectTradeAmt)>0 or sum(NotHelpDirectTradeAmt)>0");
+                    sqlstr = "select UserId,QueryCount,sum(HelpDirectTradeAmt),sum(NotHelpDirectTradeAmt) from TradeDaySummary where TradeDate='" + Date + "' and SeoTitle='self' and BrandId=" + BrandId + " group by UserId,QueryCount having sum(HelpDirectTradeAmt)>0 or sum(NotHelpDirectTradeAmt)>0 order by UserId" + LimitString;
                 }
                 if (BankCardType == 0)
                 {
-                    dt = dbconn.dtable("select UserId,QueryCount,sum(HelpDirectDebitTradeAmt),sum(NotHelpDirectDebitTradeAmt),sum(HelpDirectDebitCapTradeAmt),sum(NotHelpDirectDebitCapTradeAmt),sum(HelpDirectDebitCapNum),sum(NotHelpDirectDebitCapNum) from TradeDaySummary where TradeDate='" + Date + "' and BrandId=" + BrandId + " group by UserId,QueryCount having sum(HelpDirectDebitTradeAmt)>0 or sum(NotHelpDirectDebitTradeAmt)>0 or sum(HelpDirectDebitCapTradeAmt)>0 or sum(NotHelpDirectDebitCapTradeAmt)>0;");
+                    sqlstr = "select UserId,QueryCount,sum(HelpDirectDebitTradeAmt),sum(NotHelpDirectDebitTradeAmt),sum(HelpDirectDebitCapTradeAmt),sum(NotHelpDirectDebitCapTradeAmt),sum(HelpDirectDebitCapNum),sum(NotHelpDirectDebitCapNum) from TradeDaySummary where TradeDate='" + Date + "' and SeoTitle='self' and BrandId=" + BrandId + " group by UserId,QueryCount having sum(HelpDirectDebitTradeAmt)>0 or sum(NotHelpDirectDebitTradeAmt)>0 or sum(HelpDirectDebitCapTradeAmt)>0 or sum(NotHelpDirectDebitCapTradeAmt)>0 order by UserId" + LimitString;
                 }
-                foreach (DataRow dr in dt.Rows)
+                function.WriteLog(sqlstr, "分润监控日志");
+                DataTable dt = dbconn.dtable(sqlstr);
+                function.WriteLog(dt.Rows.Count.ToString(), "分润监控日志");
+                if(dt.Rows.Count > 0)
                 {
-                    WebCMSEntities dbnew = new WebCMSEntities();
-                    try
+                    foreach (DataRow dr in dt.Rows)
                     {
-                        int UserId = int.Parse(dr["UserId"].ToString());
-                        int QrPayFlag = int.Parse(dr["QueryCount"].ToString());
-                        List<UserLevelSet> levels = dbnew.UserLevelSet.ToList();
-                        Users selfUser = dbnew.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
-                        int Days = int.Parse(RedisDbconn.Instance.Get<string>("pobjrule:" + BrandId + ":HelpPolicy:Days")); //天数
-                        if (BankCardType == 0)
-                        {
-                            decimal HelpDirectDebitTradeAmt = decimal.Parse(dr[2].ToString()); //借记卡扶持期交易额
-                            decimal NotHelpDirectDebitTradeAmt = decimal.Parse(dr[3].ToString()); //借记卡稳定期交易额
-                            decimal HelpDirectDebitCapTradeAmt = decimal.Parse(dr[4].ToString()); //借记卡扶持期封顶交易额
-                            decimal NotHelpDirectDebitCapTradeAmt = decimal.Parse(dr[5].ToString()); //借记卡稳定期封顶交易额
-                            int HelpDirectDebitCapNum = int.Parse(dr[6].ToString().Split('.')[0]); //借记卡扶持期封顶交易笔数
-                            int NotHelpDirectDebitCapNum = int.Parse(dr[7].ToString()); //借记卡稳定期封顶交易笔数
-                            int UserLevel = selfUser.UserLevel; //当前会员等级
-                            // int LevelKindId = GetLevelKindId(BrandId, HelpTime, 0);
-                            // ProfitObjectLevels objlevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + UserLevel); //获取当前等级参数
-                            decimal getLevelProfit = (HelpDirectDebitTradeAmt + NotHelpDirectDebitTradeAmt - HelpDirectDebitCapTradeAmt - NotHelpDirectDebitCapTradeAmt) * 0.0006M + HelpDirectDebitCapNum + NotHelpDirectDebitCapNum;
-                            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,
-                            });
-                        }
-                        else
+                        WebCMSEntities dbnew = new WebCMSEntities();
+                        try
                         {
-                            decimal HelpDirectTradeAmt = decimal.Parse(dr[2].ToString()); //贷记卡扶持期交易额
-                            decimal NotHelpDirectTradeAmt = decimal.Parse(dr[3].ToString()); //贷记卡稳定期交易额
-                            int maxLevel = obj.MaxLevel; //最大等级
-                            decimal diffLevelProfit = 0;  //等级级差
-                            int curLevel = 0; //当前层级的会员等级
-                            string ParentNav = selfUser.ParentNav;
-                            if (string.IsNullOrEmpty(ParentNav))
+                            int UserId = int.Parse(dr["UserId"].ToString());
+                            int QrPayFlag = int.Parse(dr["QueryCount"].ToString());
+                            List<UserLevelSet> levels = dbnew.UserLevelSet.ToList();
+                            Users selfUser = dbnew.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
+                            int Days = int.Parse(RedisDbconn.Instance.Get<string>("pobjrule:" + BrandId + ":HelpPolicy:Days")); //天数
+                            if (BankCardType == 0)
                             {
-                                ParentNav = ",0,";
+                                decimal HelpDirectDebitTradeAmt = decimal.Parse(dr[2].ToString()); //借记卡扶持期交易额
+                                decimal NotHelpDirectDebitTradeAmt = decimal.Parse(dr[3].ToString()); //借记卡稳定期交易额
+                                decimal HelpDirectDebitCapTradeAmt = decimal.Parse(dr[4].ToString()); //借记卡扶持期封顶交易额
+                                decimal NotHelpDirectDebitCapTradeAmt = decimal.Parse(dr[5].ToString()); //借记卡稳定期封顶交易额
+                                int HelpDirectDebitCapNum = int.Parse(dr[6].ToString().Split('.')[0]); //借记卡扶持期封顶交易笔数
+                                int NotHelpDirectDebitCapNum = int.Parse(dr[7].ToString()); //借记卡稳定期封顶交易笔数
+                                int UserLevel = selfUser.UserLevel; //当前会员等级
+                                // int LevelKindId = GetLevelKindId(BrandId, HelpTime, 0);
+                                // ProfitObjectLevels objlevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + UserLevel); //获取当前等级参数
+                                decimal getLevelProfit = (HelpDirectDebitTradeAmt + NotHelpDirectDebitTradeAmt - HelpDirectDebitCapTradeAmt - NotHelpDirectDebitCapTradeAmt) * 0.0006M + HelpDirectDebitCapNum + NotHelpDirectDebitCapNum;
+                                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,
+                                });
                             }
-                            if (!string.IsNullOrEmpty(ParentNav))
+                            else
                             {
-                                ParentNav += "," + UserId + ",";
-                                string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
-                                Array.Reverse(ParentNavList); //反转顺序
-                                int level = 0;
-                                DateTime now = DateTime.Now;
-                                foreach (string UserIdString in ParentNavList)
+                                decimal HelpDirectTradeAmt = decimal.Parse(dr[2].ToString()); //贷记卡扶持期交易额
+                                decimal NotHelpDirectTradeAmt = decimal.Parse(dr[3].ToString()); //贷记卡稳定期交易额
+                                int maxLevel = obj.MaxLevel; //最大等级
+                                decimal diffLevelProfit = 0;  //等级级差
+                                int curLevel = 0; //当前层级的会员等级
+                                string ParentNav = selfUser.ParentNav;
+                                if (string.IsNullOrEmpty(ParentNav))
                                 {
-                                    level += 1;
-                                    int uid = int.Parse(UserIdString);
-                                    Users user = dbnew.Users.FirstOrDefault(m => m.Id == uid) ?? new Users();
-                                    int UserLevel = user.UserLevel; //当前会员等级
-                                    UserRankWhite rank = dbnew.UserRankWhite.FirstOrDefault(m => m.Id == user.Id && m.UpdateDate > now);
-                                    if (rank != null)
-                                    {
-                                        if (rank.Rank > UserLevel)
-                                        {
-                                            UserLevel = rank.Rank;
-                                        }
-                                    }
-                                    if (curLevel == maxLevel) //判断当前创客是否有直推的激活机具,并且在活动时间内
-                                    {
-                                        break;
-                                    }
-                                    if (UserLevel <= maxLevel && UserLevel > curLevel)
+                                    ParentNav = ",0,";
+                                }
+                                function.WriteLog(ParentNav, "分润监控日志");
+                                if (!string.IsNullOrEmpty(ParentNav))
+                                {
+                                    ParentNav += "," + UserId + ",";
+                                    string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
+                                    Array.Reverse(ParentNavList); //反转顺序
+                                    int level = 0;
+                                    DateTime now = DateTime.Now;
+                                    if (HelpDirectTradeAmt > 0)
                                     {
-                                        int LevelKindId = GetLevelKindId(BrandId, 1, 1);
-                                        ProfitObjectLevels objlevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + UserLevel); //获取当前等级参数
-                                        if (objlevel != null)
+                                        foreach (string UserIdString in ParentNavList)
                                         {
-                                            decimal getLevelProfit = 0;  //等级分润
-                                            if (objlevel.Percents > 0)
+                                            level += 1;
+                                            int uid = int.Parse(UserIdString);
+                                            Users user = dbnew.Users.FirstOrDefault(m => m.Id == uid) ?? new Users();
+                                            int UserLevel = user.UserLevel; //当前会员等级
+                                            UserRankWhite rank = dbnew.UserRankWhite.FirstOrDefault(m => m.Id == user.Id && m.UpdateDate > now);
+                                            if (rank != null)
                                             {
-                                                //获取创客分润规则,注册日开始算起,3个自然月内算扶持期
-                                                getLevelProfit += HelpDirectTradeAmt * objlevel.Percents;
-                                            }
-                                            if (objlevel.AddProfitVal > 0)
-                                            {
-                                                getLevelProfit += objlevel.AddProfitVal;
-                                            }
-                                            decimal money = getLevelProfit;
-                                            getLevelProfit -= diffLevelProfit;
-                                            if (objlevel.LevelDiff == 1)  //判断是否有级差
-                                            {
-                                                diffLevelProfit = money;
+                                                if (rank.Rank > UserLevel)
+                                                {
+                                                    UserLevel = rank.Rank;
+                                                }
                                             }
-                                            if (getLevelProfit >= obj.MinProfitVal)
+                                            if (curLevel == maxLevel) //判断当前创客是否有直推的激活机具,并且在活动时间内
                                             {
-                                                result.Add(new ProfitResult()
-                                                {
-                                                    UserId = user.Id,
-                                                    UserNav = user.ParentNav,
-                                                    Money = PublicFunction.NumberFormat(getLevelProfit),
-                                                    ProfitRate = objlevel.Percents,
-                                                    Message = "交易分润",
-                                                    BankCardType = BankCardType,
-                                                    QrPayFlag = QrPayFlag,
-                                                    DirectFlag = selfUser.Id == user.Id ? 1 : 0,
-                                                    IsSubsidy = 0,
-                                                    TradeAmount = HelpDirectTradeAmt,
-                                                    HelpFlag = 1,
-                                                });
+                                                break;
                                             }
-
-                                            // 分润补贴
-                                            if (level == 1)
+                                            if (UserLevel <= maxLevel && UserLevel > curLevel)
                                             {
-                                                int SubsidyUserId = selfUser.ParentUserId; // TODO: 确定是否100%是上级
-                                                Users subuser = dbnew.Users.FirstOrDefault(m => m.Id == SubsidyUserId) ?? new Users();
-                                                int subUserLevel = subuser.UserLevel;
-                                                if(subUserLevel < 5)
+                                                int LevelKindId = GetLevelKindId(BrandId, 1, 1);
+                                                ProfitObjectLevels objlevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + UserLevel); //获取当前等级参数
+                                                if (objlevel != null)
                                                 {
-                                                    UserRankWhite subrank = dbnew.UserRankWhite.FirstOrDefault(m => m.Id == subuser.Id && m.UpdateDate > now);
-                                                    if (subrank != null)
+                                                    decimal getLevelProfit = 0;  //等级分润
+                                                    if (objlevel.Percents > 0)
                                                     {
-                                                        if (subrank.Rank > subUserLevel)
+                                                        //获取创客分润规则,注册日开始算起,3个自然月内算扶持期
+                                                        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)
+                                                    {
+                                                        result.Add(new ProfitResult()
                                                         {
-                                                            subUserLevel = subrank.Rank;
-                                                        }
+                                                            UserId = user.Id,
+                                                            UserNav = user.ParentNav,
+                                                            Money = PublicFunction.NumberFormat(getLevelProfit),
+                                                            ProfitRate = objlevel.Percents,
+                                                            Message = "交易分润",
+                                                            BankCardType = BankCardType,
+                                                            QrPayFlag = QrPayFlag,
+                                                            DirectFlag = selfUser.Id == user.Id ? 1 : 0,
+                                                            BrandId = BrandId,
+                                                            IsSubsidy = 0,
+                                                            TradeAmount = HelpDirectTradeAmt,
+                                                            HelpFlag = 1,
+                                                        });
                                                     }
-                                                    if(subUserLevel < 5)
+
+                                                    // 分润补贴
+                                                    if (level == 1)
                                                     {
-                                                        ProfitObjectLevels sublevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + subUserLevel); //获取当前等级参数
-                                                        if (sublevel != null)
+                                                        int SubsidyUserId = selfUser.ParentUserId; // TODO: 确定是否100%是上级
+                                                        Users subuser = dbnew.Users.FirstOrDefault(m => m.Id == SubsidyUserId) ?? new Users();
+                                                        int subUserLevel = subuser.UserLevel;
+                                                        if (subUserLevel < 5)
                                                         {
-                                                            decimal otherPercent = 0.001M - sublevel.Percents;
-                                                            decimal otherMoney = HelpDirectTradeAmt * otherPercent;
-                                                            if (otherMoney >= obj.MinProfitVal)
+                                                            UserRankWhite subrank = dbnew.UserRankWhite.FirstOrDefault(m => m.Id == subuser.Id && m.UpdateDate > now);
+                                                            if (subrank != null)
+                                                            {
+                                                                if (subrank.Rank > subUserLevel)
+                                                                {
+                                                                    subUserLevel = subrank.Rank;
+                                                                }
+                                                            }
+                                                            if (subUserLevel < 5)
                                                             {
-                                                                result.Add(new ProfitResult()
+                                                                ProfitObjectLevels sublevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + subUserLevel); //获取当前等级参数
+                                                                if (sublevel != null)
                                                                 {
-                                                                    UserId = subuser.Id,
-                                                                    UserNav = subuser.ParentNav,
-                                                                    Money = PublicFunction.NumberFormat(otherMoney),
-                                                                    ProfitRate = otherPercent,
-                                                                    Message = "分润补贴",
-                                                                    BankCardType = BankCardType,
-                                                                    QrPayFlag = QrPayFlag,
-                                                                    DirectFlag = 1,
-                                                                    BrandId = BrandId,
-                                                                    IsSubsidy = 1,
-                                                                    TradeAmount = HelpDirectTradeAmt,
-                                                                    HelpFlag = 1,
-                                                                });
+                                                                    decimal otherPercent = 0.001M - sublevel.Percents;
+                                                                    decimal otherMoney = HelpDirectTradeAmt * otherPercent;
+                                                                    if (otherMoney >= obj.MinProfitVal)
+                                                                    {
+                                                                        result.Add(new ProfitResult()
+                                                                        {
+                                                                            UserId = subuser.Id,
+                                                                            UserNav = subuser.ParentNav,
+                                                                            Money = PublicFunction.NumberFormat(otherMoney),
+                                                                            ProfitRate = otherPercent,
+                                                                            Message = "分润补贴",
+                                                                            BankCardType = BankCardType,
+                                                                            QrPayFlag = QrPayFlag,
+                                                                            DirectFlag = 1,
+                                                                            BrandId = BrandId,
+                                                                            IsSubsidy = 1,
+                                                                            TradeAmount = HelpDirectTradeAmt,
+                                                                            HelpFlag = 1,
+                                                                        });
+                                                                    }
+                                                                }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
+                                            curLevel = UserLevel;
                                         }
                                     }
-                                    curLevel = UserLevel;
-                                }
-                                level = 0;
-                                foreach (string UserIdString in ParentNavList)
-                                {
-                                    level += 1;
-                                    int uid = int.Parse(UserIdString);
-                                    Users user = dbnew.Users.FirstOrDefault(m => m.Id == uid) ?? new Users();
-                                    int UserLevel = user.UserLevel; //当前会员等级
-                                    UserRankWhite rank = dbnew.UserRankWhite.FirstOrDefault(m => m.Id == user.Id && m.UpdateDate > now);
-                                    if (rank != null)
+                                    if (NotHelpDirectTradeAmt > 0)
                                     {
-                                        if (rank.Rank > UserLevel)
+                                        level = 0;
+                                        curLevel = 0;
+                                        foreach (string UserIdString in ParentNavList)
                                         {
-                                            UserLevel = rank.Rank;
-                                        }
-                                    }
-                                    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)
+                                            level += 1;
+                                            int uid = int.Parse(UserIdString);
+                                            Users user = dbnew.Users.FirstOrDefault(m => m.Id == uid) ?? new Users();
+                                            int UserLevel = user.UserLevel; //当前会员等级
+                                            UserRankWhite rank = dbnew.UserRankWhite.FirstOrDefault(m => m.Id == user.Id && m.UpdateDate > now);
+                                            if (rank != null)
                                             {
-                                                //获取创客分润规则,注册日开始算起,3个自然月内算扶持期
-                                                getLevelProfit += NotHelpDirectTradeAmt * objlevel.Percents;
-                                            }
-                                            if (objlevel.AddProfitVal > 0)
-                                            {
-                                                getLevelProfit += objlevel.AddProfitVal;
+                                                if (rank.Rank > UserLevel)
+                                                {
+                                                    UserLevel = rank.Rank;
+                                                }
                                             }
-                                            decimal money = getLevelProfit;
-                                            getLevelProfit -= diffLevelProfit;
-                                            if (objlevel.LevelDiff == 1)  //判断是否有级差
+                                            if (curLevel == maxLevel) //判断当前创客是否有直推的激活机具,并且在活动时间内
                                             {
-                                                diffLevelProfit = money;
+                                                break;
                                             }
-                                            if (getLevelProfit >= obj.MinProfitVal)
+                                            if (UserLevel <= maxLevel && UserLevel > curLevel)
                                             {
-                                                result.Add(new ProfitResult()
+                                                int LevelKindId = GetLevelKindId(BrandId, 0, 1);
+                                                ProfitObjectLevels objlevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + UserLevel); //获取当前等级参数
+                                                if (objlevel != null)
                                                 {
-                                                    UserId = user.Id,
-                                                    UserNav = user.ParentNav,
-                                                    Money = PublicFunction.NumberFormat(getLevelProfit),
-                                                    ProfitRate = objlevel.Percents,
-                                                    Message = "交易分润",
-                                                    BankCardType = BankCardType,
-                                                    QrPayFlag = QrPayFlag,
-                                                    DirectFlag = selfUser.Id == user.Id ? 1 : 0,
-                                                    IsSubsidy = 0,
-                                                    TradeAmount = NotHelpDirectTradeAmt,
-                                                    HelpFlag = 0,
-                                                });
+                                                    decimal getLevelProfit = 0;  //等级分润
+                                                    if (objlevel.Percents > 0)
+                                                    {
+                                                        //获取创客分润规则,注册日开始算起,3个自然月内算扶持期
+                                                        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,
+                                                        });
+                                                    }
+                                                }
                                             }
+                                            curLevel = UserLevel;
                                         }
                                     }
-                                    curLevel = UserLevel;
                                 }
                             }
                         }
+                        catch (Exception ex)
+                        {
+                            function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "每月统计分润异常");
+                        }
+                        dbnew.Dispose();
                     }
-                    catch (Exception ex)
-                    {
-                        function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "每月统计分润异常");
-                    }
-                    dbnew.Dispose();
                 }
             }
             return result;

+ 2 - 0
AppStart/Helper/StatService.cs

@@ -1709,6 +1709,8 @@ namespace MySystem
                 function.WriteLog(ex.ToString(), "创客升级异常");
             }
             db.Dispose();
+
+            ProfitHelperV2.Instance.StatProfit(); //统计分润
         }
 
 

+ 2 - 2
Startup.cs

@@ -203,7 +203,7 @@ namespace MySystem
             RedPackageHelper.Instance.Start(); //每天生成300个红包
             RedPackageHelper.Instance.StartStatTop10(); //红包活动统计排行
             RedPackageHelper.Instance.StartSendPrize(); //红包活动发奖
-            // BalancePayBackService.Instance.Start(); //余额支付队列
+            BalancePayBackService.Instance.Start(); //余额支付队列
             //必须打开的
 
             // StatService.Instance.StartPosActNum(); //实时统计激活数
@@ -216,7 +216,7 @@ namespace MySystem
             // StatService.Instance.StartEverDayV2();
             // RedPackageHelper.Instance.Start();
             // StatService.Instance.StatUserLevel();
-            // ProfitHelper.Instance.StatProfit("202205"); //统计分润
+            // ProfitHelperV2.Instance.StatProfit(); //统计分润
             // StatService.Instance.ListenFluxRecord();
             // StatService.Instance.StartEverDay2();
             // TestHelper.Instance.Start();

+ 2 - 2
appsettings.json

@@ -17,8 +17,8 @@
     "Host": "http://localhost:5047/",
     "SourceHost": "http://bs.kexiaoshuang.com/",
     "Database": "KxsMainServer",
-    "SqlConnStr": "server=47.109.31.237;port=3306;user=KxsMainServer;password=Rw2imhXQQt5ODWIF;database=KxsMainServer;charset=utf8;",
-    "Pxc1SqlConnStr": "server=47.109.31.237;port=3306;user=KxsMainServer;password=Rw2imhXQQt5ODWIF;database=KxsMainServer;charset=utf8;",
+    "SqlConnStr": "server=47.109.31.237;port=3306;user=KxsMainServer2;password=FrW8ZfxlcaVdm1r0;database=KxsMainServer2;charset=utf8;",
+    "Pxc1SqlConnStr": "server=47.109.31.237;port=3306;user=KxsMainServer2;password=FrW8ZfxlcaVdm1r0;database=KxsMainServer2;charset=utf8;",
     "SpSqlConnStr": "server=47.109.31.237;port=3306;user=KxsSpServer;password=jJ9qKsvwWgQA9xWG;database=KxsSpServer;charset=utf8;",
     "RedisConnStr": "47.109.31.237:6379,password=klm@redis,DefaultDatabase=1,poolsize=500,preheat=50,asyncPipeline=true",
     "TendisConnStr": "47.109.31.237:6379,password=klm@redis,DefaultDatabase=1,poolsize=500,preheat=50,asyncPipeline=true",