Example #1
0
        public ApiResult <UserOutput> Reg([FromBody] RegInput parameter)
        {
            if (!this.IsFormValid())
            {
                return(ApiResult.Failure <UserOutput>(this.FormInvalidReason(), MessageCodes.ParameterValidationFailure));
            }

            var result = Resolve <IUserBaseService>().Reg(parameter);

            return(ToResult(result));
        }
Example #2
0
        public ServiceResult Save(object model, AutoBaseModel autoModel)
        {
            var result = ServiceResult.FailedMessage("保存失败");
            var entity = model.MapTo <Employee>();

            var user = Resolve <IUserService>().GetSingleByUserNameOrMobile(entity.UserName);

            if (user == null)
            {
                if (!RegexHelper.CheckMobile(entity.UserName))
                {
                    return(ServiceResult.FailedWithMessage("当用户不存在,添加新员工时用户名必须为手机号"));
                }

                var regInput = new RegInput
                {
                    Mobile   = entity.UserName,
                    UserName = entity.UserName,
                    Password = "******" // 默认员工密码
                };

                Resolve <IUserBaseService>().Reg(regInput);
                user = Resolve <IUserService>().GetSingleByUserNameOrMobile(entity.UserName);
            }

            if (user == null)
            {
                return(ServiceResult.FailedWithMessage("用户不存在"));
            }

            if (!(user?.Id).HasValue)
            {
                return(ServiceResult.FailedMessage("找不到该用户"));
            }

            var employee = Resolve <IEmployeeService>().GetSingle(s => s.UserId == user.Id);

            if (employee != null && employee.Id != entity.Id)
            {
                return(ServiceResult.FailedMessage($"该用户已关联员工:{employee.Name}"));
            }

            //如果没有 就赋值
            entity.UserId = user.Id;

            if (!Resolve <IEmployeeService>().AddOrUpdate(entity))
            {
                return(ServiceResult.FailedWithMessage("员工添加失败"));
            }

            return(ServiceResult.Success);
        }
Example #3
0
        public ServiceResult AddSingle(Employee entity)
        {
            var user = Resolve <IUserService>().GetSingleByUserNameOrMobile(entity.UserName);

            if (user == null)
            {
                if (!RegexHelper.CheckMobile(entity.UserName))
                {
                    return(ServiceResult.Failure("当用户不存在,添加新员工时用户名必须为手机号"));
                }

                var regInput = new RegInput {
                    Mobile   = entity.UserName,
                    UserName = entity.UserName,
                    Password = "******" // 默认员工密码
                };

                Resolve <IUserBaseService>().Reg(regInput);
                user = Resolve <IUserService>().GetSingleByUserNameOrMobile(entity.UserName);
            }

            if (user == null)
            {
                return(ServiceResult.Failure("用户不存在"));
            }

            var employee = Resolve <IEmployeeService>().GetSingle(s => s.UserId == user.Id);

            if (employee != null && employee.Id != entity.Id)
            {
                return(ServiceResult.Failure($"该用户已关联员工:{employee.Name}"));
            }

            //如果没有 就赋值
            entity.UserId = user.Id;

            if (!Resolve <IEmployeeService>().AddOrUpdate(entity))
            {
                return(ServiceResult.Failure("员工添加失败"));
            }
            return(ServiceResult.Success);
        }
