<?php
namespace app\common\validate;

use think\Db;
use think\Validate;

class Burst extends Validate{

    protected $rule = [
        'title|事件名称'  =>  'require|length:1,200',
        'content|事件流程'  =>  'require|checkContent',
    ];

    protected $message = [
        'title.length' => '名称必须200字以内',
    ];

    protected $scene = [

    ];

    protected function checkContent($value, $rule, $data=[]){
        $content = json_decode($data['content'],true);
        foreach ($content as $k=>$v){
            if(!$v['title']){
                return '事件流程部分内容未填写';
            }
            if(!$v['time']){
                return '事件流程部分内容未填写';
            }
            if(count($v['options']) == 0){
                return '事件流程部分内容未填写';
            }
            foreach ($v['options'] as $key=>$val){
                if(!$val['text']){
                    return '事件流程部分内容未填写';
                }
            }
        }
        return true;
    }



}