DisasterRemovalValidation.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Module\Farm\Validations;
  3. use App\Module\Farm\Validators\LandOwnershipValidator;
  4. use App\Module\Farm\Validators\DisasterRemovalItemValidator;
  5. use UCore\ValidationCore;
  6. /**
  7. * 灾害去除验证类
  8. *
  9. * 用于验证灾害去除操作的输入数据,包括用户ID、土地ID、物品ID和灾害类型
  10. */
  11. class DisasterRemovalValidation extends ValidationCore
  12. {
  13. /**
  14. * 验证规则
  15. *
  16. * @param array $rules 自定义规则
  17. * @return array
  18. */
  19. public function rules($rules = []): array
  20. {
  21. return [
  22. [
  23. 'user_id,land_id,item_id,disaster_type', 'required'
  24. ],
  25. [
  26. 'user_id,land_id,item_id,disaster_type', 'integer', 'min' => 1,
  27. 'msg' => '{attr}必须是大于0的整数'
  28. ],
  29. // 验证土地是否属于用户
  30. [
  31. 'land_id', new LandOwnershipValidator($this, ['user_id']),
  32. 'msg' => '土地不存在或不属于当前用户'
  33. ],
  34. // 验证物品是否为对应的灾害去除道具
  35. [
  36. 'item_id', new DisasterRemovalItemValidator($this, ['user_id', 'disaster_type']),
  37. 'msg' => '物品验证失败'
  38. ]
  39. ];
  40. }
  41. /**
  42. * 设置默认值
  43. *
  44. * @return array
  45. */
  46. public function default(): array
  47. {
  48. return [];
  49. }
  50. }