GodActivationValidation.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Module\Farm\Validations;
  3. use App\Module\Farm\Validators\GodActivationValidator;
  4. use UCore\ValidationCore;
  5. /**
  6. * 神像激活验证类
  7. *
  8. * 用于验证神像激活操作的输入数据,包括用户ID、神像ID和物品ID
  9. */
  10. class GodActivationValidation extends ValidationCore
  11. {
  12. /**
  13. * 验证规则
  14. *
  15. * @param array $rules 自定义规则
  16. * @return array
  17. */
  18. public function rules($rules = []): array
  19. {
  20. return [
  21. [
  22. 'user_id,god_id,item_id', 'required'
  23. ],
  24. [
  25. 'user_id,god_id,item_id', 'integer', 'min' => 1,
  26. 'msg' => '{attr}必须是大于0的整数'
  27. ],
  28. // 验证神像激活相关逻辑
  29. [
  30. 'god_id', new GodActivationValidator($this, ['user_id', 'item_id']),
  31. 'msg' => '神像激活验证失败'
  32. ]
  33. ];
  34. }
  35. /**
  36. * 设置默认值
  37. *
  38. * @return array
  39. */
  40. public function default(): array
  41. {
  42. return [];
  43. }
  44. }