/// <summary>
        /// 更新代理返点的同时更新他的下级返点
        /// </summary>
        public void UpdateLowerAgentRebate(string agentId, string gameCode, string gameType, decimal rebate, int rebateType)
        {
            var ocAgentMannger = new OCAgentManager();
            var localAgent     = new LocalLoginBusiness();
            //查询全部下级代理
            var agentList = ocAgentMannger.QueryAgentSubUser(agentId);

            if (agentList == null || agentList.Count == 0)
            {
                return;
            }
            var keepRebate = decimal.Parse(new CacheDataBusiness().QueryCoreConfigByKey("ReservReturnPoint").ConfigValue);

            foreach (var agent in agentList)
            {
                var agenrRebate = ocAgentMannger.QueryOCAgentDefaultRebateByRebateType(agent.UserId, gameCode, gameType, rebateType);
                if (agenrRebate == null)
                {
                    continue;
                }
                if (rebate > agenrRebate.Rebate || (rebate == agenrRebate.Rebate && keepRebate == 0M))
                {
                    continue;
                }
                agenrRebate.Rebate     = rebate - keepRebate;
                agenrRebate.CreateTime = DateTime.Now;
                ocAgentMannger.UpdateOCAgentRebate(agenrRebate);

                UpdateLowerAgentRebate(agent.UserId, gameCode, gameType, agenrRebate.Rebate, rebateType);
            }
        }
Exemple #2
0
 /// <summary>
 /// 刷新Redis中用户余额
 /// </summary>
 public static void RefreshRedisUserBalance(string userId)
 {
     try
     {
         var    db          = RedisHelper.DB_UserBalance;
         string key         = string.Format("UserBalance_{0}", userId);
         var    fund        = new LocalLoginBusiness();
         var    userBalance = fund.QueryUserBalance(userId);
         var    json        = JsonHelper.Serialize(userBalance);
         db.StringSetAsync(key, json, TimeSpan.FromSeconds(60 * 2));
     }
     catch (Exception ex)
     {
         //Common.Log.LogWriterGetter.GetLogWriter().Write("BusinessHelper", "RefreshRedisUserBalance", ex);
     }
 }
Exemple #3
0
        public void Payin_To_Balance(AccountType accountType, string category, string userId, string orderId, decimal payMoney, string summary, RedBagCategory redBag = RedBagCategory.FillMoney, string operatorId = "")
        {
            //if (accountType == AccountType.Freeze)
            //    throw new Exception("退款账户不能为冻结账户");

            if (payMoney <= 0M)
            {
                return;
            }
            //throw new Exception("转入金额不能小于0.");

            var balanceManager = new LocalLoginBusiness();
            var fundManager    = new FundManager();
            //查询帐户余额

            var userBalance = balanceManager.QueryUserBalanceInfo(userId);

            if (userBalance == null)
            {
                throw new Exception("用户帐户不存在 - " + userId);
            }

            var payDetailList = new List <PayDetail>();

            payDetailList.Add(new PayDetail
            {
                AccountType = accountType,
                PayMoney    = payMoney,
                PayType     = PayType.Payin,
            });
            var before = 0M;
            var after  = 0M;

            switch (accountType)
            {
            case AccountType.Bonus:
                before = userBalance.BonusBalance;
                after  = userBalance.BonusBalance + payMoney;
                //userBalance.BonusBalance = after;
                break;

            case AccountType.Commission:
                before = userBalance.CommissionBalance;
                after  = userBalance.CommissionBalance + payMoney;
                //userBalance.CommissionBalance = after;
                break;

            case AccountType.FillMoney:
                before = userBalance.FillMoneyBalance;
                after  = userBalance.FillMoneyBalance + payMoney;
                //userBalance.FillMoneyBalance = after;
                break;

            case AccountType.Experts:
                before = userBalance.ExpertsBalance;
                after  = userBalance.ExpertsBalance + payMoney;
                //userBalance.ExpertsBalance = after;
                break;

            case AccountType.RedBag:
                before = userBalance.RedBagBalance;
                after  = userBalance.RedBagBalance + payMoney;
                //userBalance.RedBagBalance = after;
                var RedBagDetail = new C_Fund_RedBagDetail
                {
                    CreateTime     = DateTime.Now,
                    OrderId        = orderId,
                    RedBagCategory = (int)redBag,
                    RedBagMoney    = payMoney,
                    UserId         = userId,
                };
                fundManager.AddRedBagDetail(RedBagDetail);
                break;

            case AccountType.Freeze:
                before = userBalance.FreezeBalance;
                after  = userBalance.FreezeBalance + payMoney;
                //userBalance.FreezeBalance = after;
                break;

            case AccountType.CPS:
                before = userBalance.CPSBalance;
                after  = userBalance.CPSBalance + payMoney;
                //userBalance.CPSBalance = after;
                break;

            default:
                throw new ArgumentException("不支持的账户类型 - " + accountType);
            }
            var FundDetail = new C_Fund_Detail
            {
                Category      = category,
                CreateTime    = DateTime.Now,
                KeyLine       = orderId,
                OrderId       = orderId,
                AccountType   = (int)accountType,
                PayMoney      = payMoney,
                PayType       = (int)PayType.Payin,
                Summary       = summary,
                UserId        = userId,
                BeforeBalance = before,
                AfterBalance  = after,
                OperatorId    = string.IsNullOrEmpty(operatorId) ? userId : operatorId,
            };

            fundManager.AddFundDetail(FundDetail);
            //balanceManager.UpdateUserBalance(userBalance);
            PayToUserBalance(userId, payDetailList.ToArray());
        }
