|
|
@@ -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());
|
|
|
}
|
|
|
}
|