Prechádzať zdrojové kódy

修复运营中心奖励
修复每月升级

lichunlei 2 rokov pred
rodič
commit
3dfdfea676

+ 54 - 30
AppStart/Helper/OperatePrizeService.cs

@@ -36,41 +36,65 @@ namespace MySystem
                         PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == PosId);
                         if (pos != null)
                         {
-                            int OpId = pos.OpId;
-                            UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == OpId);
-                            if (account == null)
+                            int OpId = 0;
+                            int UserId = pos.BuyUserId;
+                            while(UserId > 0)
                             {
-                                account = db.UserAccount.Add(new UserAccount()
+                                Users user = db.Users.FirstOrDefault(m => m.Id == UserId);
+                                if(user != null)
                                 {
-                                    Id = OpId,
-                                    UserId = OpId,
+                                    if(user.UserType == 1)
+                                    {
+                                        OpId = user.Id;
+                                        UserId = 0;
+                                    }
+                                    else
+                                    {
+                                        UserId = user.ParentUserId;
+                                    }
+                                }
+                                else
+                                {
+                                    UserId = 0;
+                                }
+                            }
+                            if(OpId > 0)
+                            {
+                                UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == OpId);
+                                if (account == null)
+                                {
+                                    account = db.UserAccount.Add(new UserAccount()
+                                    {
+                                        Id = OpId,
+                                        UserId = OpId,
+                                    }).Entity;
+                                    db.SaveChanges();
+                                }
+                                decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
+                                decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
+                                decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
+                                account.BalanceAmount += 5;
+                                account.TotalAmount += 5;
+                                decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
+                                decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
+                                decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
+                                UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
+                                {
+                                    CreateDate = DateTime.Now,
+                                    UpdateDate = DateTime.Now,
+                                    UserId = OpId, //创客
+                                    ChangeType = 121, //变动类型
+                                    ChangeAmount = 5, //变更金额
+                                    BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
+                                    AfterTotalAmount = AfterTotalAmount, //变更后总金额
+                                    BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
+                                    AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
+                                    BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
+                                    AfterBalanceAmount = AfterBalanceAmount, //变更后余额
+                                    QueryCount = PosId,
                                 }).Entity;
                                 db.SaveChanges();
                             }
-                            decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
-                            decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
-                            decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
-                            account.BalanceAmount += 5;
-                            account.TotalAmount += 5;
-                            decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
-                            decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
-                            decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
-                            UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
-                            {
-                                CreateDate = DateTime.Now,
-                                UpdateDate = DateTime.Now,
-                                UserId = OpId, //创客
-                                ChangeType = 121, //变动类型
-                                ChangeAmount = 5, //变更金额
-                                BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
-                                AfterTotalAmount = AfterTotalAmount, //变更后总金额
-                                BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
-                                AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
-                                BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
-                                AfterBalanceAmount = AfterBalanceAmount, //变更后余额
-                                QueryCount = PosId,
-                            }).Entity;
-                            db.SaveChanges();
                         }
                         db.Dispose();
                     }

+ 2 - 2
AppStart/Helper/Profit/ProfitHelper.cs

@@ -1859,7 +1859,7 @@ namespace MySystem
             }
             db.Dispose();
 
-            HelpProfitHelper.Instance.StatProfitEveryDay(DateTime.Now.AddMonths(-1).ToString("yyyyMM")); //助利宝分润
+            // HelpProfitHelper.Instance.StatProfitEveryDay(DateTime.Now.AddMonths(-1).ToString("yyyyMM")); //助利宝分润
             ProfitCheckHelper.Instance.Start();
         }
         public List<ProfitResult> StartProftForPosByMonth(int BrandId, int BankCardType, string Month, int PageNum = 1)
@@ -1948,7 +1948,7 @@ namespace MySystem
                 DataTable dt = new DataTable();
                 if (BankCardType == 1)
                 {
-                    dt = ProfitHelperV2.Instance.GetDataTable("select SnNo,UserId,QrPayFlag,MerHelpFlag,TradeAmount,Version TradeAmount from TradeRecord" + Month + " where BrandId=" + BrandId + LimitString);
+                    dt = ProfitHelperV2.Instance.GetDataTable("select SnNo,UserId,QrPayFlag,MerHelpFlag,TradeAmount,Version from TradeRecord" + Month + " where BrandId=" + BrandId + LimitString);
                 }
                 function.WriteLog("记录条数:" + dt.Rows.Count.ToString(), "老规则分润日志");
                 foreach (DataRow dr in dt.Rows)

