44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\admin\validate\v1;
|
|
|
|
use think\Validate;
|
|
|
|
class ProductAttrValidate extends Validate
|
|
{
|
|
/**
|
|
* 定义验证规则
|
|
* 格式:'字段名' => ['规则1','规则2'...]
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $rule = [
|
|
'language_id' => 'require|number',
|
|
'attr_type' => 'in:1,2',
|
|
'attr_name' => 'require|max:64',
|
|
'is_system' => 'in:0,1',
|
|
'props.*.prop_name' => 'requireIf:attr_type,1|max:64',
|
|
'props.*.prop_value' => 'requireIf:attr_type,1|max:64',
|
|
];
|
|
|
|
/**
|
|
* 定义错误信息
|
|
* 格式:'字段名.规则名' => '错误信息'
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $message = [
|
|
'language_id.require' => '语言ID不能为空',
|
|
'language_id.number' => '语言ID必须是数字',
|
|
'attr_type.in' => '属性类型只能是1或2',
|
|
'attr_name.require' => '属性名称不能为空',
|
|
'attr_name.max' => '属性名称不能超过64个字符',
|
|
'is_system.in' => '是否系统属性只能是0或1',
|
|
'props.*.prop_name.require' => '属性特征名称不能为空',
|
|
'props.*.prop_name.max' => '属性特征名称不能超过64个字符',
|
|
'props.*.prop_value.require' => '属性特征值不能为空',
|
|
'props.*.prop_value.max' => '属性特征值不能超过64个字符',
|
|
];
|
|
}
|