初始化仓库

This commit is contained in:
Yao
2025-08-14 16:44:56 +08:00
commit 45b8c90ad8
5157 changed files with 664203 additions and 0 deletions

View File

@ -0,0 +1,117 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate;
use app\common\validate\BaseValidate;
/**
* 文件验证
* Class FileValidate
* @package app\adminapi\validate
*/
class FileValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|number',
'cid' => 'require|number',
'ids' => 'require|array',
'type' => 'require|in:10,20,30',
'pid' => 'require|number',
'name' => 'require|max:20'
];
protected $message = [
'id.require' => '缺少id参数',
'cid.require' => '缺少cid参数',
'ids.require' => '缺少ids参数',
'type.require' => '缺少type参数',
'pid.require' => '缺少pid参数',
'name.require' => '请填写分组名称',
'name.max' => '分组名称长度须为20字符内',
];
/**
* @notes id验证场景
* @return FileValidate
* @author 段誉
* @date 2021/12/29 14:32
*/
public function sceneId()
{
return $this->only(['id']);
}
/**
* @notes 重命名文件场景
* @return FileValidate
* @author 段誉
* @date 2021/12/29 14:32
*/
public function sceneRename()
{
return $this->only(['id', 'name']);
}
/**
* @notes 新增分类场景
* @return FileValidate
* @author 段誉
* @date 2021/12/29 14:33
*/
public function sceneAddCate()
{
return $this->only(['type', 'pid', 'name']);
}
/**
* @notes 编辑分类场景
* @return FileValidate
* @author 段誉
* @date 2021/12/29 14:33
*/
public function sceneEditCate()
{
return $this->only(['id', 'name']);
}
/**
* @notes 移动场景
* @return FileValidate
* @author 段誉
* @date 2021/12/29 14:33
*/
public function sceneMove()
{
return $this->only(['ids', 'cid']);
}
/**
* @notes 删除场景
* @return FileValidate
* @author 段誉
* @date 2021/12/29 14:35
*/
public function sceneDelete()
{
return $this->only(['ids']);
}
}

View File

@ -0,0 +1,103 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate;
use app\common\enum\AdminTerminalEnum;
use app\common\model\auth\Admin;
use app\common\cache\AdminAccountSafeCache;
use app\common\service\ConfigService;
use app\common\validate\BaseValidate;
use think\facade\Config;
/**
* 登录验证
* Class LoginValidate
* @package app\adminapi\validate
*/
class LoginValidate extends BaseValidate
{
protected $rule = [
'terminal' => 'require|in:' . AdminTerminalEnum::PC . ',' . AdminTerminalEnum::MOBILE,
'account' => 'require',
'password' => 'require|password',
];
protected $message = [
'account.require' => '请输入账号',
'password.require' => '请输入密码'
];
/**
* @notes @notes 密码验证
* @param $password
* @param $other
* @param $data
* @return bool|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 令狐冲
* @date 2021/7/2 14:00
*/
public function password($password, $other, $data)
{
// 登录限制
$config = [
'login_restrictions' => ConfigService::get('admin_login', 'login_restrictions'),
'password_error_times' => ConfigService::get('admin_login', 'password_error_times'),
'limit_login_time' => ConfigService::get('admin_login', 'limit_login_time'),
];
$adminAccountSafeCache = new AdminAccountSafeCache();
if ($config['login_restrictions'] == 1) {
$adminAccountSafeCache->count = $config['password_error_times'];
$adminAccountSafeCache->minute = $config['limit_login_time'];
}
//后台账号安全机制,连续输错后锁定,防止账号密码暴力破解
if ($config['login_restrictions'] == 1 && !$adminAccountSafeCache->isSafe()) {
return '密码连续' . $adminAccountSafeCache->count . '次输入错误,请' . $adminAccountSafeCache->minute . '分钟后重试';
}
$adminInfo = Admin::where('account', '=', $data['account'])
->field(['password,disable'])
->findOrEmpty();
if ($adminInfo->isEmpty()) {
return '账号不存在';
}
if ($adminInfo['disable'] === 1) {
return '账号已禁用';
}
if (empty($adminInfo['password'])) {
$adminAccountSafeCache->record();
return '账号不存在';
}
$passwordSalt = Config::get('project.unique_identification');
if ($adminInfo['password'] !== create_password($password, $passwordSalt)) {
$adminAccountSafeCache->record();
return '密码错误';
}
$adminAccountSafeCache->relieve();
return true;
}
}

View File

@ -0,0 +1,136 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\article;
use app\common\validate\BaseValidate;
use app\common\model\article\ArticleCate;
use app\common\model\article\Article;
/**
* 资讯分类管理验证
* Class ArticleCateValidate
* @package app\adminapi\validate\article
*/
class ArticleCateValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|checkArticleCate',
'name' => 'require|length:1,90',
'is_show' => 'require|in:0,1',
'sort' => 'egt:0',
];
protected $message = [
'id.require' => '资讯分类id不能为空',
'name.require' => '资讯分类不能为空',
'name.length' => '资讯分类长度须在1-90位字符',
'sort.egt' => '排序值不正确',
];
/**
* @notes 添加场景
* @return ArticleCateValidate
* @author heshihu
* @date 2022/2/10 15:11
*/
public function sceneAdd()
{
return $this->remove(['id'])
->remove('id', 'require|checkArticleCate');
}
/**
* @notes 详情场景
* @return ArticleCateValidate
* @author heshihu
* @date 2022/2/21 17:55
*/
public function sceneDetail()
{
return $this->only(['id']);
}
/**
* @notes 更改状态场景
* @return ArticleCateValidate
* @author heshihu
* @date 2022/2/21 18:02
*/
public function sceneStatus()
{
return $this->only(['id', 'is_show']);
}
public function sceneEdit()
{
}
/**
* @notes 获取所有资讯分类场景
* @return ArticleCateValidate
* @author heshihu
* @date 2022/2/15 10:05
*/
public function sceneSelect()
{
return $this->only(['type']);
}
/**
* @notes 删除场景
* @return ArticleCateValidate
* @author heshihu
* @date 2022/2/21 17:52
*/
public function sceneDelete()
{
return $this->only(['id'])
->append('id', 'checkDeleteArticleCate');
}
/**
* @notes 检查指定资讯分类是否存在
* @param $value
* @return bool|string
* @author heshihu
* @date 2022/2/10 15:10
*/
public function checkArticleCate($value)
{
$article_category = ArticleCate::findOrEmpty($value);
if ($article_category->isEmpty()) {
return '资讯分类不存在';
}
return true;
}
/**
* @notes 删除时验证该资讯分类是否已使用
* @param $value
* @return bool|string
* @author heshihu
* @date 2022/2/22 14:45
*/
public function checkDeleteArticleCate($value)
{
$article = Article::where('cid', $value)->findOrEmpty();
if (!$article->isEmpty()) {
return '资讯分类已使用,请先删除绑定该资讯分类的资讯';
}
return true;
}
}

