90 lines
1.9 KiB
PHP
90 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* 商业使用授权协议
|
|
*
|
|
* Copyright (c) 2025 [云泽网]. 保留所有权利.
|
|
*
|
|
* 本软件仅供评估使用。任何商业用途必须获得书面授权许可。
|
|
* 未经授权商业使用本软件属于侵权行为,将承担法律责任。
|
|
*
|
|
* 授权购买请联系: 357099073@qq.com
|
|
* 官方网站: https://www.yunzer.cn
|
|
*
|
|
* 评估用户须知:
|
|
* 1. 禁止移除版权声明
|
|
* 2. 禁止用于生产环境
|
|
* 3. 禁止转售或分发
|
|
*/
|
|
|
|
namespace app\api\controller;
|
|
|
|
use think\App;
|
|
use think\Request;
|
|
|
|
/**
|
|
* API控制器基础类
|
|
*/
|
|
abstract class BaseController
|
|
{
|
|
/**
|
|
* Request实例
|
|
* @var \think\Request
|
|
*/
|
|
protected $request;
|
|
|
|
/**
|
|
* 应用实例
|
|
* @var \think\App
|
|
*/
|
|
protected $app;
|
|
|
|
/**
|
|
* 构造方法
|
|
* @access public
|
|
* @param App $app 应用对象
|
|
*/
|
|
public function __construct(App $app)
|
|
{
|
|
$this->app = $app;
|
|
$this->request = $this->app->request;
|
|
}
|
|
|
|
/**
|
|
* 返回JSON响应
|
|
* @param mixed $data 数据
|
|
* @param int $code 状态码
|
|
* @param string $msg 消息
|
|
* @return \think\Response
|
|
*/
|
|
protected function json($data = [], $code = 0, $msg = 'success')
|
|
{
|
|
return json([
|
|
'code' => $code,
|
|
'msg' => $msg,
|
|
'data' => $data
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 返回成功响应
|
|
* @param mixed $data 数据
|
|
* @param string $msg 消息
|
|
* @return \think\Response
|
|
*/
|
|
protected function success($data = [], $msg = 'success')
|
|
{
|
|
return $this->json($data, 0, $msg);
|
|
}
|
|
|
|
/**
|
|
* 返回错误响应
|
|
* @param string $msg 错误消息
|
|
* @param int $code 错误码
|
|
* @param mixed $data 数据
|
|
* @return \think\Response
|
|
*/
|
|
protected function error($msg = 'error', $code = 1, $data = [])
|
|
{
|
|
return $this->json($data, $code, $msg);
|
|
}
|
|
}
|