其余文件

This commit is contained in:
2026-04-14 17:46:22 +08:00
parent 294b68fe37
commit 3691f4db22
1343 changed files with 189847 additions and 0 deletions

View File

@ -0,0 +1,314 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\basics;
use app\admin\server\AuthServer;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use app\common\utils\Time;
use think\App;
use think\Controller;
use think\exception\HttpResponseException;
use think\facade\Config;
use think\facade\Debug;
use think\facade\View;
use think\Response;
use app\common\model\system\SystemLog;
/**
* 后台基类
* Class AdminBase
* @Author FZR
* @package app\common\basics
*/
abstract class AdminBase
{
/**
* Request实例
*/
protected $request;
/**
* 应用实例
*/
protected $app;
/**
* 管理员ID
* @var null
*/
protected $adminId = null;
/**
* 管理员信息
* @var null
*/
protected $adminUser = null;
/**
* 逻辑
* @var
*/
protected $logic;
/**
* 验证器
* @var
*/
protected $validate;
/**
* 不需要登录的方法
* @var array
*/
public $like_not_need_login = [];
/**
* js数据
* @var array
*/
protected $js_data = [];
/**
* 分页
* @var int
*/
public $page_no = 1;
public $page_size = 15;
/**
* 模板颜色
* @var string
*/
public $view_theme_color = '';
/**
* 构造方法
* @access public
* @param App $app 应用对象
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = $this->app->request;
// 控制器初始化
$this->initialize();
}
/**
* 初始化
*/
protected function initialize()
{
//默认设置参数
$this->initConfig();
//验证登录
$this->checkLogin();
//验证权限
$this->checkAuth();
//默认页面参数
$this->setViewValue();
// 系统日志
$this->log();
return true;
}
//系统日志
protected function log()
{
if(request()->action() != 'login') {
$data = [
'admin_id' => $this->adminId,
'name' => $this->adminUser['name'],
'account' => $this->adminUser['account'],
'create_time' => time(),
'uri' => request()->baseUrl(),
'type' => request()->method(),
'param' => json_encode(request()->param(),JSON_UNESCAPED_UNICODE),
'ip' => request()->ip()
];
SystemLog::create($data);
}
}
/**
* Notes: 基础配置参数
* @author 段誉(2021/4/9 14:18)
*/
protected function initConfig()
{
$this->adminUser = session('admin_info');
$this->adminId = session('admin_info.id');
//分页参数
$page_no = (int)$this->request->get('page_no');
$this->page_no = $page_no && is_numeric($page_no) ? $page_no : $this->page_no;
$page_size = (int)$this->request->get('page_size');
$this->page_size = $page_size && is_numeric($page_size) ? $page_size : $this->page_size;
$this->page_size = min($this->page_size, 100);
}
/**
* 设置视图全局变量
*/
private function setViewValue()
{
$app = Config::get('project');
View::assign([
'view_env_name' => $app['env_name'],
'view_admin_name' => $app['admin_name'],
'view_theme_color' => $app['theme_color'],
'view_theme_button' => $app['theme_button'],
'front_version' => $app['front_version'],
'version' => $app['version'],
'dateTime' => Time::getTime(),
'storageUrl' => UrlServer::getFileUrl('/'),
'company_name' => ConfigServer::get('copyright', 'company_name')
]);
$this->assignJs('image_upload_url', '');
}
/**
* Notes: 检查登录
* @author 段誉(2021/4/9 14:05)
* @return bool
*/
protected function checkLogin()
{
//已登录的访问登录页
if ($this->adminUser && !$this->isNotNeedLogin()) {
return true;
}
//已登录的访问非登录页
if ($this->adminUser && $this->isNotNeedLogin()) {
$this->redirect(url('index/index'));
}
//未登录的访问非登录页
if (!$this->adminUser && $this->isNotNeedLogin()) {
return true;
}
//未登录访问登录页
$this->redirect(url('login/login'));
}
/**
* Notes: 验证登录角色权限
* @author 段誉(2021/4/13 11:34)
* @return bool
*/
protected function checkAuth()
{
//未登录的无需权限控制
if (empty(session('admin_info'))) {
return true;
}
//如果id为1视为系统超级管理无需权限控制
if (session('admin_info.id') == 1) {
return true;
}
//权限控制判断
$controller_action = request()->controller() . '/' . request()->action();// 当前访问
$controller_action = strtolower($controller_action);
//没有的权限
$none_auth = AuthServer::getRoleNoneAuthUris(session('admin_info.role_id'));
if (empty($none_auth) || !in_array($controller_action, $none_auth)) {
//通过权限控制
return true;
}
$this->redirect(url('dispatch/dispatch_error',['msg' => '权限不足,无法访问']));
return false;
}
/**
* Notes: js
* @param $name
* @param $value
* @author 段誉(2021/4/9 14:23)
*/
protected function assignJs($name, $value)
{
$this->js_data[$name] = $value;
$js_code = "<script>";
foreach ($this->js_data as $name => $value) {
if (is_array($value)) {
$value = json_encode($value);
} elseif (!is_integer($value)) {
$value = '"' . $value . '"';
}
$js_code .= $name . '=' . $value . ';';
}
$js_code .= "</script>";
View::assign('js_code', $js_code);
}
/**
* Notes: 是否无需登录
* @author 段誉(2021/4/9 14:03)
* @return bool
*/
private function isNotNeedLogin()
{
if (empty($this->like_not_need_login)) {
return false;
}
$action = strtolower(request()->action());
$data = array_map('strtolower', $this->like_not_need_login);
if (!in_array($action, $data)) {
return false;
}
return true;
}
/**
* Notes: 自定义重定向
* @param mixed ...$args
* @author 段誉(2021/4/9 14:04)
*/
public function redirect(...$args)
{
throw new HttpResponseException(redirect(...$args));
}
}

