|
|
@@ -8,6 +8,7 @@ use App\Module\Farm\Services\LandService;
|
|
|
use App\Module\GameItems\Logics\Item;
|
|
|
use App\Module\GameItems\Services\ItemService;
|
|
|
use Google\Protobuf\Internal\Message;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
use Uraus\Kku\Request\RequestLandFertilizer;
|
|
|
use Uraus\Kku\Response\ResponseLandFertilizer;
|
|
|
@@ -61,28 +62,35 @@ class FertilizerHandler extends BaseHandler
|
|
|
if ($crop_growth_time <= 0) {
|
|
|
throw new LogicException("该肥料物品无效");
|
|
|
}
|
|
|
- // 调用施肥服务
|
|
|
- $result = CropService::useFertilizer($userId, $landId,$crop_growth_time);
|
|
|
- if (!$result) {
|
|
|
- throw new LogicException("施肥失败,请检查土地状态或作物生长阶段");
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 调用施肥服务
|
|
|
+ $result = CropService::useFertilizer($userId, $landId,$crop_growth_time);
|
|
|
+ if (!$result) {
|
|
|
+ throw new LogicException("施肥失败,请检查土地状态或作物生长阶段");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 消耗物品
|
|
|
+ ItemService::consumeItem($userId, $itemId, null, 1, [
|
|
|
+ 'source_type' => 'land_fertilizer',
|
|
|
+ 'source_id' => $landId,
|
|
|
+ 'details' => [ 'land_id' => $landId ]
|
|
|
+ ]);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Log::info('用户施肥成功', [
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'land_id' => $landId,
|
|
|
+ 'item_id' => $itemId
|
|
|
+ ]);
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ DB::rollBack();
|
|
|
+ throw $e;
|
|
|
}
|
|
|
|
|
|
- // 消耗物品
|
|
|
- ItemService::consumeItem($userId, $itemId, null, 1, [
|
|
|
- 'source_type' => 'land_fertilizer',
|
|
|
- 'source_id' => $landId,
|
|
|
- 'details' => [ 'land_id' => $landId ]
|
|
|
- ]);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- Log::info('用户施肥成功', [
|
|
|
- 'user_id' => $userId,
|
|
|
- 'land_id' => $landId,
|
|
|
- 'item_id' => $itemId
|
|
|
- ]);
|
|
|
-
|
|
|
-
|
|
|
return $response;
|
|
|
}
|
|
|
|