| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace App\Module\Farm\Validations;
- use App\Module\Farm\Validators\LandOwnershipValidator;
- use App\Module\Farm\Validators\RemovableStatusValidator;
- use App\Module\Farm\Validators\RemoveToolValidator;
- use UCore\ValidationCore;
- /**
- * 作物铲除验证类
- *
- * 用于验证作物铲除操作的输入数据,包括用户ID、土地ID和工具ID
- */
- class CropRemoveValidation extends ValidationCore
- {
- /**
- * 验证规则
- *
- * @param array $rules 自定义规则
- * @return array
- */
- public function rules($rules = []): array
- {
- return [
- [
- 'user_id,land_id', 'required'
- ],
- [
- 'user_id,land_id', 'integer', 'min' => 1,
- 'msg' => '{attr}必须是大于0的整数'
- ],
- [
- 'tool_item_id', 'integer', 'min' => 0,
- 'msg' => '{attr}必须是大于等于0的整数'
- ],
- // 验证土地是否属于用户
- [
- 'land_id', new LandOwnershipValidator($this, ['user_id', 'land']),
- 'msg' => '土地不存在或不属于当前用户'
- ],
- // 验证土地状态是否可铲除
- [
- 'land_id', new RemovableStatusValidator($this, ['land']),
- 'msg' => '土地状态不允许铲除作物'
- ],
- // 验证铲除工具(如果提供)
- [
- 'tool_item_id', new RemoveToolValidator($this, ['user_id']),
- 'msg' => '铲除工具验证失败'
- ]
- ];
- }
- /**
- * 设置默认值
- *
- * @return array
- */
- public function default(): array
- {
- return [
- 'tool_item_id' => 0
- ];
- }
- }
|