| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace App\Module\Farm\Validations;
- use App\Module\Farm\Validators\LandOwnershipValidator;
- use App\Module\Farm\Validators\HarvestableStatusValidator;
- use UCore\ValidationCore;
- /**
- * 作物收获验证类
- *
- * 用于验证作物收获操作的输入数据,包括用户ID、土地ID
- */
- class CropHarvestValidation extends ValidationCore
- {
- /** @var \App\Module\Farm\Models\FarmLand|null 土地对象,由 LandOwnershipValidator 设置 */
- public ?\App\Module\Farm\Models\FarmLand $land = null;
- /**
- * 验证规则
- *
- * @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的整数'
- ],
- // 验证土地是否属于用户
- [
- 'land_id', new LandOwnershipValidator($this, ['user_id', 'land']),
- 'msg' => '土地不存在或不属于当前用户'
- ],
- // 验证土地状态是否可收获
- [
- 'land_id', new HarvestableStatusValidator($this, ['land']),
- 'msg' => '土地状态不允许收获'
- ]
- ];
- }
- /**
- * 设置默认值
- *
- * @return array
- */
- public function default(): array
- {
- return [];
- }
- }
|