初始化本地仓库
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user