From 49d7b67ea99f92a3b4cb853ae547eaa9bb0db394 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 9 Jun 2024 16:04:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(StoreProductLogic,=20StoreStorageSend):=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81=E5=AD=98=E5=82=A8=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E9=87=8D=E6=9E=84=E5=BA=93=E5=AD=98=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E4=B8=8E=E5=AD=98=E5=82=A8=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/store_product/StoreProductLogic.php | 10 +++++++-- app/queue/redis/StoreStorageSend.php | 22 +++++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 7d9bbb020..55d158f10 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -72,10 +72,16 @@ class StoreProductLogic extends BaseLogic if ($params['is_store_all'] == 1) { $store_arr = SystemStore::where('is_show', 1)->column('id'); - Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $store_arr]); + foreach($store_arr as $store_id){ + Redis::send('store-storage', ['product_arr' => ['id'=>$res['id'],'stock'=>0], 'store_id' => $store_id, 'admin_id' => Request()->adminId]); + } + // Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $store_arr]); } else { if (is_array($params['store_arr']) && count($params['store_arr']) > 0) { - Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $params['store_arr']]); + foreach($params['store_arr'] as $key =>$store_id){ + Redis::send('store-storage', ['product_arr' => ['id'=>$res['id'],'stock'=>0], 'store_id' => $store_id, 'admin_id' => Request()->adminId]); + } + // Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $params['store_arr']]); } } diff --git a/app/queue/redis/StoreStorageSend.php b/app/queue/redis/StoreStorageSend.php index da943c69a..a1b6d7a96 100644 --- a/app/queue/redis/StoreStorageSend.php +++ b/app/queue/redis/StoreStorageSend.php @@ -51,7 +51,7 @@ class StoreStorageSend implements Consumer 'sales' => 0, 'stock' => 0, ]; - $branch=StoreBranchProduct::create($product); + $branch = StoreBranchProduct::create($product); $arr = [ 'product_id' => $product_arr['id'], 'store_id' => $store_id, @@ -61,23 +61,27 @@ class StoreStorageSend implements Consumer 'bar_code' => $attr_value['bar_code'] ]; StoreBranchProductAttrValue::create($arr); - $this->storage($find, $store_id, $admin_id, $product_arr); + if ($product_arr['stock'] > 0) { + $this->storage($find, $store_id, $admin_id, $product_arr); + } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); - Log::error('store-storage队列消费失败: ' . $e->getMessage().',line:'.$e->getLine().',file:'.$e->getFile()); + Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); return false; } } else { Db::startTrans(); try { - $this->storage($find, $store_id, $admin_id, $product_arr); - Db::commit(); - return true; + if ($product_arr['stock'] > 0) { + $this->storage($find, $store_id, $admin_id, $product_arr); + } + Db::commit(); + return true; } catch (\Exception $e) { Db::rollback(); - Log::error('store-storage队列消费失败: ' . $e->getMessage().',line:'.$e->getLine().',file:'.$e->getFile()); + Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); return false; } } @@ -95,9 +99,9 @@ class StoreStorageSend implements Consumer $storage['status'] = -1; $storage['mark'] = '库存不足,主库存为:' . $find['stock']; SystemStoreStorage::create($storage); - }else{ + } else { SystemStoreStorage::create($storage); - StoreProduct::where('id', $product_arr['id'])->dec('stock',$product_arr['stock'])->update(); + StoreProduct::where('id', $product_arr['id'])->dec('stock', $product_arr['stock'])->update(); } }