diff --git a/plugin/webman/gateway/Events.php b/plugin/webman/gateway/Events.php index 1de80d0..a8d3d61 100644 --- a/plugin/webman/gateway/Events.php +++ b/plugin/webman/gateway/Events.php @@ -256,19 +256,23 @@ class Events ->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(); - if(!empty($tb_prod_cons[0]) && $tb_prod_cons[0]['quantity'] > $tb_prod_cons[0]['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; + if(!empty($tb_prod_cons)) { + foreach ($tb_prod_cons as $tb_prod_cons_k => $tb_prod_cons_v) { + if ($tb_prod_cons_v['quantity'] > $tb_prod_cons_v['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 {