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
|
* --- 手机浏览器访问 wap
|
||||||
* --- 电脑浏览器访问 web
|
* --- 电脑浏览器访问 web
|
||||||
* --- 微信小程序访问 wxapp
|
* --- 微信小程序访问 wxapp
|
||||||
@ -43,18 +47,13 @@ abstract class Auth extends Controller
|
|||||||
*/
|
*/
|
||||||
protected function initialize()
|
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->type = $this->request->header('api-name');
|
||||||
$this->error("未获取到接口类型字段!");
|
if (empty($this->type)) $this->error("接口类型异常!");
|
||||||
}
|
|
||||||
if (!isset(UserAdminService::TYPES[$this->type])) {
|
if (!isset(UserAdminService::TYPES[$this->type])) {
|
||||||
$this->error("接口类型[{$this->type}]未定义!");
|
$this->error("接口类型[{$this->type}]未定义!");
|
||||||
}
|
}
|
||||||
// 获取用户数据
|
// 读取用户数据
|
||||||
$this->user = $this->getUser();
|
$this->user = $this->getUser();
|
||||||
$this->uuid = $this->user['id'] ?? '';
|
$this->uuid = $this->user['id'] ?? '';
|
||||||
if (empty($this->uuid)) {
|
if (empty($this->uuid)) {
|
||||||
@ -70,12 +69,12 @@ abstract class Auth extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (empty($this->uuid)) {
|
if (empty($this->uuid)) {
|
||||||
$token = input('token') ?: $this->request->header('api-token');
|
$token = $this->request->header('api-token');
|
||||||
if (empty($token)) $this->error('登录认证TOKEN不能为空!');
|
if (empty($token)) $this->error('登录认证不能为空!');
|
||||||
[$state, $info, $this->uuid] = UserTokenService::instance()->check($this->type, $token);
|
[$state, $info, $this->uuid] = UserTokenService::check($this->type, $token);
|
||||||
if (empty($state)) $this->error($info, '{-null-}', 401);
|
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) {
|
} catch (HttpResponseException $exception) {
|
||||||
throw $exception;
|
throw $exception;
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
|
@ -4,6 +4,7 @@ namespace app\data\controller\api;
|
|||||||
|
|
||||||
use app\data\model\BaseUserMessage;
|
use app\data\model\BaseUserMessage;
|
||||||
use think\admin\Controller;
|
use think\admin\Controller;
|
||||||
|
use think\admin\helper\QueryHelper;
|
||||||
use think\admin\model\SystemBase;
|
use think\admin\model\SystemBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,7 +16,7 @@ class Data extends Controller
|
|||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定数据对象
|
* 获取指定数据
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
* @throws \think\db\exception\DbException
|
* @throws \think\db\exception\DbException
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
@ -32,33 +33,32 @@ class Data extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取图片内容数据
|
* 图片内容数据
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
* @throws \think\db\exception\DbException
|
* @throws \think\db\exception\DbException
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
*/
|
*/
|
||||||
public function getSlider()
|
public function getSlider()
|
||||||
{
|
{
|
||||||
$keys = input('keys', 'slider');
|
$this->keys = input('keys', '首页图片');
|
||||||
$extra = []; // 其他数据
|
if (isset(SystemBase::items('图片内容')[$this->keys])) {
|
||||||
if (in_array($keys, $extra) || isset(SystemBase::items('图片内容')[$keys])) {
|
$this->success('获取图片内容', sysdata($this->keys));
|
||||||
$this->success('获取图片内容', sysdata($keys));
|
|
||||||
} else {
|
} else {
|
||||||
$this->error('获取图片失败', []);
|
$this->error('获取图片失败', []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取系统通知数据
|
* 系统通知数据
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
|
||||||
* @throws \think\db\exception\DbException
|
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
|
||||||
*/
|
*/
|
||||||
public function getNotify()
|
public function getNotify()
|
||||||
{
|
{
|
||||||
$model = BaseUserMessage::mQuery()->where(['status' => 1, 'deleted' => 0]);
|
BaseUserMessage::mQuery(null, function (QueryHelper $query) {
|
||||||
$result = $model->equal('id')->order('sort desc,id desc')->page(true, false, false, 20);
|
if (($id = input('id')) > 0) {
|
||||||
if (($id = input('id')) > 0) BaseUserMessage::mk()->where(['id' => $id])->inc('num_read')->update([]);
|
BaseUserMessage::mk()->where(['id' => $id])->inc('num_read')->update([]);
|
||||||
$this->success('获取系统通知', $result);
|
}
|
||||||
|
$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