Exemple #4
0
        /// <summary>
        /// 收入 --添加用户成长值
        /// 返回用户vip等级
        /// </summary>
        public int Payin_UserGrowth(string category, string orderId, string userId, int userGrowth, string summary)
        {
            if (userGrowth <= 0)
            {
                return(0);
            }

            var balanceManager = new LocalLoginBusiness();
            //var fundManager = new FundManager();
            var user                  = balanceManager.GetRegisterById(userId);
            var userBalance           = balanceManager.QueryUserBalanceInfo(userId);
            var Fund_UserGrowthDetail = new C_Fund_UserGrowthDetail()
            {
                OrderId       = orderId,
                UserId        = userId,
                Category      = category,
                CreateTime    = DateTime.Now,
                BeforeBalance = userBalance.UserGrowth,
                PayMoney      = userGrowth,
                PayType       = (int)PayType.Payin,
                Summary       = summary,
                AfterBalance  = userBalance.UserGrowth + userGrowth,
            };

            DB.GetDal <C_Fund_UserGrowthDetail>().Add(Fund_UserGrowthDetail);

            var payDetailList = new List <PayDetail>();

            payDetailList.Add(new PayDetail
            {
                AccountType = AccountType.UserGrowth,
                PayMoney    = userGrowth,
                PayType     = PayType.Payin,
            });

            var vipLevel = GetUserVipLevel(userBalance.UserGrowth + userGrowth);

            //更新成长值
            //userBalance.UserGrowth += userGrowth;
            //balanceManager.UpdateUserBalance(userBalance);
            PayToUserBalance(userId, payDetailList.ToArray());
            if (user.VipLevel < vipLevel)
            {
                for (int i = user.VipLevel + 1; i <= vipLevel; i++)
                {
                    //达到相应等级赠送红包
                    if (new int[] { 3, 4, 5, 6 }.Contains(i))
                    {
                        var redBag = 0M;
                        switch (i)
                        {
                        case 3:
                            redBag = 2M;
                            break;

                        case 4:
                            redBag = 10M;
                            break;

                        case 5:
                            redBag = 20M;
                            break;

                        case 6:
                            redBag = 88M;
                            break;

                        default:
                            break;
                        }
                        if (redBag > 0M)
                        {
                            Payin_To_Balance(AccountType.RedBag, FundCategory_UserLevelUp, userId, orderId, redBag, string.Format("用户等级提升到{0}级", i), RedBagCategory.UserUpLevel);
                        }
                    }
                }
                //修改vip等级
                user.VipLevel = vipLevel;
                DB.GetDal <C_User_Register>().Update(user);
            }

            return(user.VipLevel);
        }
        public CommonActionResult UserRegister(RegisterInfo_Local regInfo, string fxid)
        {
            DB.Begin();
            try
            {
                string userId  = null;
                var    roleIds = ConfigHelper.AllConfigInfo["PageRegisterDefaultRole"].ToString().Split(',');
                #region 注册权限控制帐号

                var authBiz    = new GameBizAuthBusiness();
                var regBiz     = new RegisterBusiness();
                var userEntity = new SystemUser
                {
                    RegFrom = string.IsNullOrEmpty(regInfo.ComeFrom) ? "LOCAL" : regInfo.ComeFrom,
                    AgentId = regInfo.AgentId,
                };
                regBiz.RegisterUser(userEntity, roleIds);
                userId = userEntity.UserId;

                #endregion

                #region 注册核心系统显示帐号

                var userRegInfo = new UserRegInfo
                {
                    DisplayName = regInfo.LoginName,
                    ComeFrom    = string.IsNullOrEmpty(regInfo.ComeFrom) ? "LOCAL" : regInfo.ComeFrom,
                    Referrer    = regInfo.Referrer,
                    ReferrerUrl = regInfo.ReferrerUrl,
                    RegisterIp  = regInfo.RegisterIp,
                    RegType     = regInfo.RegType,
                    AgentId     = regInfo.AgentId,
                };

                regBiz.RegisterUser(userEntity, userRegInfo);

                #endregion

                #region 注册本地登录帐号

                var loginBiz    = new LocalLoginBusiness();
                var loginEntity = new LoginLocal
                {
                    LoginName = regInfo.LoginName,
                    Password  = regInfo.Password,
                    mobile    = regInfo.Mobile
                };
                loginBiz.Register(loginEntity, userEntity.UserId);

                #endregion

                #region 如果是通过代理链接注册,则设置用户返点 屏蔽:范
                if (!string.IsNullOrEmpty(regInfo.AgentId))
                {
                    SetUserRebate(userId, regInfo.AgentId);
                }

                #endregion

                #region 初始化用户战绩数据和中奖概率数据

                InitUserBeedingAndBounsPercent(userId);

                #endregion

                #region 初始化其它数据

                InitBlog_ProfileBonusLevel(userId);
                InitUserAttentionSummary(userId);

                #endregion

                #region fxid分享推广数据
                if (!string.IsNullOrEmpty(fxid))
                {
                    var manager = new BlogManager();
                    manager.AddBlog_UserShareSpread(new E_Blog_UserShareSpread
                    {
                        UserId               = userId,
                        AgentId              = fxid,
                        CreateTime           = DateTime.Now,
                        isGiveLotteryRedBag  = false,
                        isGiveRegisterRedBag = false,
                        UpdateTime           = DateTime.Now,
                        giveRedBagMoney      = 0,
                        isGiveRechargeRedBag = false
                    });
                }
                #endregion

                DB.Commit();

                return(new CommonActionResult
                {
                    IsSuccess = true,
                    Message = "注册成功",
                    ReturnValue = userId,
                });
            }
            catch (Exception ex) {
                DB.Rollback();
                throw ex;
            }
        }
        public void RegisterUser(SystemUser user, UserRegInfo regInfo)
        {
            DB.Begin();
            try
            {
                var loginBiz = new LocalLoginBusiness();

                var register = new C_User_Register
                {
                    DisplayName = regInfo.DisplayName,
                    ComeFrom    = regInfo.ComeFrom,
                    RegType     = regInfo.RegType,
                    RegisterIp  = regInfo.RegisterIp,
                    Referrer    = regInfo.Referrer,
                    ReferrerUrl = regInfo.ReferrerUrl,
                    IsEnable    = true,
                    IsAgent     = false,
                    IsFillMoney = false,
                    AgentId     = regInfo.AgentId,
                    CreateTime  = DateTime.Now,
                    VipLevel    = 0,
                    UserId      = user.UserId,
                };
                try
                {
                    if (!string.IsNullOrEmpty(regInfo.AgentId))
                    {
                        var agentUser = loginBiz.GetRegisterById(regInfo.AgentId);
                        if (agentUser != null)
                        {
                            register.ParentPath = agentUser.ParentPath + "/" + agentUser.UserId;
                        }
                    }
                }
                catch { }

                var AuthUser = new C_Auth_Users
                {
                    UserId     = user.UserId,
                    RegFrom    = user.RegFrom,
                    AgentId    = regInfo.AgentId,
                    CreateTime = DateTime.Now,
                };


                DB.GetDal <C_User_Register>().Add(register);
                DB.GetDal <C_Auth_Users>().Add(AuthUser);

                var balance = new C_User_Balance
                {
                    BonusBalance      = 0M,
                    FreezeBalance     = 0M,
                    CommissionBalance = 0M,
                    ExpertsBalance    = 0M,
                    FillMoneyBalance  = 0M,
                    RedBagBalance     = 0M,
                    CurrentDouDou     = 0,
                    UserGrowth        = 0,
                    IsSetPwd          = false,
                    NeedPwdPlace      = string.Empty,
                    Password          = string.Empty,
                    UserId            = user.UserId,
                    Version           = 0,
                    AgentId           = regInfo.AgentId,
                };
                DB.GetDal <C_User_Balance>().Add(balance);

                DB.Commit();
            }
            catch (Exception ex)
            {
                DB.Rollback();
                throw ex;
            }
        }