$value, 'data' => $data ]); // 获取土地对象 $land = null; if (isset($this->args[0])) { $land = $this->validation->{$this->args[0]}; } if (!$land) { Log::warning('FertilizerUsageValidator: 土地信息不存在', ['land_id' => $value]); $this->addError('土地信息不存在'); return false; } // 检查土地状态是否为种植中 // 不需要对土地状态进行验证 // if ($land->status !== LAND_STATUS::PLANTING->valueInt()) { // $this->addError('土地状态不允许使用肥料'); // return false; // } // 获取作物信息 $crop = FarmCrop::where('land_id', $value)->first(); Log::info('FertilizerUsageValidator: 查询作物信息', [ 'land_id' => $value, 'crop_found' => $crop ? true : false, 'crop_id' => $crop ? $crop->id : null ]); if (!$crop) { Log::warning('FertilizerUsageValidator: 土地上没有作物', ['land_id' => $value]); $this->addError('土地上没有作物'); return false; } // 检查作物生长阶段是否允许使用肥料 if (!GROWTH_STAGE::canUseFertilizer($crop->growth_stage)) { $this->addError('当前生长阶段不能使用肥料'); return false; } // 检查是否已经使用过肥料 if ($crop->fertilized) { $this->addError('当前阶段已经使用过肥料'); return false; } // 设置作物对象到验证类 if (isset($this->args[1])) { $this->validation->{$this->args[1]} = $crop; } return true; } catch (\Exception $e) { $this->addError('验证肥料使用条件时发生错误:' . $e->getMessage()); return false; } } }