lichunlei преди 2 години
родител
ревизия
b2751086a0
променени са 6 файла, в които са добавени 133 реда и са изтрити 366 реда
  1. 27 287
      AppStart/Helper/Profit/ProfitHelper.cs
  2. 88 77
      AppStart/Helper/Profit/ProfitHelperV2.cs
  3. 2 1
      AppStart/Helper/StatService.cs
  4. 13 0
      AppStart/Tables/SubUser.cs
  5. 2 1
      Startup.cs
  6. 1 0
      appsettings.json

+ 27 - 287
AppStart/Helper/Profit/ProfitHelper.cs

@@ -1846,182 +1846,6 @@ namespace MySystem
                                         SubsidyProfit = SubsidyProfit, //商户(非云闪付)贷记卡交易分润补贴金额
                                     });
                                 }
-                                // 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)
-                                //         {
-                                //             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; //(非扶持期)(非云闪付)贷记卡商户交易对应分润比例
-                                //             }
-                                //         }
-                                //     }
-                                //     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.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, //(云闪付)借记卡非封顶交易分润比例或增或减
-                                //     });
-                                // }
                             }
                             db.SaveChanges();
                             PageNum += 1;
@@ -2123,11 +1947,7 @@ namespace MySystem
                 DataTable dt = new DataTable();
                 if (BankCardType == 1)
                 {
-                    dt = dbconn.dtable("select SnNo,UserId,QrPayFlag,MerHelpFlag,sum(TradeAmount) from TradeRecord where Id>2030000 and CreateDate>='" + start + "' and CreateDate<'" + end + "' and BankCardType!=0 and BrandId=" + BrandId + " group by SnNo,UserId,QrPayFlag,MerHelpFlag" + LimitString);
-                }
-                if (BankCardType == 0)
-                {
-                    dt = dbconn.dtable("select SnNo,UserId,QrPayFlag,MerHelpFlag,TradeAmount from TradeRecord where Id>2030000 and CreateDate>='" + start + "' and CreateDate<'" + end + "' and BankCardType=0 and BrandId=" + BrandId + LimitString);
+                    dt = ProfitHelperV2.Instance.GetDataTable("select SnNo,UserId,QrPayFlag,MerHelpFlag,TradeAmount TradeAmount from TradeRecord" + Month + " where BrandId=" + BrandId);
                 }
                 function.WriteLog("记录条数:" + dt.Rows.Count.ToString(), "老规则分润日志");
                 foreach (DataRow dr in dt.Rows)
@@ -2146,37 +1966,10 @@ namespace MySystem
                             int QrPayFlag = int.Parse(dr["QrPayFlag"].ToString());
                             decimal TradeAmt = decimal.Parse(dr[4].ToString());
                             List<UserLevelSet> levels = dbnew.UserLevelSet.ToList();
