初始化本地仓库

This commit is contained in:
2026-08-31 11:33:59 +08:00
commit 663f74b633
2390 changed files with 402918 additions and 0 deletions
@@ -0,0 +1,97 @@
<?php
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: https://madong.tech
*/
namespace app\adminapi\validate;
use core\base\BaseValidate;
class TestValidate extends BaseValidate
{
/**
* 场景.
*
* @var \string[][]
*/
protected array $scene = [
'login' => [
'account',
'password',
'captcha',
],
'save' => [
'account',
'password',
'avatar',
'real_name',
'roles',
],
'update' => [
'account',
'avatar',
'real_name',
'roles',
],
'password' => [
'password',
'password_confirm',
],
];
/**
* @return array
*/
public function rules(): array
{
return [
'account' => 'required|min:5|max:50|alpha_num',
'password' => [
'required',
'min:5',
'max:50',
],
'captcha' => 'required',
'password_confirm' => [
'required',
'password_confirm_api:' . input('password'),
],
'avatar' => 'required',
'real_name' => 'required',
'roles' => 'required',
];
}
/**
* 设置错误提醒.
*
* @return string[]
*/
public function message(): array
{
return [
'account.required' => '账号必须填写',
'account.min' => '账号长度不正确',
'account.max' => '账号长度超出限制',
'account.alpha_num' => '账号不正确',
'password.required' => '密码必须填写',
'password.min' => '密码长度不正确,最少5个字符',
'password.max' => '密码长度不正确',
'password.regex' => '输入的密码不符合规则,请输入的组合',
'password_confirm.password_confirm_api' => '两次输入的密码不正确',
'password_confirm.required' => '请填写确认密码',
'captcha.required' => '验证码必须填写',
'captcha.captcha_api' => '验证码不正确',
'avatar.required' => '请选择头像',
'real_name.required' => '请填写管理员姓名',
'roles.required' => '请选择管理员身份',
];
}
}
@@ -0,0 +1,92 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\adminapi\validate\crontab;
use core\base\BaseValidate;
class CrontabValidate extends BaseValidate
{
/**
* 定义验证规则
*/
protected array $rule = [
'data' => 'require',
'title' => 'require',
'type' => 'require',
'rule' => 'require',
'target' => 'require',
'enabled' => 'require',
];
/**
* 定义错误信息
*/
protected array $message = [
'data.require' => '唯一标识ID不能为空',
'title.require' => '任务名称必须填写',
// 'title.task_enabled' => '定时任务未开启,.env文件APP_TASK_ENABLED=true',
'type.require' => '任务类型必须填写',
'rule.require' => '任务规则必须填写',
'target.require' => '调用目标必须填写',
'enabled.require' => '任务状态必须填写',
];
/**
* 验证是否启动定时任务
*
* @param $value
* @param $rule
* @param array $data
*
* @return bool
*/
protected function task_enabled($value, $rule, array $data = []): bool
{
return config('madong.scheduler.app.enable', false);
}
/**
* 定义场景
*/
protected array $scene = [
'start' => [
'data',
],
'resume' => [
'data',
],
'pause' => [
'data',
],
'execute' => [
'data',
],
'destroy' => [
'data',
],
'store' => [
'title',
'type',
'target',
'enabled',
],
'update' => [
'title',
'type',
'rule',
'target',
'enabled',
],
];
}
@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\adminapi\validate\gateway;
use app\model\gateway\RateLimiter;
use core\base\BaseValidate;
class RateLimiterValidate extends BaseValidate
{
/**
* 定义验证规则
*/
protected array $rule = [
'name' => 'require|unique_name',
'match_type' => 'require',
'methods' => 'require',
'path' => 'require',
'limit_value' => 'require',
'period' => 'require',
'message' => 'require',
];
/**
* 定义错误信息
*/
protected array $message = [
'name.require' => '规则名称不能为空',
'name.unique_name' => '规则名称已被占用',
'match_type.require' => '匹配类型不能为空',
'http_methods.require' => '请求方法不能为空',
'path.require' => '请求路径不能为空',
'limit_value.unique_db' => '限制值必须填写',
'period.require' => '统计周期不能为空',
'message.require' => '提示消息不能为空',
];
/**
* 数据中心代码重复验证
*
* @param $value
* @param $rule
* @param array $data
*
* @return bool
*/
protected function unique_name($value, $rule, array $data = []): bool
{
$query = RateLimiter::where('name', $value);
// 如果是更新操作,可以排除当前记录
if (isset($data['id'])) {
$query->where('id', '<>', $data['id']);
}
return $query->count() === 0;
}
/**
* 定义场景
*/
protected array $scene = [
'store' => [
'name',
'match_type',
'methods',
'path',
'limit_value',
'period',
'message',
],
'update' => [
'id',
],
'destroy' => [
'id',
],
];
}
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\adminapi\validate\gateway;
use app\model\gateway\RateLimiter;
use core\base\BaseValidate;
class RateRestrictionsValidate extends BaseValidate
{
/**
* 定义验证规则
*/
protected array $rule = [
'name' => 'require|unique_name',
'match_type' => 'require',
'methods' => 'require',
'path' => 'require',
'message' => 'require',
];
/**
* 定义错误信息
*/
protected array $message = [
'name.require' => '名称不能为空',
'name.unique_name' => '名称已被占用',
'match_type.require' => '类型不能为空',
'http_methods.require' => '请求方法不能为空',
'path.require' => '请求路径不能为空',
'message.require' => '提示消息不能为空',
];
/**
* 重复验证
*
* @param $value
* @param $rule
* @param array $data
*
* @return bool
*/
protected function unique_name($value, $rule, array $data = []): bool
{
$query = RateLimiter::where('name', $value);
// 如果是更新操作,可以排除当前记录
if (isset($data['id'])) {
$query->where('id', '<>', $data['id']);
}
return $query->count() === 0;
}
/**
* 定义场景
*/
protected array $scene = [
'store' => [
'name',
// 'match_type',
'methods',
'path',
'message',
],
'update' => [
'id',
],
'destroy' => [
'id',
],
];
}
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\adminapi\validate\generator;
use core\base\BaseValidate;
/**
* 代码生成器
* Class Generator
*
* @package app\validate\generator
*/
class GeneratorValidate extends BaseValidate
{
protected array $rule = [
'table_name' => 'require|max:64',
'table_content' => 'require|max:64',
];
protected array $message = [
'table_name.require' => 'validate_generator.table_name_require',
'table_name.max' => 'validate_generator.table_name_max',
'table_content.require' => 'validate_generator.table_content_require',
'table_content.max' => 'validate_generator.table_content_max',
];
protected array $scene = [
'store' => ['table_name'],
"update" => ['table_name', 'table_content', 'class_name', 'module_name', 'table_column'],
];
}
@@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
namespace app\adminapi\validate\member;
use app\model\member\Member;
use core\base\BaseValidate;
use Illuminate\Validation\Rule;
/**
* 会员验证器
*/
class MemberAuthValidate extends BaseValidate
{
/**
* 验证规则
*/
public function rules(): array
{
$id = request()->route->param('id');
return [
'username' => ['required', 'max:50', Rule::unique(Member::class, 'username')->ignore($id, 'id')],
'email' => ['email', 'max:100'],
'phone' => ['max:20'],
'password' => 'required|min:6|max:20',
'nickname' => 'max:50',
'level_id' => 'integer|min:1',
'points' => 'integer|min:0',
'balance' => 'number|min:0',
'gender' => 'in:0,1,2',
'birthday' => 'date',
'enabled' => 'in:0,1',
];
}
/**
* 验证消息
*/
protected array $message = [
'username.required' => '用户名不能为空',
'username.max' => '用户名不能超过50个字符',
'username.unique' => '用户名已存在',
'email.email' => '邮箱格式不正确',
'email.max' => '邮箱不能超过100个字符',
'email.unique' => '邮箱已存在',
'phone.max' => '手机号格式不正确',
'phone.unique' => '手机号已存在',
'password.required' => '密码不能为空',
'password.min' => '密码不能少于6个字符',
'password.max' => '密码不能超过20个字符',
'nickname.max' => '昵称不能超过50个字符',
'level_id.integer' => '等级ID必须为整数',
'level_id.min' => '等级ID不能小于1',
'points.integer' => '积分必须为整数',
'points.min' => '积分不能小于0',
'balance.number' => '余额必须为数字',
'balance.min' => '余额不能小于0',
'gender.in' => '性别值不正确',
'birthday.date' => '生日格式不正确',
'enabled.in' => '状态值不正确',
];
/**
* 验证场景
*/
protected array $scene = [
'get' => [
'member_id',
],
];
}
@@ -0,0 +1,91 @@
<?php
declare(strict_types=1);
namespace app\adminapi\validate\member;
use app\model\member\MemberLevel;
use core\base\BaseValidate;
use Illuminate\Validation\Rule;
/**
* 会员等级验证器
*/
class MemberLevelValidate extends BaseValidate
{
/**
* 验证规则
*/
public function rules(): array
{
$id = request()->route->param('id');
return [
'name' => [
'required',
'max:50',
Rule::unique(MemberLevel::class, 'name')->ignore($id, 'id'),
],
'level' => [
'required',
'integer',
'min:1',
Rule::unique(MemberLevel::class, 'level')->ignore($id, 'id'),
],
'min_points' => 'integer|min:0',
'max_points' => 'integer|min:0',
'discount' => 'numeric|between:0,1',
'color' => 'max:20',
'description' => 'max:255',
'enabled' => 'in:0,1',
];
}
/**
* 验证消息
*/
protected array $message = [
'name.required' => '等级名称不能为空',
'name.max' => '等级名称不能超过50个字符',
'name.unique' => '等级名称已存在',
'level.required' => '等级值不能为空',
'level.integer' => '等级值必须为整数',
'level.min' => '等级值不能小于1',
'level.unique' => '等级值已存在',
'min_points.integer' => '最低积分必须为整数',
'min_points.min' => '最低积分不能小于0',
'max_points.integer' => '最高积分必须为整数',
'max_points.min' => '最高积分不能小于0',
'discount.number' => '折扣率必须为数字',
'discount.between' => '折扣率必须在0到1之间',
'color.max' => '等级颜色不能超过20个字符',
'description.max' => '等级描述不能超过255个字符',
'enabled.in' => '状态值不正确',
];
/**
* 验证场景
*/
protected array $scene = [
'store' => [
'name',
'level',
'min_points',
'max_points',
'discount',
'color',
'description',
'enabled',
],
'update' => [
'name',
'level',
'min_points',
'max_points',
'discount',
'color',
'description',
'enabled'
],
];
}
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
namespace app\adminapi\validate\member;
use core\base\BaseValidate;
/**
* 会员积分验证器
*/
class MemberPointsValidate extends BaseValidate
{
/**
* 验证规则
*/
public function rules(): array
{
return [
'member_id' => 'required|integer|gt:0',
'points' => 'required|integer|gt:0',
'type' => 'required|integer|in:1,2',
'source' => 'nullable|string|max:255',
'remark' => 'nullable|string|max:255',
'operator' => 'nullable|string|max:50',
];
}
/**
* 验证消息
*/
protected array $message = [
'member_id.required' => '会员ID不能为空',
'member_id.integer' => '会员ID必须为整数',
'member_id.gt' => '会员ID必须大于0',
'points.required' => '积分数量不能为空',
'points.integer' => '积分数量必须为整数',
'points.gt' => '积分数量必须大于0',
'type.required' => '积分类型不能为空',
'type.integer' => '积分类型必须为整数',
'type.in' => '积分类型只能是1(增加)或2(减少)',
'source.max' => '积分来源不能超过255个字符',
'remark.max' => '备注不能超过255个字符',
'operator.max' => '操作人不能超过50个字符',
];
/**
* 验证场景
*/
protected array $scene = [
'store' => [
'member_id',
'points',
'type',
'source',
'remark',
'operator',
],
];
}
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace app\adminapi\validate\member;
use app\model\member\MemberTag;
use core\base\BaseValidate;
use Illuminate\Validation\Rule;
/**
* 会员标签验证器
*/
class MemberTagValidate extends BaseValidate
{
/**
* 验证规则
*/
public function rules(): array
{
return [
'name' => ['required', 'max:50', Rule::unique(MemberTag::class, 'name')->ignore(request()->route->param('id'), 'id')],
'color' => 'max:20',
'sort' => 'integer|min:0',
'status' => 'in:0,1',
];
}
/**
* 验证消息
*/
protected array $message = [
'name.required' => '标签名称不能为空',
'name.max' => '标签名称不能超过50个字符',
'name.unique' => '标签名称已存在',
'color.max' => '标签颜色不能超过20个字符',
'sort.integer' => '排序必须为整数',
'sort.min' => '排序不能小于0',
'status.in' => '状态值不正确',
];
/**
* 验证场景
*/
protected array $scene = [
'store' => ['name', 'color', 'sort', 'status'],
'update' => ['name', 'color', 'sort', 'status'],
];
}
@@ -0,0 +1,151 @@
<?php
declare(strict_types=1);
namespace app\adminapi\validate\member;
use app\model\member\Member;
use core\base\BaseValidate;
use Illuminate\Validation\Rule;
/**
* 会员验证器
*/
class MemberValidate extends BaseValidate
{
/**
* 验证规则
*/
public function rules(): array
{
$id = request()->route->param('id');
return [
'username' => ['required', 'max:50', Rule::unique(Member::class, 'username')->ignore($id, 'id')],
'email' => ['email', 'max:100'],
'phone' => ['max:20'],
'password' => 'required|min:6|max:60',
'nickname' => 'max:50',
'level_id' => 'integer|min:1',
'points' => 'integer|min:0',
'balance' => 'number|min:0',
'gender' => 'in:0,1,2',
'birthday' => 'date',
'enabled' => 'in:0,1',
];
}
/**
* 验证消息
*/
protected array $message = [
'username.required' => '用户名不能为空',
'username.max' => '用户名不能超过50个字符',
'username.unique' => '用户名已存在',
'email.email' => '邮箱格式不正确',
'email.max' => '邮箱不能超过100个字符',
'email.unique' => '邮箱已存在',
'phone.max' => '手机号格式不正确',
'phone.unique' => '手机号已存在',
'password.required' => '密码不能为空',
'password.min' => '密码不能少于6个字符',
'password.max' => '密码不能超过60个字符',
'nickname.max' => '昵称不能超过50个字符',
'level_id.integer' => '等级ID必须为整数',
'level_id.min' => '等级ID不能小于1',
'points.integer' => '积分必须为整数',
'points.min' => '积分不能小于0',
'balance.number' => '余额必须为数字',
'balance.min' => '余额不能小于0',
'gender.in' => '性别值不正确',
'birthday.date' => '生日格式不正确',
'enabled.in' => '状态值不正确',
];
/**
* 验证场景
*/
protected array $scene = [
'store' => [
'username',
'email',
'phone',
'password',
'nickname',
'level_id',
'points',
'balance',
'gender',
'birthday',
'enabled',
],
'update' => [
'username',
'email',
'phone',
'nickname',
'level_id',
'points',
'balance',
'gender',
'birthday',
'enabled',
],
];
/**
* 创建验证
*/
public function sceneCreate(): MemberValidate
{
return $this->only($this->scene['create']);
}
/**
* 更新验证
*/
// public function sceneUpdate(): MemberValidate
// {
// return $this->only($this->scene['update'])
// ->append('id', 'require|integer|min:1')
// ->remove('password', 'require');
// }
/**
* 重置密码验证
*/
public function sceneResetPassword(): MemberValidate
{
return $this->only([])
->append('id', 'require|integer|min:1')
->append('password', 'require|min:6|max:20');
}
/**
* 调整积分验证
*/
public function sceneAdjustPoints(): MemberValidate
{
return $this->only([])
->append('id', 'require|integer|min:1')
->append('points', 'require|integer');
}
/**
* 批量删除验证
*/
public function sceneBatchDelete(): MemberValidate
{
return $this->only([])
->append('ids', 'require|array|min:1');
}
/**
* 状态更新验证
*/
public function sceneStatus(): MemberValidate
{
return $this->only([])
->append('id', 'require|integer|min:1')
->append('status', 'require|in:0,1');
}
}
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace app\adminapi\validate\plugin;
use core\base\BaseValidate;
class ApplicationAuthValidate extends BaseValidate
{
protected array $rule = [
'id' => 'require',
'name' => 'require|max:100',
'expired_at' => 'integer',
'enabled' => 'require|in:0,1',
'description' => 'max:500',
];
protected array $message = [
'id.require' => '参数错误缺少id',
'name.require' => '应用名称必须填写',
'name.max' => '应用名称最多100个字符',
'expired_at.integer' => '失效时间格式错误',
'enabled.require' => '状态必须填写',
'enabled.in' => '状态值错误',
'description.max' => '描述最多500个字符',
];
protected array $scene = [
'store' => [
'name',
'expired_at',
'enabled',
'description',
],
'update' => [
'id',
'name',
'expired_at',
'enabled',
'description',
],
];
}
@@ -0,0 +1,120 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: https://madong.tech
*/
namespace app\adminapi\validate\plugin;
use app\model\plugin\Plugin;
use core\base\BaseValidate;
use Illuminate\Validation\Rule;
/**
* Plugin验证器
*
* @author Mr.April
* @since 1.0
*/
class PluginValidate extends BaseValidate
{
/**
* 场景
*
* @var array
*/
protected array $scene = [
'store' => [
'author',
'version',
'cover',
'key',
'desc',
'title',
'icon',
'type',
],
'update' => [
'author',
'version',
'cover',
'desc',
'title',
'icon',
'type',
'id',
],
];
/**
* 验证规则
*
* @return array
*/
public function rules(): array
{
$id = request()->route->param('id');
return [
'author' => 'string',
'version' => 'string',
'cover' => 'string',
'updated_at' => 'integer',
'id' => 'integer|string',
'key' => ['required', 'max:50', Rule::unique(Plugin::class, 'key')->ignore($id, 'id')],
'desc' => 'string',
'support_app' => 'required|string',
'installed_at' => 'required|integer',
'title' => 'required|string',
'icon' => 'string',
'status' => 'required|integer',
'type' => 'required|string',
'created_at' => 'integer',
'variables' => 'string',
];
}
/**
* 错误信息
*
* @return array
*/
public function message(): array
{
return [
'author.required' => '作者必须填写',
'author.string' => '作者必须是字符串',
'version.required' => '版本号必须填写',
'version.string' => '版本号必须是字符串',
'cover.required' => '封面必须填写',
'cover.string' => '封面必须是字符串',
'updated_at.integer' => '更新时间必须是整数',
'id.integer' => '主键必须是整数或字符串',
'id.string' => '主键必须是整数或字符串',
'key.required' => '插件标识必须填写',
'key.string' => '插件标识必须是字符串',
'key.unique' => '插件Key已被占用',
'desc.string' => '插件描述必须是字符串',
'support_app.required' => '插件支持的应用空表示通用插件必须填写',
'support_app.string' => '插件支持的应用空表示通用插件必须是字符串',
'installed_at.required' => '安装时间必须填写',
'installed_at.integer' => '安装时间必须是整数',
'title.required' => '插件名称必须填写',
'title.string' => '插件名称必须是字符串',
'icon.required' => '插件图标必须填写',
'icon.string' => '插件图标必须是字符串',
'status.required' => '状态必须填写',
'status.integer' => '状态必须是整数',
'type.required' => '插件类型app,plugin必须填写',
'type.string' => '插件类型app,plugin必须是字符串',
'created_at.integer' => '创建时间必须是整数',
'variables.string' => '必须是字符串',
];
}
}
@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace app\adminapi\validate\profile;
use core\base\BaseValidate;
/**
* 个人中心验证器
*/
final class ProfileValidate extends BaseValidate
{
public function rules(): array
{
return [
'real_name' => 'required|min:2|max:50',
'nick_name' => 'required|min:2|max:30',
'email' => 'required|email',
'mobile_phone' => 'required|regex:/^1[3-9]\d{9}$/',
'sex' => 'required|in:0,1,2',
'signed' => 'max:255',
'address' => 'max:255',
'old_password' => 'required|min:6|max:20',
'new_password' => 'required|min:6|max:20',
'confirm_password' => 'required|same:new_password',
'avatar' => 'required',
];
}
public function message(): array
{
return [
'real_name.required' => '真实姓名不能为空',
'real_name.min' => '真实姓名最少2个字符',
'real_name.max' => '真实姓名最多50个字符',
'nick_name.required' => '昵称不能为空',
'nick_name.min' => '昵称最少2个字符',
'nick_name.max' => '昵称最多30个字符',
'email.required' => '邮箱不能为空',
'email.email' => '邮箱格式不正确',
'mobile_phone.required' => '手机号不能为空',
'mobile_phone.regex' => '手机号格式不正确',
'sex.required' => '请选择性别',
'sex.in' => '性别参数不正确',
'signed.max' => '个人签名最多255个字符',
'address.max' => '地址最多255个字符',
'old_password.required' => '请输入当前密码',
'old_password.min' => '当前密码最少6个字符',
'old_password.max' => '当前密码最多20个字符',
'new_password.required' => '请输入新密码',
'new_password.min' => '新密码最少6个字符',
'new_password.max' => '新密码最多20个字符',
'confirm_password.required' => '请确认新密码',
'confirm_password.same' => '两次输入的密码不一致',
'avatar.required' => '请上传头像',
];
}
protected array $scene = [
'update-profile' => [
'real_name',
'nick_name',
'email',
'mobile_phone',
'sex',
'signed',
'address',
],
'update-password' => [
'old_password',
'new_password',
'confirm_password',
],
'update-avatar' => ['avatar'],
];
}
@@ -0,0 +1,88 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\adminapi\validate\system;
use app\model\system\Admin;
use core\base\BaseValidate;
use Illuminate\Validation\Rule;
class AdminValidate extends BaseValidate
{
/**
* 定义验证规则
*/
public function rules(): array
{
$id = request()->route->param('id');
return [
'user_name' => ['required', 'max:50', Rule::unique(Admin::class, 'user_name')->ignore($id, 'id')],
'real_name' => 'required',
'password' => 'required|min:5|max:18',
'dept_id' => 'required',
'mobile_phone' => 'required|mobile',
'old_password' => 'required',
'new_password' => 'required|min:5|max:18',
'id' => 'required',
];
}
/**
* 定义错误信息
*/
protected array $message = [
'id.required' => '缺少参数id',
'user_name.required' => '用户名必须填写',
'user_name.max' => '用户名最多不能超过18个字符',
'user_name.unique' => '用户名已被占用',
'real_name.required' => '姓名必须填写',
'password.required' => '密码必须填写',
'password.min' => '密码最少为5位',
'password.max' => '密码长度不能超过18位',
'old_password.required' => '旧密码不能为空',
'new_password.required' => '密码必须填写',
'new_password.min' => '密码最少为5位',
'new_password.max' => '密码长度不能超过18位',
'dept_id' => '部门必须填写',
'mobile_phone.required' => '手机号码必须填写',
'mobile_phone.mobile' => '无效手机号码',
];
/**
* 定义场景
*/
protected array $scene = [
'store' => [
'user_name',
'password',
'mobile_phone',
],
'update' => [
'user_name',
'mobile_phone',
],
'update-info' => [
'real_name',
'mobile_phone',
'sex',
],
'update-pwd' => [
'new_password',
'old_password',
],
'update-preferences' => [
'id',
],
];
}
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\adminapi\validate\system;
use core\base\BaseValidate;
class AuthValidate extends BaseValidate
{
/**
* 定义验证规则
*/
protected array $rule = [
];
/**
* 定义错误信息
*/
protected array $message = [
];
/**
* 定义场景
*/
protected array $scene = [
'store' => [
],
'update' => [
],
];
}
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\adminapi\validate\system;
use core\base\BaseValidate;
class DeptValidate extends BaseValidate
{
/**
* 定义验证规则
*/
protected array $rule = [
'code' => 'require|alphaDash',
'name' => 'require|max:16',
'enabled' => 'require',
];
/**
* 定义错误信息
*/
protected array $message = [
'code.require' => '部门标识必须填写',
'code.alphaDash' => '部门标识只能由英文字母组成',
'name.require' => '部门名称必须填写',
'name.max' => '部门名称最多不能超过16个字符',
'enabled' => '状态必须填写',
];
/**
* 定义场景
*/
protected array $scene = [
'store' => [
'code',
'name',
'enabled',
],
'update' => [
'code',
'name',
'enabled',
],
];
}
@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\adminapi\validate\system;
use core\base\BaseValidate;
class DictItemValidate extends BaseValidate
{
/**
* 定义验证规则
*/
protected array $rule = [
'label' => 'require',
'value' => 'require',
'enabled' => 'require',
'dict_id' => 'require',
'code' => 'require',
];
/**
* 定义错误信息
*/
protected array $message = [
'label' => '字典名称必须填写',
'value' => '字典标识必须填写',
'enabled' => '状态必须填写',
'dict_id' => '字典类型必须填写',
'code' => '字典标识必须填写',
];
/**
* 定义场景
*/
protected array $scene = [
'store' => [
'label',
'value',
'enabled',
'dict_id',
'code',
],
'update' => [
'label',
'value',
'enabled',
'dict_id',
'code',
],
];
}
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\adminapi\validate\system;
use core\base\BaseValidate;
class DictValidate extends BaseValidate
{
/**
* 定义验证规则
*/
protected array $rule = [
'name' => 'require|max:16',
'code' => 'require|alphaDash',
'enabled' => 'require',
'data_type' => 'require',
'sort' => 'number',
];
/**
* 定义错误信息
*/
protected array $message = [
'name.require' => '字典名称必须填写',
'name.max' => '字典名称最多不能超过16个字符',
'code.require' => '字典标识必须填写',
'code.alphaDash' => '字典标识只能由英文字母组成',
'data_type.require' => '字典数据类型必须填写',
'enabled' => '状态必须填写',
'sort.number' => '排序只能是数字',
];
/**
* 定义场景
*/
protected array $scene = [
'store' => [
'name',
'code',
'enabled',
'data_type',
'sort',
],
'update' => [
'name',
'code',
'data_type',
'enabled',
'sort',
],
];
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace app\adminapi\validate\system;
use core\base\BaseValidate;
class FeedbackValidate extends BaseValidate
{
protected array $rule = [
'id' => 'require',
'type' => 'require|in:bug,suggestion,correction',
'content' => 'require|max:2000',
'contact' => 'max:100',
'images' => 'array',
'source' => 'require|in:app,web',
'reply_content' => 'max:2000',
];
protected array $message = [
'type.require' => '请选择反馈类型',
'type.in' => '反馈类型不正确',
'content.require' => '请填写问题描述',
'content.max' => '问题描述不能超过2000个字符',
'contact.max' => '联系方式不能超过100个字符',
'images.array' => '截图附件格式不正确',
'source.require' => '请选择反馈来源',
'source.in' => '反馈来源不正确',
'reply_content.max' => '回复内容不能超过2000个字符',
];
protected array $scene = [
'store' => ['type', 'content', 'contact', 'images', 'source'],
'update' => ['id', 'type', 'content', 'contact', 'images', 'source'],
'reply' => ['id', 'reply_content'],
];
}
@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\adminapi\validate\system;
use core\base\BaseValidate;
/**
* 菜单验证器
*/
class MenuValidate extends BaseValidate
{
/**
* 定义验证规则
*/
protected array $rule = [
'pid' => 'require',
'code' => 'require',
'title' => 'require|max:16',
'type' => 'number',
'sort' => 'number',
'enabled' => 'number',
];
/**
* 定义错误信息
*/
protected array $message = [
'pid.require' => '菜单上级必须填写',
'code.require' => '菜单标识必须填写',
'title.require' => '菜单名称必须填写',
'title.max' => '菜单名称最多不能超过16个字符',
'enabled' => '状态必须填写',
];
/**
* 定义场景
*/
protected array $scene = [
'store' => [
'code',
'title',
'type',
'sort',
'enabled',
],
'update' => [
'code',
'title',
'type',
'sort',
'enabled',
],
'batch-store' => [
'title',
'type',
'sort',
],
];
}
@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\adminapi\validate\system;
use core\base\BaseValidate;
class MessageValidate extends BaseValidate
{
/**
* 定义验证规则
*/
protected array $rule = [
'id' => 'require',
'title' => 'require',
'content' => 'require',
'status' => 'require',
];
/**
* 定义错误信息
*/
protected array $message = [
'id.require' => '参数错误缺少id',
'title.require' => '公告名称必须填写',
'content.require' => '公共内容不能为空',
'status' => '状态必须填写',
];
/**
* 定义场景
*/
protected array $scene = [
'store' => [
'title',
'type',
'content',
],
'update' => [
'id',
'title',
'type',
'content',
],
'update-read'=>[
'id',
'status'
]
];
}
@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\adminapi\validate\system;
use core\base\BaseValidate;
class NoticeValidate extends BaseValidate
{
/**
* 定义验证规则
*/
protected array $rule = [
'id' => 'require',
'message_id' => 'require',
'title' => 'require',
'content' => 'require',
'enabled' => 'require',
];
/**
* 定义错误信息
*/
protected array $message = [
'id.require' => '参数错误缺少id',
'message_id.require' => '参数错误缺少message_id',
'title.require' => '公告名称必须填写',
'content.require' => '公共内容不能为空',
'enabled' => '状态必须填写',
];
/**
* 定义场景
*/
protected array $scene = [
'store' => [
'title',
'type',
'content',
],
'update' => [
'id',
'title',
'type',
'content',
],
];
}
@@ -0,0 +1,85 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\adminapi\validate\system;
use app\model\org\Post;
use core\base\BaseValidate;
/**
* 用户角色验证器
*/
class PostValidate extends BaseValidate
{
/**
* 定义验证规则
*/
protected array $rule = [
'dept_id' => 'require',
'code' => 'require|alphaNum|unique',
'name' => 'require|max:16',
'sort' => 'number',
'enabled' => 'require',
];
/**
* 定义错误信息
*/
protected array $message = [
'code.require' => '职位标识必须填写',
'code.alphaNum' => '职位标识只能由英文字或者数字母组成',
'code.unique' => '职位代码已被占用',
'name.require' => '职位名称必须填写',
'name.max' => '职位名称最多不能超过16个字符',
'enabled' => '状态必须填写',
];
/**
* 重复验证
*
* @param $value
* @param $rule
* @param array $data
*
* @return bool
*/
protected function unique($value, $rule, array $data = []): bool
{
$query = Post::where('code', $value);
// 如果是更新操作,可以排除当前记录
if (isset($data['id'])) {
$query->where('id', '<>', $data['id']);
}
return $query->count() === 0;
}
/**
* 定义场景
*/
protected array $scene = [
'store' => [
'code',
'name',
'sort',
'enabled',
],
'update' => [
'code',
'name',
'sort',
'enabled',
],
];
}
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace app\adminapi\validate\system;
use core\base\BaseValidate;
class RoleValidate extends BaseValidate
{
/**
* 定义验证规则
*/
protected array $rule = [
'id' => 'require',
'code' => 'require|alpha',
'name' => 'require|max:16',
'data_scope' => 'require',
];
/**
* 定义错误信息
*/
protected array $message = [
'id.require' => '参数id不能为空',
'code.require' => '角色标识必须填写',
'code.alpha' => '角色标识只能由英文字母组成',
'name.require' => '角色名称必须填写',
'name.max' => '角色名称最多不能超过16个字符',
'data_scope.require' => '数据权限不能为空',
];
/**
* 定义场景
*/
protected array $scene = [
'store' => [
'code',
'name',
],
'update' => [
'id',
'code',
'name',
],
'data-scope' => [
'id',
'data_scope',
],
];
}
@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
namespace app\adminapi\validate\web;
use app\model\web\Link;
use core\base\BaseValidate;
use Illuminate\Validation\Rule;
/**
* 友情链接验证器
*/
class LinkValidate extends BaseValidate
{
/**
* 验证规则
*/
public function rules(): array
{
$id = request()->route->param('id');
return [
'name' => ['required', 'max:50', Rule::unique(Link::class, 'name')->ignore($id, 'id')],
'url' => ['required', 'url', 'max:255'],
'logo' => ['max:255'],
'description' => ['max:255'],
'sort' => ['integer', 'min:0'],
'enabled' => ['integer', 'in:0,1'],
];
}
/**
* 验证消息
*/
protected array $message = [
'name.required' => '链接名称不能为空',
'name.max' => '链接名称不能超过50个字符',
'name.unique' => '链接名称已存在',
'url.required' => '链接地址不能为空',
'url.url' => '链接地址格式不正确',
'url.max' => '链接地址不能超过255个字符',
'logo.max' => '链接图标不能超过255个字符',
'description.max' => '描述不能超过255个字符',
'sort.integer' => '排序必须为整数',
'sort.min' => '排序不能小于0',
'enabled.integer' => '状态必须为整数',
'enabled.in' => '状态值不正确',
];
/**
* 验证场景
*/
protected array $scene = [
'store' => [
'name',
'url',
'logo',
'description',
'sort',
'enabled',
],
'update' => [
'name',
'url',
'logo',
'description',
'sort',
'enabled',
],
];
}
@@ -0,0 +1,116 @@
<?php
declare(strict_types=1);
namespace app\adminapi\validate\web;
use app\model\web\Menu;
use core\base\BaseValidate;
use Illuminate\Validation\Rule;
/**
* 菜单验证器
*/
class MenuValidate extends BaseValidate
{
/**
* 验证规则
*/
public function rules(): array
{
$id = request()->route->param('id');
return [
'id' => ['sometimes', 'bail', 'string', 'integer'],
'app' => ['max:50'],
'category' => ['integer', 'in:1,2'],
'source' => ['max:50'],
'name' => ['required', 'max:50', Rule::unique(Menu::class, 'name')->ignore($id, 'id')],
'type' => ['integer', 'in:1,2,3,4'],
'parent_id' => ['sometimes', 'bail', 'string', 'integer'],
'level' => ['integer', 'min:0'],
'path' => ['max:255'],
'title' => ['max:50'],
'url' => ['max:255'],
'icon' => ['max:50'],
'target' => ['integer', 'in:1,2'],
'is_show' => ['boolean'],
'enabled' => ['boolean'],
'sort' => ['integer', 'min:0'],
];
}
/**
* 验证消息
*/
protected array $message = [
'id.string' => 'ID必须为字符串或整数',
'id.integer' => 'ID必须为字符串或整数',
'app.max' => '应用名称不能超过50个字符',
'category.integer' => '菜单分类必须为整数',
'category.in' => '菜单分类值不正确',
'source.max' => '来源不能超过50个字符',
'name.required' => '菜单名称不能为空',
'name.max' => '菜单名称不能超过50个字符',
'name.unique' => '菜单名称已存在',
'type.integer' => '菜单类型必须为整数',
'type.in' => '菜单类型值不正确',
'pid.string' => '父菜单ID必须为字符串或整数',
'pid.integer' => '父菜单ID必须为字符串或整数',
'path.max' => '路由路径不能超过255个字符',
'title.max' => '菜单标题不能超过50个字符',
'url.max' => '链接地址不能超过255个字符',
'icon.max' => '图标不能超过50个字符',
'target.integer' => '打开方式必须为整数',
'target.in' => '打开方式值不正确',
'is_show.boolean' => '是否显示必须为布尔值',
'enabled.boolean' => '是否启用必须为布尔值',
'sort.integer' => '排序必须为整数',
'sort.min' => '排序不能小于0',
];
/**
* 验证场景
*/
protected array $scene = [
'store' => [
'id',
'app',
'category',
'source',
'name',
'type',
'parent_id',
'level',
'path',
'title',
'url',
'icon',
'target',
'is_show',
'enabled',
'belong',
'belong_id',
'sort',
],
'update' => [
'id',
'app',
'category',
'source',
'name',
'type',
'parent_id',
'level',
'path',
'title',
'url',
'icon',
'target',
'is_show',
'enabled',
'belong',
'belong_id',
'sort',
],
];
}