View File

@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\article;
use app\common\validate\BaseValidate;
use app\common\model\article\Article;
/**
* 资讯管理验证
* Class ArticleValidate
* @package app\adminapi\validate\article
*/
class ArticleValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|checkArticle',
'title' => 'require|length:1,255',
// 'image' => 'require',
'cid' => 'require',
'is_show' => 'require|in:0,1',
];
protected $message = [
'id.require' => '资讯id不能为空',
'title.require' => '标题不能为空',
'title.length' => '标题长度须在1-255位字符',
// 'image.require' => '封面图必须存在',
'cid.require' => '所属栏目必须存在',
];
/**
* @notes 添加场景
* @return ArticleValidate
* @author heshihu
* @date 2022/2/22 9:57
*/
public function sceneAdd()
{
return $this->remove(['id'])
->remove('id','require|checkArticle');
}
/**
* @notes 详情场景
* @return ArticleValidate
* @author heshihu
* @date 2022/2/22 10:15
*/
public function sceneDetail()
{
return $this->only(['id']);
}
/**
* @notes 更改状态场景
* @return ArticleValidate
* @author heshihu
* @date 2022/2/22 10:18
*/
public function sceneStatus()
{
return $this->only(['id', 'is_show']);
}
public function sceneEdit()
{
}
/**
* @notes 删除场景
* @return ArticleValidate
* @author heshihu
* @date 2022/2/22 10:17
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 检查指定资讯是否存在
* @param $value
* @return bool|string
* @author heshihu
* @date 2022/2/22 10:11
*/
public function checkArticle($value)
{
$article = Article::findOrEmpty($value);
if ($article->isEmpty()) {
return '资讯不存在';
}
return true;
}
}

View File

@ -0,0 +1,197 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\auth;
use app\common\validate\BaseValidate;
use app\common\model\auth\Admin;
/**
* 管理员验证
* Class AdminValidate
* @package app\adminapi\validate\auth
*/
class AdminValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|checkAdmin',
'account' => 'require|length:1,32|unique:'.Admin::class,
'name' => 'require|length:1,16|unique:'.Admin::class,
'password' => 'require|length:6,32|edit',
'password_confirm' => 'requireWith:password|confirm',
'role_id' => 'require',
'disable' => 'require|in:0,1|checkAbleDisable',
'multipoint_login' => 'require|in:0,1',
];
protected $message = [
'id.require' => '管理员id不能为空',
'account.require' => '账号不能为空',
'account.length' => '账号长度须在1-32位字符',
'account.unique' => '账号已存在',
'password.require' => '密码不能为空',
'password.length' => '密码长度须在6-32位字符',
'password_confirm.requireWith' => '确认密码不能为空',
'password_confirm.confirm' => '两次输入的密码不一致',
'name.require' => '名称不能为空',
'name.length' => '名称须在1-16位字符',
'name.unique' => '名称已存在',
'role_id.require' => '请选择角色',
'disable.require' => '请选择状态',
'disable.in' => '状态值错误',
'multipoint_login.require' => '请选择是否支持多处登录',
'multipoint_login.in' => '多处登录状态值为误',
];
/**
* @notes 添加场景
* @return AdminValidate
* @author 段誉
* @date 2021/12/29 15:46
*/
public function sceneAdd()
{
return $this->remove(['password', 'edit'])
->remove('id', true)
->remove('disable', true);
}
/**
* @notes 详情场景
* @return AdminValidate
* @author 段誉
* @date 2021/12/29 15:46
*/
public function sceneDetail()
{
return $this->only(['id']);
}
/**
* @notes 编辑场景
* @return AdminValidate
* @author 段誉
* @date 2021/12/29 15:47
*/
public function sceneEdit()
{
return $this->remove('password', 'require|length')
->append('id', 'require|checkAdmin')
->remove('role_id', 'require')
->append('role_id', 'checkRole');
}
/**
* @notes 删除场景
* @return AdminValidate
* @author 段誉
* @date 2021/12/29 15:47
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 编辑情况下,检查是否填密码
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2021/12/29 10:19
*/
public function edit($value, $rule, $data)
{
if (empty($data['password']) && empty($data['password_confirm'])) {
return true;
}
$len = strlen($value);
if ($len < 6 || $len > 32) {
return '密码长度须在6-32位字符';
}
return true;
}
/**
* @notes 检查指定管理员是否存在
* @param $value
* @return bool|string
* @author 段誉
* @date 2021/12/29 10:19
*/
public function checkAdmin($value)
{
$admin = Admin::findOrEmpty($value);
if ($admin->isEmpty()) {
return '管理员不存在';
}
return true;
}
/**
* @notes 禁用校验
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/8/11 9:59
*/
public function checkAbleDisable($value, $rule, $data)
{
$admin = Admin::findOrEmpty($data['id']);
if ($admin->isEmpty()) {
return '管理员不存在';
}
if ($value && $admin['root']) {
return '超级管理员不允许被禁用';
}
return true;
}
/**
* @notes 校验角色
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2023/9/6 16:58
*/
public function checkRole($value, $rule, $data)
{
$admin = Admin::findOrEmpty($data['id']);
if ($admin->isEmpty()) {
return '管理员不存在';
}
if ($admin['root']) {
return true;
}
if (empty($data['role_id'])) {
return '请选择角色';
}
return true;
}
}

View File