-                            Users selfUser = dbnew.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
+                            SubUser selfUser = ProfitHelperV2.Instance.GetUser(UserId, Month) ?? new SubUser();
                             int Days = int.Parse(RedisDbconn.Instance.Get<string>("pobjrule:" + BrandId + ":HelpPolicy:Days")); //天数
                             if (BankCardType == 0)
                             {
-                                int UserLevel = selfUser.UserLevel; //当前会员等级
-                                // int HelpTime = 0; //扶持期-1,稳定期=0
-                                // if (pos.BindingTime.Value.AddDays(Days) > DateTime.Now && Deposit > 0 && pos.ActivationState == 1)
-                                // {
-                                //     HelpTime = 1;
-                                // }
-                                // int LevelKindId = GetLevelKindId(BrandId, HelpTime, 0);
-                                // ProfitObjectLevels objlevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + UserLevel); //获取当前等级参数
-                                decimal getLevelProfit = TradeAmt * 0.0006M;
-                                if (getLevelProfit > 1) getLevelProfit = 1;
-                                result.Add(new ProfitResult()
-                                {
-                                    UserId = selfUser.Id,
-                                    UserNav = selfUser.ParentNav,
-                                    Money = PublicFunction.NumberFormat(getLevelProfit),
-                                    ProfitRate = 0.0006M,
-                                    Message = "储蓄卡分润",
-                                    BankCardType = BankCardType,
-                                    QrPayFlag = QrPayFlag,
-                                    BrandId = pos.BrandId,
-                                    DirectFlag = 1,
-                                    IsSubsidy = 0,
-                                    MerchantId = pos.BindMerchantId,
-                                    TradeAmount = TradeAmt,
-                                    HelpFlag = HelpTime,
-                                    PosSn = pos.PosSn,
-                                });
                             }
                             else
                             {
@@ -2184,15 +1977,6 @@ namespace MySystem
                                 decimal diffLevelProfit = 0;  //等级级差
                                 int curLevel = 0; //当前层级的会员等级
                                 string ParentNav = selfUser.ParentNav;
-                                // if (UserId != pos.UserId)
-                                // {
-                                //     Users user = dbnew.Users.FirstOrDefault(m => m.Id == pos.UserId);
-                                //     if (user != null)
-                                //     { 
-                                //         ParentNav = user.ParentNav;
-                                //         UserId = pos.UserId;
-                                //     }
-                                // }
                                 if (string.IsNullOrEmpty(ParentNav) && pos.BuyUserId == 1 && pos.UserId == 1)
                                 {
                                     ParentNav = ",0,";
@@ -2209,27 +1993,14 @@ namespace MySystem
                                     {
                                         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.CreateDate < ThisMonth && m.UpdateDate > ThisMonth);
-                                        if (rank != null)
-                                        {
-                                            if (rank.Rank > UserLevel)
-                                            {
-                                                UserLevel = rank.Rank;
-                                            }
-                                        }
+                                        SubUser user = ProfitHelperV2.Instance.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 HelpTime = 0; //扶持期-1,稳定期=0
-                                            // if (pos.BindingTime.Value.AddDays(Days) > DateTime.Now && Deposit > 0 && pos.ActivationState == 1)
-                                            // {
-                                            //     HelpTime = 1;
-                                            // }
                                             int LevelKindId = GetLevelKindId(BrandId, HelpTime, 1);
                                             ProfitObjectLevels objlevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + UserLevel); //获取当前等级参数
                                             if (objlevel != null)
@@ -2250,70 +2021,39 @@ namespace MySystem
                                                 {
                                                     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,
-                                                        DirectFlag = selfUser.Id == user.Id ? 1 : 0,
-                                                        BrandId = pos.BrandId,
-                                                        IsSubsidy = 0,
-                                                        MerchantId = pos.BindMerchantId,
-                                                        TradeAmount = TradeAmt,
-                                                        HelpFlag = HelpTime,
-                                                        PosSn = pos.PosSn,
-                                                    });
-                                                }
 
                                                 // 分润补贴
                                                 if (HelpTime == 1 && level == 1)
                                                 {
                                                     int SubsidyUserId = pos.BuyUserId;
-                                                    Users subuser = dbnew.Users.FirstOrDefault(m => m.Id == SubsidyUserId) ?? new Users();
-                                                    int subUserLevel = subuser.UserLevel;
+                                                    SubUser subuser = ProfitHelperV2.Instance.GetUser(SubsidyUserId, Month) ?? new SubUser();
+                                                    int subUserLevel = subuser.PreUserLevel > subuser.UserLevel ? subuser.PreUserLevel : subuser.UserLevel;
                                                     if(subUserLevel < 5)
                                                     {
-                                                        UserRankWhite subrank = dbnew.UserRankWhite.FirstOrDefault(m => m.Id == subuser.Id && m.CreateDate < ThisMonth && m.UpdateDate > ThisMonth);
-                                                        if (subrank != null)
-                                                        {
-                                                            if (subrank.Rank > subUserLevel)
-                                                            {
-                                                                subUserLevel = subrank.Rank;
-                                                            }
-                                                        }
-                                                        if(subUserLevel < 5)
+                                                        ProfitObjectLevels sublevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + subUserLevel); //获取当前等级参数
+                                                        if (sublevel != null)
                                                         {
-                                                            ProfitObjectLevels sublevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + subUserLevel); //获取当前等级参数
-                                                            if (sublevel != null)
+                                                            decimal otherPercent = 0.001M - sublevel.Percents;
+                                                            decimal otherMoney = TradeAmt * otherPercent;
+                                                            if (otherMoney >= obj.MinProfitVal)
                                                             {
-                                                                decimal otherPercent = 0.001M - sublevel.Percents;
-                                                                decimal otherMoney = TradeAmt * otherPercent;
-                                                                if (otherMoney >= obj.MinProfitVal)
+                                                                result.Add(new ProfitResult()
                                                                 {
-                                                                    result.Add(new ProfitResult()
-                                                                    {
-                                                                        UserId = subuser.Id,
-                                                                        UserNav = subuser.ParentNav,
-                                                                        Money = PublicFunction.NumberFormat(otherMoney),
-                                                                        ProfitRate = otherPercent,
-                                                                        Message = "分润补贴",
-                                                                        BankCardType = BankCardType,
-                                                                        QrPayFlag = QrPayFlag,
-                                                                        DirectFlag = 1,
-                                                                        BrandId = pos.BrandId,
-                                                                        IsSubsidy = 1,
-                                                                        MerchantId = pos.BindMerchantId,
-                                                                        TradeAmount = TradeAmt,
-                                                                        HelpFlag = HelpTime,
-                                                                        PosSn = pos.PosSn,
-                                                                    });
-                                                                }
+                                                                    UserId = subuser.Id,
+                                                                    UserNav = subuser.ParentNav,
+                                                                    Money = PublicFunction.NumberFormat(otherMoney),
+                                                                    ProfitRate = otherPercent,
+                                                                    Message = "分润补贴",
+                                                                    BankCardType = BankCardType,
+                                                                    QrPayFlag = QrPayFlag,
+                                                                    DirectFlag = 1,
+                                                                    BrandId = pos.BrandId,
+                                                                    IsSubsidy = 1,
+                                                                    MerchantId = pos.BindMerchantId,
+                                                                    TradeAmount = TradeAmt,
+                                                                    HelpFlag = HelpTime,
+                                                                    PosSn = pos.PosSn,
+                                                                });
                                                             }
                                                         }
                                                     }

