public async Task <IActionResult> BindUser([FromBody] UserReuqest request) { var result = await _userInfoService.SaveUpdateAsync(request); if (result != null && !string.IsNullOrEmpty(result.PhoneNumber)) { result.PhoneNumber = result.PhoneNumber.MaskPhone(); } return(new ApiResult <UserInfo>(result)); }
/// <summary> /// 修改或者注册用户信息 /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <UserInfo> SaveUpdateAsync(UserReuqest request) { var result = new UserInfoEntity(); if (!string.IsNullOrEmpty(request.Id)) { result = await _userInfoData.GetUserById(request.Id); } if (result == null) { result = new UserInfoEntity(); } //新账号需要判断手机号和密码是否正常 if (string.IsNullOrEmpty(result.Id)) { if (string.IsNullOrEmpty(request.PhoneNumber)) { throw new ApiException(-1, "手机号不能为空"); } if (!request.PhoneNumber.IsPhone()) { throw new ApiException(-1, "手机号不正确"); } if (string.IsNullOrEmpty(request.NickName)) { throw new ApiException(-1, "昵称不能为空"); } if (string.IsNullOrEmpty(request.PassWord)) { throw new ApiException(-1, "密码不能为空"); } } //修改头像 if (!string.IsNullOrEmpty(request.HeadImg)) { result.HeadImg = request.HeadImg; } //修改昵称 if (!string.IsNullOrEmpty(request.NickName)) { result.NickName = request.NickName; } //修改密码时间判断密码长度 if (!string.IsNullOrEmpty(request.PassWord)) { if (request.PassWord.Length < 6) { throw new ApiException(-1, "密码长度不能小于6位"); } result.PassWord = request.PassWord; } //修改手机时判断手机是否被绑定 if (!string.IsNullOrEmpty(request.PhoneNumber)) { if (request.PhoneNumber.IndexOf("*") < 0) { var old = await _userInfoData.GetUserByAccount(request.PhoneNumber); if (old != null && old.Id.ToString() != request.Id) { throw new ApiException(-1, "手机号已被注册或已被其它账号绑定"); } result.PhoneNumber = request.PhoneNumber; } } result = await _userInfoData.SaveUpdate(result); return(result.Convert <UserInfoEntity, UserInfo>()); }