库存处理

This commit is contained in:
2026-04-11 10:40:42 +08:00
parent 5fd950efbb
commit c351e81aa3

View File

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