+ 88 - 77
AppStart/Helper/Profit/ProfitHelperV2.cs

@@ -34,6 +34,21 @@ namespace MySystem
             th.Start();
         }
         public void StatProfitDo()
+        {
+            while (true)
+            {
+                string content = "1"; //RedisDbconn.Instance.RPop<string>("DoProfitQueue");
+                if(!string.IsNullOrEmpty(content))
+                {
+                    StatProfiting();
+                }
+                else
+                {
+                    Thread.Sleep(60000);
+                }
+            }
+        }
+        public void StatProfiting()
         {
             string Month = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
             string check = function.ReadInstance("/ProfitStat/" + Month + "-1.txt");
@@ -361,7 +376,7 @@ namespace MySystem
                     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 = dbconn.dtable(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)
                 {
@@ -371,9 +386,9 @@ namespace MySystem
                         try
                         {
                             int UserId = int.Parse(dr["UserId"].ToString());
-                            int QrPayFlag = int.Parse(dr["QueryCount"].ToString());
+                            int QrPayFlag = int.Parse(dr["QrPayFlag"].ToString());
                             List<UserLevelSet> levels = dbnew.UserLevelSet.ToList();
-                            Users selfUser = dbnew.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
+                            SubUser selfUser = GetUser(UserId, Month) ?? new SubUser();
                             int Days = int.Parse(RedisDbconn.Instance.Get<string>("pobjrule:" + BrandId + ":HelpPolicy:Days")); //天数
                             if (BankCardType == 0)
                             {
@@ -431,16 +446,8 @@ namespace MySystem
                                         {
                                             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.CreateDate < ThisMonth && m.UpdateDate > ThisMonth);
-                                            if (rank != null)
-                                            {
-                                                if (rank.Rank > UserLevel)
-                                                {
-                                                    UserLevel = rank.Rank;
-                                                }
-                                            }
+                                            SubUser user = GetUser(uid, Month) ?? new SubUser();
+                                            int UserLevel = user.PreUserLevel > user.UserLevel ? user.PreUserLevel : user.UserLevel; //当前会员等级
                                             if (curLevel == maxLevel) //判断当前创客是否有直推的激活机具,并且在活动时间内
                                             {
                                                 break;
@@ -487,50 +494,50 @@ namespace MySystem
                                                     }
 
                                                     // 分润补贴
-                                                    if (level == 1)
-                                                    {
-                                                        int SubsidyUserId = selfUser.ParentUserId;
-                                                        Users subuser = dbnew.Users.FirstOrDefault(m => m.Id == SubsidyUserId) ?? new Users();
-                                                        int subUserLevel = subuser.UserLevel;
-                                                        if (subUserLevel < 5)
-                                                        {
-                                                            UserRankWhite subrank = dbnew.UserRankWhite.FirstOrDefault(m => m.Id == subuser.Id && m.CreateDate < ThisMonth && m.UpdateDate > ThisMonth);
-                                                            if (subrank != null)
-                                                            {
-                                                                if (subrank.Rank > subUserLevel)
-                                                                {
-                                                                    subUserLevel = subrank.Rank;
-                                                                }
-                                                            }
-                                                            if (subUserLevel < 5)
-                                                            {
-                                                                ProfitObjectLevels sublevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + subUserLevel); //获取当前等级参数
-                                                                if (sublevel != null)
-                                                                {
-                                                                    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,
-                                                                        });
-                                                                    }
-                                                                }
-                                                            }
-                                                        }
-                                                    }
+                                                    // if (level == 1)
+                                                    // {
+                                                    //     int SubsidyUserId = selfUser.ParentUserId;
+                                                    //     Users subuser = dbnew.Users.FirstOrDefault(m => m.Id == SubsidyUserId) ?? new Users();
+                                                    //     int subUserLevel = subuser.UserLevel;
+                                                    //     if (subUserLevel < 5)
+                                                    //     {
+                                                    //         UserRankWhite subrank = dbnew.UserRankWhite.FirstOrDefault(m => m.Id == subuser.Id && m.CreateDate < ThisMonth && m.UpdateDate > ThisMonth);
+                                                    //         if (subrank != null)
+                                                    //         {
+                                                    //             if (subrank.Rank > subUserLevel)
+                                                    //             {
+                                                    //                 subUserLevel = subrank.Rank;
+                                                    //             }
+                                                    //         }
+                                                    //         if (subUserLevel < 5)
+                                                    //         {
+                                                    //             ProfitObjectLevels sublevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + subUserLevel); //获取当前等级参数
+                                                    //             if (sublevel != null)
+                                                    //             {
+                                                    //                 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;
@@ -546,16 +553,8 @@ namespace MySystem
                                         {
                                             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.CreateDate < ThisMonth && m.UpdateDate > ThisMonth);
