mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
修改接口
This commit is contained in:
parent
008126ae17
commit
b9ffff7114
@ -16,6 +16,10 @@ abstract class Auth extends Controller
|
||||
{
|
||||
/**
|
||||
* 当前接口请求终端类型
|
||||
* >>>>>>>>>>>>>>>>>>>>>>
|
||||
* >>> api-name 接口类型
|
||||
* >>> api-token 接口认证
|
||||
* >>>>>>>>>>>>>>>>>>>>>>
|
||||
* --- 手机浏览器访问 wap
|
||||
* --- 电脑浏览器访问 web
|
||||
* --- 微信小程序访问 wxapp
|
||||
@ -43,18 +47,13 @@ abstract class Auth extends Controller
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
// 接收接口类型
|
||||
$this->type = $this->request->request('api');
|
||||
$this->type = $this->type ?: $this->request->header('api-name');
|
||||
$this->type = $this->type ?: $this->request->header('api-type');
|
||||
// 检查接口类型
|
||||
if (empty($this->type)) {
|
||||
$this->error("未获取到接口类型字段!");
|
||||
}
|
||||
$this->type = $this->request->header('api-name');
|
||||
if (empty($this->type)) $this->error("接口类型异常!");
|
||||
if (!isset(UserAdminService::TYPES[$this->type])) {
|
||||
$this->error("接口类型[{$this->type}]未定义!");
|
||||
}
|
||||
// 获取用户数据
|
||||
// 读取用户数据
|
||||
$this->user = $this->getUser();
|
||||
$this->uuid = $this->user['id'] ?? '';
|
||||
if (empty($this->uuid)) {
|
||||
@ -70,12 +69,12 @@ abstract class Auth extends Controller
|
||||
{
|
||||
try {
|
||||
if (empty($this->uuid)) {
|
||||
$token = input('token') ?: $this->request->header('api-token');
|
||||
if (empty($token)) $this->error('登录认证TOKEN不能为空!');
|
||||
[$state, $info, $this->uuid] = UserTokenService::instance()->check($this->type, $token);
|
||||
$token = $this->request->header('api-token');
|
||||
if (empty($token)) $this->error('登录认证不能为空!');
|
||||
[$state, $info, $this->uuid] = UserTokenService::check($this->type, $token);
|
||||
if (empty($state)) $this->error($info, '{-null-}', 401);
|
||||
}
|
||||
return UserAdminService::instance()->get($this->uuid, $this->type);
|
||||
return UserAdminService::get($this->uuid, $this->type);
|
||||
} catch (HttpResponseException $exception) {
|
||||
throw $exception;
|
||||
} catch (\Exception $exception) {
|
||||
|
@ -4,6 +4,7 @@ namespace app\data\controller\api;
|
||||
|
||||
use app\data\model\BaseUserMessage;
|
||||
use think\admin\Controller;
|
||||
use think\admin\helper\QueryHelper;
|
||||
use think\admin\model\SystemBase;
|
||||
|
||||
/**
|
||||
@ -15,7 +16,7 @@ class Data extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取指定数据对象
|
||||
* 获取指定数据
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
@ -32,33 +33,32 @@ class Data extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片内容数据
|
||||
* 图片内容数据
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getSlider()
|
||||
{
|
||||
$keys = input('keys', 'slider');
|
||||
$extra = []; // 其他数据
|
||||
if (in_array($keys, $extra) || isset(SystemBase::items('图片内容')[$keys])) {
|
||||
$this->success('获取图片内容', sysdata($keys));
|
||||
$this->keys = input('keys', '首页图片');
|
||||
if (isset(SystemBase::items('图片内容')[$this->keys])) {
|
||||
$this->success('获取图片内容', sysdata($this->keys));
|
||||
} else {
|
||||
$this->error('获取图片失败', []);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统通知数据
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* 系统通知数据
|
||||
*/
|
||||
public function getNotify()
|
||||
{
|
||||
$model = BaseUserMessage::mQuery()->where(['status' => 1, 'deleted' => 0]);
|
||||
$result = $model->equal('id')->order('sort desc,id desc')->page(true, false, false, 20);
|
||||
if (($id = input('id')) > 0) BaseUserMessage::mk()->where(['id' => $id])->inc('num_read')->update([]);
|
||||
$this->success('获取系统通知', $result);
|
||||
BaseUserMessage::mQuery(null, function (QueryHelper $query) {
|
||||
if (($id = input('id')) > 0) {
|
||||
BaseUserMessage::mk()->where(['id' => $id])->inc('num_read')->update([]);
|
||||
}
|
||||
$query->equal('id')->where(['status' => 1, 'deleted' => 0]);
|
||||
$this->success('获取系统通知', $query->order('sort desc,id desc')->page(true, false, false, 20));
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user