Эх сурвалжийг харах

新增加激活奖励和开机奖励的新算法,按商户判断,待测试
大POS上线

lichunlei 3 жил өмнө
parent
commit
d3db5b3247

+ 603 - 254
AppStart/Helper/StatService.cs

@@ -287,159 +287,330 @@ namespace MySystem
             }
             }
             foreach (PosMachinesTwo pos in posList.ToList())
             foreach (PosMachinesTwo pos in posList.ToList())
             {
             {
+                // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && !string.IsNullOrEmpty(m.MerIdcardNo));
                 PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
                 PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
                 if (merchant != null)
                 if (merchant != null)
                 {
                 {
-                    Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId);
-                    // if (user != null)
+                    // PosMerchantOtherInfo otherInfo = db.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == merchant.MerIdcardNo && m.PrizeFlag1 == 0);
+                    // if (otherInfo != null)
                     // {
                     // {
-                    //     if (user.MerchantType == 1)
-                    //     { 
-                    //         user = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId);
-                    //     }
-                    // }
-                    string ParentNav = "";
-                    if (user != null)
-                    {
-                        int GetUserId = user.Id;
-                        ParentNav = user.ParentNav;
-                        int TopUserId = 0;
-                        if (!string.IsNullOrEmpty(ParentNav))
+                    //     otherInfo.PrizeFlag1 = 1;
+                    //     db.SaveChanges();
+                        string ParentNav = "";
+                        Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId);
+                        if (user != null)
                         {
                         {
-                            TopUserId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
-                        }
-                        decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
-                        if (pos.BrandId == 1)
-                        {
-                            ActPrize = ActPrize / 100;
-                        }
-                        if (ActPrize > 0)
-                        {
-                            bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn);
-                            if (!check)
+                            int GetUserId = user.Id;
+                            ParentNav = user.ParentNav;
+                            int TopUserId = 0;
+                            if (!string.IsNullOrEmpty(ParentNav))
                             {
                             {
-                                if (ActPrize == 99)
-                                {
-                                    ActPrize = 100;
-                                }
-                                else if (ActPrize == 199)
-                                {
-                                    ActPrize = 200;
-                                }
-                                else if (ActPrize == 299)
-                                {
-                                    ActPrize = 300;
-                                }
-                                Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
-                                db.ActiveReward.Add(new ActiveReward()
-                                {
-                                    CreateDate = DateTime.Now,
-                                    UpdateDate = DateTime.Now,
-                                    UserId = GetUserId, //创客
-                                    MerchantId = pos.BindMerchantId, //商户
-                                    StandardDate = pos.ActivationTime, //达标日期
-                                    RewardAmount = ActPrize, //奖励金额
-                                    BrandId = pos.BrandId, //品牌
-                                    UserNav = ParentNav, //创客父级
-                                    DirectBuddyNo = merchant.UserId, //商户直属创客
-                                    KqMerNo = merchant.KqMerNo, //渠道商户编号
-                                    KqSnNo = pos.PosSn, //渠道SN号
-                                    SnType = pos.PosSnType, //机具类型
-                                    SnApplyUserId = pos.BuyUserId, //机具申请创客
-                                    ActType = 0, //激活类型
-                                    SnStoreId = pos.StoreId, //SN仓库
-                                    RewardTips = "激活奖励", //奖励描述
-                                    Remark = "激活奖励", //备注
-                                    ActDate = pos.ActivationTime, //激活时间
-                                    TopUserId = TopUserId, //顶级创客
-                                    SeoTitle = machineUser.RealName,
-                                });
-                                db.SaveChanges();
-                                string IdBrand = GetUserId + "_" + pos.BrandId;
-                                UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
-                                if (userData == null)
+                                TopUserId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
+                            }
+                            decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
+                            if (pos.BrandId == 1 || pos.BrandId == 3)
+                            {
+                                ActPrize = ActPrize / 100;
+                            }
+                            if (ActPrize > 0)
+                            {
+                                bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn);
+                                if (!check)
                                 {
                                 {
-                                    userData = db.UserMachineData.Add(new UserMachineData()
+                                    if (ActPrize == 99)
                                     {
                                     {
-                                        IdBrand = IdBrand,
-                                    }).Entity;
+                                        ActPrize = 100;
+                                    }
+                                    else if (ActPrize == 199)
+                                    {
+                                        ActPrize = 200;
+                                    }
+                                    else if (ActPrize == 299)
+                                    {
+                                        ActPrize = 300;
+                                    }
+                                    Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
+                                    db.ActiveReward.Add(new ActiveReward()
+                                    {
+                                        CreateDate = DateTime.Now,
+                                        UpdateDate = DateTime.Now,
+                                        UserId = GetUserId, //创客
+                                        MerchantId = pos.BindMerchantId, //商户
+                                        StandardDate = pos.ActivationTime, //达标日期
+                                        RewardAmount = ActPrize, //奖励金额
+                                        BrandId = pos.BrandId, //品牌
+                                        UserNav = ParentNav, //创客父级
+                                        DirectBuddyNo = merchant.UserId, //商户直属创客
+                                        KqMerNo = merchant.KqMerNo, //渠道商户编号
+                                        KqSnNo = pos.PosSn, //渠道SN号
+                                        SnType = pos.PosSnType, //机具类型
+                                        SnApplyUserId = pos.BuyUserId, //机具申请创客
+                                        ActType = 0, //激活类型
+                                        SnStoreId = pos.StoreId, //SN仓库
+                                        RewardTips = "激活奖励", //奖励描述
+                                        Remark = "激活奖励", //备注
+                                        ActDate = pos.ActivationTime, //激活时间
+                                        TopUserId = TopUserId, //顶级创客
+                                        SeoTitle = machineUser.RealName,
+                                    });
                                     db.SaveChanges();
                                     db.SaveChanges();
-                                }
-                                userData.ActProfit += ActPrize;
-                                db.SaveChanges();
-                                RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
-                                UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
-                                if (account == null)
-                                {
-                                    account = db.UserAccount.Add(new UserAccount()
+                                    string IdBrand = GetUserId + "_" + pos.BrandId;
+                                    UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
+                                    if (userData == null)
                                     {
                                     {
-                                        Id = GetUserId,
-                                        UserId = GetUserId,
+                                        userData = db.UserMachineData.Add(new UserMachineData()
+                                        {
+                                            IdBrand = IdBrand,
+                                        }).Entity;
+                                        db.SaveChanges();
+                                    }
+                                    userData.ActProfit += ActPrize;
+                                    db.SaveChanges();
+                                    RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
+                                    UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
+                                    if (account == null)
+                                    {
+                                        account = db.UserAccount.Add(new UserAccount()
+                                        {
+                                            Id = GetUserId,
+                                            UserId = GetUserId,
+                                        }).Entity;
+                                        db.SaveChanges();
+                                    }
+                                    decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
+                                    decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
+                                    decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
+                                    account.BalanceAmount += ActPrize;
+                                    account.TotalAmount += ActPrize;
+                                    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 = GetUserId, //创客
+                                        ChangeType = 0, //变动类型
+                                        ProductType = pos.BrandId, //产品类型
+                                        ChangeAmount = ActPrize, //变更金额
+                                        BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
+                                        AfterTotalAmount = AfterTotalAmount, //变更后总金额
+                                        BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
+                                        AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
+                                        BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
+                                        AfterBalanceAmount = AfterBalanceAmount, //变更后余额
                                     }).Entity;
                                     }).Entity;
                                     db.SaveChanges();
                                     db.SaveChanges();
+                                    RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
+
+                                    string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
+                                    string monthString = pos.ActivationTime.Value.ToString("yyyyMM");
+                                    // 激活奖励列表
+                                    List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
+                                    if (!dates.Contains(dateString))
+                                    {
+                                        RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
+                                    }
+                                    RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, ActPrize);
+
+                                    List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
+                                    if (!months.Contains(monthString))
+                                    {
+                                        RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
+                                    }
+                                    RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, ActPrize);
+
+                                    // 激活奖励详情
+                                    List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
+                                    if (!actPrizeList.Contains(pos.BindMerchantId))
+                                    {
+                                        RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
+                                    }
+                                    RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, ActPrize);
+
+                                    //收支明细
+                                    RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
+                                    RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, ActPrize);
                                 }
                                 }