@ -0,0 +1,195 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\auth;
use app\common\validate\BaseValidate;
use app\common\model\auth\{SystemRole,SystemMenu};
/**
* 系统菜单
* Class SystemMenuValidate
* @package app\adminapi\validate\auth
*/
class MenuValidate extends BaseValidate
{
protected $rule = [
'id' => 'require',
'pid' => 'require|checkPid',
'type' => 'require|in:M,C,A',
'name' => 'require|length:1,30|checkUniqueName',
'icon' => 'max:100',
'sort' => 'require|egt:0',
'perms' => 'max:100',
'paths' => 'max:200',
'component' => 'max:200',
'selected' => 'max:200',
'params' => 'max:200',
'is_cache' => 'require|in:0,1',
'is_show' => 'require|in:0,1',
'is_disable' => 'require|in:0,1',
];
protected $message = [
'id.require' => '参数缺失',
'pid.require' => '请选择上级菜单',
'type.require' => '请选择菜单类型',
'type.in' => '菜单类型参数值错误',
'name.require' => '请填写菜单名称',
'name.length' => '菜单名称长度需为1~30个字符',
'icon.max' => '图标名称不能超过100个字符',
'sort.require' => '请填写排序',
'sort.egt' => '排序值需大于或等于0',
'perms.max' => '权限字符不能超过100个字符',
'paths.max' => '路由地址不能超过200个字符',
'component.max' => '组件路径不能超过200个字符',
'selected.max' => '选中菜单路径不能超过200个字符',
'params.max' => '路由参数不能超过200个字符',
'is_cache.require' => '请选择缓存状态',
'is_cache.in' => '缓存状态参数值错误',
'is_show.require' => '请选择显示状态',
'is_show.in' => '显示状态参数值错误',
'is_disable.require' => '请选择菜单状态',
'is_disable.in' => '菜单状态参数值错误',
];
/**
* @notes 添加场景
* @return MenuValidate
* @author 段誉
* @date 2022/6/29 18:26
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 详情场景
* @return MenuValidate
* @author 段誉
* @date 2022/6/29 18:27
*/
public function sceneDetail()
{
return $this->only(['id']);
}
/**
* @notes 删除场景
* @return MenuValidate
* @author 段誉
* @date 2022/6/29 18:27
*/
public function sceneDelete()
{
return $this->only(['id'])
->append('id', 'checkAbleDelete');
}
/**
* @notes 更新状态场景
* @return MenuValidate
* @author 段誉
* @date 2022/7/6 17:04
*/
public function sceneStatus()
{
return $this->only(['id', 'is_disable']);
}
/**
* @notes 校验菜单名称是否已存在
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/6/29 18:24
*/
protected function checkUniqueName($value, $rule, $data)
{
if ($data['type'] != 'M') {
return true;
}
$where[] = ['type', '=', $data['type']];
$where[] = ['name', '=', $data['name']];
if (!empty($data['id'])) {
$where[] = ['id', '<>', $data['id']];
}
$check = SystemMenu::where($where)->findOrEmpty();
if (!$check->isEmpty()) {
return '菜单名称已存在';
}
return true;
}
/**
* @notes 是否有子级菜单
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/6/30 9:40
*/
protected function checkAbleDelete($value, $rule, $data)
{
$hasChild = SystemMenu::where(['pid' => $value])->findOrEmpty();
if (!$hasChild->isEmpty()) {
return '存在子菜单,不允许删除';
}
// 已绑定角色菜单不可以删除
$isBindRole = SystemRole::hasWhere('roleMenuIndex', ['menu_id' => $value])->findOrEmpty();
if (!$isBindRole->isEmpty()) {
return '已分配菜单不可删除';
}
return true;
}
/**
* @notes 校验上级
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/6/30 9:51
*/
protected function checkPid($value, $rule, $data)
{
if (!empty($data['id']) && $data['id'] == $value) {
return '上级菜单不能选择自己';
}
return true;
}
}

View File

@ -0,0 +1,119 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\auth;
use app\common\validate\BaseValidate;
use app\common\model\auth\{AdminRole, SystemRole, Admin};
/**
* 角色验证器
* Class RoleValidate
* @package app\adminapi\validate\auth
*/
class RoleValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|checkRole',
'name' => 'require|max:64|unique:' . SystemRole::class . ',name',
'menu_id' => 'array',
];
protected $message = [
'id.require' => '请选择角色',
'name.require' => '请输入角色名称',
'name.max' => '角色名称最长为16个字符',
'name.unique' => '角色名称已存在',
'menu_id.array' => '权限格式错误'
];
/**
* @notes 添加场景
* @return RoleValidate
* @author 段誉
* @date 2021/12/29 15:47
*/
public function sceneAdd()
{
return $this->only(['name', 'menu_id']);
}
/**
* @notes 详情场景
* @return RoleValidate
* @author 段誉
* @date 2021/12/29 15:47
*/
public function sceneDetail()
{
return $this->only(['id']);
}
/**
* @notes 删除场景
* @return RoleValidate
* @author 段誉
* @date 2021/12/29 15:48
*/
public function sceneDel()
{
return $this->only(['id'])
->append('id', 'checkAdmin');
}
/**
* @notes 验证角色是否存在
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2021/12/29 15:48
*/
public function checkRole($value, $rule, $data)
{
if (!SystemRole::find($value)) {
return '角色不存在';
}
return true;
}
/**
* @notes 验证角色是否被使用
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2021/12/29 15:49
*/
public function checkAdmin($value, $rule, $data)
{
if (AdminRole::where(['role_id' => $value])->find()) {
return '有管理员在使用该角色,不允许删除';
}
return true;
}
}

View File

@ -0,0 +1,73 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\auth;
use app\common\validate\BaseValidate;
use app\common\model\auth\Admin;
use think\facade\Config;
/**
* 编辑超级管理员验证
* Class editSelfValidate
* @package app\adminapi\validate\auth
*/
class editSelfValidate extends BaseValidate
{
protected $rule = [
'name' => 'require|length:1,16',
'avatar' => 'require',
'password' => 'length:6,32|checkPassword',
'password_confirm' => 'requireWith:password|confirm',
];
protected $message = [
'name.require' => '请填写名称',
'name.length' => '名称须在1-16位字符',
'avatar.require' => '请选择头像',
'password_now.length' => '密码长度须在6-32位字符',
'password_confirm.requireWith' => '确认密码不能为空',
'password_confirm.confirm' => '两次输入的密码不一致',
];
/**
* @notes 校验密码
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/4/8 17:40
*/
public function checkPassword($value, $rule, $data)
{
if (empty($data['password_old'])) {
return '请填写当前密码';
}
$admin = Admin::findOrEmpty($data['admin_id']);
$passwordSalt = Config::get('project.unique_identification');
$oldPassword = create_password($data['password_old'], $passwordSalt);
if ($admin['password'] != $oldPassword) {
return '当前密码错误';
}
return true;
}
}

View File

@ -0,0 +1,36 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\channel;
use app\common\validate\BaseValidate;
/**
* 小程序设置
* Class MnpSettingsValidate
* @package app\adminapi\validate\channel
*/
class MnpSettingsValidate extends BaseValidate
{
protected $rule = [
'app_id' => 'require',
'app_secret' => 'require',
];
protected $message = [
'app_id.require' => '请填写AppID',
'app_secret.require' => '请填写AppSecret',
];
}

View File

