6
0
Fork 0

Merge branch '1.x' of gitee.com:zi-chunsheng-e-commerce/mall-server into 1.x

release
李静 2022-02-23 17:44:58 +08:00
commit 650dfe02f9
1 changed files with 11 additions and 9 deletions

View File

@ -135,23 +135,24 @@ class SocialiteAuthController extends Controller
$socialiteUser = SocialiteUser::firstOrCreate($socialite); $socialiteUser = SocialiteUser::firstOrCreate($socialite);
$user = null; $user = null;
$input = $request->input(); $input = $request->input();
$phone = $input['phone'] ?? '';
switch ($type) { switch ($type) {
case 'default'://手机号+密码 case 'default'://手机号+密码
$user = User::where('phone', $input['phone'])->first(); $user = User::where('phone', $phone)->first();
//手机号不存在,或者密码错误 //手机号不存在,或者密码错误
if (! $user?->verifyPassword($input['password'])) { if (! $user?->verifyPassword($input['password'])) {
throw new BizException(__('Incorrect account or password')); throw new BizException(__('Incorrect account or password'));
} }
break; break;
case 'sms_code'://手机号+验证码 case 'sms-code'://手机号+验证码
app(SmsCodeService::class)->validate( app(SmsCodeService::class)->validate(
$input['phone'], $input['phone'],
SmsCode::TYPE_REGISTER, SmsCode::TYPE_REGISTER,
$input['verify_code'] $input['verify_code']
); );
$user = User::where('phone', $input['phone'])->first(); $user = User::where('phone', $phone)->first();
break; break;
case 'wechat_mini'://微信小程序解密手机号 case 'wechat-mini'://微信小程序解密手机号
//解密失败 //解密失败
$app = EasyWeChatFactory::miniProgram([ $app = EasyWeChatFactory::miniProgram([
'app_id' => config('wechat.mini_program.default.app_id', ''), 'app_id' => config('wechat.mini_program.default.app_id', ''),
@ -177,7 +178,9 @@ class SocialiteAuthController extends Controller
$user = User::where('phone', $phone)->first(); $user = User::where('phone', $phone)->first();
break; break;
} }
if (empty($phone)) {
throw new BizException('系统错误,未找到手机号');
}
//走登录逻辑 //走登录逻辑
if ($user) { if ($user) {
$token = $this->loginUser($user, $request); $token = $this->loginUser($user, $request);
@ -187,15 +190,14 @@ class SocialiteAuthController extends Controller
$inviter = $this->findUserByCode((string) Arr::get($input, 'inviter_code')); $inviter = $this->findUserByCode((string) Arr::get($input, 'inviter_code'));
try { try {
DB::beginTransaction(); DB::beginTransaction();
$user = User::create([
$user = User::create( 'phone' => $phone,
array_merge($input, [
'password' => Str::random(6), //先随机一个密码 'password' => Str::random(6), //先随机一个密码
'phone_verified_at' => $time, 'phone_verified_at' => $time,
'register_ip' => $ip, 'register_ip' => $ip,
'last_login_at' => $time, 'last_login_at' => $time,
'last_login_ip' => $ip, 'last_login_ip' => $ip,
]), ],
$inviter $inviter
); );