| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace App\Module\Farm\Validations;
- use App\Module\Farm\Validators\LandOwnershipValidator;
- use App\Module\Farm\Validators\DisasterRemovalItemValidator;
- use UCore\ValidationCore;
- /**
- * 灾害去除验证类
- *
- * 用于验证灾害去除操作的输入数据,包括用户ID、土地ID、物品ID和灾害类型
- */
- class DisasterRemovalValidation extends ValidationCore
- {
- /**
- * 验证规则
- *
- * @param array $rules 自定义规则
- * @return array
- */
- public function rules($rules = []): array
- {
- return [
- [
- 'user_id,land_id,item_id,disaster_type', 'required'
- ],
- [
- 'user_id,land_id,item_id,disaster_type', 'integer', 'min' => 1,
- 'msg' => '{attr}必须是大于0的整数'
- ],
- // 验证土地是否属于用户
- [
- 'land_id', new LandOwnershipValidator($this, ['user_id']),
- 'msg' => '土地不存在或不属于当前用户'
- ],
- // 验证物品是否为对应的灾害去除道具
- [
- 'item_id', new DisasterRemovalItemValidator($this, ['user_id', 'disaster_type']),
- 'msg' => '物品验证失败'
- ]
- ];
- }
- /**
- * 设置默认值
- *
- * @return array
- */
- public function default(): array
- {
- return [];
- }
- }
|