113
app/common/basics/Api.php Normal file
View File

@ -0,0 +1,113 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\basics;
use think\App;
/**
* API接口基类
* Class Api
* @Author FZR
* @package app\common\basics
*/
abstract class Api
{
/**
* Request实例
*/
protected $request;
/**
* 应用实例
*/
protected $app;
/**
* 用户ID
* @var int
*/
protected $user_id = null;
/**
* 用户信息
* @var array
*/
public $user_info = [];
/**
* 客户端
* @var null
*/
public $client = null;
/**
* 页码
* @var int
*/
public $page_no = 1;
/**
* 每页显示条数
* @var int
*/
public $page_size = 15;
/**
* 无需登录即可访问的方法
* @var array
*/
public $like_not_need_login = [];
/**
* 构造方法
* @access public
* @param App $app 应用对象
*/
public function __construct(App $app)
{
$this->app = app();
$this->request = request();
// 控制器初始化
$this->initialize();
}
/**
* 初始化
*/
protected function initialize()
{
//用户信息
$this->user_info = $this->request->user_info ?? [];
if(boolval($this->user_info)) {
$this->user_id = $this->user_info['id'] ?? null;
$this->client = $this->user_info['client'] ?? null;
}
//分页参数
$page_no = (int)$this->request->get('page_no');
$this->page_no = $page_no && is_numeric($page_no) ? $page_no : $this->page_no;
$page_size = (int)$this->request->get('page_size');
$this->page_size = $page_size && is_numeric($page_size) ? $page_size : $this->page_size;
$this->page_size = min($this->page_size, 100);
}
}

View File

@ -0,0 +1,68 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\basics;
use think\App;
use think\exception\HttpResponseException;
/**
* index基类
* Class AdminBase
* @Author mjf
* @package app\common\basics
*/
abstract class IndexBase
{
/**
* Request实例
*/
protected $request;
/**
* 应用实例
*/
protected $app;
/**
* 构造方法
* @access public
* @param App $app 应用对象
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = $this->app->request;
}
/**
* Notes: 自定义重定向
* @param mixed ...$args
* @author 段誉(2021/4/9 14:04)
*/
public function redirect(...$args)
{
throw new HttpResponseException(redirect(...$args));
}
}

View File