-                                decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
-                                decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
-                                decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
-                                account.BalanceAmount += ActPrize;
-                                account.TotalAmount += ActPrize;
-                                decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
-                                decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
-                                decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
-                                UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
+                            }
+                        }
+                    // }
+                }
+            }
+            db.Dispose();
+        }
+
+
+        //根据商户信息发放激活奖励
+        public void dosomething32(int merid = 0)
+        {
+            WebCMSEntities db = new WebCMSEntities();
+            DateTime yesterday = DateTime.Now.AddHours(-3);
+            DateTime today = DateTime.Now;
+            IQueryable<PosMerchantInfo> merList = db.PosMerchantInfo.Where(m => m.ActiveStatus == 1 && !string.IsNullOrEmpty(m.SeoKeyword));
+            if (merid > 0)
+            { 
+                merList = merList.Where(m => m.Id == merid);
+            }
+            else
+            {
+                merList = merList.Where(m => m.MerStandardDate >= yesterday && m.MerStandardDate < today);
+            }
+            foreach (PosMerchantInfo merchant in merList.ToList())
+            {
+                // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && !string.IsNullOrEmpty(m.MerIdcardNo));
+                // PosMerchantOtherInfo otherInfo = db.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == merchant.MerIdcardNo && m.PrizeFlag1 == 0);
+                // if (otherInfo != null)
+                // {
+                //     otherInfo.PrizeFlag1 = 1;
+                //     db.SaveChanges();
+                MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.MerchantNo) ?? new MachineForMerNo();
+                PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forMerNo.SnId) ?? new PosMachinesTwo();
+                string ParentNav = "";
+                Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId);
+                if (user != null)
+                {
+                    int GetUserId = user.Id;
+                    ParentNav = user.ParentNav;
+                    int TopUserId = 0;
+                    if (!string.IsNullOrEmpty(ParentNav))
+                    {
+                        TopUserId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
+                    }
+                    decimal ActPrize = decimal.Parse(function.CheckNum(merchant.SeoKeyword));
+                    if (pos.BrandId == 1 || pos.BrandId == 3)
+                    {
+                        ActPrize = ActPrize / 100;
+                    }
+                    if (ActPrize > 0)
+                    {
+                        bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn);
+                        if (!check)
+                        {
+                            if (ActPrize == 99)
+                            {
+                                ActPrize = 100;
+                            }
+                            else if (ActPrize == 199)
+                            {
+                                ActPrize = 200;
+                            }
+                            else if (ActPrize == 299)
+                            {
+                                ActPrize = 300;
+                            }
+                            Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
+                            db.ActiveReward.Add(new ActiveReward()
+                            {
+                                CreateDate = DateTime.Now,
+                                UpdateDate = DateTime.Now,
+                                UserId = GetUserId, //创客
+                                MerchantId = pos.BindMerchantId, //商户
+                                StandardDate = pos.ActivationTime, //达标日期
+                                RewardAmount = ActPrize, //奖励金额
+                                BrandId = pos.BrandId, //品牌
+                                UserNav = ParentNav, //创客父级
+                                DirectBuddyNo = merchant.UserId, //商户直属创客
+                                KqMerNo = merchant.KqMerNo, //渠道商户编号
+                                KqSnNo = pos.PosSn, //渠道SN号
+                                SnType = pos.PosSnType, //机具类型
+                                SnApplyUserId = pos.BuyUserId, //机具申请创客
+                                ActType = 0, //激活类型
+                                SnStoreId = pos.StoreId, //SN仓库
+                                RewardTips = "激活奖励", //奖励描述
+                                Remark = "激活奖励", //备注
+                                ActDate = pos.ActivationTime, //激活时间
+                                TopUserId = TopUserId, //顶级创客
+                                SeoTitle = machineUser.RealName,
+                            });
+                            db.SaveChanges();
+                            string IdBrand = GetUserId + "_" + pos.BrandId;
+                            UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
+                            if (userData == null)
+                            {
+                                userData = db.UserMachineData.Add(new UserMachineData()
                                 {
                                 {
-                                    CreateDate = DateTime.Now,
-                                    UpdateDate = DateTime.Now,
-                                    UserId = GetUserId, //创客
-                                    ChangeType = 0, //变动类型
-                                    ProductType = pos.BrandId, //产品类型
-                                    ChangeAmount = ActPrize, //变更金额
-                                    BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
-                                    AfterTotalAmount = AfterTotalAmount, //变更后总金额
-                                    BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
-                                    AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
-                                    BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
-                                    AfterBalanceAmount = AfterBalanceAmount, //变更后余额
+                                    IdBrand = IdBrand,
                                 }).Entity;
                                 }).Entity;
                                 db.SaveChanges();
                                 db.SaveChanges();
-                                RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
-
-                                string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
-                                string monthString = pos.ActivationTime.Value.ToString("yyyyMM");
-                                // 激活奖励列表
-                                List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
-                                if (!dates.Contains(dateString))
-                                {
-                                    RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
-                                }
-                                RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, ActPrize);
-
-                                List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
-                                if (!months.Contains(monthString))
+                            }
+                            userData.ActProfit += ActPrize;
+                            db.SaveChanges();
+                            RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
+                            UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
+                            if (account == null)
+                            {
+                                account = db.UserAccount.Add(new UserAccount()
                                 {
                                 {
-                                    RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
-                                }
-                                RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, ActPrize);
+                                    Id = GetUserId,
+                                    UserId = GetUserId,
+                                }).Entity;
+                                db.SaveChanges();
+                            }
+                            decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
+                            decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
+                            decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
+                            account.BalanceAmount += ActPrize;
+                            account.TotalAmount += ActPrize;
+                            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 = GetUserId, //创客
+                                ChangeType = 0, //变动类型
+                                ProductType = pos.BrandId, //产品类型
+                                ChangeAmount = ActPrize, //变更金额
+                                BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
+                                AfterTotalAmount = AfterTotalAmount, //变更后总金额
+                                BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
+                                AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
+                                BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
+                                AfterBalanceAmount = AfterBalanceAmount, //变更后余额
+                            }).Entity;
+                            db.SaveChanges();
+                            RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
+
+                            string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
+                            string monthString = pos.ActivationTime.Value.ToString("yyyyMM");
+                            // 激活奖励列表
+                            List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
+                            if (!dates.Contains(dateString))
+                            {
+                                RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
+                            }
+                            RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, ActPrize);
 
 
-                                // 激活奖励详情
-                                List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
-                                if (!actPrizeList.Contains(pos.BindMerchantId))
-                                {
-                                    RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
-                                }
-                                RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, ActPrize);
+                            List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
+                            if (!months.Contains(monthString))
+                            {
+                                RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
+                            }
+                            RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, ActPrize);
 
 
-                                //收支明细
-                                RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
-                                RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, ActPrize);
+                            // 激活奖励详情
+                            List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
+                            if (!actPrizeList.Contains(pos.BindMerchantId))
+                            {
+                                RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
                             }
                             }
