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()]; } } }