Files
orico-official-website/app/admin/validate/v1/SysBannerItemValidate.php

65 lines
2.4 KiB
PHP

<?php
declare (strict_types = 1);
namespace app\admin\validate\v1;
use think\Validate;
class SysBannerItemValidate extends Validate
{
/**
* 定义验证规则
* 格式:'字段名' => ['规则1','规则2'...]
*
* @var array
*/
protected $rule = [
'id' => 'require|integer',
'banner_id' => 'require|integer',
'title' => 'require|max:256',
'title_txt_color' => 'max:7',
'desc' => 'max:1024',
'desc_txt_color' => 'max:7',
'type' => 'in:image,video',
'image' => 'max:255',
'video' => 'max:255',
'link_to' => 'requireIf:type,image|max:64|in:article,article_category,product,product_category,custom',
'link' => 'max:255',
'sort' => 'integer',
'status' => 'in:-1,1'
];
/**
* 定义错误信息
* 格式:'字段名.规则名' => '错误信息'
*
* @var array
*/
protected $message = [
'id.require' => 'ID不能为空',
'id.integer' => 'ID必须是整数',
'banner_id.require' => '横幅项分类不能为空',
'banner_id.integer' => '横幅项分类必须是整数',
'title.require' => '名称不能为空',
'title.max' => '名称最多不能超过256个字符',
'title_txt_color.max' => '名称字体颜色最多不能超过7个字符',
'desc.max' => '描述最多不能超过1024个字符',
'desc_txt_color.max' => '描述字体颜色最多不能超过7个字符',
'type.in' => '显示类型必须是image或video',
'image.max' => '图片地址最多不能超过255个字符',
'video.max' => '视频地址最多不能超过255个字符',
'link_to.requireIf' => '链接类型不能为空',
'link_to.max' => '链接类型最多不能超过64个字符',
'link_to.in' => '链接类型必须是article,article_category,product,product_category,custom中之一',
'link.max' => '链接最多不能超过255个字符',
'sort.integer' => '排序值必须是整数',
'status.in' => '状态必须是-1或1'
];
// 新增场景
public function sceneAdd()
{
return $this->remove('id', 'require|integer');
}
}