mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-23 18:00:29 +08:00
Update UserService.php
This commit is contained in:
parent
0b6df3500b
commit
88c558e248
@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
namespace app\data\service;
|
namespace app\data\service;
|
||||||
|
|
||||||
|
use think\admin\Exception;
|
||||||
use think\admin\Service;
|
use think\admin\Service;
|
||||||
|
use think\db\exception\DataNotFoundException;
|
||||||
|
use think\db\exception\DbException;
|
||||||
|
use think\db\exception\ModelNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户数据接口服务
|
* 用户数据接口服务
|
||||||
@ -57,13 +61,18 @@ class UserService extends Service
|
|||||||
* @param string $type 接口类型
|
* @param string $type 接口类型
|
||||||
* @param integer $uuid 用户UID
|
* @param integer $uuid 用户UID
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws Exception
|
||||||
|
* @throws DbException
|
||||||
*/
|
*/
|
||||||
public function get(string $type, int $uuid): array
|
public function get(string $type, int $uuid): array
|
||||||
{
|
{
|
||||||
$user = $this->app->db->name('DataUser')->where(['id' => $uuid, 'deleted' => 0])->findOrEmpty();
|
$user = $this->app->db->name('DataUser')->where(['id' => $uuid, 'deleted' => 0])->findOrEmpty();
|
||||||
$data = $this->app->db->name('DataUserToken')->where(['uid' => $uuid, 'type' => $type])->where(function ($query) {
|
if (empty($user)) throw new Exception('指定UID用户不存在');
|
||||||
$query->where(['tokenv' => ''])->whereOr(['tokenv' => $this->_buildTokenVerify()]);
|
$data = $this->app->db->name('DataUserToken')->where(['uid' => $uuid, 'type' => $type])->findOrEmpty();
|
||||||
})->findOrEmpty();
|
if (empty($data)) {
|
||||||
|
[$state, $info, $data] = $this->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']);
|
unset($user['deleted'], $user['password']);
|
||||||
return $user;
|
return $user;
|
||||||
@ -76,7 +85,8 @@ class UserService extends Service
|
|||||||
* @param string $type 接口类型
|
* @param string $type 接口类型
|
||||||
* @param boolean $force 强刷令牌
|
* @param boolean $force 强刷令牌
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \think\db\exception\DbException
|
* @throws Exception
|
||||||
|
* @throws DbException
|
||||||
*/
|
*/
|
||||||
public function set(array $map, array $data, string $type, bool $force = false): array
|
public function set(array $map, array $data, string $type, bool $force = false): array
|
||||||
{
|
{
|
||||||
@ -99,9 +109,9 @@ class UserService extends Service
|
|||||||
* @param string $token 认证令牌
|
* @param string $token 认证令牌
|
||||||
* @param array $data 认证数据
|
* @param array $data 认证数据
|
||||||
* @return array [ 检查状态,状态描述,用户UID, 有效时间 ]
|
* @return array [ 检查状态,状态描述,用户UID, 有效时间 ]
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
* @throws DataNotFoundException
|
||||||
* @throws \think\db\exception\DbException
|
* @throws DbException
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
* @throws ModelNotFoundException
|
||||||
*/
|
*/
|
||||||
public function check(string $type, string $token, array $data = []): array
|
public function check(string $type, string $token, array $data = []): array
|
||||||
{
|
{
|
||||||
@ -125,7 +135,7 @@ class UserService extends Service
|
|||||||
* 延期 TOKEN 有效时间
|
* 延期 TOKEN 有效时间
|
||||||
* @param string $type 接口类型
|
* @param string $type 接口类型
|
||||||
* @param string $token 授权令牌
|
* @param string $token 授权令牌
|
||||||
* @throws \think\db\exception\DbException
|
* @throws DbException
|
||||||
*/
|
*/
|
||||||
public function expire(string $type, string $token)
|
public function expire(string $type, string $token)
|
||||||
{
|
{
|
||||||
@ -168,7 +178,7 @@ class UserService extends Service
|
|||||||
* @param int $uuid 授权用户
|
* @param int $uuid 授权用户
|
||||||
* @param string $type 接口类型
|
* @param string $type 接口类型
|
||||||
* @return array [创建状态, 状态描述, 令牌数据]
|
* @return array [创建状态, 状态描述, 令牌数据]
|
||||||
* @throws \think\db\exception\DbException
|
* @throws DbException
|
||||||
*/
|
*/
|
||||||
public function token(int $uuid, string $type): array
|
public function token(int $uuid, string $type): array
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user