初始化项目
This commit is contained in:
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use cores\BaseController;
|
||||
use cores\exception\BaseException;
|
||||
use app\admin\service\admin\User as AdminUserService;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 超管后台控制器基类
|
||||
* Class Controller
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class Controller extends BaseController
|
||||
{
|
||||
// 商家登录信息
|
||||
protected $admin;
|
||||
|
||||
// 当前控制器名称
|
||||
protected $controller = '';
|
||||
|
||||
// 当前方法名称
|
||||
protected $action = '';
|
||||
|
||||
// 当前路由uri
|
||||
protected $routeUri = '';
|
||||
|
||||
// 当前路由:分组名称
|
||||
protected $group = '';
|
||||
|
||||
// 登录验证白名单
|
||||
protected $allowAllAction = [
|
||||
// 登录页面
|
||||
'passport/login',
|
||||
];
|
||||
|
||||
// 无需全局layout
|
||||
protected $notLayoutAction = [];
|
||||
|
||||
/**
|
||||
* 强制验证当前访问的控制器方法method
|
||||
* 例: [ 'login' => 'POST' ]
|
||||
* @var array
|
||||
*/
|
||||
protected $methodRules = [];
|
||||
|
||||
/**
|
||||
* 后台初始化
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
// 设置管理员登录信息
|
||||
$this->setAdminInfo();
|
||||
// 当前路由信息
|
||||
$this->getRouteInfo();
|
||||
// 验证登录
|
||||
$this->checkLogin();
|
||||
// 强制验证当前访问的控制器方法method
|
||||
$this->checkMethodRules();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置管理员登录信息
|
||||
*/
|
||||
private function setAdminInfo()
|
||||
{
|
||||
$this->admin = AdminUserService::getLoginInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析当前路由参数 (分组名称、控制器名称、方法名)
|
||||
*/
|
||||
protected function getRouteInfo()
|
||||
{
|
||||
// 控制器名称
|
||||
$this->controller = uncamelize($this->request->controller());
|
||||
// 方法名称
|
||||
$this->action = $this->request->action();
|
||||
// 控制器分组 (用于定义所属模块)
|
||||
$group = strstr($this->controller, '.', true);
|
||||
$this->group = $group !== false ? $group : $this->controller;
|
||||
// 当前uri
|
||||
$this->routeUri = "{$this->controller}/$this->action";
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台菜单配置
|
||||
* @return array
|
||||
*/
|
||||
private function menus(): array
|
||||
{
|
||||
// 获取后台菜单内容 [app/admin/config/menus.php]
|
||||
$menus = \think\facade\Config::get('menus');
|
||||
foreach ($menus as $group => &$first) {
|
||||
$first['active'] = $group === $this->group;
|
||||
// 遍历:二级菜单
|
||||
if (isset($first['submenu'])) {
|
||||
foreach ($first['submenu'] as $secondKey => &$second) {
|
||||
// 二级菜单所有uri
|
||||
$secondUris = $second['uris'] ?? [$second['index']];
|
||||
// 二级菜单:active
|
||||
!isset($second['active']) && $second['active'] = in_array($this->routeUri, $secondUris);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $menus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证登录状态
|
||||
* @return void
|
||||
* @throws BaseException
|
||||
*/
|
||||
private function checkLogin(): void
|
||||
{
|
||||
// 验证当前请求是否在白名单
|
||||
if (in_array($this->routeUri, $this->allowAllAction)) {
|
||||
return;
|
||||
}
|
||||
// 验证登录状态
|
||||
if (empty($this->admin) || (int)$this->admin['is_login'] !== 1) {
|
||||
throwError('请先登录后再访问', config('status.not_logged'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回封装后的 API 数据到客户端
|
||||
* @param int|null $status 状态码
|
||||
* @param string $message
|
||||
* @param array $data
|
||||
* @return Json
|
||||
*/
|
||||
protected function renderJson(int $status = null, string $message = '', array $data = []): Json
|
||||
{
|
||||
return json(compact('status', 'message', 'data'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回操作成功json
|
||||
* @param array|string $data
|
||||
* @param string $message
|
||||
* @return Json
|
||||
*/
|
||||
protected function renderSuccess($data = [], string $message = 'success'): Json
|
||||
{
|
||||
if (is_string($data)) {
|
||||
$message = $data;
|
||||
$data = [];
|
||||
}
|
||||
return $this->renderJson(config('status.success'), $message, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回操作失败json
|
||||
* @param string $message
|
||||
* @param array $data
|
||||
* @return Json
|
||||
*/
|
||||
protected function renderError(string $message = 'error', array $data = []): Json
|
||||
{
|
||||
return $this->renderJson(config('status.error'), $message, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取post数据 (数组)
|
||||
* @param $key
|
||||
* @return mixed
|
||||
*/
|
||||
protected function postData($key = null)
|
||||
{
|
||||
return $this->request->post(empty($key) ? '' : "{$key}/a");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取post数据 (数组)
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
protected function postForm(string $key = 'form')
|
||||
{
|
||||
return $this->postData($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制验证当前访问的控制器方法method
|
||||
* @throws BaseException
|
||||
*/
|
||||
private function checkMethodRules(): void
|
||||
{
|
||||
if (!isset($this->methodRules[$this->action])) {
|
||||
return;
|
||||
}
|
||||
$methodRule = $this->methodRules[$this->action];
|
||||
$currentMethod = $this->request->method();
|
||||
if (empty($methodRule)) {
|
||||
return;
|
||||
}
|
||||
if (is_array($methodRule) && in_array($currentMethod, $methodRule)) {
|
||||
return;
|
||||
}
|
||||
if (is_string($methodRule) && $methodRule == $currentMethod) {
|
||||
return;
|
||||
}
|
||||
throwError('illegal request method');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\model\admin\User as UserModel;
|
||||
|
||||
/**
|
||||
* 超管后台认证
|
||||
* Class Passport
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Passport extends Controller
|
||||
{
|
||||
/**
|
||||
* 强制验证当前访问的控制器方法method
|
||||
* @var array
|
||||
*/
|
||||
protected $methodRules = [
|
||||
'login' => 'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* 超管后台登录
|
||||
* @return array|string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
// 超管后台用户登录
|
||||
$model = new UserModel;
|
||||
if (($userInfo = $model->login($this->postData())) === false) {
|
||||
return $this->renderError($model->getError() ?: '登录失败');
|
||||
}
|
||||
return $this->renderSuccess([
|
||||
'userId' => $userInfo['admin_user_id'],
|
||||
'token' => $model->getToken()
|
||||
], '登录成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\model\Store as StoreModel;
|
||||
|
||||
/**
|
||||
* 小程序商城管理
|
||||
* Class Store
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class Store extends Controller
|
||||
{
|
||||
/**
|
||||
* 强制验证当前访问的控制器方法method
|
||||
* @var array
|
||||
*/
|
||||
protected $methodRules = [
|
||||
'index' => 'GET',
|
||||
'recycle' => 'GET',
|
||||
'add' => 'POST',
|
||||
'move' => 'POST',
|
||||
'delete' => 'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* 小程序商城列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// 商城列表
|
||||
$model = new StoreModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 回收站列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function recycle()
|
||||
{
|
||||
// 商城列表
|
||||
$model = new StoreModel;
|
||||
$list = $model->getList(true);
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 回收小程序
|
||||
* @param int $storeId
|
||||
* @return array
|
||||
*/
|
||||
public function recovery(int $storeId)
|
||||
{
|
||||
// 小程序详情
|
||||
$model = StoreModel::detail($storeId);
|
||||
if (!$model->recycle()) {
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 移出回收站
|
||||
* @param int $storeId
|
||||
* @return array
|
||||
*/
|
||||
public function move(int $storeId)
|
||||
{
|
||||
// 小程序详情
|
||||
$model = StoreModel::detail($storeId);
|
||||
if (!$model->recycle(false)) {
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return $this->renderError('很抱歉,免费版暂不支持多开商城');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\admin\controller\admin;
|
||||
|
||||
use app\admin\controller\Controller;
|
||||
use app\admin\model\admin\User as AdminUserModel;
|
||||
|
||||
/**
|
||||
* 超管后台管理员控制器
|
||||
* Class User
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class User extends Controller
|
||||
{
|
||||
/**
|
||||
* 强制验证当前访问的控制器方法method
|
||||
* 例: [ 'login' => 'POST' ]
|
||||
* @var array
|
||||
*/
|
||||
protected $methodRules = [
|
||||
'detail' => 'GET',
|
||||
'renew' => 'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取当前用户信息
|
||||
* @return array
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$userInfo = AdminUserModel::detail($this->admin['user']['admin_user_id']);
|
||||
return $this->renderSuccess(['userInfo' => $userInfo]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新当前管理员信息
|
||||
* @return array|string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function renew()
|
||||
{
|
||||
// 获取当前用户信息
|
||||
$model = AdminUserModel::detail($this->admin['user']['admin_user_id']);
|
||||
// 更新用户信息
|
||||
if ($model->renew($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\admin\controller\setting;
|
||||
|
||||
use app\admin\controller\Controller;
|
||||
use app\admin\service\Cache as CacheService;
|
||||
|
||||
/**
|
||||
* 清理缓存
|
||||
* Class Index
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class Cache extends Controller
|
||||
{
|
||||
/**
|
||||
* 清理缓存
|
||||
* @return array|string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
// 清理缓存
|
||||
$CacheService = new CacheService;
|
||||
if (!$CacheService->rmCache($this->postForm())) {
|
||||
return $this->renderError($CacheService->getError() ?: '操作失败');
|
||||
}
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\admin\controller\setting;
|
||||
|
||||
use think\response\Json;
|
||||
use app\admin\controller\Controller;
|
||||
use app\common\library\helper;
|
||||
|
||||
/**
|
||||
* 环境检测
|
||||
* Class Science
|
||||
* @package app\admin\controller\setting
|
||||
*/
|
||||
class Science extends Controller
|
||||
{
|
||||
/**
|
||||
* 环境检测
|
||||
* @return Json
|
||||
*/
|
||||
public function info(): Json
|
||||
{
|
||||
return $this->renderSuccess([
|
||||
'scienceInfo' => [
|
||||
'server' => $this->server(), // 服务器信息
|
||||
'phpinfo' => $this->phpinfo(), // PHP环境要求
|
||||
'writeable' => $this->writeable(), // 目录权限监测
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务器信息
|
||||
* @return array
|
||||
*/
|
||||
private function server(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'name' => '服务器操作系统',
|
||||
'key' => 'system',
|
||||
'value' => PHP_OS,
|
||||
'status' => PHP_SHLIB_SUFFIX === 'dll' ? 'warning' : 'normal',
|
||||
'remark' => '建议使用 Linux 系统以提升程序性能'
|
||||
],
|
||||
[
|
||||
'name' => 'Web服务器环境',
|
||||
'key' => 'webserver',
|
||||
'value' => $this->request->server('SERVER_SOFTWARE'),
|
||||
'status' => PHP_SAPI === 'isapi' ? 'warning' : 'normal',
|
||||
'remark' => '建议使用 Apache 或 Nginx 以提升程序性能'
|
||||
],
|
||||
[
|
||||
'name' => 'PHP版本',
|
||||
'key' => 'php',
|
||||
'value' => PHP_VERSION,
|
||||
'status' => version_compare(PHP_VERSION, '7.4.0') === -1 ? 'danger' : 'normal',
|
||||
'remark' => 'PHP版本必须为 7.4.0 及以上'
|
||||
],
|
||||
[
|
||||
'name' => 'PHP运行位数',
|
||||
'key' => 'system',
|
||||
'value' => (PHP_INT_SIZE === 4 ? '32' : '64') . '位',
|
||||
'status' => PHP_INT_SIZE === 4 ? 'warning' : 'normal',
|
||||
'remark' => '建议使用 64位 PHP以提升程序性能'
|
||||
],
|
||||
// [
|
||||
// 'name' => '文件上传功能',
|
||||
// 'key' => 'file_uploads',
|
||||
// 'value' => !ini_get('file_uploads') ? '关闭' : '开启',
|
||||
// 'status' => !ini_get('file_uploads') ? 'danger' : 'normal',
|
||||
// 'remark' => '文件上传必须开启 file_uploads'
|
||||
// ],
|
||||
[
|
||||
'name' => '文件上传最大值',
|
||||
'key' => 'upload_max_filesize',
|
||||
'value' => ini_get('upload_max_filesize'),
|
||||
'status' => $this->compareBytes(ini_get('upload_max_filesize'), '10m') ? 'danger' : 'normal',
|
||||
'remark' => '不能小于10MB;请修改php.ini中upload_max_filesize'
|
||||
],
|
||||
[
|
||||
'name' => 'POST数据最大值',
|
||||
'key' => 'post_max_size',
|
||||
'value' => ini_get('post_max_size'),
|
||||
'status' => $this->compareBytes(ini_get('post_max_size'), '12m') ? 'danger' : 'normal',
|
||||
'remark' => '不能小于12MB;请修改php.ini中post_max_size'
|
||||
],
|
||||
[
|
||||
'name' => '程序运行目录',
|
||||
'key' => 'root_path',
|
||||
'value' => str_replace('\\', '/', root_path()),
|
||||
'status' => 'normal',
|
||||
'remark' => ''
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP环境要求
|
||||
* @return string[][]
|
||||
*/
|
||||
private function phpinfo(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'name' => 'PHP版本',
|
||||
'key' => 'php_version',
|
||||
'value' => '7.4.0及以上',
|
||||
'status' => version_compare(PHP_VERSION, '7.4.0') === -1 ? 'danger' : 'normal',
|
||||
'remark' => 'PHP版本必须为 7.4.0及以上'
|
||||
],
|
||||
[
|
||||
'name' => 'Mysqlnd',
|
||||
'key' => 'mysqlnd',
|
||||
'value' => '支持',
|
||||
'status' => extension_loaded('mysqlnd') ? 'normal' : 'danger',
|
||||
'remark' => '您的PHP环境不支持mysqlnd, 系统无法正常运行'
|
||||
],
|
||||
// [
|
||||
// 'name' => 'Redis',
|
||||
// 'key' => 'redis',
|
||||
// 'value' => '支持',
|
||||
// 'status' => extension_loaded('redis') ? 'normal' : 'warning',
|
||||
// 'remark' => '您的PHP环境不支持redis, 系统无法使用队列服务'
|
||||
// ],
|
||||
[
|
||||
'name' => 'ZIP',
|
||||
'key' => 'zip',
|
||||
'value' => '支持',
|
||||
'status' => extension_loaded('zip') ? 'normal' : 'warning',
|
||||
'remark' => '您的PHP环境不支持zip, 系统无法使用zip压缩文件'
|
||||
],
|
||||
[
|
||||
'name' => 'CURL',
|
||||
'key' => 'curl',
|
||||
'value' => '支持',
|
||||
'status' => extension_loaded('curl') && function_exists('curl_init') ? 'normal' : 'danger',
|
||||
'remark' => '您的PHP环境不支持CURL, 系统无法正常运行'
|
||||
],
|
||||
[
|
||||
'name' => 'JSON',
|
||||
'key' => 'json',
|
||||
'value' => '支持',
|
||||
'status' => extension_loaded('json') ? 'normal' : 'danger',
|
||||
'remark' => '您的PHP环境不支持JSON, 系统无法正常运行'
|
||||
],
|
||||
[
|
||||
'name' => 'Fileinfo',
|
||||
'key' => 'fileinfo',
|
||||
'value' => '支持',
|
||||
'status' => extension_loaded('fileinfo') ? 'normal' : 'danger',
|
||||
'remark' => '您的PHP环境不支持fileinfo, 系统无法上传文件'
|
||||
],
|
||||
[
|
||||
'name' => 'OpenSSL',
|
||||
'key' => 'openssl',
|
||||
'value' => '支持',
|
||||
'status' => extension_loaded('openssl') ? 'normal' : 'danger',
|
||||
'remark' => '没有启用OpenSSL, 将无法访问微信平台的接口'
|
||||
],
|
||||
[
|
||||
'name' => 'PDO',
|
||||
'key' => 'pdo',
|
||||
'value' => '支持',
|
||||
'status' => extension_loaded('PDO') && extension_loaded('pdo_mysql') ? 'normal' : 'danger',
|
||||
'remark' => '您的PHP环境不支持PDO, 系统无法正常运行'
|
||||
],
|
||||
[
|
||||
'name' => 'GD',
|
||||
'key' => 'gd',
|
||||
'value' => '支持',
|
||||
'status' => extension_loaded('gd') ? 'normal' : 'danger',
|
||||
'remark' => '您的PHP环境不支持GD, 系统无法正常生成图片'
|
||||
],
|
||||
[
|
||||
'name' => 'BCMath',
|
||||
'key' => 'bcmath',
|
||||
'value' => '支持',
|
||||
'status' => extension_loaded('bcmath') ? 'normal' : 'danger',
|
||||
'remark' => '您的PHP环境不支持BCMath, 系统无法正常运行'
|
||||
],
|
||||
[
|
||||
'name' => 'Mbstring',
|
||||
'key' => 'mbstring',
|
||||
'value' => '支持',
|
||||
'status' => extension_loaded('mbstring') ? 'normal' : 'danger',
|
||||
'remark' => '您的PHP环境不支持mbstring, 系统无法正常运行'
|
||||
],
|
||||
[
|
||||
'name' => 'SimpleXML',
|
||||
'key' => 'simplexML',
|
||||
'value' => '支持',
|
||||
'status' => extension_loaded('SimpleXML') ? 'normal' : 'danger',
|
||||
'remark' => '您的PHP环境不支持SimpleXML, 系统无法解析xml 无法使用微信支付'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 目录权限监测
|
||||
* @return array[]
|
||||
*/
|
||||
private function writeable(): array
|
||||
{
|
||||
$paths = [
|
||||
'data' => realpath(data_path()) . '/',
|
||||
'uploads' => realpath(web_path()) . '/uploads/',
|
||||
'downloads' => realpath(web_path()) . '/downloads/',
|
||||
'temp' => realpath(web_path()) . '/temp/',
|
||||
];
|
||||
return [
|
||||
[
|
||||
'name' => '系统数据目录',
|
||||
'key' => 'data',
|
||||
'value' => str_replace('\\', '/', $paths['data']),
|
||||
'status' => helper::checkWriteable($paths['data']) ? 'normal' : 'danger',
|
||||
'remark' => '目录不可写,系统将无法正常写入文件'
|
||||
],
|
||||
[
|
||||
'name' => '文件上传目录',
|
||||
'key' => 'uploads',
|
||||
'value' => str_replace('\\', '/', $paths['uploads']),
|
||||
'status' => helper::checkWriteable($paths['uploads']) ? 'normal' : 'danger',
|
||||
'remark' => '目录不可写,系统将无法正常上传文件'
|
||||
],
|
||||
[
|
||||
'name' => '文件下载目录',
|
||||
'key' => 'downloads',
|
||||
'value' => str_replace('\\', '/', $paths['downloads']),
|
||||
'status' => helper::checkWriteable($paths['downloads']) ? 'normal' : 'danger',
|
||||
'remark' => '目录不可写,系统将无法正常上传文件'
|
||||
],
|
||||
[
|
||||
'name' => '临时文件目录',
|
||||
'key' => 'temp',
|
||||
'value' => str_replace('\\', '/', $paths['temp']),
|
||||
'status' => helper::checkWriteable($paths['temp']) ? 'normal' : 'danger',
|
||||
'remark' => '目录不可写,系统将无法正常写入文件'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较数据大小
|
||||
* @param string $size1
|
||||
* @param string $size2
|
||||
* @return bool
|
||||
*/
|
||||
private function compareBytes(string $size1, string $size2): bool
|
||||
{
|
||||
$size1 = helper::convertToBytes($size1);
|
||||
$size2 = helper::convertToBytes($size2);
|
||||
return $size1 < $size2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\admin\controller\store;
|
||||
|
||||
use app\admin\controller\Controller;
|
||||
use app\admin\model\store\Api as ApiModel;
|
||||
|
||||
/**
|
||||
* 商家后台API权限控制器
|
||||
* Class Api
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Api extends Controller
|
||||
{
|
||||
/**
|
||||
* 权限列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$model = new ApiModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加权限
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// 新增记录
|
||||
$model = new ApiModel;
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新权限
|
||||
* @param $apiId
|
||||
* @return array|string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function edit(int $apiId)
|
||||
{
|
||||
// 权限详情
|
||||
$model = ApiModel::detail($apiId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除权限
|
||||
* @param $apiId
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function delete(int $apiId)
|
||||
{
|
||||
// 权限详情
|
||||
$model = ApiModel::detail($apiId);
|
||||
if (!$model->remove()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\admin\controller\store;
|
||||
|
||||
use app\admin\controller\Controller;
|
||||
use app\admin\model\store\Menu as MenuModel;
|
||||
|
||||
/**
|
||||
* 商家后台菜单控制器
|
||||
* Class Menu
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Menu extends Controller
|
||||
{
|
||||
/**
|
||||
* 菜单列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$model = new MenuModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单详情
|
||||
* @param int $menuId
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function info(int $menuId)
|
||||
{
|
||||
// 菜单详情
|
||||
$model = MenuModel::detail($menuId);
|
||||
return $this->renderSuccess(['info' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加菜单
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// 新增记录
|
||||
$model = new MenuModel;
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新菜单
|
||||
* @param $menuId
|
||||
* @return array|string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function edit(int $menuId)
|
||||
{
|
||||
// 菜单详情
|
||||
$model = MenuModel::detail($menuId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置菜单绑定的Api
|
||||
* @param int $menuId
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function setApis(int $menuId)
|
||||
{
|
||||
// 菜单详情
|
||||
$model = MenuModel::detail($menuId);
|
||||
// 更新记录
|
||||
if ($model->setApis($this->postForm())) {
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
* @param $menuId
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function delete(int $menuId)
|
||||
{
|
||||
// 菜单详情
|
||||
$model = MenuModel::detail($menuId);
|
||||
if (!$model->remove()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user