You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.0 KiB
80 lines
2.0 KiB
<?php
|
|
declare (strict_types=1);
|
|
|
|
namespace app\api\validate;
|
|
|
|
use think\Validate;
|
|
|
|
class Dictionary extends Validate
|
|
{
|
|
/**
|
|
* 定义验证规则
|
|
* 格式:'字段名' => ['规则1','规则2'...]
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $rule = [
|
|
'id' => 'number|length:1,10',
|
|
'dict_type_id|字典类型id' => "require|integer",
|
|
'dict_name|字典名称' => 'require|length:1,100',
|
|
'dict_value|字典值' => "require|checkValue",
|
|
|
|
];
|
|
|
|
// 验证名称是否存在
|
|
protected function checkValue($value, $rule, $data=[])
|
|
{
|
|
$_op = new \app\api\model\Dictionary();
|
|
$count = $_op->chekName($value);
|
|
return $count == 0 ? true : '该类型下字典值不能重复';
|
|
}
|
|
|
|
/**
|
|
* 定义错误信息
|
|
* 格式:'字段名.规则名' => '错误信息'
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $message = [
|
|
'dict_name.require' => '请输入字典标志',
|
|
'dict_name.length' => '字典标志长度为1~100',
|
|
'dict_value.require' => '请输入字典值',
|
|
'dict_value.length' => '字典值为1~100',
|
|
'dict_type_id.require' => '字典类型不能为空',
|
|
'dict_type_id.integer' => '字典类型为存数字',
|
|
|
|
];
|
|
|
|
/**
|
|
* 验证场景规则
|
|
* @var array
|
|
*/
|
|
protected $scene = [
|
|
'read' => ['id'],
|
|
];
|
|
|
|
/**
|
|
* 修改场景验证
|
|
* @return Manager
|
|
*/
|
|
public function sceneUpdate()
|
|
{
|
|
// return $this->remove('dict_symbol', 'dict_value')->append('');
|
|
|
|
}
|
|
/**
|
|
* 自定义查询场景验证 可灵活设置验证字段
|
|
* @return Manager
|
|
*/
|
|
public function sceneLists()
|
|
{
|
|
//需删除以上代码,重新定义
|
|
return $this->only(['dict_type_id','dict_name', 'dict_value'])
|
|
->remove('dict_name', 'require')
|
|
->remove('dict_value', 'require')
|
|
->remove('dict_value', 'checkValue')
|
|
// ->remove('dict_type_id', 'require|integer')
|
|
;
|
|
}
|
|
|
|
}
|
|
|