From c351e81aa369b0700ffc872b75b439f7869ed5a3 Mon Sep 17 00:00:00 2001 From: ASUS <515617283@qq.com> Date: Sat, 11 Apr 2026 10:40:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=93=E5=AD=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/webman/gateway/Events.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/plugin/webman/gateway/Events.php b/plugin/webman/gateway/Events.php index 84fd469..32c7e73 100644 --- a/plugin/webman/gateway/Events.php +++ b/plugin/webman/gateway/Events.php @@ -246,9 +246,31 @@ class Events if ( (!empty($message['operate_type']) && ($message['operate_type'] == 'add' || $message['operate_type'] == 'edit')) && (!empty($message['product_id']) && !empty($message['shop_id']) && !empty($message['number'])) && - (!empty($product) && $product[0]['is_stock'] == 1) + (!empty($product) && $product[0]['is_auto_sold_stock'] == 1) ) { $gate_way = GateWay::class; + $tb_prod_cons = Db::name('prod_cons_relation') + ->alias('r') + ->join('tb_cons_info cons', 'r.cons_info_id = cons.id AND cons.is_stock = 1', 'inner') + ->where('r.product_id', $message['product_id']) + ->fieldRaw('r.cons_info_id AS consId, SUM(r.surplus_stock * ' . $message['number'] . ') AS quantity, cons.stock_number AS current_quantity') + ->group('r.cons_info_id') + ->select()->toArray(); + p($tb_prod_cons); + if($tb_prod_cons['quantity'] > $tb_prod_cons['current_quantity']) { + $snd_data = [ + 'msg' => '此商品库存不足', + 'operate_type' => $message['operate_type'], + 'msg_id' => 'out_of_stock' . Random::build(), + 'type' => 'out_of_stock', + 'id' => !empty($message['id'])?$message['id']:'', + 'data_type' => 'cart', + 'status' => 0, + 'data' => [] + ]; + $gate_way::sendToClient($client_id, json_encode($snd_data)); + return; + } $number = $message['number']; try { // Redis::select(3);