|
@@ -2,14 +2,13 @@
|
|
|
|
|
|
|
|
namespace App\Module\Farm\Validators;
|
|
namespace App\Module\Farm\Validators;
|
|
|
|
|
|
|
|
-use App\Module\Farm\Logics\LandLogic;
|
|
|
|
|
use App\Module\Farm\Models\FarmLand;
|
|
use App\Module\Farm\Models\FarmLand;
|
|
|
use App\Module\Farm\Services\LandService;
|
|
use App\Module\Farm\Services\LandService;
|
|
|
use UCore\Validator;
|
|
use UCore\Validator;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 土地升级路径验证器
|
|
* 土地升级路径验证器
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* 验证土地是否有可用的升级路径
|
|
* 验证土地是否有可用的升级路径
|
|
|
*/
|
|
*/
|
|
|
class LandUpgradePathValidator extends Validator
|
|
class LandUpgradePathValidator extends Validator
|
|
@@ -24,7 +23,7 @@ class LandUpgradePathValidator extends Validator
|
|
|
public function validate(mixed $value, array $data): bool
|
|
public function validate(mixed $value, array $data): bool
|
|
|
{
|
|
{
|
|
|
$landId = (int)$value;
|
|
$landId = (int)$value;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 从 args 获取用户ID的键名,默认为 'user_id'
|
|
// 从 args 获取用户ID的键名,默认为 'user_id'
|
|
|
$userIdKey = $this->args[0] ?? 'user_id';
|
|
$userIdKey = $this->args[0] ?? 'user_id';
|
|
|
$userId = $data[$userIdKey] ?? null;
|
|
$userId = $data[$userIdKey] ?? null;
|
|
@@ -37,7 +36,7 @@ class LandUpgradePathValidator extends Validator
|
|
|
try {
|
|
try {
|
|
|
// 获取可用的升级路径
|
|
// 获取可用的升级路径
|
|
|
$upgradePaths = LandService::getAvailableUpgradePaths($userId, $landId);
|
|
$upgradePaths = LandService::getAvailableUpgradePaths($userId, $landId);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (empty($upgradePaths)) {
|
|
if (empty($upgradePaths)) {
|
|
|
$this->addError('当前没有可用的升级路径');
|
|
$this->addError('当前没有可用的升级路径');
|
|
|
return false;
|
|
return false;
|
|
@@ -45,34 +44,31 @@ class LandUpgradePathValidator extends Validator
|
|
|
|
|
|
|
|
// 选择第一个可用的升级路径
|
|
// 选择第一个可用的升级路径
|
|
|
$upgradePath = $upgradePaths[0];
|
|
$upgradePath = $upgradePaths[0];
|
|
|
-
|
|
|
|
|
- // 获取土地信息进行二次验证
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 获取土地信息
|
|
|
$land = FarmLand::where('id', $landId)
|
|
$land = FarmLand::where('id', $landId)
|
|
|
->where('user_id', $userId)
|
|
->where('user_id', $userId)
|
|
|
->first();
|
|
->first();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (!$land) {
|
|
if (!$land) {
|
|
|
$this->addError('土地不存在');
|
|
$this->addError('土地不存在');
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 验证升级路径的有效性
|
|
|
|
|
- $checkResult = LandLogic::checkUpgradePath(
|
|
|
|
|
- $userId,
|
|
|
|
|
- $land->land_type,
|
|
|
|
|
- $upgradePath['to_type_id'],
|
|
|
|
|
- false // 不检查材料,材料检查由专门的验证器处理
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- if ($checkResult->error) {
|
|
|
|
|
- $this->addError($checkResult->message);
|
|
|
|
|
|
|
+ // 获取升级配置(只检查配置是否存在,不进行其他验证)
|
|
|
|
|
+ $upgradeConfig = \App\Module\Farm\Models\FarmLandUpgradeConfig::where('from_type_id', $land->land_type)
|
|
|
|
|
+ ->where('to_type_id', $upgradePath['to_type_id'])
|
|
|
|
|
+ ->first();
|
|
|
|
|
+
|
|
|
|
|
+ if (!$upgradeConfig) {
|
|
|
|
|
+ $this->addError('升级配置不存在');
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 将升级配置保存到验证对象中,供后续使用
|
|
// 将升级配置保存到验证对象中,供后续使用
|
|
|
$upgradeConfigKey = $this->args[1] ?? null;
|
|
$upgradeConfigKey = $this->args[1] ?? null;
|
|
|
if ($upgradeConfigKey) {
|
|
if ($upgradeConfigKey) {
|
|
|
- $this->validation->$upgradeConfigKey = $checkResult->data['config'];
|
|
|
|
|
|
|
+ $this->validation->$upgradeConfigKey = $upgradeConfig;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
return true;
|