初始化项目

This commit is contained in:
2026-09-01 22:15:50 +08:00
commit b5a26a8848
11217 changed files with 1710987 additions and 0 deletions
@@ -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('操作成功');
}
}
+97
View File
@@ -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('删除成功');
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\model;
use app\common\model\Store as StoreModel;
/**
* 商家记录表模型
* Class Store
* @package app\admin\model
*/
class Store extends StoreModel
{
/**
* 获取列表数据
* @param bool $isRecycle
* @return \think\Paginator
* @throws \think\db\exception\DbException
*/
public function getList(bool $isRecycle = false): \think\Paginator
{
return $this->where('is_recycle', '=', (int)$isRecycle)
->where('is_delete', '=', 0)
->order(['create_time' => 'desc'])
->paginate(15);
}
/**
* 移入移出回收站
* @param bool $isRecycle
* @return false|int
*/
public function recycle($isRecycle = true)
{
return $this->save(['is_recycle' => (int)$isRecycle]);
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\model;
use app\common\model\UploadFile as UploadFileModel;
/**
* 文件库模型
* Class UploadFile
* @package app\admin\model
*/
class UploadFile extends UploadFileModel
{
}
+110
View File
@@ -0,0 +1,110 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\model\admin;
use app\common\model\admin\User as UserModel;
use app\admin\service\admin\User as AdminUserService;
/**
* 超管后台用户模型
* Class User
* @package app\admin\model\admin
*/
class User extends UserModel
{
/**
* 隐藏的字段
* @var array
*/
protected $hidden = [
'password',
];
// 用户登录token
private $token;
/**
* 超管后台用户登录
* @param array $data
* @return array|bool|null|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function login(array $data)
{
// 验证用户名密码是否正确
if (!$user = $this->getUserInfoByLogin($data)) {
$this->error = '登录失败, 用户名或密码错误';
return false;
}
// 记录登录状态, 并记录token
$this->token = AdminUserService::login($user->toArray());
return $user;
}
/**
* 返回生成的token
* @return mixed
*/
public function getToken()
{
return $this->token;
}
/**
* 获取登录的用户信息
* @param $data
* @return array|false|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getUserInfoByLogin(array $data)
{
// 用户信息
$useInfo = static::withoutGlobalScope()
->where(['user_name' => $data['username']])
->find();
if (empty($useInfo)) return false;
// 验证密码是否正确
if (!password_verify($data['password'], $useInfo['password'])) {
return false;
}
return $useInfo;
}
/**
* 更新当前管理员信息
* @param $data
* @return bool
*/
public function renew(array $data)
{
if ($data['password'] !== $data['password_confirm']) {
$this->error = '确认密码不正确';
return false;
}
// 更新管理员信息
if ($this->save([
'user_name' => $data['user_name'],
'password' => encryption_hash($data['password']),
]) === false) {
return false;
}
// 更新登录信息
AdminUserService::update($this->toArray());
return true;
}
}
+129
View File
@@ -0,0 +1,129 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\model\store;
use app\common\model\store\Api as ApiModel;
/**
* 商家后台API权限模型
* Class Api
* @package app\admin\model\store
*/
class Api extends ApiModel
{
/**
* 获取权限列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList()
{
$all = static::getAll();
return $this->getTreeData($all);
}
/**
* 新增记录
* @param $data
* @return false|int
*/
public function add(array $data)
{
return $this->allowField(['name', 'parent_id', 'url', 'sort'])->save($data);
}
/**
* 更新记录
* @param $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function edit($data)
{
// 判断上级角色是否为当前子级
if ($data['parent_id'] > 0) {
// 获取所有上级id集
$parentIds = $this->getTopApiIds($data['parent_id']);
if (in_array($this['api_id'], $parentIds)) {
$this->error = '上级权限不允许设置为当前子权限';
return false;
}
}
return $this->allowField(['name', 'parent_id', 'url', 'sort'])->save($data) !== false;
}
/**
* 删除权限
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \Exception
*/
public function remove()
{
// 判断是否存在下级权限
if (self::detail(['parent_id' => $this['api_id']])) {
$this->error = '当前权限下存在子权限,请先删除';
return false;
}
return $this->delete();
}
/**
* 获取所有上级id集
* @param int $apiId
* @param null $all
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getTopApiIds(int $apiId, $all = null)
{
static $ids = [];
is_null($all) && $all = $this->getAll();
foreach ($all as $item) {
if ($item['api_id'] == $apiId && $item['parent_id'] > 0) {
$ids[] = $item['parent_id'];
$this->getTopApiIds($item['parent_id'], $all);
}
}
return $ids;
}
/**
* 获取树状列表
* @param array $list
* @param int $parentId
* @return array
*/
private function getTreeData(array &$list, int $parentId = 0)
{
$data = [];
foreach ($list as $key => $item) {
if ($item['parent_id'] == $parentId) {
$children = $this->getTreeData($list, (int)$item['api_id']);
!empty($children) && $item['children'] = $children;
$data[] = $item;
unset($list[$key]);
}
}
return $data;
}
}
+116
View File
@@ -0,0 +1,116 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\model\store;
use app\common\model\store\Menu as MenuModel;
use app\admin\model\store\MenuApi as MenuApiModel;
/**
* 商家后台菜单模型
* Class Menu
* @package app\admin\model\store
*/
class Menu extends MenuModel
{
/**
* 新增记录
* @param $data
* @return false|int
*/
public function add(array $data)
{
return $this->save($data);
}
/**
* 更新记录
* @param array $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function edit(array $data)
{
// 判断上级角色是否为当前子级
if (isset($data['parent_id']) && $data['parent_id'] > 0) {
// 获取所有上级id集
$parentIds = $this->getTopMenuIds($data['parent_id']);
if (in_array($this['menu_id'], $parentIds)) {
$this->error = '上级菜单不允许设置为当前子菜单';
return false;
}
}
// 如果模块是操作, 不允许修改上级菜单id
if ($this['module'] == 20 && isset($data['parent_id'])) {
unset($data['parent_id']);
}
return $this->save($data) !== false;
}
/**
* 设置菜单的API权限
* @param array $data
* @return bool|int
*/
public function setApis(array $data)
{
if (!isset($data['apiIds']) || empty($data['apiIds'])) {
$this->error = 'API权限不能为空';
return false;
}
// 根据菜单id批量更新API关联记录
return (new MenuApiModel)->updateByMenuId($this['menu_id'], $data['apiIds']);
}
/**
* 删除菜单
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \Exception
*/
public function remove()
{
// 判断是否存在下级菜单
if (self::detail(['parent_id' => $this['menu_id']])) {
$this->error = '当前菜单下存在子菜单或操作,请先删除';
return false;
}
return $this->delete();
}
/**
* 获取所有上级id集
* @param int $menuId
* @param null $menuList
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getTopMenuIds(int $menuId, $menuList = null)
{
static $ids = [];
is_null($menuList) && $menuList = $this->getAll();
foreach ($menuList as $item) {
if ($item['menu_id'] == $menuId && $item['parent_id'] > 0) {
$ids[] = $item['parent_id'];
$this->getTopMenuIds($item['parent_id'], $menuList);
}
}
return $ids;
}
}
@@ -0,0 +1,64 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\model\store;
use app\common\model\store\MenuApi as MenuApiModel;
/**
* 商家后台用户角色与菜单权限关系表模型
* Class MenuApi
* @package app\admin\model\store
*/
class MenuApi extends MenuApiModel
{
/**
* 根据菜单id批量更新记录
* @param int $menuId
* @param array $apiIds
* @return int
*/
public function updateByMenuId(int $menuId, array $apiIds)
{
return $this->transaction(function () use ($menuId, $apiIds) {
$this->removeByMenuId($menuId);
return $this->insertByMenuId($menuId, $apiIds);
});
}
/**
* 根据菜单id批量删除记录
* @param int $menuId
* @return bool
* @throws \Exception
*/
private function removeByMenuId(int $menuId)
{
return $this->where('menu_id', '=', $menuId)->delete();
}
/**
* 根据菜单id批量新增记录
* @param int $menuId
* @param array $apiIds
* @return bool
*/
private function insertByMenuId(int $menuId, array $apiIds)
{
$data = [];
foreach ($apiIds as $api) {
$data[] = ['menu_id' => $menuId, 'api_id' => $api];
}
return (bool)$this->addAll($data);
}
}
+60
View File
@@ -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\model\store;
use cores\exception\BaseException;
use app\common\model\store\User as StoreUserModel;
/**
* 商家用户模型
* Class StoreUser
* @package app\admin\model
*/
class User extends StoreUserModel
{
/**
* 商家用户登录
* @param int $storeId
* @throws BaseException
* @throws \think\Exception
*/
public function login(int $storeId)
{
// 获取该商户管理员用户信息
$userInfo = $this->getSuperStoreUser($storeId);
if (empty($userInfo)) {
throwError('超级管理员用户信息不存在');
}
}
/**
* 获取该商户管理员用户信息
* @param int $storeId
* @return static|null
*/
private function getSuperStoreUser(int $storeId)
{
return static::detail(['store_id' => $storeId, 'is_super' => 1], ['wxapp']);
}
/**
* 删除小程序下的商家用户
* @param $storeId
* @return false|int
*/
public static function setDelete(int $storeId)
{
static::update(['is_delete' => '1'], ['store_id' => $storeId]);
return true;
}
}
+94
View File
@@ -0,0 +1,94 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\service;
use app\common\service\BaseService;
use think\facade\Cache as CacheDriver;
/**
* 清理缓存
* Class Cache
*/
class Cache extends BaseService
{
// 缓存驱动句柄
/** @var $CacheDriver \think\Cache */
private $cache;
/**
* 构造方法
* Cache constructor.
*/
public function initialize()
{
// 实例化缓存驱动
$this->cache = CacheDriver::instance();
}
/**
* 删除缓存
* @param $data
* @return bool
*/
public function rmCache($data)
{
// 数据缓存
if (in_array('data', $data['item'])) {
// 强制模式
$isForce = isset($data['isForce']) && $data['isForce'];
// 清除缓存
$isForce ? $this->cache->clear() : $this->cache->tag('cache')->clear();
}
// 临时文件
if (in_array('temp', $data['item'])) {
$paths = [
'temp' => web_path() . 'temp/',
'runtime-image' => runtime_root_path() . 'image/',
'runtime-local' => runtime_root_path() . 'local/',
];
foreach ($paths as $path) {
$this->deleteFolder($path);
}
}
return true;
}
/**
* 递归删除指定目录下所有文件
* @param $path
* @return bool
*/
private function deleteFolder($path)
{
if (!is_dir($path))
return false;
// 扫描一个文件夹内的所有文件夹和文件
foreach (scandir($path) as $val) {
// 排除目录中的.和..
if (!in_array($val, ['.', '..', '.gitignore'])) {
// 如果是目录则递归子目录,继续操作
if (is_dir($path . $val)) {
// 子目录中操作删除文件夹和文件
$this->deleteFolder($path . $val . '/');
// 目录清空后删除空文件夹
rmdir($path . $val . '/');
} else {
// 如果是文件直接删除
unlink($path . $val);
}
}
}
return true;
}
}
+120
View File
@@ -0,0 +1,120 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\service\admin;
use think\facade\Cache;
use app\common\service\BaseService;
/**
* 超管用户服务类
* Class User
*/
class User extends BaseService
{
// 用于生成token的自定义盐
const TOKEN_SALT = '_admin_user_salt_';
/**
* 获取登录的信息
* @return mixed
*/
public static function getLoginInfo()
{
if (($token = self::getToken()) !== false) {
return Cache::get($token);
}
return false;
}
/**
* 记录登录信息
* @param array $userInfo
* @return string
*/
public static function login(array $userInfo)
{
// 生成token
$token = self::makeToken((int)$userInfo['admin_user_id']);
// 记录缓存, 7天
Cache::set($token, [
'user' => [
'admin_user_id' => (int)$userInfo['admin_user_id'],
'user_name' => $userInfo['user_name'],
],
'is_login' => true,
], 86400 * 7);
return $token;
}
/**
* 清空登录状态
* @return bool
*/
public static function logout()
{
Cache::delete(self::getToken());
return true;
}
/**
* 更新登录信息
* @param array $userInfo
* @return mixed
*/
public static function update(array $userInfo)
{
return Cache::set(self::getToken(), [
'user' => [
'admin_user_id' => $userInfo['admin_user_id'],
'user_name' => $userInfo['user_name'],
],
'is_login' => true,
], 86400 * 7);
}
/**
* 生成用户认证的token
* @param int $userId
* @return string
*/
private static function makeToken(int $userId)
{
// 生成一个不会重复的随机字符串
$guid = get_guid_v4();
// 当前时间戳 (精确到毫秒)
$timeStamp = microtime(true);
// 自定义一个盐
$salt = self::TOKEN_SALT;
return md5("{$timeStamp}_{$userId}_{$guid}_{$salt}");
}
/**
* 获取用户认证Token
* @return bool|string
*/
private static function getToken()
{
// 获取请求中的token
$token = request()->header('Access-Token');
// 调试模式下可通过param
if (empty($token) && is_debug()) {
$token = request()->param('Access-Token');
}
// 不存在token报错
if (empty($token)) {
return false;
}
return $token;
}
}
@@ -0,0 +1,25 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\service\store;
use app\common\service\store\User as Basics;
use app\admin\model\store\User as StoreUserModel;
/**
* 超管用户服务类
* Class User
*/
class User extends Basics
{
}