@ -0,0 +1,137 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\basics;
use think\App;
/**
* 客服模块基类
* Class KefuBase
* @package app\common\basics
*/
abstract class KefuBase
{
/**
* Request实例
*/
protected $request;
/**
* 应用实例
*/
protected $app;
/**
* 商家信息
* @var
*/
protected $shop;
/**
* 商家id
* @var
*/
protected $shop_id;
/**
* 客服id
* @var
*/
protected $kefu_id;
/**
* 客服名称
* @var
*/
protected $kefu_name;
/**
* 客服信息
* @var array
*/
public $kefu_info = [];
/**
* 客户端
* @var null
*/
public $client = null;
/**
* 页码
* @var int
*/
public $page_no = 1;
/**
* 每页显示条数
* @var int
*/
public $page_size = 15;
/**
* 无需登录即可访问的方法
* @var array
*/
public $like_not_need_login = [];
/**
* 构造方法
* @access public
* @param App $app 应用对象
*/
public function __construct(App $app)
{
$this->app = app();
$this->request = request();
// 控制器初始化
$this->initialize();
}
/**
* 初始化
*/
protected function initialize()
{
//客服信息
if (isset($this->request->kefu_info) && $this->request->kefu_info) {
$this->kefu_info = $this->request->kefu_info ?? [];
}
if(boolval($this->kefu_info)) {
$this->shop_id = $this->kefu_info['shop_id'] ?? 0;
$this->kefu_id = $this->kefu_info['id'] ?? null;
$this->kefu_name = $this->kefu_info['nickname'] ?? null;
$this->client = $this->kefu_info['client'] ?? null;
}
//分页参数
$page_no = (int)$this->request->get('page_no');
$this->page_no = $page_no && is_numeric($page_no) ? $page_no : $this->page_no;
$page_size = (int)$this->request->get('page_size');
$this->page_size = $page_size && is_numeric($page_size) ? $page_size : $this->page_size;
$this->page_size = min($this->page_size, 100);
}
}

View File

@ -0,0 +1,46 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\basics;
/**
* 逻辑层基类
* Class Logic
* @Author FZR
* @package app\common\basics
*/
abstract class Logic
{
/**
* 错误信息
* @var string
*/
protected static $error;
/**
* 返回错误信息
* @access public
* @return string|array
*/
public static function getError()
{
return self::$error;
}
}

View File

@ -0,0 +1,94 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\basics;
use app\common\server\UrlServer;
use think\Model;
/**
* 模型 基类
* Class Models
* @Author FZR
* @package app\common\basics
*/
abstract class Models extends Model
{
// 定义公共操作 如 删除 切换状态等
/**
* updateData 回调 记录update的条数
* @var integer
*/
public $_updateResult;
final protected function checkResult($result) : void
{
$this->_updateResult = $result;
}
final function getUpdateResult() : int
{
return $this->_updateResult;
}
/**
* NOTE: 修改器-图片转相对路径
* @author: 张无忌
* @param $value
* @return mixed|string
*/
public function setImageAttr($value)
{
return $value ? UrlServer::setFileUrl($value) : '';
}
/**
* NOTE: 获取器-补全图片路径
* @author: 张无忌
* @param $value
* @return string
*/
public function getImageAttr($value,$data)
{
if(!$value && isset($data['goods_snap'])){
return UrlServer::getFileUrl($data['goods_snap']['image']);
}
return $value ? UrlServer::getFileUrl($value) : '';
}
/**
* @notes 统一处理用户nickname
* @param $nickname
* @return string
* @author lbzy
* @datetime 2023-09-06 10:35:17
*/
function getNicknameAttr($nickname)
{
if (in_array(app('http')->getName(), [ 'admin', 'shop' ]) && request()->isAjax()) {
$nickname = htmlspecialchars($nickname);
}
return $nickname;
}
}

View File

@ -0,0 +1,138 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\basics;
use think\App;
/**
* 商家后台移动端API接口基类
* Class ShopApi
* @package app\common\basics
*/
abstract class ShopApi
{
/**
* Request实例
*/
protected $request;
/**
* 应用实例
*/
protected $app;
/**
* 商家信息
* @var
*/
protected $shop;
/**
* 商家id
* @var
*/
protected $shop_id;
/**
* 管理员id
* @var
*/
protected $admin_id;
/**
* 管理员名称
* @var
*/
protected $admin_name;
/**
* 管理员信息
* @var array
*/
public $admin_info = [];
public $shop_info = [];
/**
* 客户端
* @var null
*/
public $client = null;
/**
* 页码
* @var int
*/
public $page_no = 1;
/**
* 每页显示条数
* @var int
*/
public $page_size = 15;
/**
* 无需登录即可访问的方法
* @var array
*/
public $like_not_need_login = [];
/**
* 构造方法
* @access public
* @param App $app 应用对象
*/
public function __construct(App $app)
{
$this->app = app();
$this->request = request();
// 控制器初始化
$this->initialize();
}
/**
* 初始化
*/
protected function initialize()
{
//用户信息
$this->admin_info = $this->request->admin_info ?? [];
if(boolval($this->admin_info)) {
$this->shop = $this->admin_info ?? null;
$this->shop_id = $this->admin_info['shop_id'] ?? null;
$this->shop_name = $this->admin_info['shop_name'] ?? null;
$this->admin_id = $this->admin_info['id'] ?? null;
$this->admin_name = $this->admin_info['name'] ?? null;
$this->client = $this->admin_info['client'] ?? null;
}
//分页参数
$page_no = (int)$this->request->get('page_no');
$this->page_no = $page_no && is_numeric($page_no) ? $page_no : $this->page_no;
$page_size = (int)$this->request->get('page_size');
$this->page_size = $page_size && is_numeric($page_size) ? $page_size : $this->page_size;
$this->page_size = min($this->page_size, 100);
}
}