@ -0,0 +1,72 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\channel;
use app\common\validate\BaseValidate;
/**
* 微信公众号回复验证器
* Class OfficialAccountReplyValidate
* @package app\adminapi\validate\channel
*/
class OfficialAccountReplyValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|integer',
'reply_type' => 'require|in:1,2,3',
'name' => 'require',
'content_type' => 'require|in:1',
'content' => 'require',
'status' => 'require|in:0,1',
'keyword' => 'requireIf:reply_type,2',
'matching_type' => 'requireIf:reply_type,2|in:1,2',
'sort' => 'requireIf:reply_type,2',
'reply_num' => 'requireIf:reply_type,2|in:1',
'new_sort' => 'require|integer|egt:0',
];
protected $message = [
'reply_type.require' => '请输入回复类型',
'reply_type.in' => '回复类型状态值错误',
'name.require' => '请输入规则名称',
'content_type.require' => '请选择内容类型',
'content_type.in' => '内容类型状态值有误',
'content.require' => '请输入回复内容',
'status.require' => '请选择启用状态',
'status.in' => '启用状态值错误',
'keyword.requireIf' => '请输入关键词',
'matching_type.requireIf' => '请选择匹配类型',
'matching_type.in' => '匹配类型状态值错误',
'sort.requireIf' => '请输入排序值',
'sort.integer' => '排序值须为整型',
'sort.egt' => '排序值须大于或等于0',
'reply_num.requireIf' => '请选择回复数量',
'reply_num.in' => '回复数量状态值错误',
'id.require' => '参数缺失',
'id.integer' => '参数格式错误',
'new_sort.require' => '请输入新排序值',
'new_sort.integer' => '新排序值须为整型',
'new_sort.egt' => '新排序值须大于或等于0',
];
protected $scene = [
'add' => ['reply_type', 'name', 'content_type', 'content', 'status', 'keyword', 'matching_type', 'sort', 'reply_num'],
'detail' => ['id'],
'delete' => ['id'],
'sort' => ['id', 'new_sort'],
'status' => ['id'],
'edit' => ['id', 'reply_type', 'name', 'content_type', 'content', 'status','keyword', 'matching_type', 'sort', 'reply_num']
];
}

View File

@ -0,0 +1,38 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\channel;
use app\common\validate\BaseValidate;
/**
* 公众号设置
* Class OfficialAccountSettingValidate
* @package app\adminapi\validate\channel
*/
class OfficialAccountSettingValidate extends BaseValidate
{
protected $rule = [
'app_id' => 'require',
'app_secret' => 'require',
'encryption_type' => 'require|in:1,2,3',
];
protected $message = [
'app_id.require' => '请填写AppID',
'app_secret.require' => '请填写AppSecret',
'encryption_type.require' => '请选择消息加密方式',
'encryption_type.in' => '消息加密方式状态值错误',
];
}

View File

@ -0,0 +1,34 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\channel;
use app\common\validate\BaseValidate;
/**
* 开放平台验证
* Class OpenSettingValidate
* @package app\adminapi\validate\channel
*/
class OpenSettingValidate extends BaseValidate
{
protected $rule = [
'app_id' => 'require',
'app_secret' => 'require',
];
protected $message = [
'app_id.require' => '请输入appId',
'app_secret.require' => '请输入appSecret',
];
}

View File

@ -0,0 +1,33 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\channel;
use app\common\validate\BaseValidate;
/**
* H5设置验证器
* Class HFiveSettingValidate
* @package app\adminapi\validate\setting\h5
*/
class WebPageSettingValidate extends BaseValidate
{
protected $rule = [
'status' => 'require|in:0,1'
];
protected $message = [
'status.require' => '请选择启用状态',
'status.in' => '启用状态值有误',
];
}

View File

@ -0,0 +1,138 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\crontab;
use app\common\validate\BaseValidate;
use Cron\CronExpression;
/**
* 定时任务验证器
* Class CrontabValidate
* @package app\adminapi\validate\crontab
*/
class CrontabValidate extends BaseValidate
{
protected $rule = [
'name' => 'require',
'type' => 'require|in:1',
'command' => 'require',
'status' => 'require|in:1,2,3',
'expression' => 'require|checkExpression',
'id' => 'require',
'operate' => 'require'
];
protected $message = [
'name.require' => '请输入定时任务名称',
'type.require' => '请选择类型',
'type.in' => '类型值错误',
'command.require' => '请输入命令',
'status.require' => '请选择状态',
'status.in' => '状态值错误',
'expression.require' => '请输入运行规则',
'id.require' => '参数缺失',
'operate.require' => '请选择操作',
];
/**
* @notes 添加定时任务场景
* @return CrontabValidate
* @author 段誉
* @date 2022/3/29 14:39
*/
public function sceneAdd()
{
return $this->remove('id', 'require')->remove('operate', 'require');
}
/**
* @notes 查看定时任务详情场景
* @return CrontabValidate
* @author 段誉
* @date 2022/3/29 14:39
*/
public function sceneDetail()
{
return $this->only(['id']);
}
/**
* @notes 编辑定时任务
* @return CrontabValidate
* @author 段誉
* @date 2022/3/29 14:39
*/
public function sceneEdit()
{
return $this->remove('operate', 'require');
}
/**
* @notes 删除定时任务场景
* @return CrontabValidate
* @author 段誉
* @date 2022/3/29 14:40
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes CrontabValidate
* @return CrontabValidate
* @author 段誉
* @date 2022/3/29 14:40
*/
public function sceneOperate()
{
return $this->only(['id', 'operate']);
}
/**
* @notes 获取规则执行时间场景
* @return CrontabValidate
* @author 段誉
* @date 2022/3/29 14:40
*/
public function sceneExpression()
{
return $this->only(['expression']);
}
/**
* @notes 校验运行规则
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/3/29 14:40
*/
public function checkExpression($value, $rule, $data)
{
if (CronExpression::isValidExpression($value) === false) {
return '定时任务运行规则错误';
}
return true;
}
}

View File

@ -0,0 +1,40 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\decorate;
use app\common\validate\BaseValidate;
/**
* 装修页面验证
* Class DecoratePageValidate
* @package app\adminapi\validate\decorate
*/
class DecoratePageValidate extends BaseValidate
{
protected $rule = [
'id' => 'require',
'type' => 'require',
'data' => 'require',
];
protected $message = [
'id.require' => '参数缺失',
'type.require' => '装修类型参数缺失',
'data.require' => '装修信息参数缺失',
];
}

View File

