Bläddra i källkod

feat(game): 添加农场种子配置并优化物品添加流程

- 在 JsonController 中添加农场种子配置类 FarmSeedJsonConfig
- 在 AddItemForm 中实现物品添加的事务处理,提高数据一致性
notfff 7 månader sedan
förälder
incheckning
4e402a8191

+ 2 - 0
app/Module/AppGame/HttpControllers/JsonController.php

@@ -7,6 +7,7 @@ use App\Module\Game\DCache\ChestJsonConfig;
 use App\Module\Game\DCache\DismantleJsonConfig;
 use App\Module\Game\DCache\FarmHouseJsonConfig;
 use App\Module\Game\DCache\FarmLandJsonConfig;
+use App\Module\Game\DCache\FarmSeedJsonConfig;
 use App\Module\Game\DCache\FarmShrineJsonConfig;
 use App\Module\Game\DCache\FundCurrencyJsonConfig;
 use App\Module\Game\DCache\ItemJsonConfig;
@@ -49,6 +50,7 @@ class JsonController extends Controller
             'currencies' => FundCurrencyJsonConfig::class,
             'recipe' => RecipeJsonConfig::class,
             'dismantle' => DismantleJsonConfig::class,
+            'farm_seed' => FarmSeedJsonConfig::class,
         ];
 
         // 检查请求的配置表是否存在

+ 5 - 1
app/Module/GameItems/AdminForms/AddItemForm.php

@@ -8,6 +8,7 @@ use Dcat\Admin\Contracts\LazyRenderable;
 use Dcat\Admin\Traits\LazyWidget;
 use Dcat\Admin\Widgets\Form;
 use Exception;
+use Illuminate\Support\Facades\DB;
 
 /**
  * 添加物品表单
@@ -31,6 +32,7 @@ class AddItemForm extends Form implements LazyRenderable
             $itemId = (int) $input['item_id'];
             $quantity = (int) $input['quantity'];
 
+            DB::beginTransaction();
             // 调用ItemService添加物品
             $itemService = new ItemService();
             $result = $itemService->addItem($userId, $itemId, $quantity, [
@@ -44,13 +46,15 @@ class AddItemForm extends Form implements LazyRenderable
             ]);
 
             if (!empty($result['success'])) {
+                DB::commit();
                 return $this->response()
                     ->success('物品添加成功')
                     ->refresh();
             }
-
+            DB::rollBack();
             return $this->response()->error('物品添加失败');
         } catch (Exception $e) {
+            DB::rollBack();
             return $this->response()->error('操作失败: ' . $e->getMessage());
         }
     }