+ 1 - 1
AppStart/Helper/Profit/ProfitHelperV2.cs

@@ -38,7 +38,7 @@ namespace MySystem
             while (true)
             {
                 string content = RedisDbconn.Instance.RPop<string>("DoProfitQueue");
-                if(!string.IsNullOrEmpty(content) && DateTime.Now.Day < 11)
+                if(!string.IsNullOrEmpty(content) && DateTime.Now.Day < 15)
                 {
                     StatProfiting();
                 }

+ 158 - 144
AppStart/Helper/StatService.cs

@@ -836,176 +836,183 @@ namespace MySystem
         }
         public void StartOpenRewardDo()
         {
-            string content = RedisDbconn.Instance.RPop<string>("OpenRewardQueue");
-            if(!string.IsNullOrEmpty(content))
+            while(true)
             {
-                try
+                string content = RedisDbconn.Instance.RPop<string>("OpenRewardQueue");
+                if(!string.IsNullOrEmpty(content))
                 {
-                    int PosId = int.Parse(content);
-                    WebCMSEntities db = new WebCMSEntities();
-                    List<PosMachinesTwo> posList = db.PosMachinesTwo.Where(m => m.Id == PosId && m.ActivationState == 1 && !string.IsNullOrEmpty(m.SeoKeyword) && m.SeoKeyword != "0" && m.CreditTrade >= 1000).ToList();
-                    foreach (PosMachinesTwo pos in posList)
+                    try
                     {
-                        if (pos.BindingTime > DateTime.Now.AddDays(-30))
+                        int PosId = int.Parse(content);
+                        WebCMSEntities db = new WebCMSEntities();
+                        List<PosMachinesTwo> posList = db.PosMachinesTwo.Where(m => m.Id == PosId && m.ActivationState == 1 && !string.IsNullOrEmpty(m.SeoKeyword) && m.SeoKeyword != "0" && m.CreditTrade >= 1000).ToList();
+                        foreach (PosMachinesTwo pos in posList)
                         {
-                            decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
-                            if (ActPrize > 0)
+                            if (pos.BindingTime > DateTime.Now.AddDays(-30))
                             {
-                                PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
-                                if (merchant != null)
+                                decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
+                                if (ActPrize > 0)
                                 {
-                                    Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
-                                    if (user != null)
+                                    PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
+                                    if (merchant != null)
                                     {
-                                        if (!string.IsNullOrEmpty(user.ParentNav))
+                                        Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
+                                        if (user != null)
                                         {
-                                            decimal Prize = 20;
-                                            string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
-                                            for (int i = ParentNavs.Length - 1; i >= 0; i--)
+                                            if (!string.IsNullOrEmpty(user.ParentNav))
                                             {
-                                                int UserId = int.Parse(ParentNavs[i]);
-                                                Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
-                                                if (puser != null && Prize > 0)
+                                                decimal Prize = 20;
+                                                string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
+                                                for (int i = ParentNavs.Length - 1; i >= 0; i--)
                                                 {
-                                                    int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
-                                                    int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
-                                                    int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
-                                                    // int BigCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.BrandId == 3); //判断是否拥有2台大机
-                                                    // int BigActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1 && m.BrandId == 3); //判断是否拥有2台激活大机(不限购买或赠送)
-                                                    if (machineCount + ActiveCount + couponCount >= 3)
+                                                    int UserId = int.Parse(ParentNavs[i]);
+                                                    Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
+                                                    if (puser != null && Prize > 0)
                                                     {
-                                                        int pTopUserId = 0;
-                                                        if (!string.IsNullOrEmpty(puser.ParentNav))
-                                                        {
-                                                            pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
-                                                        }
-                                                        Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
-                                                        OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
+                                                        int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
+                                                        int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
+                                                        int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
+                                                        // int BigCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.BrandId == 3); //判断是否拥有2台大机
+                                                        // int BigActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1 && m.BrandId == 3); //判断是否拥有2台激活大机(不限购买或赠送)
+                                                        if (machineCount + ActiveCount + couponCount >= 3)
                                                         {
-                                                            CreateDate = DateTime.Now,
-                                                            UpdateDate = DateTime.Now,
-                                                            TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
-                                                            TradeDate = DateTime.Now, //达标日期
-                                                            UserId = puser.Id, //创客
-                                                            BrandId = pos.BrandId, //品牌
-                                                            ProductName = RelationClass.GetKqProductsInfo(pos.BrandId), //产品名称
-                                                            MerchantId = pos.BindMerchantId, //商户
-                                                            DirectUserId = merchant.UserId, //商户直属人
-                                                            SnNo = pos.PosSn, //SN号
-                                                            MerNo = merchant.KqMerNo, //渠道商户号
-                                                            SnType = pos.PosSnType, //机具类型
-                                                            StandardDate = pos.ActivationTime, //商户的激活日期
-                                                            SnStoreId = pos.StoreId, //SN仓库
-                                                            MerBuddyType = puser.MerchantType, //商户创客类型
-                                                            RewardType = 1, //奖励类型 1-开机直接奖励,2-开机间接奖励
-                                                            RewardTips = "开机奖励", //奖励描述
-                                                            CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
-                                                            DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
-                                                            CreditRewardAmount = Prize, //贷记卡交易奖励金额
-                                                            RewardDesc = "开机奖励", //奖励描述
-                                                            TopUserId = pTopUserId, //顶级创客
-                                                            SeoTitle = machineUser.RealName,
-                                                        }).Entity;
-                                                        db.OpenReward.Add(new OpenReward()
-                                                        {
-                                                            CreateDate = DateTime.Now,
-                                                            UpdateDate = DateTime.Now,
-                                                            TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
-                                                            TradeDate = DateTime.Now, //达标日期
-                                                            UserId = puser.Id, //创客
-                                                            BrandId = pos.BrandId, //品牌
-                                                            RewardType = 2, //奖励类型
-                                                            CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
-                                                            DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
-                                                            CreditRewardAmount = Prize, //贷记卡交易奖励金额
-                                                            RewardDesc = "开机奖励", //奖励描述
-                                                            TopUserId = pTopUserId, //顶级创客
-                                                        });
-                                                        string IdBrand = puser.Id + "_" + pos.BrandId;
-                                                        UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
-                                                        if (userData == null)
-                                                        {
-                                                            userData = db.UserMachineData.Add(new UserMachineData()
+                                                            int pTopUserId = 0;
+                                                            if (!string.IsNullOrEmpty(puser.ParentNav))
                                                             {
-                                                                IdBrand = IdBrand,
+                                                                pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
+                                                            }
+                                                            Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
+                                                            OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
+                                                            {
+                                                                CreateDate = DateTime.Now,
+                                                                UpdateDate = DateTime.Now,
+                                                                TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
+                                                                TradeDate = DateTime.Now, //达标日期
+                                                                UserId = puser.Id, //创客
+                                                                BrandId = pos.BrandId, //品牌
+                                                                ProductName = RelationClass.GetKqProductsInfo(pos.BrandId), //产品名称
+                                                                MerchantId = pos.BindMerchantId, //商户
+                                                                DirectUserId = merchant.UserId, //商户直属人
+                                                                SnNo = pos.PosSn, //SN号
+                                                                MerNo = merchant.KqMerNo, //渠道商户号
+                                                                SnType = pos.PosSnType, //机具类型
+                                                                StandardDate = pos.ActivationTime, //商户的激活日期
+                                                                SnStoreId = pos.StoreId, //SN仓库
+                                                                MerBuddyType = puser.MerchantType, //商户创客类型
+                                                                RewardType = 1, //奖励类型 1-开机直接奖励,2-开机间接奖励
+                                                                RewardTips = "开机奖励", //奖励描述
+                                                                CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
+                                                                DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
+                                                                CreditRewardAmount = Prize, //贷记卡交易奖励金额
+                                                                RewardDesc = "开机奖励", //奖励描述
+                                                                TopUserId = pTopUserId, //顶级创客
+                                                                SeoTitle = machineUser.RealName,
                                                             }).Entity;
+                                                            db.OpenReward.Add(new OpenReward()
+                                                            {
+                                                                CreateDate = DateTime.Now,
+                                                                UpdateDate = DateTime.Now,
+                                                                TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
+                                                                TradeDate = DateTime.Now, //达标日期
+                                                                UserId = puser.Id, //创客
+                                                                BrandId = pos.BrandId, //品牌
+                                                                RewardType = 2, //奖励类型
+                                                                CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
+                                                                DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
+                                                                CreditRewardAmount = Prize, //贷记卡交易奖励金额
+                                                                RewardDesc = "开机奖励", //奖励描述
+                                                                TopUserId = pTopUserId, //顶级创客
+                                                            });
+                                                            string IdBrand = puser.Id + "_" + pos.BrandId;
+                                                            UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
+                                                            if (userData == null)
+                                                            {
+                                                                userData = db.UserMachineData.Add(new UserMachineData()
+                                                                {
+                                                                    IdBrand = IdBrand,
+                                                                }).Entity;
+                                                                db.SaveChanges();
+                                                            }
+                                                            userData.OpenProfit += Prize;
                                                             db.SaveChanges();
-                                                        }
-                                                        userData.OpenProfit += Prize;
-                                                        db.SaveChanges();
-                                                        //账户入库
-                                                        UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
-                                                        if (account == null)
-                                                        {
-                                                            account = db.UserAccount.Add(new UserAccount()
+                                                            //账户入库
+                                                            UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
+                                                            if (account == null)
+                                                            {
+                                                                account = db.UserAccount.Add(new UserAccount()
+                                                                {
+                                                                    Id = puser.Id,
+                                                                    UserId = puser.Id,
+                                                                }).Entity;
+                                                                db.SaveChanges();
+                                                            }
+                                                            //收支明细入库
+                                                            decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
+                                                            decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
+                                                            decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
+                                                            account.BalanceAmount += Prize;
+                                                            account.TotalAmount += Prize;
+                                                            decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
+                                                            decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
+                                                            decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
+                                                            UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
                                                             {
-                                                                Id = puser.Id,
-                                                                UserId = puser.Id,
+                                                                CreateDate = DateTime.Now,
+                                                                UpdateDate = DateTime.Now,
+                                                                UserId = puser.Id, //创客
+                                                                ChangeType = 50, //变动类型
+                                                                ProductType = pos.BrandId, //产品类型
+                                                                ChangeAmount = Prize, //变更金额
+                                                                BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
+                                                                AfterTotalAmount = AfterTotalAmount, //变更后总金额
+                                                                BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
+                                                                AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
+                                                                BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
+                                                                AfterBalanceAmount = AfterBalanceAmount, //变更后余额
                                                             }).Entity;
                                                             db.SaveChanges();
-                                                        }
-                                                        //收支明细入库
-                                                        decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
-                                                        decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
-                                                        decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
-                                                        account.BalanceAmount += Prize;
-                                                        account.TotalAmount += Prize;
-                                                        decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
-                                                        decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
-                                                        decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
-                                                        UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
-                                                        {
-                                                            CreateDate = DateTime.Now,
-                                                            UpdateDate = DateTime.Now,
-                                                            UserId = puser.Id, //创客
-                                                            ChangeType = 50, //变动类型
-                                                            ProductType = pos.BrandId, //产品类型
-                                                            ChangeAmount = Prize, //变更金额
-                                                            BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
-                                                            AfterTotalAmount = AfterTotalAmount, //变更后总金额
-                                                            BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
-                                                            AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
-                                                            BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
-                                                            AfterBalanceAmount = AfterBalanceAmount, //变更后余额
-                                                        }).Entity;
-                                                        db.SaveChanges();
-
-                                                        string dateString = DateTime.Now.ToString("yyyyMMdd");
-                                                        string monthString = DateTime.Now.ToString("yyyyMM");
-                                                        // 开机奖励列表
-                                                        List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
-                                                        if (!dates.Contains(dateString))
-                                                        {
-                                                            RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
-                                                        }
-                                                        RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
 
-                                                        List<string> months = RedisDbconn.Instance.GetList<string>("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId);
-                                                        if (!months.Contains(monthString))
-                                                        {
-                                                            RedisDbconn.Instance.AddList("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId, monthString);
-                                                        }
-                                                        RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + monthString, Prize);
+                                                            string dateString = DateTime.Now.ToString("yyyyMMdd");
+                                                            string monthString = DateTime.Now.ToString("yyyyMM");
+                                                            // 开机奖励列表
+                                                            List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
+                                                            if (!dates.Contains(dateString))
+                                                            {
+                                                                RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
+                                                            }
+                                                            RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
+
+                                                            List<string> months = RedisDbconn.Instance.GetList<string>("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId);
+                                                            if (!months.Contains(monthString))
+                                                            {
+                                                                RedisDbconn.Instance.AddList("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId, monthString);
+                                                            }
+                                                            RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + monthString, Prize);
 
-                                                        // 开机奖励详情
-                                                        RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
+                                                            // 开机奖励详情
+                                                            RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
 
-                                                        Prize = 0;
+                                                            Prize = 0;
+                                                        }
                                                     }
                                                 }
                                             }
                                         }
+                                        // }
                                     }
-                                    // }
                                 }
                             }
                         }
+                        db.Dispose();
+                    }
+                    catch(Exception ex)
+                    {
+                        function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "实时获取开机奖励异常");
                     }
-                    db.Dispose();
                 }
