From 607b523fcd4109659411bb2781bbca683eea37ed Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 22 Jan 2025 10:22:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(admin):=20=E6=B7=BB=E5=8A=A0=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E5=9B=9E=E6=BB=9A=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 IndexController 中添加 demo3 方法,用于触发库存回滚 - 在 DemoLogic 中实现 test3 方法,执行库存回滚逻辑 - 使用 WarehouseProduct 和 WarehouseProductStorege 模型处理库存数据 - 库存回滚成功后更新数据库并记录日志 --- app/admin/controller/IndexController.php | 6 ++++++ app/api/logic/DemoLogic.php | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/admin/controller/IndexController.php b/app/admin/controller/IndexController.php index 8adcaad5c..be3c3f21e 100644 --- a/app/admin/controller/IndexController.php +++ b/app/admin/controller/IndexController.php @@ -30,4 +30,10 @@ class IndexController extends BaseAdminController $res=DemoLogic::test(); return $this->success('成功'); } + public function demo3() + { + $id=$this->request->get('id'); + $res=DemoLogic::test3($id); + return $this->success('成功'); + } } \ No newline at end of file diff --git a/app/api/logic/DemoLogic.php b/app/api/logic/DemoLogic.php index 915729556..808353560 100644 --- a/app/api/logic/DemoLogic.php +++ b/app/api/logic/DemoLogic.php @@ -6,6 +6,8 @@ use app\common\logic\BaseLogic; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_group_price\StoreProductGroupPrice; +use app\common\model\warehouse_product\WarehouseProduct; +use app\common\model\warehouse_product_storege\WarehouseProductStorege; use think\facade\Db; class DemoLogic extends BaseLogic @@ -92,4 +94,21 @@ class DemoLogic extends BaseLogic SqlChannelLog('StoreBranchProduct', $find['id'], $v['cart_num'], -1, Request()->url(), 1); } } + + /** + * 库存回滚 + */ + public static function test3($id) + { + $arr=WarehouseProduct::where('oid', $id)->select(); + foreach ($arr as $k => $v) { + $find=WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id',1)->find(); + $nums = bcadd($find->nums, $v['nums'], 2); + $res=WarehouseProductStorege::where('id', $v['id'])->update(['nums' => $nums]); + if($res){ + SqlChannelLog('WarehouseProductStorege', $v['id'], $v['nums'], 1, Request()->url(), 1); + $v->save(['delete_time'=>time()]); + } + } + } } From 3b13ad4a2eb7c79e83db6d99ea4866698ca0b41c Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 22 Jan 2025 11:18:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor(DemoLogic):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E5=9B=9E=E6=BB=9A=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 test3 函数中添加 $warehouse_id 参数,默认值为 1 - 修改查询条件,使用 $warehouse_id 替代硬编码的 1 - 修复更新语句中的 ID,使用 $find['id'] 替代 $v['id'] --- app/api/logic/DemoLogic.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/api/logic/DemoLogic.php b/app/api/logic/DemoLogic.php index 808353560..20886ce22 100644 --- a/app/api/logic/DemoLogic.php +++ b/app/api/logic/DemoLogic.php @@ -98,13 +98,13 @@ class DemoLogic extends BaseLogic /** * 库存回滚 */ - public static function test3($id) + public static function test3($id,$warehouse_id=1) { $arr=WarehouseProduct::where('oid', $id)->select(); foreach ($arr as $k => $v) { - $find=WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id',1)->find(); + $find=WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id',$warehouse_id)->find(); $nums = bcadd($find->nums, $v['nums'], 2); - $res=WarehouseProductStorege::where('id', $v['id'])->update(['nums' => $nums]); + $res=WarehouseProductStorege::where('id', $find['id'])->update(['nums' => $nums]); if($res){ SqlChannelLog('WarehouseProductStorege', $v['id'], $v['nums'], 1, Request()->url(), 1); $v->save(['delete_time'=>time()]);