TP验证规则Validate

use think\Validate;

<?php
namespace app\common\model;

use think\Validate;
use think\Db;

class InvoiceRecords extends BaseModel
{
    protected $table = 't_invoice_record';

    protected $rule = [
        'type'  => 'in:1,2',
        'invoice_tel'  => 'mobile',
        'email'  => 'email',

    ];
    protected $message = [
        'type' => '开票类型错误',
        'invoice_tel' => '手机号错误',
        'email' => '邮箱格式错误',

    ];

    public function addInfoData($member_id, $type, $money, $invoice_name, $invoice_tel, $email, $taxpayer_number, $id)
    {
        $data = [
            'type' => $type,
            'invoice_tel' => $invoice_tel,
            'email' => $email,
        ];
        $validate = new Validate($this->rule, $this->message);
        if (!$validate->check($data)) {
            return ['code' => 400, 'msg' => $validate->getError()];
        }
    }
}

 

posted @ 2019-12-06 22:40  在斑马线上散布  阅读(1369)  评论(0编辑  收藏  举报
夫人不言,言必有中。这是高级臣僚的一种可贵品质,言辞精炼,直抵要害。