CropPickValidation.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Module\Farm\Validations;
  3. use UCore\ValidationCore;
  4. /**
  5. * 作物摘取验证类
  6. *
  7. * @property int $pickerId 摘取者ID
  8. * @property int $cropId 作物ID
  9. * @property int $pickAmount 摘取数量
  10. * @property string $pickSource 摘取来源
  11. * @property int|null $sourceId 来源ID(可选)
  12. */
  13. class CropPickValidation extends ValidationCore
  14. {
  15. public int $pickerId;
  16. public int $cropId;
  17. public int $pickAmount;
  18. public string $pickSource;
  19. public ?int $sourceId = null;
  20. /**
  21. * 获取验证规则
  22. *
  23. * @param array $rules 自定义规则
  24. * @return array
  25. */
  26. public function rules($rules = []): array
  27. {
  28. return [
  29. [
  30. 'pickerId,cropId,pickAmount,pickSource', 'required'
  31. ],
  32. [
  33. 'pickerId,cropId,pickAmount', 'integer', 'min' => 1,
  34. 'msg' => '{attr}必须是大于0的整数'
  35. ],
  36. [
  37. 'pickSource', 'string', 'max' => 50,
  38. 'msg' => '摘取来源必须是字符串且长度不能超过50个字符'
  39. ],
  40. [
  41. 'sourceId', 'integer', 'min' => 1,
  42. 'msg' => '来源ID必须是大于0的整数'
  43. ],
  44. ];
  45. }
  46. }