@ -0,0 +1,179 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\dept;
use app\common\model\auth\Admin;
use app\common\model\auth\AdminDept;
use app\common\model\dept\Dept;
use app\common\validate\BaseValidate;
/**
* 部门验证器
* Class DeptValidate
* @package app\adminapi\validate\dept
*/
class DeptValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|checkDept',
'pid' => 'require|integer',
'name' => 'require|unique:'.Dept::class.'|length:1,30',
'status' => 'require|in:0,1',
'sort' => 'egt:0',
];
protected $message = [
'id.require' => '参数缺失',
'name.require' => '请填写部门名称',
'name.length' => '部门名称长度须在1-30位字符',
'name.unique' => '部门名称已存在',
'sort.egt' => '排序值不正确',
'pid.require' => '请选择上级部门',
'pid.integer' => '上级部门参数错误',
'status.require' => '请选择部门状态',
];
/**
* @notes 添加场景
* @return DeptValidate
* @author 段誉
* @date 2022/5/25 18:16
*/
public function sceneAdd()
{
return $this->remove('id', true)->append('pid', 'checkDept');
}
/**
* @notes 详情场景
* @return DeptValidate
* @author 段誉
* @date 2022/5/25 18:16
*/
public function sceneDetail()
{
return $this->only(['id']);
}
/**
* @notes 编辑场景
* @return DeptValidate
* @author 段誉
* @date 2022/5/26 18:42
*/
public function sceneEdit()
{
return $this->append('pid', 'checkPid');
}
/**
* @notes 删除场景
* @return DeptValidate
* @author 段誉
* @date 2022/5/25 18:16
*/
public function sceneDelete()
{
return $this->only(['id'])->append('id', 'checkAbleDetele');
}
/**
* @notes 校验部门
* @param $value
* @return bool|string
* @author 段誉
* @date 2022/5/25 18:17
*/
public function checkDept($value)
{
$dept = Dept::findOrEmpty($value);
if ($dept->isEmpty()) {
return '部门不存在';
}
return true;
}
/**
* @notes 校验能否删除
* @param $value
* @return bool|string
* @author 段誉
* @date 2022/5/26 14:22
*/
public function checkAbleDetele($value)
{
$hasLower = Dept::where(['pid' => $value])->findOrEmpty();
if (!$hasLower->isEmpty()) {
return '已关联下级部门,暂不可删除';
}
$check = AdminDept::where(['dept_id' => $value])->findOrEmpty();
if (!$check->isEmpty()) {
return '已关联管理员,暂不可删除';
}
$dept = Dept::findOrEmpty($value);
if ($dept['pid'] == 0) {
return '顶级部门不可删除';
}
return true;
}
/**
* @notes 校验部门
* @param $value
* @param $rule
* @param array $data
* @return bool|string
* @author 段誉
* @date 2022/5/26 18:41
*/
public function checkPid($value, $rule, $data = [])
{
// 当前编辑的部门id信息是否存在
$dept = Dept::findOrEmpty($data['id']);
if ($dept->isEmpty()) {
return '当前部门信息缺失';
}
// 顶级部门不校验上级部门id
if ($dept['pid'] == 0) {
return true;
}
if ($data['id'] == $value) {
return '上级部门不可是当前部门';
}
$leaderDept = Dept::findOrEmpty($value);
if ($leaderDept->isEmpty()) {
return '部门不存在';
}
return true;
}
}

View File

@ -0,0 +1,127 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\dept;
use app\common\model\auth\Admin;
use app\common\model\auth\AdminJobs;
use app\common\model\dept\Jobs;
use app\common\validate\BaseValidate;
/**
* 岗位验证
* Class JobsValidate
* @package app\adminapi\validate\dept
*/
class JobsValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|checkJobs',
'name' => 'require|unique:'.Jobs::class.'|length:1,50',
'code' => 'require|unique:'.Jobs::class,
'status' => 'require|in:0,1',
'sort' => 'egt:0',
];
protected $message = [
'id.require' => '参数缺失',
'name.require' => '请填写岗位名称',
'name.length' => '岗位名称长度须在1-50位字符',
'name.unique' => '岗位名称已存在',
'code.require' => '请填写岗位编码',
'code.unique' => '岗位编码已存在',
'sort.egt' => '排序值不正确',
'status.require' => '请选择岗位状态',
'status.in' => '岗位状态值错误',
];
/**
* @notes 添加场景
* @return JobsValidate
* @author 段誉
* @date 2022/5/26 9:53
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 详情场景
* @return JobsValidate
* @author 段誉
* @date 2022/5/26 9:53
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function sceneEdit()
{
}
/**
* @notes 删除场景
* @return JobsValidate
* @author 段誉
* @date 2022/5/26 9:54
*/
public function sceneDelete()
{
return $this->only(['id'])->append('id', 'checkAbleDetele');
}
/**
* @notes 校验岗位
* @param $value
* @return bool|string
* @author 段誉
* @date 2022/5/26 9:55
*/
public function checkJobs($value)
{
$jobs = Jobs::findOrEmpty($value);
if ($jobs->isEmpty()) {
return '岗位不存在';
}
return true;
}
/**
* @notes 校验能否删除
* @param $value
* @return bool|string
* @author 段誉
* @date 2022/5/26 14:22
*/
public function checkAbleDetele($value)
{
$check = AdminJobs::where(['jobs_id' => $value])->findOrEmpty();
if (!$check->isEmpty()) {
return '已关联管理员,暂不可删除';
}
return true;
}
}

View File

@ -0,0 +1,119 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\dict;
use app\common\model\dict\DictData;
use app\common\model\dict\DictType;
use app\common\validate\BaseValidate;
/**
* 字典数据验证
* Class DictDataValidate
* @package app\adminapi\validate\dict
*/
class DictDataValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|checkDictData',
'name' => 'require|length:1,255',
'value' => 'require',
'type_id' => 'require|checkDictType',
'status' => 'require|in:0,1',
];
protected $message = [
'id.require' => '参数缺失',
'name.require' => '请填写字典数据名称',
'name.length' => '字典数据名称长度须在1-255位字符',
'value.require' => '请填写字典数据值',
'type_id.require' => '字典类型缺失',
'status.require' => '请选择字典数据状态',
'status.in' => '字典数据状态参数错误',
];
/**
* @notes 添加场景
* @return DictDataValidate
* @author 段誉
* @date 2022/6/20 16:54
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes ID场景
* @return DictDataValidate
* @author 段誉
* @date 2022/6/20 16:54
*/
public function sceneId()
{
return $this->only(['id']);
}
/**
* @notes 编辑场景
* @return DictDataValidate
* @author 段誉
* @date 2022/6/20 18:36
*/
public function sceneEdit()
{
return $this->remove('type_id', true);
}
/**
* @notes 校验字典数据
* @param $value
* @return bool|string
* @author 段誉
* @date 2022/6/20 16:55
*/
protected function checkDictData($value)
{
$article = DictData::findOrEmpty($value);
if ($article->isEmpty()) {
return '字典数据不存在';
}
return true;
}
/**
* @notes 校验字典类型
* @param $value
* @return bool|string
* @author 段誉
* @date 2022/6/20 17:03
*/
protected function checkDictType($value)
{
$type = DictType::findOrEmpty($value);
if ($type->isEmpty()) {
return '字典类型不存在';
}
return true;
}
}