+                            RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, ActPrize);
+
+                            //收支明细
+                            RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
+                            RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, ActPrize);
                         }
                         }
                     }
                     }
                 }
                 }
+                // }
             }
             }
             db.Dispose();
             db.Dispose();
         }
         }
 
 
+        
+
         //3. 前一天的激活记录,根据创客类型,如果是商户型创客,则开机奖励的起始人从此人上级计算。如果不是,则从此人开始计算
         //3. 前一天的激活记录,根据创客类型,如果是商户型创客,则开机奖励的起始人从此人上级计算。如果不是,则从此人开始计算
         public void dosomething4(string date)
         public void dosomething4(string date)
         { 
         { 
@@ -454,163 +625,341 @@ namespace MySystem
                     decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
                     decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
                     if (ActPrize > 0)
                     if (ActPrize > 0)
                     {
                     {
+                        // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && !string.IsNullOrEmpty(m.MerIdcardNo));
                         PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
                         PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
                         if (merchant != null)
                         if (merchant != null)
                         {
                         {
-                            // 从机具所属人上级开始分开机奖励
-                            Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId);
-                            // Users user = db.Users.FirstOrDefault(m => m.Id == merchant.UserId);
-                            // if (user != null)
+                            // PosMerchantOtherInfo otherInfo = db.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == merchant.MerIdcardNo && m.PrizeFlag2 == 0);
+                            // if (otherInfo != null)
                             // {
                             // {
-                            //     if (user.MerchantType == 1)
-                            //     {
-                            //         user = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId);
-                            //     }
-                            // }
-                            if (user != null)
-                            {
-                                if (!string.IsNullOrEmpty(user.ParentNav))
+                            //     otherInfo.PrizeFlag2 = 1;
+                            //     db.SaveChanges();
+                                // 从机具所属人上级开始分开机奖励
+                                Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId);
+                                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.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
-                                            if (machineCount >= 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.UserId) ?? new Users();
-                                                OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
-                                                {
-                                                    CreateDate = DateTime.Now,
-                                                    UpdateDate = DateTime.Now,
-                                                    TradeMonth = yesterday.ToString("yyyyMM"), //交易月
-                                                    TradeDate = yesterday, //达标日期
-                                                    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()
+                                                int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
+                                                int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有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 >= 3 || ActiveCount >= 3 || BigCount >= 2 || BigActiveCount >= 2)
                                                 {
                                                 {
-                                                    CreateDate = DateTime.Now,
-                                                    UpdateDate = DateTime.Now,
-                                                    TradeMonth = yesterday.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))
+                                                    {
+                                                        pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
+                                                    }
+                                                    Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
+                                                    OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
                                                     {
                                                     {
-                                                        IdBrand = IdBrand,
+                                                        CreateDate = DateTime.Now,
+                                                        UpdateDate = DateTime.Now,
+                                                        TradeMonth = yesterday.ToString("yyyyMM"), //交易月
+                                                        TradeDate = yesterday, //达标日期
+                                                        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;
                                                     }).Entity;
+                                                    db.OpenReward.Add(new OpenReward()
+                                                    {
+                                                        CreateDate = DateTime.Now,
+                                                        UpdateDate = DateTime.Now,
+                                                        TradeMonth = yesterday.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();
                                                     db.SaveChanges();
-                                                }
-                                                userData.OpenProfit += Prize;
-                                                db.SaveChanges();
-                                                RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
-                                                //账户入库
-                                                UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
-                                                if (account == null)
-                                                {
-                                                    account = db.UserAccount.Add(new UserAccount()
+                                                    RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
+                                                    //账户入库
+                                                    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;
                                                     }).Entity;
                                                     db.SaveChanges();
                                                     db.SaveChanges();
+                                                    RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
+
+                                                    string dateString = yesterday.ToString("yyyyMMdd");
+                                                    string monthString = yesterday.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("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
+                                                    RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, Prize);
+
+                                                    Prize -= 10;
                                                 }
                                                 }
-                                                //收支明细入库
-                                                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()
+                                            }
+                                        }
+                                    }
+                                }
+                            // }
+                        }
+                    }
+                }
+            }
+            db.Dispose();
+        }
+
+        public void dosomething42(string date)
+        { 
+            WebCMSEntities db = new WebCMSEntities();
+            DateTime yesterday = DateTime.Parse(date + " 00:00:00");
+            DateTime today = DateTime.Parse(DateTime.Parse(date).AddDays(1).ToString("yyyy-MM-dd") + " 00:00:00");
+            List<PosMerchantInfo> merList = db.PosMerchantInfo.Where(m => m.ActiveStatus == 1 && m.MerStandardDate >= yesterday && m.MerStandardDate < today && !string.IsNullOrEmpty(m.SeoKeyword) && m.SeoKeyword != "0").ToList();
+            foreach (PosMerchantInfo merchant in merList)
+            {
+                MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.MerchantNo) ?? new MachineForMerNo();
+                PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forMerNo.SnId) ?? new PosMachinesTwo();
+                if (pos.ActivationTime > DateTime.Now.AddDays(-20) && pos.CreditTrade >= 1000)
+                {
+                    decimal ActPrize = decimal.Parse(function.CheckNum(merchant.SeoKeyword));
+                    if (ActPrize > 0)
+                    {
+                        // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && !string.IsNullOrEmpty(m.MerIdcardNo));
+                        // PosMerchantOtherInfo otherInfo = db.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == merchant.MerIdcardNo && m.PrizeFlag2 == 0);
+                        // if (otherInfo != null)
+                        // {
+                        //     otherInfo.PrizeFlag2 = 1;
+                        //     db.SaveChanges();
+                        // 从机具所属人上级开始分开机奖励
+                        Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId);
+                        if (user != null)
+                        {
+                            if (!string.IsNullOrEmpty(user.ParentNav))
+                            {
+                                decimal Prize = 20;
+                                string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
+                                for (int i = ParentNavs.Length - 1; i >= 0; i--)
+                                {
+                                    int UserId = int.Parse(ParentNavs[i]);
+                                    Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
+                                    if (puser != null && Prize > 0)
+                                    {
+                                        int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
+                                        int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有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 >= 3 || ActiveCount >= 3 || BigCount >= 2 || BigActiveCount >= 2)
+                                        {
+                                            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.UserId) ?? new Users();
+                                            OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
+                                            {
+                                                CreateDate = DateTime.Now,
+                                                UpdateDate = DateTime.Now,
+                                                TradeMonth = yesterday.ToString("yyyyMM"), //交易月
+                                                TradeDate = yesterday, //达标日期
+                                                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 = yesterday.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()
                                                 {
                                                 {
-                                                    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, //变更后余额
+                                                    IdBrand = IdBrand,
                                                 }).Entity;
                                                 }).Entity;
                                                 db.SaveChanges();
                                                 db.SaveChanges();
-                                                RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
-
-                                                string dateString = yesterday.ToString("yyyyMMdd");
-                                                string monthString = yesterday.ToString("yyyyMM");
-                                                // 开机奖励列表
-                                                List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
-                                                if (!dates.Contains(dateString))
+                                            }
+                                            userData.OpenProfit += Prize;
+                                            db.SaveChanges();
+                                            RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
+                                            //账户入库
+                                            UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
+                                            if (account == null)
+                                            {
+                                                account = db.UserAccount.Add(new UserAccount()
                                                 {
                                                 {
-                                                    RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
-                                                }
-                                                RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
+                                                    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()
+                                            {
+                                                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();
+                                            RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
+
+                                            string dateString = yesterday.ToString("yyyyMMdd");
+                                            string monthString = yesterday.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);
+                                            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);
 
 
-                                                //收支明细
-                                                RedisDbconn.Instance.AddList("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
-                                                RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, Prize);
+                                            //收支明细
+                                            RedisDbconn.Instance.AddList("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
+                                            RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, Prize);
 
 
-                                                Prize -= 10;
-                                            }
+                                            Prize -= 10;
                                         }
                                         }
                                     }
                                     }
                                 }
                                 }
                             }
                             }
                         }
                         }
