修复注册用户录入错误

This commit is contained in:
mkm 2023-02-02 11:55:44 +08:00
parent 4752d306d2
commit 17a7c82c5e

View File

@ -356,6 +356,8 @@ class Auth extends BaseController
// if (!$sms_code) return app('json')->fail('验证码不正确'); // if (!$sms_code) return app('json')->fail('验证码不正确');
$user = $repository->accountByUser($data['phone']); $user = $repository->accountByUser($data['phone']);
$auth = $this->parseAuthToken($data['auth_token']); $auth = $this->parseAuthToken($data['auth_token']);
Db::startTrans();
try {
if (!$user) { if (!$user) {
$user = $repository->registr($data['phone'], null, $data['user_type']); $user = $repository->registr($data['phone'], null, $data['user_type']);
$msg = Db::connect('nongke')->table('fa_szxc_information_usermsg')->where('phone', $data['phone'])->find(); $msg = Db::connect('nongke')->table('fa_szxc_information_usermsg')->where('phone', $data['phone'])->find();
@ -381,6 +383,8 @@ class Auth extends BaseController
'nickname' => '微信用户' . $time, 'nickname' => '微信用户' . $time,
'avatar' => 'https://lihai001.oss-cn-chengdu.aliyuncs.com/uploads/20230104/32a639be4ee32349705e947fbbd1e114.png', 'avatar' => 'https://lihai001.oss-cn-chengdu.aliyuncs.com/uploads/20230104/32a639be4ee32349705e947fbbd1e114.png',
'level' => 1, 'level' => 1,
'prevtime' => $time,
'jointime' => $time,
'createtime' => $time, 'createtime' => $time,
'updatetime' => $time, 'updatetime' => $time,
'status' => 'normal' 'status' => 'normal'
@ -394,6 +398,12 @@ class Auth extends BaseController
Db::name('nk_user')->insert($datas); Db::name('nk_user')->insert($datas);
} }
} }
Db::commit();
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return app('json')->error($e->getMessage());
}
if ($auth && !$user['wechat_user_id']){ if ($auth && !$user['wechat_user_id']){
$repository->syncBaseAuth($auth, $user); $repository->syncBaseAuth($auth, $user);
} }