View File

@ -0,0 +1,133 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\dict;
use app\common\model\dict\DictData;
use app\common\model\dict\DictType;
use app\common\validate\BaseValidate;
/**
* 字典类型验证
* Class DictTypeValidate
* @package app\adminapi\validate\dict
*/
class DictTypeValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|checkDictType',
'name' => 'require|length:1,255',
'type' => 'require|unique:' . DictType::class,
'status' => 'require|in:0,1',
'remark' => 'max:200',
];
protected $message = [
'id.require' => '参数缺失',
'name.require' => '请填写字典名称',
'name.length' => '字典名称长度须在1~255位字符',
'type.require' => '请填写字典类型',
'type.unique' => '字典类型已存在',
'status.require' => '请选择状态',
'remark.max' => '备注长度不能超过200',
];
/**
* @notes 添加场景
* @return DictTypeValidate
* @author 段誉
* @date 2022/6/20 16:00
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 详情场景
* @return DictTypeValidate
* @author 段誉
* @date 2022/6/20 16:00
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function sceneEdit()
{
}
/**
* @notes 删除场景
* @return DictTypeValidate
* @author 段誉
* @date 2022/6/20 16:03
*/
public function sceneDelete()
{
return $this->only(['id'])
->append('id', 'checkAbleDelete');
}
/**
* @notes 检查字典类型是否存在
* @param $value
* @return bool|string
* @author 段誉
* @date 2022/6/20 16:04
*/
protected function checkDictType($value)
{
$dictType = DictType::findOrEmpty($value);
if ($dictType->isEmpty()) {
return '字典类型不存在';
}
return true;
}
/**
* @notes 验证是否可删除
* @param $value
* @return bool|string
* @author 段誉
* @date 2022/6/20 16:04
*/
protected function checkAbleDelete($value)
{
$dictData = DictData::whereIn('type_id', $value)->select();
foreach ($dictData as $item) {
if (!empty($item)) {
return '字典类型已被使用,请先删除绑定该字典类型的数据';
}
}
return true;
}
}

View File