+                        // }
                     }
                     }
                 }
                 }
             }
             }

+ 6 - 1
AppStart/Helper/SycnSpServer/SycnSpMerchantService.cs

@@ -31,13 +31,18 @@ namespace MySystem
                     {
                     {
                         TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
                         TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
                     }
                     }
+                    int BrandId = int.Parse(Mer.ProductType);
+                    if(Mer.MerNo.StartsWith("M900"))
+                    {
+                        BrandId = 3;
+                    }
                     PxcModels.PosMerchantInfo add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
                     PxcModels.PosMerchantInfo add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
                     {
                     {
                         CreateDate = Mer.CreateTime,
                         CreateDate = Mer.CreateTime,
                         UpdateDate = Mer.UpdateTime,
                         UpdateDate = Mer.UpdateTime,
                         TopUserId = TopUserId,
                         TopUserId = TopUserId,
                         MerUserType = user.MerchantType,
                         MerUserType = user.MerchantType,
-                        BrandId = int.Parse(Mer.ProductType),
+                        BrandId = BrandId,
                         SnStoreId = pos.StoreId,
                         SnStoreId = pos.StoreId,
                         SnType = pos.PosSnType,
                         SnType = pos.PosSnType,
                         UserId = pos.UserId,
                         UserId = pos.UserId,

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

@@ -74,7 +74,7 @@ namespace MySystem
                                 decimal TradeAmount = trade.TradeAmount;
                                 decimal TradeAmount = trade.TradeAmount;
                                 int BankCardType = -1;
                                 int BankCardType = -1;
                                 int QrPayFlag = 0;
                                 int QrPayFlag = 0;
-                                if (pos.BrandId == 1)
+                                if (pos.BrandId == 1 || pos.BrandId == 3)
                                 {
                                 {
                                     TradeAmount = TradeAmount / 100;
                                     TradeAmount = TradeAmount / 100;
                                     BankCardType = int.Parse(trade.BankCardType);
                                     BankCardType = int.Parse(trade.BankCardType);
@@ -92,6 +92,11 @@ namespace MySystem
                                     }
                                     }
                                     if(trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
                                     if(trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
                                 }
                                 }
+                                int BrandId = int.Parse(trade.ProductType);
+                                if (trade.MerNo.StartsWith("M900"))
+                                {
+                                    BrandId = 3;
+                                }
                                 db.TradeRecord.Add(new PxcModels.TradeRecord()
                                 db.TradeRecord.Add(new PxcModels.TradeRecord()
                                 {
                                 {
                                     CreateDate = trade.CreateDate,
                                     CreateDate = trade.CreateDate,
@@ -109,7 +114,7 @@ namespace MySystem
                                     TradeAmount = TradeAmount, //交易金额
                                     TradeAmount = TradeAmount, //交易金额
                                     BankCardType = BankCardType, //银行卡类型
                                     BankCardType = BankCardType, //银行卡类型
                                     QrPayFlag = QrPayFlag, //云闪付标识
                                     QrPayFlag = QrPayFlag, //云闪付标识
-                                    BrandId = int.Parse(trade.ProductType), //品牌
+                                    BrandId = BrandId, //品牌
                                     Remark = trade.Remark, //备注
                                     Remark = trade.Remark, //备注
                                     TopUserId = TopUserId, //顶级创客
                                     TopUserId = TopUserId, //顶级创客
                                     MerUserId = pos.UserId, //商户直属创客
                                     MerUserId = pos.UserId, //商户直属创客

+ 24 - 0
Controllers/HomeController.cs

@@ -156,5 +156,29 @@ namespace MySystem.Controllers
             }
             }
             return "ok";
             return "ok";
         }
         }
+
+        public string mutilactprize()
+        {
+            List<int> ids = new List<int>();
+            WebCMSEntities db = new WebCMSEntities();
+            SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
+            foreach (int id in ids)
+            {
+                PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == id);
+                if (pos != null)
+                {
+                    SpModels.ActivateRecord act = spdb.ActivateRecord.FirstOrDefault(m => m.SnNo == pos.PosSn && m.SeoTitle != "0" && !string.IsNullOrEmpty(m.SeoTitle));
+                    if (act != null)
+                    {
+                        pos.SeoKeyword = act.SeoTitle;
+                        db.SaveChanges();
+                        StatService.Instance.dosomething3(pos.Id);
+                    }
+                }
+            }
+            db.Dispose();
+            spdb.Dispose();
+            return "ok";
+        }
     }
     }
 }
 }

