63 lines
1.3 KiB
PHP
63 lines
1.3 KiB
PHP
<?php
|
|
namespace app\common\validate;
|
|
|
|
use think\facade\Request;
|
|
use think\Validate;
|
|
|
|
class BaseValidate extends Validate{
|
|
/**
|
|
* 定义验证规则
|
|
* 格式:'字段名' => ['规则1','规则2'...]
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $rule = [];
|
|
|
|
/**
|
|
* 定义错误信息
|
|
* 格式:'字段名.规则名' => '错误信息'
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $message = [];
|
|
|
|
/**
|
|
*
|
|
* 公用验证方法
|
|
* @param array $data 待验证数据
|
|
* @param string $scene 验证场景
|
|
* @return array
|
|
*/
|
|
public function checkParam($scene=''){
|
|
$res = [];
|
|
|
|
if (request()->isPost()){
|
|
$data = input('param.');
|
|
|
|
if ($scene==''){
|
|
$result = $this->check($data);
|
|
}else{
|
|
$result = $this->scene($scene)->check($data);
|
|
}
|
|
|
|
if (!$result){
|
|
$res['code'] = 5000;
|
|
$res['scene'] = $scene;
|
|
$res['msg'] = $this->getError();
|
|
|
|
}else{
|
|
$res['code'] = 200;
|
|
$res['msg'] = 'success';
|
|
}
|
|
}else{
|
|
$res['code'] = 5010;
|
|
$res['msg'] = '非法请求';
|
|
}
|
|
|
|
if ($res['code']!=200){
|
|
ajax_return($res);
|
|
}
|
|
return $res;
|
|
|
|
}
|
|
} |