-                catch(Exception ex)
+                else
                 {
-                    function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "实时获取开机奖励异常");
+                    Thread.Sleep(5000);
                 }
             }
         }
@@ -1205,7 +1212,7 @@ namespace MySystem
             function.WriteLog(DateTime.Now.ToString(), "执行流量费返佣");
             SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
             WebCMSEntities db = new WebCMSEntities();
-            DateTime start = DateTime.Now.AddDays(-1);
+            DateTime start = DateTime.Now.AddDays(-2);
             List<SpModels.TradeFluxRecord> trades = spdb.TradeFluxRecord.Where(m => m.CreateDate >= start && m.Status == 1).ToList();
             foreach (SpModels.TradeFluxRecord trade in trades)
             {
@@ -1832,7 +1839,7 @@ namespace MySystem
         {
             while (true)
             {
-                if(DateTime.Now.Day == 1 && DateTime.Now.Hour >= 4)
+                if(DateTime.Now.Day == 1 && DateTime.Now.Hour > 1)
                 {
                     string Month = DateTime.Now.AddDays(-1).ToString("yyyy-MM");
                     string flag = function.ReadInstance("/ProfitFlag/" + Month + ".txt");
@@ -1860,7 +1867,7 @@ namespace MySystem
                 int startid = 0;
                 while(op)
                 {
-                    var users = db.Users.Select(m => new { m.Id, m.AuthFlag }).Where(m => m.Id > startid && m.AuthFlag == 1 && m.Id == 66575).OrderBy(m => m.Id).Take(50).ToList();
+                    var users = db.Users.Select(m => new { m.Id, m.AuthFlag }).Where(m => m.Id > startid && m.AuthFlag == 1).OrderBy(m => m.Id).Take(500).ToList();
                     function.WriteLog(users.Count.ToString(), "创客升级日志");
                     if(users.Count > 0)
                     {
@@ -1876,7 +1883,7 @@ namespace MySystem
                                 bool check = db.TradeDaySummary.Any(m => m.UserId == user.Id && m.TradeMonth == TradeMonth && m.SeoTitle == "team");
                                 if (check)
                                 {
-                                    TradeAmount += db.TradeDaySummary.Where(m => m.UserId == user.Id && m.TradeMonth == TradeMonth && m.SeoTitle == "team").Sum(m => m.HelpNonDirectTradeAmt + m.NotHelpNonDirectTradeAmt);
+                                    TradeAmount += db.TradeDaySummary.Where(m => m.UserId == user.Id && m.TradeMonth == TradeMonth && m.SeoTitle == "team").Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt + m.ProfitNonDirectTradeAmt + m.ProfitNonDirectDebitTradeAmt);
                                 }
                                 //助利宝团队交易额
                                 DataTable checkdt = OtherMySqlConn.dtable("SELECT SUM(TradeAmount) TradeAmount FROM HelpProfitMerTradeSummay WHERE (MerchantId IN(SELECT MerchantId FROM HelpProfitMerIds WHERE UserId IN(SELECT Id from Users WHERE ParentNav like '%," + user.Id + ",%' OR Id=" + user.Id + "))) AND TradeMonth=" + TradeMonth + "");
@@ -1927,8 +1934,8 @@ namespace MySystem
                                     function.WriteLog("升级:" + user.Id.ToString() + BeforeLevel + "->" + AfterLevel, "创客升级日志");
                                     user.UserLevel = AfterLevel;
                                     DateTime checkTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
-                                    bool checkExist = db.UserRank.Any(m => m.CreateDate >= checkTime && m.UserId == user.Id);
-                                    if(!checkExist)
+                                    UserRank rank = db.UserRank.FirstOrDefault(m => m.CreateDate >= checkTime && m.UserId == user.Id);
+                                    if(rank == null)
                                     {
                                         db.UserRank.Add(new UserRank()
                                         {
@@ -1945,6 +1952,12 @@ namespace MySystem
                                         });
                                         db.SaveChanges();
                                     }
+                                    else
+                                    {
+                                        rank.TradeAmt = TradeAmount;
+                                        rank.Rank = AfterLevel;
+                                        db.SaveChanges();
+                                    }
                                 }
                                 // 降级逻辑
                                 // if(!upFlag && AfterLevel > 5)
@@ -1973,6 +1986,7 @@ namespace MySystem
                             }
                             startid = subuser.Id;
                         }
+                        function.WriteLog(startid.ToString(), "创客升级日志");
                     }
                     else
                     {

+ 2 - 5
AppStart/Helper/SycnSpServer/SycnSpTradeService.cs

@@ -288,11 +288,8 @@ namespace MySystem
                                                 RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
                                             }
                                             //发放运营中心奖励
-                                            if(pos.OpId > 0)
-                                            {
-                                                RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
-                                                AlipayPayBack2Service.Instance.ActReserveBack(pos.OpId, pos.OpReserve1, pos.OpReserve2, pos.OpReserve3);
-                                            }
+                                            RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
+                                            AlipayPayBack2Service.Instance.ActReserveBack(pos.OpId, pos.OpReserve1, pos.OpReserve2, pos.OpReserve3);
                                         }
                                         // 立刷60天内刷满10000,再返40
                                         if (pos.BrandId == 6 && decimal.Parse(function.CheckNum(pos.SeoKeyword)) > 0 && pos.ActivationState == 1 && pos.CreditTrade >= 10000 && pos.BindingTime > DateTime.Now.AddDays(-60))