Example #4
0
        public Tuple <ServiceResult, UserOutput> Reg(RegInput regInput)
        {
            var config = Resolve <IAutoConfigService>().GetValue <AdminCenterConfig>();

            if (!config.IsAllowUserReg)
            {
                return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Failure("系统维护升级中,禁止会员注册,请稍后重试"),
                                                             null));
            }

            var userConfig = Resolve <IAutoConfigService>().GetValue <UserConfig>();

            if (userConfig.NeedPhoneVierfyCode)
            {
                if (!Resolve <ISmsService>().CheckVerifiyCode(regInput.Mobile, regInput.VerifiyCode.ConvertToLong()))
                {
                    return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Failure("手机验证码错误"), null));
                }
            }

            // 验证推荐账号
            if (!regInput.ParentUserName.IsNullOrEmpty())
            {
                if (regInput.ParentUserName == regInput.Mobile || regInput.ParentUserName == regInput.UserName)
                {
                    return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Failure("推荐账号不能为注册账号"), null));
                }

                var parentUser = Resolve <IUserService>().GetSingle(s => s.UserName == regInput.ParentUserName);
                if (parentUser != null)
                {
                    if (parentUser.Status != Status.Normal)
                    {
                        return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Failure("推荐人状态不正常"), null));
                    }

                    regInput.ParentId = parentUser.Id;
                }
                else
                {
                    return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Failure("推荐账号不存在"), null));
                }
            }
            else
            {
                if (userConfig.RegRequiredParentUser)
                {
                    return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Failure("注册必须要推荐账号"), null));
                }
            }

            var user = new User {
                UserName = regInput?.UserName?.TrimEnd(' '),
                Mobile   = regInput?.Mobile?.TrimEnd(' '),
                Email    = regInput?.Email?.TrimEnd(' '),
                Name     = regInput?.Name?.TrimEnd(' '),
                ParentId = regInput.ParentId,
                Status   = regInput.Status,
            };

            if (regInput.UserName.IsNullOrEmpty())
            {
                user.UserName = regInput.Mobile;
            }

            if (user.Email.IsNullOrEmpty())
            {
                user.Email = user.UserName + userConfig.RegEmailPostfix;
            }

            user.Detail = new UserDetail {
                Password    = regInput.Password,
                PayPassword = regInput.PayPassword,
                OpenId      = regInput.OpenId
            };

            if (!regInput.OpenId.IsNullOrEmpty())
            {
                user.Detail.OpenId = regInput.OpenId;
            }

            if (!user.Detail.PayPassword.IsNullOrEmpty())
            {
                if (!RegexHelper.CheckPayPasswrod(user.Detail.PayPassword))
                {
                    return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Failure("支付密码必须为六位数字"), null));
                }
                user.Detail.PayPassword = regInput.PayPassword.ToMd5HashString();
            }

            var result = Register(user);

            if (!result.Succeeded)
            {
                return(new Tuple <ServiceResult, UserOutput>(result, null));
            }

            var userOutput = Resolve <IUserDetailService>().GetUserOutput(user.Id);

            return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Success, userOutput));
        }
Example #5
0
        public ServiceResult Reg(UserLevelRegForm regForm)
        {
            regForm.IdCard = regForm.IdCard.Trim().ToLower();
            var config = Resolve <IAutoConfigService>().GetValue <UserLevelRegConfig>();

            if (config.CardNumber > 0)
            {
                var cardList = Resolve <IUserLevelService>().GetIdList(r => r.IdCard == regForm.IdCard);
                if (cardList.Count >= config.CardNumber)
                {
                    return(ServiceResult.Failure($"同一号码注册不能超过{config.CardNumber}个"));
                }
            }
            if (config.MobileNumber > 0)
            {
                var cardList = Resolve <IUserLevelService>().GetIdList(r => r.Mobile == regForm.Mobile);
                if (cardList.Count >= config.MobileNumber)
                {
                    return(ServiceResult.Failure($"同一号码注册不能超过{config.MobileNumber}个"));
                }
            }

            var userLevelConfigList = Resolve <IAutoConfigService>().GetList <UserLevelConfig>();
            var userLevelConfig     = userLevelConfigList.FirstOrDefault(r => r.Id == regForm.ConfigId);

            if (userLevelConfig == null || userLevelConfig.Status != Status.Normal)
            {
                return(ServiceResult.Failure($"消费套餐不存在"));
            }

            var regInput = new RegInput {
                Name           = regForm.Name,
                UserName       = regForm.UserName,
                ParentUserName = regForm.ParentUserName,
                VerifiyCode    = regForm.VerifiyCode,
                Mobile         = regForm.Mobile,
                Status         = Status.Freeze,
                Password       = regForm.Password,
                PayPassword    = regForm.PayPassword,
            };

            // 注册会员
            var regResult = Resolve <IUserBaseService>().Reg(regInput);

            if (!regResult.Item1.Succeeded)
            {
                return(regResult.Item1);
            }

            // 添加会员消费记录
            var userOutput = regResult.Item2;

            var result  = ServiceResult.Success;
            var context = Repository <IUserLevelRepository>().RepositoryContext;

            try {
                context.BeginTransaction();
                var userLevel = regForm.MapTo <UserLevel>();
                userLevel.UserId    = userOutput.Id;
                userLevel.ParentId  = userOutput.ParentId;
                userLevel.LevelName = userLevelConfig.Name;
                userLevel.Status    = UserLevelStatus.NotActivated;

                Add(userLevel);
                var userLevelRecord = userLevelConfig.MapTo <UserLevelRecord>();
                userLevelRecord.ConfigId = userLevelConfig.Id;
                userLevelRecord.UserId   = userLevel.UserId;
                userLevelRecord.LevelId  = userLevel.Id;
                Resolve <IUserLevelRecordService>().Add(userLevelRecord);

                context.SaveChanges();
                context.CommitTransaction();
            } catch (Exception ex) {
                context.RollbackTransaction();
                result = ServiceResult.Failure(ex.Message);
            } finally {
                context.DisposeTransaction();
            }

            return(result);
        }
Example #6
0
        public Tuple <ServiceResult, UserOutput> Reg(RegInput regInput)
        {
            var config = Resolve <IAutoConfigService>().GetValue <AdminCenterConfig>();

            if (!config.IsAllowUserReg)
            {
                return(new Tuple <ServiceResult, UserOutput>(ServiceResult.FailedWithMessage("系统维护升级中,禁止会员注册,请稍后重试"),
                                                             null));
            }

            var userConfig = Resolve <IAutoConfigService>().GetValue <UserConfig>();

            if (userConfig.NeedPhoneVierfyCode)
            {
                //if (!_messageManager.CheckMobileVerifiyCode(parameter.Mobile,
                //    parameter.MobileVerifiyCode.ConvertToLong())) {
                //    return ApiResult.Failure<UserOutput>("手机验证码错误", MessageCodes.ParameterValidationFailure);
                //}
            }

            // 验证推荐账号
            if (!regInput.ParentUserName.IsNullOrEmpty())
            {
                if (regInput.ParentUserName == regInput.Mobile || regInput.ParentUserName == regInput.UserName)
                {
                    return(new Tuple <ServiceResult, UserOutput>(ServiceResult.FailedWithMessage("推荐账号不能为注册账号"), null));
                }

                var parentUser = Resolve <IUserService>().GetSingle(s => s.UserName == regInput.ParentUserName);
                if (parentUser != null)
                {
                    if (parentUser.Status != Status.Normal)
                    {
                        return(new Tuple <ServiceResult, UserOutput>(ServiceResult.FailedWithMessage("推荐人状态不正常"), null));
                    }

                    regInput.ParentId = parentUser.Id;
                }
                else
                {
                    return(new Tuple <ServiceResult, UserOutput>(ServiceResult.FailedWithMessage("推荐账号不存在"), null));
                }
            }

            if (userConfig.NeedSelectServiceCenter && regInput.ParentId <= 0)
            {
                return(new Tuple <ServiceResult, UserOutput>(ServiceResult.FailedWithMessage("推荐人不能为空"), null));
            }

            var user = new User
            {
                UserName = regInput?.UserName?.TrimEnd(' '),
                Mobile   = regInput?.Mobile?.TrimEnd(' '),
                Email    = regInput?.Email?.TrimEnd(' '),
                Name     = regInput?.Name?.TrimEnd(' ')
            };

            if (regInput.UserName.IsNullOrEmpty())
            {
                user.UserName = regInput.Mobile;
            }

            if (user.Email.IsNullOrEmpty())
            {
                user.Email = user.UserName + userConfig.RegEmailPostfix;
            }

            user.Detail = new UserDetail
            {
                Password    = regInput.Password,
                PayPassword = regInput.PayPassword,
                OpenId      = regInput.OpenId
            };

            if (!regInput.ServiceCenter.IsNullOrEmpty())
            {
                var serviceUser = Resolve <IUserService>().GetSingle(regInput.ServiceCenter);
                if (serviceUser == null)
                {
                    return(new Tuple <ServiceResult, UserOutput>(ServiceResult.FailedWithMessage("服务中心不存在"), null));
                }

                if (serviceUser.Status != Status.Normal)
                {
                    return(new Tuple <ServiceResult, UserOutput>(ServiceResult.FailedWithMessage("服务中心用户状态不正常"), null));
                }
            }

            if (!regInput.OpenId.IsNullOrEmpty())
            {
                user.Detail.OpenId = regInput.OpenId;
            }

            if (!user.Detail.PayPassword.IsNullOrEmpty())
            {
                user.Detail.PayPassword = regInput.PayPassword.ToMd5HashString();
            }

            var result = Register(user);

            if (result.Succeeded)
            {
                return(new Tuple <ServiceResult, UserOutput>(result, null));
            }

            var userOutput = Resolve <IUserDetailService>().GetUserOutput(user.Id);

            return(new Tuple <ServiceResult, UserOutput>(ServiceResult.Success, userOutput));
        }
