库存处理

This commit is contained in:
2026-04-11 10:58:35 +08:00
parent 98fb3dc53a
commit 65b5295edc
2 changed files with 23 additions and 23 deletions

View File

@@ -46,7 +46,7 @@ class Base
}elseif (strstr($data_arr['operate_type'], 'del')) { }elseif (strstr($data_arr['operate_type'], 'del')) {
$operate_type = 'del'; $operate_type = 'del';
}elseif (strstr($data_arr['operate_type'], 'cleanup')) { }elseif (strstr($data_arr['operate_type'], 'cleanup')) {
$operate_type = 'cleanup'; $operate_type = ' ';
}elseif (strstr($data_arr['operate_type'], 'clearOrder')) { }elseif (strstr($data_arr['operate_type'], 'clearOrder')) {
$operate_type = 'clearOrder'; $operate_type = 'clearOrder';
}elseif (strstr($data_arr['operate_type'], 'batch')) { }elseif (strstr($data_arr['operate_type'], 'batch')) {

View File

@@ -246,30 +246,30 @@ class Events
if ( if (
(!empty($message['operate_type']) && ($message['operate_type'] == 'add' || $message['operate_type'] == 'edit')) && (!empty($message['operate_type']) && ($message['operate_type'] == 'add' || $message['operate_type'] == 'edit')) &&
(!empty($message['product_id']) && !empty($message['shop_id']) && !empty($message['number'])) && (!empty($message['product_id']) && !empty($message['shop_id']) && !empty($message['number'])) &&
(!empty($product) && $product[0]['is_auto_sold_stock'] == 1) (!empty($product) && $product[0]['is_stock'] == 1)
) { ) {
$gate_way = GateWay::class; $gate_way = GateWay::class;
$tb_prod_cons = Db::name('tb_prod_cons_relation') // $tb_prod_cons = Db::name('tb_prod_cons_relation')
->alias('r') // ->alias('r')
->join('tb_cons_info cons', 'r.cons_info_id = cons.id AND cons.is_stock = 1', 'inner') // ->join('tb_cons_info cons', 'r.cons_info_id = cons.id AND cons.is_stock = 1', 'inner')
->where('r.product_id', $message['product_id']) // ->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') // ->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') // ->group('r.cons_info_id')
->select()->toArray(); // ->select()->toArray();
if($tb_prod_cons[0]['quantity'] > $tb_prod_cons[0]['current_quantity']) { // if($tb_prod_cons[0]['quantity'] > $tb_prod_cons[0]['current_quantity']) {
$snd_data = [ // $snd_data = [
'msg' => '此商品库存不足', // 'msg' => '此商品库存不足',
'operate_type' => $message['operate_type'], // 'operate_type' => $message['operate_type'],
'msg_id' => 'out_of_stock' . Random::build(), // 'msg_id' => 'out_of_stock' . Random::build(),
'type' => 'out_of_stock', // 'type' => 'out_of_stock',
'id' => !empty($message['id'])?$message['id']:'', // 'id' => !empty($message['id'])?$message['id']:'',
'data_type' => 'cart', // 'data_type' => 'cart',
'status' => 0, // 'status' => 0,
'data' => [] // 'data' => []
]; // ];
$gate_way::sendToClient($client_id, json_encode($snd_data)); // $gate_way::sendToClient($client_id, json_encode($snd_data));
return; // return;
} // }
$number = $message['number']; $number = $message['number'];
try { try {
// Redis::select(3); // Redis::select(3);