+ 17 - 0
Models/PosMerchantOtherInfo.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+
+namespace MySystem.Models
+{
+    public partial class PosMerchantOtherInfo
+    {
+        public string CertId { get; set; }
+        public string MerNo { get; set; }
+        public string RealName { get; set; }
+        public int MerchantId { get; set; }
+        public int PrizeFlag4 { get; set; }
+        public int PrizeFlag3 { get; set; }
+        public int PrizeFlag2 { get; set; }
+        public int PrizeFlag1 { get; set; }
+    }
+}

+ 32 - 0
Models/WebCMSEntities.cs

@@ -99,6 +99,7 @@ namespace MySystem.Models
         public virtual DbSet<PosMachines> PosMachines { get; set; }
         public virtual DbSet<PosMachines> PosMachines { get; set; }
         public virtual DbSet<PosMachinesTwo> PosMachinesTwo { get; set; }
         public virtual DbSet<PosMachinesTwo> PosMachinesTwo { get; set; }
         public virtual DbSet<PosMerchantInfo> PosMerchantInfo { get; set; }
         public virtual DbSet<PosMerchantInfo> PosMerchantInfo { get; set; }
+        public virtual DbSet<PosMerchantOtherInfo> PosMerchantOtherInfo { get; set; }
         public virtual DbSet<ProductComment> ProductComment { get; set; }
         public virtual DbSet<ProductComment> ProductComment { get; set; }
         public virtual DbSet<ProductCommentAgree> ProductCommentAgree { get; set; }
         public virtual DbSet<ProductCommentAgree> ProductCommentAgree { get; set; }
         public virtual DbSet<ProductFareAreas> ProductFareAreas { get; set; }
         public virtual DbSet<ProductFareAreas> ProductFareAreas { get; set; }
