QuestionValidate.php 1.8 KB
<?php
// +----------------------------------------------------------------------
// |评分题目验证
// +----------------------------------------------------------------------
// |魏强
// +----------------------------------------------------------------------
namespace app\admin\validate;

use think\Validate;

class QuestionValidate extends Validate
{
    protected $rule = [
        'type'             => 'checkType',
        'hint_type'        => 'checkHint',
        'score'            => 'checkScore'
    ];


    // 自定义验证规则
    protected function checkHint($value, $rule, $post)
    {
        if (!empty($value)) {
            if(empty($post['hint_title'])){
                return '提示信息标题不能为空';
            }
            else if(empty($post['hint_content'])){
                return '提示信息内容不能为空';
            } elseif(empty($post['hint_text'])){
                return '提示标注不能为空';
            } else {
                return true;
            }
        } else {
            return true;
        }
    }

    protected function checkType($value,$rule,$post){
        if (!empty($value)) {
            if(empty($post['max'])){
                return '评分区间不能为空';
            }
            else if(empty($post['content'])){
                return '评分内容不能为空';
            } else {
                return true;
            }
        } else {
            return true;
        }
    }

    protected function checkScore($value,$rule,$post){
        return true;
        if(!empty($post['parent_id'])){
            if(empty($value)){
                return '题目分值不能为空';
            } else {
                return true;
            }
        } else {
            return true;
        }
    }

}