-                                            if (rank != null)
-                                            {
-                                                if (rank.Rank > UserLevel)
-                                                {
-                                                    UserLevel = rank.Rank;
-                                                }
-                                            }
+                                            SubUser user = GetUser(uid, Month) ?? new SubUser();
+                                            int UserLevel = user.PreUserLevel > user.UserLevel ? user.PreUserLevel : user.UserLevel; //当前会员等级
                                             if (curLevel == maxLevel) //判断当前创客是否有直推的激活机具,并且在活动时间内
                                             {
                                                 break;
@@ -615,16 +614,8 @@ namespace MySystem
                                         {
                                             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.CreateDate < ThisMonth && m.UpdateDate > now);
-                                            if (rank != null)
-                                            {
-                                                if (rank.Rank > UserLevel)
-                                                {
-                                                    UserLevel = rank.Rank;
-                                                }
-                                            }
+                                            SubUser user = GetUser(uid, Month) ?? new SubUser();
+                                            int UserLevel = user.PreUserLevel > user.UserLevel ? user.PreUserLevel : user.UserLevel; //当前会员等级
                                             if (curLevel == maxLevel) //判断当前创客是否有直推的激活机具,并且在活动时间内
                                             {
                                                 break;
@@ -689,5 +680,25 @@ namespace MySystem
         }
         #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;
+        }
     }
 }

+ 2 - 1
AppStart/Helper/StatService.cs

@@ -1648,7 +1648,8 @@ namespace MySystem
                     //     function.WritePage("/ProfitFlag/", Month + ".txt", DateTime.Now.ToString("HH:mm:ss"));
                     //     StatUserLevelStart();
                     // }
-                    ProfitHelperV2.Instance.StatProfit();
+                    // ProfitHelperV2.Instance.StatProfit();
+                    RedisDbconn.Instance.AddList("DoTableEveryMonthQueue", "1");
                 }
                 Thread.Sleep(600000);
             }

+ 13 - 0
AppStart/Tables/SubUser.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+namespace MySystem
+{
+    public class SubUser
+    {
+        public int Id { get; set; }
+        public int ParentUserId { get; set; }
+        public string ParentNav { get; set; }
+        public int UserLevel { get; set; }
+        public int PreUserLevel { get; set; }
+    }
+}

+ 2 - 1
Startup.cs

@@ -203,7 +203,8 @@ namespace MySystem
             // RecommendActStatService.Instance.Start(); //推荐王奖励数据统计
             // StoreApplyHelper.Instance.Start(); // 每月1号重置仓库额度
             // StoreApplyHelper.Instance.StartEverTime();
-            StatService.Instance.StatUserLevel(); //升级并分润
+            // StatService.Instance.StatUserLevel(); //升级并分润
+            ProfitHelperV2.Instance.StatProfit();
             //必须打开的
 
             // HelpProfitHelper.Instance.Start(); //助利宝分润

+ 1 - 0
appsettings.json

@@ -19,6 +19,7 @@
     "Database": "KxsMainServer",
     "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;",
+    "MainSqlConnStr": "server=47.109.31.237;port=3306;user=KxsMainServer;password=FrW8ZfxlcaVdm1r0;database=KxsMainServer;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",
     "IOSAppVersion": "1.0.0",