'require', 'type' => 'require|check_type', 'apply_goods' => 'requireIf:type,1', 'total_amount' => 'require|gt:0', 'pay_type' => 'require|check_pay_type', 'approve_user' => 'require', ]; /** * 提示消息 */ protected $message = [ ]; /** * 验证场景 */ protected $scene = [ 'create' => ['reason', 'type', 'apply_goods', 'total_amount', 'pay_type', 'approve_user'], 'update' => ['reason', 'type', 'apply_goods', 'total_amount', 'pay_type', 'approve_user'], 'edit' => ['reason', 'type', 'apply_goods', 'total_amount', 'pay_type'], ]; /** * 构造函数 * @access public * @param array $rules 验证规则 * @param array $message 验证提示信息 * @param array $field 验证字段描述信息 */ public function __construct(array $rules = [], $message = [], $field = []) { $this->field = [ 'reason' => '申购事由', 'type' => '采购类型', 'apply_goods' => '申购物品', 'total_amount' => '总金额', 'pay_type' => '支付方式', 'approve_user' => '审批人', ]; $this->message = array_merge($this->message, [ 'type.check_type' => '请选择正确的采购类型', 'apply_goods.requireIf' => '请添加申购物品', 'pay_type.check_pay_type' => '请选择正确的支付方式', ]); parent::__construct($rules, $message, $field); } protected function check_type($value, $rule, $data) { $get_type_list = ApplyConstant::get_type_list(); if (!array_key_exists($value, $get_type_list)) { return false; } return true; } protected function check_pay_type($value, $rule, $data) { $get_type_list = ApplyConstant::get_pay_type_list(); if (!array_key_exists($value, $get_type_list)) { return false; } return true; } }