Example #7
0
        /// <summary>
        ///     商家服务订购
        /// </summary>
        /// <param name="orderBuyInput"></param>
        /// <returns></returns>
        public async Task <Tuple <ServiceResult, OrderBuyOutput> > Buy(UserRightsOrderInput orderBuyInput)
        {
            #region 安全验证

            var result         = ServiceResult.Success;
            var orderBuyOutput = new OrderBuyOutput();
            var user           = Resolve <IUserService>().GetNomarlUser(orderBuyInput.UserId);
            if (user == null)
            {
                return(Tuple.Create(ServiceResult.Failure("用户不存在,或状态不正常"), orderBuyOutput));
            }

            orderBuyInput.BuyUser = user; // 购买用户等于当前用户

            user.Detail = null;           // 减少体积保存
            user.Map    = null;
            if (orderBuyInput.GradeId.IsGuidNullOrEmpty())
            {
                return(Tuple.Create(ServiceResult.Failure("等级Id不能为空"), orderBuyOutput));
            }

            orderBuyInput.User = user;
            var userGrades = Resolve <IAutoConfigService>().GetList <UserGradeConfig>();
            var buyGrade   = userGrades.FirstOrDefault(r => r.Id == orderBuyInput.GradeId);
            if (buyGrade == null)
            {
                return(Tuple.Create(ServiceResult.Failure("购买的等级不存在"), orderBuyOutput));
            }

            var userRightConfig = Resolve <IAutoConfigService>().GetList <UserRightsConfig>()
                                  .FirstOrDefault(c => c.GradeId == buyGrade.Id);
            if (userRightConfig != null && !userRightConfig.IsOpen)
            {
                return(Tuple.Create(ServiceResult.Failure("该等级暂未开放"), orderBuyOutput));
            }

            orderBuyInput.BuyGrade     = buyGrade;
            orderBuyInput.CurrentGrade = userGrades.FirstOrDefault(r => r.Id == user.GradeId);
            if (orderBuyInput.CurrentGrade == null)
            {
                return(Tuple.Create(ServiceResult.Failure("您的等级不存在"), orderBuyOutput));
            }

            // 准营销中心,和营销中心的开通只能是管理员 动态配置,不用写死
            //if (orderBuyInput.GradeId == Guid.Parse("f2b8d961-3fec-462d-91e8-d381488ea972") || orderBuyInput.GradeId == Guid.Parse("cc873faa-749b-449b-b85a-c7d26f626feb"))
            //{
            if (orderBuyInput.OpenType == UserRightOpenType.AdminOpenHightGrade)
            {
                if (!Resolve <IUserService>().IsAdmin(user.Id))
                {
                    return(Tuple.Create(ServiceResult.Failure("您不是管理员无权开通"), orderBuyOutput));
                }

                if (orderBuyInput.Parent.IsNullOrEmpty())
                {
                    return(Tuple.Create(ServiceResult.Failure("推荐人不能为空"), orderBuyOutput));
                }

                orderBuyInput.ParnetUser = Resolve <IUserService>().GetSingleByUserNameOrMobile(orderBuyInput.Parent);
                if (orderBuyInput.ParnetUser == null)
                {
                    return(Tuple.Create(ServiceResult.Failure("推荐人不能为空,不能开通营销中心"), orderBuyOutput));
                }
            }
            //}

            if (orderBuyInput.OpenType == UserRightOpenType.OpenToOtherByPay ||
                orderBuyInput.OpenType == UserRightOpenType.AdminOpenHightGrade ||
                orderBuyInput.OpenType == UserRightOpenType.OpenToOtherByRight)
            {
                if (orderBuyInput.Mobile.IsNullOrEmpty())
                {
                    return(Tuple.Create(ServiceResult.Failure("请输入手机号码"), orderBuyOutput));
                }

                if (orderBuyInput.Name.IsNullOrEmpty())
                {
                    return(Tuple.Create(ServiceResult.Failure("请输入公司名称或姓名"), orderBuyOutput));
                }

                // 查找是否为注册用户
                var find = Resolve <IUserService>().GetSingleByUserNameOrMobile(orderBuyInput.Mobile);
                if (find != null)
                {
                    var findUserGrade = userGrades.FirstOrDefault(r => r.Id == find.GradeId);
                    if (findUserGrade == null)
                    {
                        return(Tuple.Create(ServiceResult.Failure("激活的用户等级不存在"), orderBuyOutput));
                    }

                    if (findUserGrade.Price > 0.01m)
                    {
                        return(Tuple.Create(ServiceResult.Failure("该用户已激活"), orderBuyOutput));
                    }

                    //var records = Resolve<IRecordService>().GetListNoTracking(s => s.Type == typeof(UserDetail).FullName);
                    //var findRecord = records.FirstOrDefault(s => s.UserId == user.Id);
                    //var findUser = findRecord?.Value?.ToObject<RegInput>();
                    //if (findUser != null)
                    //    orderBuyInput.RegInfo = findUser;
                    //else
                    //{
                    orderBuyInput.RegInfo = new RegInput {
                        Mobile      = find.Mobile,
                        UserName    = find.Mobile,
                        Name        = find.Name,
                        Password    = "******",
                        PayPassword = "******",
                        ParentId    = find.ParentId
                    };
                    // }
                }
                else
                {
                    if (!RegexHelper.CheckMobile(orderBuyInput.Mobile))
                    {
                        return(Tuple.Create(ServiceResult.Failure("手机号码格式不正确"), orderBuyOutput));
                    }
                    // 注册新用户
                    var password    = RandomHelper.PassWord();
                    var payPassword = RandomHelper.PayPassWord();
                    var regInput    = new RegInput {
                        Mobile      = orderBuyInput.Mobile,
                        UserName    = orderBuyInput.Mobile,
                        Name        = orderBuyInput.Name,
                        Password    = password,
                        PayPassword = payPassword,
                        ParentId    = orderBuyInput.UserId
                    };
                    orderBuyInput.RegInfo = regInput;
                    // 如果是管理员,则推荐人Id改为输入的推荐人Id
                    if (orderBuyInput.OpenType == UserRightOpenType.AdminOpenHightGrade)
                    {
                        regInput.ParentId = orderBuyInput.ParnetUser.Id;
                    }
                    //
                    var userRegResult = Resolve <IUserBaseService>().Reg(regInput);
                    if (!userRegResult.Item1.Succeeded)
                    {
                        return(Tuple.Create(ServiceResult.Failure("新会员注册失败" + userRegResult),
                                            orderBuyOutput));
                    }
                    // await Resolve<IRecordService>().AddAsync(new Record() { Type = typeof(UserDetail).FullName, Value = regInput.ToJsons() });

                    find = Resolve <IUserService>().GetSingle(orderBuyInput.Mobile);

                    var message =
                        $"恭喜您,您的账号已注册成功。您的登录账号为:{regInput.Mobile},初始登录密码:{password} 初始支付密码:{payPassword} 请妥善保管.";
                    Resolve <ISmsService>().SendRaw(find.Mobile, message);

                    message =
                        $"您推荐的商家已注册成功.登录账号:{regInput.Mobile},初始登录密码:{password} 初始支付密码:{payPassword} 请尽快让商家悉知,第一时间指导商家使用系统.";

                    var userDetail = Resolve <IUserDetailService>().GetSingle(u => u.UserId == user.Id);
                    userDetail.RegionId = orderBuyInput.RegionId.ToInt64();
                    Resolve <IUserDetailService>().Update(userDetail);
                    Resolve <ISmsService>().SendRaw(user.Mobile, message);
                }

                orderBuyInput.BuyUser = find;
            }

            #endregion 安全验证

            orderBuyInput.UserRightList = GetList(r => r.UserId == user.Id);

            // 如果是帮别人开通
            if (orderBuyInput.OpenType == UserRightOpenType.OpenToOtherByRight)
            {
                return(await OpenToOther(orderBuyInput));
            }

            // 其他三种情况都需要支付 +或者管理员帮他们开通
            return(await OpenSelfOrUpgrade(orderBuyInput));
        }