| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace App\Module\Farm\Validations;
- use App\Module\Farm\Validators\LandOwnershipValidator;
- use App\Module\Farm\Validators\LandUpgradePathValidator;
- use App\Module\Farm\Validators\LandUpgradeMaterialsValidator;
- use App\Module\Farm\Validators\LandUpgradeStatusValidator;
- use App\Module\Farm\Validators\LandUpgradeHouseLevelValidator;
- use App\Module\Farm\Validators\LandUpgradeSpecialLimitValidator;
- use UCore\ValidationCore;
- /**
- * 土地升级验证类
- *
- * 用于验证土地升级操作的输入数据,包括用户ID、土地ID和目标类型
- *
- */
- class LandUpgradeValidation extends ValidationCore
- {
- /** @var \App\Module\Farm\Models\FarmLand|null 土地对象,由 LandOwnershipValidator 设置 */
- public ?\App\Module\Farm\Models\FarmLand $land = null;
- /** @var \App\Module\Farm\Models\FarmLandUpgradeConfig|null 升级配置,由 LandUpgradePathValidator 设置 */
- public ?\App\Module\Farm\Models\FarmLandUpgradeConfig $upgrade_config = 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 LandUpgradeStatusValidator($this, ['land']),
- 'msg' => '土地状态不允许升级'
- ],
- // 验证升级路径是否可用
- [
- 'land_id', new LandUpgradePathValidator($this, ['user_id', 'upgrade_config']),
- 'msg' => '升级路径验证失败'
- ],
- // 验证房屋等级是否满足要求
- [
- 'land_id', new LandUpgradeHouseLevelValidator($this, ['user_id', 'upgrade_config']),
- 'msg' => '房屋等级不足'
- ],
- // 验证特殊土地数量限制
- [
- 'land_id', new LandUpgradeSpecialLimitValidator($this, ['user_id', 'upgrade_config']),
- 'msg' => '特殊土地数量已达上限'
- ],
- // 验证升级材料是否足够
- [
- 'land_id', new LandUpgradeMaterialsValidator($this, ['user_id', 'upgrade_config']),
- 'msg' => '升级材料不足'
- ]
- ];
- }
- /**
- * 设置默认值
- *
- * @return array
- */
- public function default(): array
- {
- return [];
- }
- }
|