123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- declare (strict_types = 1);
- namespace app\common;
- use think\exception\ValidateException;
- use think\Validate;
- class BaseValidate extends Validate
- {
- /**
- * @param $params
- * @param null $scene
- * @return bool
- */
- public function goCheck($params,$scene = '')
- {
- //须设置content-type:application/json
- $result = $this->scene($scene)->check($params);
- if (!$result) {
- throw new ValidateException(is_array($this->error) ? implode(
- ';', $this->error) : $this->error);
- }else{
- return true;
- }
- }
- /**
- * 正整数验证
- * @param $value
- * @param string $rule
- * @param string $data
- * @param string $field
- * @return bool|string
- */
- protected function isPositiveInteger($value, $rule='', $data='', $field='')
- {
- if (is_numeric($value) && is_int($value + 0) && ($value + 0) > 0) {
- return true;
- }
- return $field . '必须是正整数';
- }
- }
|