first commit
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\apiout;
|
||||
|
||||
use think\App;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\facade\Request;
|
||||
use think\facade\Session;
|
||||
use think\facade\View;
|
||||
use think\Response;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
abstract class BaseController
|
||||
{
|
||||
/**
|
||||
* Request实例
|
||||
* @var \think\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* 应用实例
|
||||
* @var \think\App
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* 是否批量验证
|
||||
* @var bool
|
||||
*/
|
||||
protected $batchValidate = false;
|
||||
|
||||
/**
|
||||
* 控制器中间件
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [];
|
||||
|
||||
/**
|
||||
* 分页数量
|
||||
* @var string
|
||||
*/
|
||||
protected $pageSize = '';
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @access public
|
||||
* @param App $app 应用对象
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->request = $this->app->request;
|
||||
$this->module = strtolower(app('http')->getName());
|
||||
$this->controller = strtolower($this->request->controller());
|
||||
$this->action = strtolower($this->request->action());
|
||||
$this->uid = 0;
|
||||
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 检测权限
|
||||
// $this->checkLogin();
|
||||
//每页显示数据量
|
||||
$this->pageSize = Request::param('page_size', \think\facade\Config::get('app.page_size'));
|
||||
//显示当前登录账户权限
|
||||
// $this->showLoginUserInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示当前登录账户信息
|
||||
*/
|
||||
protected function showLoginUserInfo()
|
||||
{
|
||||
$session_admin = get_config('app.session_admin');
|
||||
if (Session::has($session_admin)) {
|
||||
$loginUser = Session::get($session_admin);
|
||||
// 输出当前登录账户信息
|
||||
// echo '当前登录账户信息:' . $loginUser['username'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*验证用户登录
|
||||
*/
|
||||
protected function checkLogin()
|
||||
{
|
||||
$session_admin = get_config('app.session_admin');
|
||||
if (!Session::has($session_admin)) {
|
||||
$this->apiError('请先登录');
|
||||
} else {
|
||||
$this->uid = Session::get($session_admin)['id'];
|
||||
View::assign('login_user', $this->uid);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Api处理成功结果返回方法
|
||||
* @param $message
|
||||
* @param null $redirect
|
||||
* @param null $extra
|
||||
* @return mixed
|
||||
* @throws ReturnException
|
||||
*/
|
||||
protected function apiSuccess($msg = 'success', $data = [])
|
||||
{
|
||||
return $this->apiReturn($data, 0, $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Api处理结果失败返回方法
|
||||
* @param $error_code
|
||||
* @param $message
|
||||
* @param null $redirect
|
||||
* @param null $extra
|
||||
* @return mixed
|
||||
* @throws ReturnException
|
||||
*/
|
||||
protected function apiError($msg = 'fail', $data = [], $code = 1)
|
||||
{
|
||||
return $this->apiReturn($data, $code, $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回封装后的API数据到客户端
|
||||
* @param mixed $data 要返回的数据
|
||||
* @param integer $code 返回的code
|
||||
* @param mixed $msg 提示信息
|
||||
* @param string $type 返回数据格式
|
||||
* @param array $header 发送的Header信息
|
||||
* @return Response
|
||||
*/
|
||||
protected function apiReturn($data, int $code = 0, $msg = '', string $type = '', array $header = []): Response
|
||||
{
|
||||
$result = [
|
||||
'code' => $code,
|
||||
'msg' => $msg,
|
||||
'time' => time(),
|
||||
'data' => $data,
|
||||
];
|
||||
|
||||
$type = $type ?: 'json';
|
||||
$response = Response::create($result, $type)->header($header);
|
||||
|
||||
throw new HttpResponseException($response);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\apiout\controller;
|
||||
|
||||
use app\apiout\BaseController;
|
||||
use think\facade\Db;
|
||||
use think\Response;
|
||||
use app\model\PicbedFolder as PicbedFolderList;
|
||||
|
||||
class Index extends BaseController
|
||||
{
|
||||
// 推送数据
|
||||
public function pullart()
|
||||
{
|
||||
// 允许来自任何来源的跨域请求
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Headers: Content-Type');
|
||||
|
||||
// 获取请求中的 folder 参数
|
||||
$folderId = $this->request->get('folder');
|
||||
|
||||
$query = Db::name('PicbedImages');
|
||||
|
||||
// 根据 folderId 判断是否筛选
|
||||
if ($folderId !== 'all') {
|
||||
$query->where('folder', $folderId); // 筛选条件
|
||||
}
|
||||
|
||||
$images = $query->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 获取当前请求的域名
|
||||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
$baseUrl = $protocol . '://' . $host;
|
||||
|
||||
$images = array_map(function ($image) use ($baseUrl) {
|
||||
return [
|
||||
'id' => $image['id'], // 新增 id
|
||||
'name' => htmlspecialchars($image['name'], ENT_QUOTES),
|
||||
'path' => $baseUrl . '/' . $image['path'],
|
||||
'folder' => $image['folder']
|
||||
];
|
||||
}, $images);
|
||||
|
||||
return json(['code' => 0, 'msg' => '', 'data' => $images]);
|
||||
}
|
||||
|
||||
//获取文件夹目录
|
||||
public function getpicbedfolder()
|
||||
{
|
||||
$folder = PicbedFolderList::field('id, admin_id, name, sort')
|
||||
->where('delete_time', null)
|
||||
->where('status', '<>', 2)
|
||||
->select();
|
||||
return json(['code' => 0, 'msg' => '', 'data' => $folder]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
// 这是系统自动生成的event定义文件
|
||||
return [
|
||||
|
||||
];
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
// 这是系统自动生成的middleware定义文件
|
||||
return [
|
||||
//开启session中间件
|
||||
//'think\middleware\SessionInit',
|
||||
//验证勾股cms是否完成安装
|
||||
\app\home\middleware\Install::class,
|
||||
];
|
||||
Reference in New Issue
Block a user