Prechádzať zdrojové kódy

feat(crop): 添加作物生长阶段变化事件通知

- 在 CropLogic 中,当作物生长阶段发生变化时,触发 CropGrowthStageChangedEvent 事件
- 在 LandInfoDto 中添加作物下一阶段时间和阶段开始时间的处理
notfff 7 mesiacov pred
rodič
commit
e3dfb60bd4

+ 24 - 0
app/Module/AppGame/Proto/LandInfoDto.php

@@ -52,6 +52,30 @@ class LandInfoDto
                     $dataLand->setSeedPlantingTimes($landInfoDto->crop->plantTime);
                 }
             }
+            // 下一阶段的时间
+            if (!empty($landInfoDto->crop->stageEndTime)) {
+                if (is_string($landInfoDto->crop->stageEndTime)) {
+                    $nextGrowthTime = strtotime($landInfoDto->crop->stageEndTime);
+                    $dataLand->setStageNextTimes($nextGrowthTime);
+                }
+                else if (is_numeric($landInfoDto->crop->stageEndTime)) {
+                    $dataLand->setStageNextTimes($landInfoDto->crop->stageEndTime);
+
+                }
+            }
+
+            // 阶段开始时间
+            if (!empty($landInfoDto->crop->stageStartTime)) {
+                if (is_string($landInfoDto->crop->stageStartTime)) {
+                    $nextGrowthTime = strtotime($landInfoDto->crop->stageStartTime);
+                    $dataLand->setStageStartTimes($nextGrowthTime);
+                }
+                else if (is_numeric($landInfoDto->crop->stageStartTime)) {
+                    $dataLand->setStageStartTimes($landInfoDto->crop->stageStartTime);
+
+                }
+            }
+
 
             // 设置种子状态,这里需要将Farm模块的生长阶段映射到Proto的种子状态
             // 假设我们有一个映射关系,这里简单地直接使用生长阶段值

+ 2 - 0
app/Module/Farm/Logics/CropLogic.php

@@ -371,6 +371,8 @@ class CropLogic
                         'new_end_time' => $crop->stage_end_time->format('Y-m-d H:i:s'),
                         'stage_start_time' => $crop->stage_start_time ? $crop->stage_start_time->format('Y-m-d H:i:s') : null
                     ]);
+                    event(new CropGrowthStageChangedEvent($crop->user_id, $crop, $crop->growth_stage->value, $crop->growth_stage->value));
+
                 } else {
                     Log::warning('作物已经到达或超过结束时间,无法减少生长时间', [
                         'crop_id' => $crop->id,