@@ -6711,6 +6712,37 @@ namespace MySystem.Models
                 entity.Property(e => e.UserId).HasColumnType("int(11)");
                 entity.Property(e => e.UserId).HasColumnType("int(11)");
             });
             });
 
 
+            modelBuilder.Entity<PosMerchantOtherInfo>(entity =>
+            {
+                entity.HasKey(e => e.CertId)
+                    .HasName("PRIMARY");
+
+                entity.Property(e => e.CertId)
+                    .HasColumnType("varchar(18)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.MerNo)
+                    .HasColumnType("varchar(50)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.MerchantId).HasColumnType("int(11)");
+
+                entity.Property(e => e.PrizeFlag1).HasColumnType("int(11)");
+
+                entity.Property(e => e.PrizeFlag2).HasColumnType("int(11)");
+
+                entity.Property(e => e.PrizeFlag3).HasColumnType("int(11)");
+
+                entity.Property(e => e.PrizeFlag4).HasColumnType("int(11)");
+
+                entity.Property(e => e.RealName)
+                    .HasColumnType("varchar(30)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+            });
+
             modelBuilder.Entity<ProductComment>(entity =>
             modelBuilder.Entity<ProductComment>(entity =>
             {
             {
                 entity.Property(e => e.Id).HasColumnType("int(11)");
                 entity.Property(e => e.Id).HasColumnType("int(11)");

+ 17 - 0
PxcModels/PosMerchantOtherInfo.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+
+namespace MySystem.PxcModels
+{
+    public partial class PosMerchantOtherInfo
+    {
+        public string CertId { get; set; }
+        public string MerNo { get; set; }
+        public string RealName { get; set; }
+        public int MerchantId { get; set; }
+        public int PrizeFlag4 { get; set; }
+        public int PrizeFlag3 { get; set; }
+        public int PrizeFlag2 { get; set; }
+        public int PrizeFlag1 { get; set; }
+    }
+}

+ 32 - 0
PxcModels/WebCMSEntities.cs

@@ -99,6 +99,7 @@ namespace MySystem.PxcModels
         public virtual DbSet<PosMachines> PosMachines { get; set; }
         public virtual DbSet<PosMachines> PosMachines { get; set; }
         public virtual DbSet<PosMachinesTwo> PosMachinesTwo { get; set; }
         public virtual DbSet<PosMachinesTwo> PosMachinesTwo { get; set; }
         public virtual DbSet<PosMerchantInfo> PosMerchantInfo { get; set; }
         public virtual DbSet<PosMerchantInfo> PosMerchantInfo { get; set; }
+        public virtual DbSet<PosMerchantOtherInfo> PosMerchantOtherInfo { get; set; }
         public virtual DbSet<ProductComment> ProductComment { get; set; }
         public virtual DbSet<ProductComment> ProductComment { get; set; }
         public virtual DbSet<ProductCommentAgree> ProductCommentAgree { get; set; }
         public virtual DbSet<ProductCommentAgree> ProductCommentAgree { get; set; }
         public virtual DbSet<ProductFareAreas> ProductFareAreas { get; set; }
         public virtual DbSet<ProductFareAreas> ProductFareAreas { get; set; }
@@ -6711,6 +6712,37 @@ namespace MySystem.PxcModels
                 entity.Property(e => e.UserId).HasColumnType("int(11)");
                 entity.Property(e => e.UserId).HasColumnType("int(11)");
             });
             });
 
 
+            modelBuilder.Entity<PosMerchantOtherInfo>(entity =>
+            {
+                entity.HasKey(e => e.CertId)
+                    .HasName("PRIMARY");
+
+                entity.Property(e => e.CertId)
+                    .HasColumnType("varchar(18)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.MerNo)
+                    .HasColumnType("varchar(50)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.MerchantId).HasColumnType("int(11)");
+
+                entity.Property(e => e.PrizeFlag1).HasColumnType("int(11)");
+
+                entity.Property(e => e.PrizeFlag2).HasColumnType("int(11)");
+
+                entity.Property(e => e.PrizeFlag3).HasColumnType("int(11)");
+
+                entity.Property(e => e.PrizeFlag4).HasColumnType("int(11)");
+
+                entity.Property(e => e.RealName)
+                    .HasColumnType("varchar(30)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+            });
+
             modelBuilder.Entity<ProductComment>(entity =>
             modelBuilder.Entity<ProductComment>(entity =>
             {
             {
                 entity.Property(e => e.Id).HasColumnType("int(11)");
                 entity.Property(e => e.Id).HasColumnType("int(11)");

BIN
bin/Debug/netcoreapp3.0/MySystem.dll


BIN
bin/Debug/netcoreapp3.0/MySystem.pdb


BIN
bin/release/netcoreapp3.0/MySystem.dll


BIN
bin/release/netcoreapp3.0/MySystem.pdb


BIN
obj/Debug/netcoreapp3.0/MySystem.dll


BIN
obj/Debug/netcoreapp3.0/MySystem.pdb


BIN
obj/release/netcoreapp3.0/MySystem.csprojAssemblyReference.cache


BIN
obj/release/netcoreapp3.0/MySystem.dll


BIN
obj/release/netcoreapp3.0/MySystem.pdb