@ -0,0 +1,39 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\notice;
use app\common\validate\BaseValidate;
/**
* 通知验证
* Class NoticeValidate
* @package app\adminapi\validate\notice
*/
class NoticeValidate extends BaseValidate
{
protected $rule = [
'id' => 'require',
];
protected $message = [
'id.require' => '参数缺失',
];
protected function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,51 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\notice;
use app\common\validate\BaseValidate;
/**
* 短信配置验证
* Class SmsConfigValidate
* @package app\adminapi\validate\notice
*/
class SmsConfigValidate extends BaseValidate
{
protected $rule = [
'type' => 'require',
'sign' => 'require',
'app_id' => 'requireIf:type,tencent',
'app_key' => 'requireIf:type,ali',
'secret_id' => 'requireIf:type,tencent',
'secret_key' => 'require',
'status' => 'require',
];
protected $message = [
'type.require' => '请选择类型',
'sign.require' => '请输入签名',
'app_id.requireIf' => '请输入app_id',
'app_key.requireIf' => '请输入app_key',
'secret_id.requireIf' => '请输入secret_id',
'secret_key.require' => '请输入secret_key',
'status.require' => '请选择状态',
];
protected function sceneDetail()
{
return $this->only(['type']);
}
}

View File

@ -0,0 +1,122 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\recharge;
use app\common\enum\PayEnum;
use app\common\enum\RefundEnum;
use app\common\enum\YesNoEnum;
use app\common\model\recharge\RechargeOrder;
use app\common\model\refund\RefundRecord;
use app\common\model\user\User;
use app\common\validate\BaseValidate;
/**
* 充值退款校验
* Class RechargeRefundValidate
* @package app\adminapi\validate\recharge
*/
class RechargeRefundValidate extends BaseValidate
{
protected $rule = [
'recharge_id' => 'require|checkRecharge',
'record_id' => 'require|checkRecord',
];
protected $message = [
'recharge_id.require' => '参数缺失',
'record_id.require' => '参数缺失',
];
public function sceneRefund()
{
return $this->only(['recharge_id']);
}
public function sceneAgain()
{
return $this->only(['record_id']);
}
/**
* @notes 校验充值订单能否发起退款
* @param $rechargeId
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2023/2/28 17:00
*/
protected function checkRecharge($rechargeId, $rule, $data)
{
$order = RechargeOrder::findOrEmpty($rechargeId);
if ($order->isEmpty()) {
return '充值订单不存在';
}
if ($order['pay_status'] != PayEnum::ISPAID) {
return '当前订单不可退款';
}
// 校验订单是否已退款
if ($order['refund_status'] == YesNoEnum::YES) {
return '订单已发起退款,退款失败请到退款记录重新退款';
}
// 校验余额
$user = User::findOrEmpty($order['user_id']);
if ($user['user_money'] < $order['order_amount']) {
return '退款失败:用户余额已不足退款金额';
}
return true;
}
/**
* @notes 校验退款记录
* @param $recordId
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2023/3/1 9:40
*/
protected function checkRecord($recordId, $rule, $data)
{
$record = RefundRecord::findOrEmpty($recordId);
if ($record->isEmpty()) {
return '退款记录不存在';
}
if($record['refund_status'] == RefundEnum::REFUND_SUCCESS) {
return '该退款记录已退款成功';
}
$order = RechargeOrder::findOrEmpty($record['order_id']);
$user = User::findOrEmpty($record['user_id']);
if ($user['user_money'] < $order['order_amount']) {
return '退款失败:用户余额已不足退款金额';
}
return true;
}
}

View File

@ -0,0 +1,131 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\setting;
use app\common\enum\PayEnum;
use app\common\model\pay\PayConfig;
use app\common\validate\BaseValidate;
class PayConfigValidate extends BaseValidate
{
protected $rule = [
'id' => 'require',
'name' => 'require|checkName',
'icon' => 'require',
'sort' => 'require|number|max:5',
'config' => 'checkConfig',
];
protected $message = [
'id.require' => 'id不能为空',
'name.require' => '支付名称不能为空',
'icon.require' => '支付图标不能为空',
'sort.require' => '排序不能为空',
'sort,number' => '排序必须是纯数字',
'sort.max' => '排序最大不能超过五位数',
'config.require' => '支付参数缺失',
];
public function sceneGet()
{
return $this->only(['id']);
}
/**
* @notes 校验支付配置记录
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2023/2/23 16:19
*/
public function checkConfig($config, $rule, $data)
{
$result = PayConfig::where('id', $data['id'])->find();
if (empty($result)) {
return '支付方式不存在';
}
if ($result['pay_way'] != PayEnum::BALANCE_PAY && !isset($config)) {
return '支付配置不能为空';
}
if ($result['pay_way'] == PayEnum::WECHAT_PAY) {
if (empty($config['interface_version'])) {
return '微信支付接口版本不能为空';
}
if (empty($config['merchant_type'])) {
return '商户类型不能为空';
}
if (empty($config['mch_id'])) {
return '微信支付商户号不能为空';
}
if (empty($config['pay_sign_key'])) {
return '商户API密钥不能为空';
}
if (empty($config['apiclient_cert'])) {
return '微信支付证书不能为空';
}
if (empty($config['apiclient_key'])) {
return '微信支付证书密钥不能为空';
}
}
if ($result['pay_way'] == PayEnum::ALI_PAY) {
if (empty($config['mode'])) {
return '模式不能为空';
}
if (empty($config['merchant_type'])) {
return '商户类型不能为空';
}
if (empty($config['app_id'])) {
return '应用ID不能为空';
}
if (empty($config['private_key'])) {
return '应用私钥不能为空';
}
if (empty($config['ali_public_key'])) {
return '支付宝公钥不能为空';
}
}
return true;
}
/**
* @notes 校验支付名
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2023/2/23 16:19
*/
public function checkName($value, $rule, $data)
{
$result = PayConfig::where('name', $value)
->where('id', '<>', $data['id'])
->findOrEmpty();
if (!$result->isEmpty()) {
return '支付名称已存在';
}
return true;
}
}

View File

@ -0,0 +1,70 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\setting;
use app\common\validate\BaseValidate;
/**
* 存储引擎验证
* Class StorageValidate
* @package app\adminapi\validate\setting
*/
class StorageValidate extends BaseValidate
{
protected $rule = [
'engine' => 'require',
'status' => 'require',
];
/**
* @notes 设置存储引擎参数场景
* @return StorageValidate
* @author 段誉
* @date 2022/4/20 16:18
*/
public function sceneSetup()
{
return $this->only(['engine', 'status']);
}
/**
* @notes 获取配置参数信息场景
* @return StorageValidate
* @author 段誉
* @date 2022/4/20 16:18
*/
public function sceneDetail()
{
return $this->only(['engine']);
}
/**
* @notes 切换存储引擎场景
* @return StorageValidate
* @author 段誉
* @date 2022/4/20 16:18
*/
public function sceneChange()
{
return $this->only(['engine']);
}
}

View File

@ -0,0 +1,51 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\setting;
use app\common\validate\BaseValidate;
/**
* 交易设置验证
* Class TransactionSettingsValidate
* @package app\adminapi\validate\setting
*/
class TransactionSettingsValidate extends BaseValidate
{
protected $rule = [
'cancel_unpaid_orders' => 'require|in:0,1',
'cancel_unpaid_orders_times' => 'requireIf:cancel_unpaid_orders,1|integer|gt:0',
'verification_orders' => 'require|in:0,1',
'verification_orders_times' => 'requireIf:verification_orders,1|integer|gt:0',
];
protected $message = [
'cancel_unpaid_orders.require' => '请选择系统取消待付款订单方式',
'cancel_unpaid_orders.in' => '系统取消待付款订单状态值有误',
'cancel_unpaid_orders_times.requireIf' => '系统取消待付款订单时间未填写',
'cancel_unpaid_orders_times.integer' => '系统取消待付款订单时间须为整型',
'cancel_unpaid_orders_times.gt' => '系统取消待付款订单时间须大于0',
'verification_orders.require' => '请选择系统自动核销订单方式',
'verification_orders.in' => '系统自动核销订单状态值有误',
'verification_orders_times.requireIf' => '系统自动核销订单时间未填写',
'verification_orders_times.integer' => '系统自动核销订单时间须为整型',
'verification_orders_times.gt' => '系统自动核销订单时间须大于0',
];
public function sceneSetConfig()
{
return $this->only(['cancel_unpaid_orders','cancel_unpaid_orders_times','verification_orders','verification_orders_times']);
}
}

View File

@ -0,0 +1,58 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\setting;
use app\common\validate\BaseValidate;
/**
* 用户设置验证
* Class UserConfigValidate
* @package app\adminapi\validate\setting
*/
class UserConfigValidate extends BaseValidate
{
protected $rule = [
'login_way' => 'requireIf:scene,register|array',
'coerce_mobile' => 'requireIf:scene,register|in:0,1',
'login_agreement' => 'in:0,1',
'third_auth' => 'in:0,1',
'wechat_auth' => 'in:0,1',
'default_avatar' => 'require',
];
protected $message = [
'default_avatar.require' => '请上传用户默认头像',
'login_way.requireIf' => '请选择登录方式',
'login_way.array' => '登录方式值错误',
'coerce_mobile.requireIf' => '请选择注册强制绑定手机',
'coerce_mobile.in' => '注册强制绑定手机值错误',
'wechat_auth.in' => '公众号微信授权登录值错误',
'third_auth.in' => '第三方登录值错误',
'login_agreement.in' => '政策协议值错误',
];
//用户设置验证
public function sceneUser()
{
return $this->only(['default_avatar']);
}
//注册验证
public function sceneRegister()
{
return $this->only(['login_way', 'coerce_mobile', 'login_agreement', 'third_auth', 'wechat_auth']);
}
}

View File

@ -0,0 +1,51 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\setting;
use app\common\validate\BaseValidate;
/**
* 网站设置验证器
* Class WebSettingValidate
* @package app\adminapi\validate\setting
*/
class WebSettingValidate extends BaseValidate
{
protected $rule = [
'name' => 'require|max:30',
'web_favicon' => 'require',
'web_logo' => 'require',
'login_image' => 'require',
'shop_name' => 'require',
'shop_logo' => 'require',
'pc_logo' => 'require'
];
protected $message = [
'name.require' => '请填写网站名称',
'name.max' => '网站名称最长为12个字符',
'web_favicon.require' => '请上传网站图标',
'web_logo.require' => '请上传网站logo',
'login_image.require' => '请上传登录页广告图',
'shop_name.require' => '请填写前台名称',
'shop_logo.require' => '请上传前台logo',
'pc_logo.require' => '请上传PC端logo'
];
protected $scene = [
'website' => ['name', 'web_favicon', 'web_logo', 'login_image', 'shop_name', 'shop_logo', 'pc_logo'],
'siteStatistics' => [''],
];
}

View File

@ -0,0 +1,98 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\tools;
use app\common\model\tools\GenerateTable;
use app\common\validate\BaseValidate;
/**
* 编辑表验证
* Class EditTableValidate
* @package app\adminapi\validate\tools
*/
class EditTableValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|checkTableData',
'table_name' => 'require',
'table_comment' => 'require',
'template_type' => 'require|in:0,1',
'generate_type' => 'require|in:0,1',
'module_name' => 'require',
'table_column' => 'require|array|checkColumn',
];
protected $message = [
'id.require' => '表id缺失',
'table_name.require' => '请填写表名称',
'table_comment.require' => '请填写表描述',
'template_type.require' => '请选择模板类型',
'template_type.in' => '模板类型参数错误',
'generate_type.require' => '请选择生成方式',
'generate_type.in' => '生成方式类型错误',
'module_name.require' => '请填写模块名称',
'table_column.require' => '表字段信息缺失',
'table_column.array' => '表字段信息类型错误',
];
/**
* @notes 校验当前数据表是否存在
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/6/15 18:58
*/
protected function checkTableData($value, $rule, $data)
{
$table = GenerateTable::findOrEmpty($value);
if ($table->isEmpty()) {
return '信息不存在';
}
return true;
}
/**
* @notes 校验表字段参数
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/6/20 10:42
*/
protected function checkColumn($value, $rule, $data)
{
foreach ($value as $item) {
if (!isset($item['id'])) {
return '表字段id参数缺失';
}
if (!isset($item['query_type'])) {
return '请选择查询方式';
}
if (!isset($item['view_type'])) {
return '请选择显示类型';
}
}
return true;
}
}

