Commit 23e6620a by 杨树贤

优化

parent 53a50fbf
......@@ -3,8 +3,39 @@
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\UserService;
class UserController extends Controller
{
//绑定邮箱
public function bindEmail(\Request $request)
{
$ucId = $request->input('uc_id');
if (empty($ucId)) {
return $this->setError('uc_id不能为空');
}
$email = $request->input('email');
if (empty($email)) {
return $this->setError('email不能为空');
}
UserService::bindEmail($ucId, $email);
return $this->setSuccess('绑定成功');
}
//绑定手机号
public function bindMobile(\Request $request)
{
$ucId = $request->input('uc_id');
if (empty($ucId)) {
return $this->setError('uc_id不能为空');
}
$mobile = $request->input('mobile');
if (empty($mobile)) {
return $this->setError('mobile不能为空');
}
UserService::bindEmail($ucId, $mobile);
return $this->setSuccess('绑定成功');
}
}
......@@ -28,7 +28,7 @@ class UserRegister extends FormRequest
{
return [
'password' => 'required',
'salt' => 'required',
//'salt' => 'required',
'mobile' => 'required_without:email',
'email' => 'required_without:mobile',
'init_org_id' => 'required'
......
......@@ -61,7 +61,35 @@ class UserService
UserModel::where('uc_id', $user['uc_id'])->update(['last_login_time' => time()]);
return $user ?: [];
}
//绑定邮箱
public static function bindEmail($ucId, $email)
{
//先去判断这个email是否已经被其它账号使用了
$exists = UserModel::where('uc_id', '!=', $ucId)->where('email', $email)->exists();
if ($exists) {
throw new InvalidRequestException('该邮箱已经被其它账户绑定了,请确认后重新提交');
}
return UserModel::where('uc_id', $ucId)->update([
'email' => $email,
'update_time' => time(),
]);
}
//绑定手机
public static function bindMobile($ucId, $mobile)
{
//先去判断这个email是否已经被其它账号使用了
$exists = UserModel::where('uc_id', '!=', $ucId)->where('mobile', $mobile)->exists();
if ($exists) {
throw new InvalidRequestException('该手机号已经被其它账户绑定了,请确认后重新提交');
}
return UserModel::where('uc_id', $ucId)->update([
'mobile' => $mobile,
'update_time' => time(),
]);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment