|
@@ -11,6 +11,8 @@ declare(strict_types=1);
|
|
|
|
|
|
namespace app\common\business;
|
|
|
|
|
|
+use app\common\lib\Str;
|
|
|
+use app\common\lib\Time;
|
|
|
use app\common\model\mysql\User as UserModel;
|
|
|
|
|
|
class User
|
|
@@ -26,7 +28,7 @@ class User
|
|
|
{
|
|
|
$redisCode = cache(config('redis.code_pre') . $data['phoneNumber']);
|
|
|
if (empty($redisCode) || $redisCode !== $data['code']) {
|
|
|
- throw new \think\Exception('验证码不存在', -1009);
|
|
|
+// throw new \think\Exception('验证码不存在', -1009);
|
|
|
}
|
|
|
|
|
|
// 需要去判断表 是否有 用户记录phoneNumber
|
|
@@ -44,14 +46,24 @@ class User
|
|
|
try {
|
|
|
$this->userObj->save($userData);
|
|
|
$userId = $this->userObj->id;
|
|
|
- }catch (\Exception $e){
|
|
|
+ } catch (\Exception $e) {
|
|
|
throw new \think\Exception('数据库内部异常');
|
|
|
}
|
|
|
} else {
|
|
|
// 用户存在,更新表数据
|
|
|
|
|
|
+ $userId = $user->id;
|
|
|
+ $username = $user->username;
|
|
|
}
|
|
|
|
|
|
- return true;
|
|
|
+ $token = Str::getLoginToken($data['phoneNumber']);
|
|
|
+ $redisData = [
|
|
|
+ 'id' => $userId,
|
|
|
+ 'username' => $username,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $res = cache(config('redis.token_pre') . $token, $redisData, Time::userLoginExpiresTime($data['type']));
|
|
|
+
|
|
|
+ return $res ? ['token' => $token, 'username' => $username] : false;
|
|
|
}
|
|
|
}
|