View File

@ -0,0 +1,131 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\tools;
use app\common\model\tools\GenerateTable;
use app\common\validate\BaseValidate;
use think\facade\Db;
/**
* 代码生成选择表验证
* Class SelectTableValidate
* @package app\adminapi\validate\tools
*/
class GenerateTableValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|checkTableData',
'table' => 'require|array|checkTable',
'file' => 'require'
];
protected $message = [
'id.require' => '参数缺失',
'table.require' => '参数缺失',
'table.array' => '参数类型错误',
'file.require' => '下载失败',
];
/**
* @notes 选择数据表场景
* @return GenerateTableValidate
* @author 段誉
* @date 2022/6/15 18:58
*/
public function sceneSelect()
{
return $this->only(['table']);
}
/**
* @notes 需要校验id的场景
* @return GenerateTableValidate
* @author 段誉
* @date 2022/6/15 18:58
*/
public function sceneId()
{
return $this->only(['id']);
}
/**
* @notes 下载场景
* @return GenerateTableValidate
* @author 段誉
* @date 2022/6/24 10:02
*/
public function sceneDownload()
{
return $this->only(['file']);
}
/**
* @notes 校验选择的数据表信息
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/6/15 18:58
*/
protected function checkTable($value, $rule, $data)
{
foreach ($value as $item) {
if (!isset($item['name']) || !isset($item['comment'])) {
return '参数缺失';
}
$exist = Db::query("SHOW TABLES LIKE'" . $item['name'] . "'");
if (empty($exist)) {
return '当前数据库不存在' . $item['name'] . '表';
}
}
return true;
}
/**
* @notes 校验当前数据表是否存在
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/6/15 18:58
*/
protected function checkTableData($value, $rule, $data)
{
if (!is_array($value)) {
$value = [$value];
}
foreach ($value as $item) {
$table = GenerateTable::findOrEmpty($item);
if ($table->isEmpty()) {
return '信息不存在';
}
}
return true;
}
}

View File

@ -0,0 +1,66 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\user;
use app\common\enum\user\AccountLogEnum;
use app\common\model\user\User;
use app\common\validate\BaseValidate;
/**
* 调整用户钱包验证器
* Class AdjustUserMoney
* @package app\adminapi\validate\user
*/
class AdjustUserMoney extends BaseValidate
{
protected $rule = [
'user_id' => 'require',
'action' => 'require|in:' . AccountLogEnum::INC . ',' .AccountLogEnum::DEC,
'num' => 'require|gt:0|checkMoney',
'remark' => 'max:128',
];
protected $message = [
'id.require' => '请选择用户',
'action.require' => '请选择调整类型',
'action.in' => '调整类型错误',
'num.require' => '请输入调整数量',
'num.gt' => '调整余额必须大于零',
'remark' => '备注不可超过128个符号',
];
protected function checkMoney($vaule, $rule, $data)
{
$user = User::find($data['user_id']);
if (empty($user)) {
return '用户不存在';
}
if (1 == $data['action']) {
return true;
}
$surplusMoeny = $user->user_money - $vaule;
if ($surplusMoeny < 0) {
return '用户可用余额仅剩' . $user->user_money;
}
return true;
}
}

View File

@ -0,0 +1,128 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\user;
use app\common\model\user\User;
use app\common\validate\BaseValidate;
/**
* 用户验证
* Class UserValidate
* @package app\adminapi\validate\user
*/
class UserValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|checkUser',
'field' => 'require|checkField',
'value' => 'require',
];
protected $message = [
'id.require' => '请选择用户',
'field.require' => '请选择操作',
'value.require' => '请输入内容',
];
/**
* @notes 详情场景
* @return UserValidate
* @author 段誉
* @date 2022/9/22 16:35
*/
public function sceneDetail()
{
return $this->only(['id']);
}
/**
* @notes 用户信息校验
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/9/22 17:03
*/
public function checkUser($value, $rule, $data)
{
$userIds = is_array($value) ? $value : [$value];
foreach ($userIds as $item) {
if (!User::find($item)) {
return '用户不存在!';
}
}
return true;
}
/**
* @notes 校验是否可更新信息
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/9/22 16:37
*/
public function checkField($value, $rule, $data)
{
$allowField = ['account', 'sex', 'mobile', 'real_name'];
if (!in_array($value, $allowField)) {
return '用户信息不允许更新';
}
switch ($value) {
case 'account':
//验证手机号码是否存在
$account = User::where([
['id', '<>', $data['id']],
['account', '=', $data['value']]
])->findOrEmpty();
if (!$account->isEmpty()) {
return '账号已被使用';
}
break;
case 'mobile':
if (false == $this->validate($data['value'], 'mobile', $data)) {
return '手机号码格式错误';
}
//验证手机号码是否存在
$mobile = User::where([
['id', '<>', $data['id']],
['mobile', '=', $data['value']]
])->findOrEmpty();
if (!$mobile->isEmpty()) {
return '手机号码已存在';
}
break;
}
return true;
}
}