View File

@ -0,0 +1,307 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\basics;
use app\common\server\ConfigServer;
use app\common\server\UrlServer;
use app\common\utils\Time;
use app\shop\server\AuthServer;
use think\App;
use think\exception\HttpResponseException;
use think\facade\Config;
use think\facade\View;
/**
* 后台基类
* Class ShopBase
* @Author FZR
* @package app\common\basics
*/
abstract class ShopBase
{
/**
* Request实例
*/
protected $request;
/**
* 应用实例
*/
protected $app;
/**
* 商家信息
* @var
*/
protected $shop;
/**
* 商家id
* @var
*/
protected $shop_id;
/**
* 商家名称
* @var
*/
protected $shop_name;
/**
* 管理员id
* @var
*/
protected $admin_id;
/**
* 管理员名称
* @var
*/
protected $admin_name;
/**
* 逻辑
* @var
*/
protected $logic;
/**
* 验证器
* @var
*/
protected $validate;
/**
* 不需要登录的方法
* @var array
*/
public $like_not_need_login = [];
/**
* js数据
* @var array
*/
protected $js_data = [];
/**
* 分页
* @var int
*/
public $page_no = 1;
public $page_size = 15;
/**
* 模板颜色
* @var string
*/
public $view_theme_color = '';
/**
* 构造方法
* @access public
* @param App $app 应用对象
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = $this->app->request;
// 控制器初始化
$this->initialize();
}
/**
* 初始化
*/
protected function initialize()
{
//默认设置参数
$this->initConfig();
//验证登录
$this->checkLogin();
//验证权限
$this->checkAuth();
//默认页面参数
$this->setViewValue();
return true;
}
/**
* Notes: 基础配置参数
* @author 段誉(2021/4/9 14:18)
*/
protected function initConfig()
{
$this->shop = session('shop_info');
$this->shop_id = session('shop_info.shop_id');
$this->shop_name = session('shop_info.shop_name');
$this->admin_id = session('shop_info.id');
$this->admin_name = session('shop_info.name');
//分页参数
$page_no = (int)$this->request->get('page_no');
$this->page_no = $page_no && is_numeric($page_no) ? $page_no : $this->page_no;
$page_size = (int)$this->request->get('page_size');
$this->page_size = $page_size && is_numeric($page_size) ? $page_size : $this->page_size;
$this->page_size = min($this->page_size, 100);
}
/**
* 设置视图全局变量
*/
private function setViewValue()
{
$app = Config::get('project');
View::assign([
'view_env_name' => $app['env_name'],
'view_admin_name' => $app['admin_name'],
'view_theme_color' => $app['theme_color'],
'view_theme_button' => $app['theme_button'],
'front_version' => $app['front_version'],
'version' => $app['version'],
'dateTime' => Time::getTime(),
'storageUrl' => UrlServer::getFileUrl('/'),
'company_name' => ConfigServer::get('copyright', 'company_name')
]);
$this->assignJs('image_upload_url', '');
}
/**
* Notes: 检查登录
* @author 段誉(2021/4/9 14:05)
* @return bool
*/
protected function checkLogin()
{
//已登录的访问登录页
if ($this->shop && !$this->isNotNeedLogin()) {
return true;
}
//已登录的访问非登录页
if ($this->shop && $this->isNotNeedLogin()) {
$this->redirect(url('index/index'));
}
//未登录的访问非登录页
if (!$this->shop && $this->isNotNeedLogin()) {
return true;
}
//未登录访问登录页
$this->redirect(url('login/login'));
}
/**
* Notes: 验证登录角色权限
* @author 段誉(2021/4/13 11:34)
* @return bool
*/
protected function checkAuth()
{
//未登录的无需权限控制
if (empty(session('shop_info'))) {
return true;
}
//如果id为1视为系统超级管理无需权限控制
if (session('shop_info.id') == 1) {
return true;
}
//权限控制判断
$controller_action = request()->controller() . '/' . request()->action();// 当前访问
$controller_action = strtolower($controller_action);
//没有的权限
$none_auth = AuthServer::getRoleNoneAuthUris(session('shop_info.role_id'));
if (empty($none_auth) || !in_array($controller_action, $none_auth)) {
//通过权限控制
return true;
}
$this->redirect(url('dispatch/dispatch_error',['msg' => '权限不足,无法访问']));
return false;
}
/**
* Notes: js
* @param $name
* @param $value
* @author 段誉(2021/4/9 14:23)
*/
protected function assignJs($name, $value)
{
$this->js_data[$name] = $value;
$js_code = "<script>";
foreach ($this->js_data as $name => $value) {
if (is_array($value)) {
$value = json_encode($value);
} elseif (!is_integer($value)) {
$value = '"' . $value . '"';
}
$js_code .= $name . '=' . $value . ';';
}
$js_code .= "</script>";
View::assign('js_code', $js_code);
}
/**
* Notes: 是否无需登录
* @author 段誉(2021/4/9 14:03)
* @return bool
*/
private function isNotNeedLogin()
{
if (empty($this->like_not_need_login)) {
return false;
}
$action = strtolower(request()->action());
$data = array_map('strtolower', $this->like_not_need_login);
if (!in_array($action, $data)) {
return false;
}
return true;
}
/**
* Notes: 自定义重定向
* @param mixed ...$args
* @author 段誉(2021/4/9 14:04)
*/
public function redirect(...$args)
{
throw new HttpResponseException(redirect(...$args));
}
}

