BaseValidate.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\common;
  4. use think\exception\ValidateException;
  5. use think\Validate;
  6. class BaseValidate extends Validate
  7. {
  8. /**
  9. * @param $params
  10. * @param null $scene
  11. * @return bool
  12. */
  13. public function goCheck($params,$scene = '')
  14. {
  15. //须设置content-type:application/json
  16. $result = $this->scene($scene)->check($params);
  17. if (!$result) {
  18. throw new ValidateException(is_array($this->error) ? implode(
  19. ';', $this->error) : $this->error);
  20. }else{
  21. return true;
  22. }
  23. }
  24. /**
  25. * 正整数验证
  26. * @param $value
  27. * @param string $rule
  28. * @param string $data
  29. * @param string $field
  30. * @return bool|string
  31. */
  32. protected function isPositiveInteger($value, $rule='', $data='', $field='')
  33. {
  34. if (is_numeric($value) && is_int($value + 0) && ($value + 0) > 0) {
  35. return true;
  36. }
  37. return $field . '必须是正整数';
  38. }
  39. }