123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace app\common\validate;
- use think\Validate;
- class QualityPlan extends Validate
- {
- /**
- * 定义验证规则
- * 格式:'字段名' => ['规则1','规则2'...]
- *
- * @var array
- */
- protected $rule = [
- 'title|计划名称' => 'require|length:1,100',
- 'start_time|计划开始时间' => 'require|date|checkStartTime',
- 'end_time|计划结束时间' => 'require|date',
- 'content' => 'require|checkContent'
- ];
- /**
- * 定义错误信息
- * 格式:'字段名.规则名' => '错误信息'
- *
- * @var array
- */
- protected $message = [
- 'title.length' => '计划名称必须在100字以内',
- 'content.require' => '未设置任务',
- ];
- protected function checkStartTime($value,$rule,$data=[])
- {
- $curDay = date('Y-m-d');
- if($curDay > $data['start_time']){
- return '计划开始时间不能小于当前时间';
- }
- if($data['start_time'] > $data['end_time']){
- return '计划结束时间不能大于计划开始时间';
- }
- return true;
- }
- protected function checkContent($value,$rule,$data=[])
- {
- $content = json_decode($data['content'],true);
- if(!$content){
- return '未设置任务';
- }
- if(empty($content['addrForms'])){
- return '未设置检查内容';
- }
- if(empty($content['tasks']['list'])){
- return '未设置任务';
- }
- return true;
- }
- }
|