View File

@ -0,0 +1,107 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\basics;
use app\common\server\JsonServer;
use think\response\Json;
/**
* 验证器基类
* Class Validate
* @Author FZR
* @package app\common\basics
*/
abstract class Validate extends \think\Validate
{
/**
* 切面验证接收到的参数
* @param null $scene (场景验证)
* @param array $validate_data 验证参数,可追加和覆盖掉接收的参数
* @author FZR
* @return mixed|Json
*/
public function goCheck($scene=null,$validate_data = [])
{
// 1.接收参数
$params = request()->param();
//合并验证参数
$params = array_merge($params,$validate_data);
// 2.验证参数
if (!($scene ? $this->scene($scene)->check($params) : $this->check($params))) {
$exception = is_array($this->error)
? implode(';', $this->error) : $this->error;
JsonServer::throw($exception);
}
// 3.成功返回数据
return $params;
}
/**
* @notes 验证联系方式
* @param $value
* @param $rule
* @param $data
* @return string|bool
* @author lbzy
* @datetime 2024-10-28 18:00:59
*/
function checkMobile($value, $rule, $data)
{
$checkList = $rule['check'] ?? [ 'land' ];
$arr = [
'land' => [
'title' => '手机号',
'preg' => '/^1[3-9]\d{9}$/',
],
'hk' => [
'title' => '手机号',
'preg' => '/^(00|\+)?(852)[5|6|9]\d{7}$/',
],
'taiWan' => [
'title' => '手机号',
'preg' => '/^(00|\+)?(886)[0][9]\d{8}$/',
],
'aoMen' => [
'title' => '手机号',
'preg' => '/^(00|\+)?(853)?[6]\d{7}$/',
],
'landTel' => [
'title' => '电话',
'preg' => '/^(?:(?:\d{3}-?)?\d{8}|^(?:\d{4}-?)?\d{7,8})(?:-\d+)?$/',
],
];
$result = false;
foreach ($checkList as $key) {
if (! isset($arr[$key])) {
return '不存在的手机或电话地区';
}
if (preg_match($arr[$key]['preg'], $value)) {
$result = true;
break;
}
}
return $result ? true : ($rule['msg'] ?? '联系方式错误');
}
}