+ 0 - 11
Controllers/HomeController.cs

@@ -130,17 +130,6 @@ namespace MySystem.Controllers
             StatService.Instance.dosomething1(date);
             return "ok";
         }
-        // 补流量费奖励
-        public string addflux(string date)
-        {
-            StatService.Instance.doFluxRecord(date);
-            return "ok";
-        }
-        public string addflux2(string date)
-        {
-            StatService.Instance.CheckFluxForTrade(date);
-            return "ok";
-        }
         // 补发小盟主15000返现
         public string LeaderBack(int oid)
         {

+ 1 - 1
Startup.cs

@@ -207,6 +207,7 @@ namespace MySystem
             StatService.Instance.StatUserLevel(); //升级
             ProfitHelperV2.Instance.StatProfit(); //创客分润
             StatService.Instance.StartOpenReward(); //实时获取开机奖励
+            StatService.Instance.ListenFluxRecord(); //实时获取流量费分佣
             //必须打开的
 
             HelpProfitPreMerchantHelper.Instance.Start(); //助利宝每天增加指定数量商机
@@ -228,7 +229,6 @@ namespace MySystem
             // StatService.Instance.StartEverDayV2();
             // RedPackageHelper.Instance.Start();
             // ProfitHelperV2.Instance.StatProfit(); //统计分润
-            // StatService.Instance.ListenFluxRecord();
             // StatService.Instance.StartEverDay2();
             // TestHelper.Instance.Start();
             // TestService.Instance.Start();