修改用户服务

This commit is contained in:
邹景立 2021-03-12 14:03:38 +08:00
parent 7b7db7ee4f
commit 03a755acd9
2 changed files with 12 additions and 10 deletions

View File

@ -8,7 +8,7 @@ use think\admin\Controller;
use think\exception\HttpResponseException;
/**
* 授权认证基类
* 接口授权认证基类
* Class Auth
* @package app\store\controller\api
*/
@ -70,7 +70,7 @@ abstract class Auth extends Controller
[$state, $info, $this->uuid] = UserTokenService::instance()->check($this->type, $token);
if (empty($state)) $this->error($info, '{-null-}', 401);
}
return UserService::instance()->get($this->type, $this->uuid);
return UserService::instance()->get($this->uuid, $this->type);
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $exception) {

View File

@ -50,22 +50,24 @@ class UserService extends Service
/**
* 获取用户数据
* @param string $type 接口类型
* @param integer $uuid 用户UID
* @param ?string $type 接口类型
* @return array
* @throws DbException
* @throws Exception
*/
public function get(string $type, int $uuid): array
public function get(int $uuid, ?string $type = null): array
{
$user = $this->app->db->name('DataUser')->where(['id' => $uuid, 'deleted' => 0])->findOrEmpty();
if (empty($user)) throw new Exception('指定UID用户不存在');
$data = $this->app->db->name('DataUserToken')->where(['uid' => $uuid, 'type' => $type])->findOrEmpty();
if (empty($data)) {
[$state, $info, $data] = UserTokenService::instance()->token($uuid, $type);
if (empty($state) || empty($data)) throw new Exception($info);
if (!is_null($type)) {
$data = $this->app->db->name('DataUserToken')->where(['uid' => $uuid, 'type' => $type])->findOrEmpty();
if (empty($data)) {
[$state, $info, $data] = UserTokenService::instance()->token($uuid, $type);
if (empty($state) || empty($data)) throw new Exception($info);
}
$user['token'] = ['token' => $data['token'], 'expire' => $data['time']];
}
$user['token'] = ['token' => $data['token'], 'expire' => $data['time']];
unset($user['deleted'], $user['password']);
return $user;
}
@ -94,7 +96,7 @@ class UserService extends Service
if ($force) {
UserTokenService::instance()->token(intval($uuid), $type);
}
return $this->get($type, $uuid);
return $this->get($uuid, $type);
}
/**