From ea4716f661f7b89ed93013ca754762f0a2a30f72 Mon Sep 17 00:00:00 2001
From: mkm <727897186@qq.com>
Date: Tue, 13 Aug 2024 11:38:12 +0800
Subject: [PATCH 1/3] =?UTF-8?q?feat(store=5Fproduct):=20=E4=BF=AE=E6=94=B9?=
 =?UTF-8?q?=E5=BA=93=E5=AD=98=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C?=
 =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../logic/store_product/StoreProductLogic.php | 103 ++++++------------
 .../SystemStoreStorageLogic.php               |  10 +-
 .../WarehouseProductLogic.php                 |   1 -
 .../WarehouseProductStoregeLogic.php          |   1 +
 4 files changed, 34 insertions(+), 81 deletions(-)

diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php
index cf07e3b44..de0280785 100644
--- a/app/admin/logic/store_product/StoreProductLogic.php
+++ b/app/admin/logic/store_product/StoreProductLogic.php
@@ -13,8 +13,6 @@ use app\common\model\store_product_attr_value\StoreProductAttrValue;
 use app\common\model\store_product_cate\StoreProductCate;
 use app\common\model\system_store\SystemStore;
 use app\common\model\system_store_storage\SystemStoreStorage;
-use app\common\model\warehouse_product_storege\WarehouseProductStorege;
-use app\Request;
 use Illuminate\Support\Facades\Log;
 use think\facade\Db;
 use Webman\RedisQueue\Redis;
@@ -456,21 +454,22 @@ class StoreProductLogic extends BaseLogic
                 Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
                 return false;
             }
-        } else {
-            //更新门店库存
-            Db::startTrans();
-            try {
-                // if ($product_arr['stock'] > 0) {
-                //     self::storage($find, $store_id, $admin_id, $product_arr,1,$warehouse_id);
-                // }
-                Db::commit();
-                return true;
-            } catch (\Exception $e) {
-                Db::rollback();
-                Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
-                return false;
-            }
-        }
+        } 
+        // else {
+        //     //更新门店库存
+        //     Db::startTrans();
+        //     try {
+        //         // if ($product_arr['stock'] > 0) {
+        //         //     self::storage($find, $store_id, $admin_id, $product_arr,1,$warehouse_id);
+        //         // }
+        //         Db::commit();
+        //         return true;
+        //     } catch (\Exception $e) {
+        //         Db::rollback();
+        //         Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
+        //         return false;
+        //     }
+        // }
     }
 
     /**兑换 */
@@ -497,9 +496,7 @@ class StoreProductLogic extends BaseLogic
                     'stock' => 0,
                 ];
                 StoreBranchProductExchange::create($product);
-                // if ($product_arr['stock'] > 0) {
-                //     self::storage($find, $store_id, $admin_id, $product_arr,$warehouse_id);
-                // }
+
                 Db::commit();
                 return true;
             } catch (\Exception $e) {
@@ -507,56 +504,20 @@ class StoreProductLogic extends BaseLogic
                 Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
                 return false;
             }
-        } else {
-            Db::startTrans();
-            try {
-                // if ($product_arr['stock'] > 0) {
-                //     self::storage($find, $store_id, $admin_id, $product_arr,2,$warehouse_id);
-                // }
-                Db::commit();
-                return true;
-            } catch (\Exception $e) {
-                Db::rollback();
-                Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
-                return false;
-            }
-        }
-    }
-    public static function storage($find, $store_id, $admin_id, $product_arr,$stock_type=1,$warehouse_id=0)
-    {
-        $storage = [
-            'product_id' => $product_arr['id'],
-            'store_id' => $store_id,
-            'nums' => $product_arr['stock'],
-            'admin_id' => $admin_id,
-            'type' => $stock_type,
-            'warehouse_id'=>$warehouse_id,
-        ];
-        $data=[
-            'warehouse_id'=>$warehouse_id,
-            'product_id' => $product_arr['id'],
-            'store_id' => $store_id,
-            'financial_pm' => 0,
-            'batch' => $product_arr['batch']??1,
-            'nums' => $product_arr['stock'],
-            'status' =>1,
-            'admin_id' =>$admin_id,
-        ];
-        $warehouse=WarehouseProductStorege::where('warehouse_id',$warehouse_id)->where('product_id',$product_arr['id'])->find();
-        if ($warehouse) {
-            if($warehouse['nums']< $product_arr['stock']){
-                $storage['status'] = -1;
-                $data['status'] = -1;
-                $storage['mark'] = '库存【'.$warehouse_id.'】不足,分库存为:' .$warehouse['nums'];
-                $data['mark'] = '库存【'.$warehouse_id.'】不足,分库存为:' .$warehouse['nums'].' 总仓库存为:'.$find['stock'];
-            }
-            $res=WarehouseProductLogic::add($data);
-            $storage['outbound_id']=$res['id']??0;
-            SystemStoreStorage::create($storage);
-        } else {
-            $res=WarehouseProductLogic::add($data);
-            $storage['outbound_id']=$res['id']??0;
-            SystemStoreStorage::create($storage);
-        }
+        } 
+        // else {
+        //     Db::startTrans();
+        //     try {
+        //         // if ($product_arr['stock'] > 0) {
+        //         //     self::storage($find, $store_id, $admin_id, $product_arr,2,$warehouse_id);
+        //         // }
+        //         Db::commit();
+        //         return true;
+        //     } catch (\Exception $e) {
+        //         Db::rollback();
+        //         Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
+        //         return false;
+        //     }
+        // }
     }
 }
diff --git a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php
index 9e95ec0a1..03fac3aea 100644
--- a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php
+++ b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php
@@ -61,14 +61,7 @@ class SystemStoreStorageLogic extends BaseLogic
      */
     public static function edit(array $params): bool
     {
-        $find=SystemStoreStorage::where('id', $params['id'])->find();
-
-        //查看仓库库存
-        $productStorege=WarehouseProductStorege::where('product_id', $params['product_id'],['warehouse_id'=>$find['warehouse_id']])->find();
-        if($productStorege && $productStorege['nums']<$params['nums']){
-            self::setError('库存不足,仓库库存为:'.$productStorege['nums']);
-            return false;
-        }
+        return true;
         Db::startTrans();
         try {
             SystemStoreStorage::where('id', $params['id'])->update([
@@ -77,7 +70,6 @@ class SystemStoreStorageLogic extends BaseLogic
                 'status' => 0,
                 'mark' => '',
             ]);
-            StoreProduct::where('id', $params['product_id'])->inc('stock',bcsub($find['nums'] ,$params['nums'],2))->update();
             Db::commit();
             return true;
         } catch (\Exception $e) {
diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php
index 7aef771d7..78b0db945 100644
--- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php
+++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php
@@ -42,7 +42,6 @@ class WarehouseProductLogic extends BaseLogic
                 $after_nums=$storege['nums']-$params['nums'];
                 if($after_nums<0){
                     throw new BusinessException('库存不足');
-                    return false;
                 }
                 WarehouseProductStorege::where('id', $storege['id'])->dec('nums', $params['nums'])->update();
             } else {
diff --git a/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php b/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php
index eac41ece8..a1da050dd 100644
--- a/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php
+++ b/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php
@@ -56,6 +56,7 @@ class WarehouseProductStoregeLogic extends BaseLogic
      */
     public static function edit(array $params): bool
     {
+        return true;
         Db::startTrans();
         try {
             WarehouseProductStorege::where('id', $params['id'])->update([

From f57cebc64904baf2786172ef4488fbf0437f4d6a Mon Sep 17 00:00:00 2001
From: mkm <727897186@qq.com>
Date: Tue, 13 Aug 2024 12:00:00 +0800
Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86?=
 =?UTF-8?q?=E4=BB=93=E5=BA=93=E4=BA=A7=E5=93=81=E9=80=BB=E8=BE=91=E5=92=8C?=
 =?UTF-8?q?=E4=BB=93=E5=BA=93=E4=BA=A7=E5=93=81=E5=BA=93=E5=AD=98=E9=80=BB?=
 =?UTF-8?q?=E8=BE=91=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=BA=A7=E5=93=81?=
 =?UTF-8?q?ID=E5=88=B0=E4=BB=93=E5=BA=93=E4=BA=A7=E5=93=81=E7=9A=84?=
 =?UTF-8?q?=E5=AD=98=E5=82=A8=E4=B8=AD=EF=BC=8C=E5=B9=B6=E4=BF=AE=E5=A4=8D?=
 =?UTF-8?q?=E4=BA=86=E7=9B=B8=E5=85=B3=E6=93=8D=E4=BD=9C=E7=9A=84=E9=94=99?=
 =?UTF-8?q?=E8=AF=AF=E3=80=82=E5=90=8C=E6=97=B6=E5=88=A0=E9=99=A4=E4=BA=86?=
 =?UTF-8?q?=E4=BB=93=E5=BA=93=E4=BA=A7=E5=93=81=E5=BA=93=E5=AD=98=E6=A8=A1?=
 =?UTF-8?q?=E5=9E=8B=EF=BC=8C=E5=B9=B6=E6=9B=B4=E6=96=B0=E4=BA=86=E7=9B=B8?=
 =?UTF-8?q?=E5=85=B3=E6=96=87=E6=A1=A3=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../WarehouseProductLists.php                 |  2 +-
 .../WarehouseProductLogic.php                 |  4 +-
 .../WarehouseProductStoregeLogic.php          | 39 +------------------
 app/queue/redis/StoreStorageSend.php          |  1 -
 4 files changed, 5 insertions(+), 41 deletions(-)

diff --git a/app/admin/lists/warehouse_product/WarehouseProductLists.php b/app/admin/lists/warehouse_product/WarehouseProductLists.php
index 8183d703e..3b9976f2a 100644
--- a/app/admin/lists/warehouse_product/WarehouseProductLists.php
+++ b/app/admin/lists/warehouse_product/WarehouseProductLists.php
@@ -89,7 +89,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
                 }
                 if($item->product_id){
                     $find=StoreProduct::where('id',$item->product_id)->field('image,store_name')->find();
-                    $item->store_name=$find->store_name;
+                    $item->store_name=$find->store_name.'|'.$item->product_id;
                     $item->image=$find->image;
                 }else{
                     $item->store_name='';
diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php
index 78b0db945..508f1f370 100644
--- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php
+++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php
@@ -148,7 +148,7 @@ class WarehouseProductLogic extends BaseLogic
         if ($res) {
             $res->delete();
             if ($res['financial_pm'] == 1) {
-                WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->dec('nums', $res['nums'])->update();
+                WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id',$res['product_id'])->dec('nums', $res['nums'])->update();
             } elseif ($res['financial_pm'] == 0) {
                 $find = SystemStoreStorage::where(['outbound_id' => $res['id']])->find();
                 if ($find) {
@@ -162,7 +162,7 @@ class WarehouseProductLogic extends BaseLogic
                     }
                     $find->delete();
                 }
-                WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->inc('nums', $res['nums'])->update();
+                WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id',$res['product_id'])->inc('nums', $res['nums'])->update();
             }
 
             return true;
diff --git a/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php b/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php
index a1da050dd..2bd0c5e6d 100644
--- a/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php
+++ b/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php
@@ -26,24 +26,7 @@ class WarehouseProductStoregeLogic extends BaseLogic
      */
     public static function add(array $params): bool
     {
-        Db::startTrans();
-        try {
-            WarehouseProductStorege::create([
-                'warehouse_id' => $params['warehouse_id'],
-                'product_id' => $params['product_id'],
-                'nums' => $params['nums'],
-                'price' => $params['price'],
-                'total_price' => $params['total_price'],
-                'status' => $params['status']
-            ]);
-
-            Db::commit();
-            return true;
-        } catch (\Exception $e) {
-            Db::rollback();
-            self::setError($e->getMessage());
-            return false;
-        }
+        return true;
     }
 
 
@@ -57,24 +40,6 @@ class WarehouseProductStoregeLogic extends BaseLogic
     public static function edit(array $params): bool
     {
         return true;
-        Db::startTrans();
-        try {
-            WarehouseProductStorege::where('id', $params['id'])->update([
-                'warehouse_id' => $params['warehouse_id'],
-                'product_id' => $params['product_id'],
-                'nums' => $params['nums'],
-                'price' => $params['price'],
-                'total_price' => $params['total_price'],
-                'status' => $params['status']
-            ]);
-
-            Db::commit();
-            return true;
-        } catch (\Exception $e) {
-            Db::rollback();
-            self::setError($e->getMessage());
-            return false;
-        }
     }
 
 
@@ -100,6 +65,6 @@ class WarehouseProductStoregeLogic extends BaseLogic
      */
     public static function detail($params): array
     {
-        return WarehouseProductStorege::findOrEmpty($params['id'])->toArray();
+        return [];
     }
 }
\ No newline at end of file
diff --git a/app/queue/redis/StoreStorageSend.php b/app/queue/redis/StoreStorageSend.php
index e9dd5bed0..be8c44b25 100644
--- a/app/queue/redis/StoreStorageSend.php
+++ b/app/queue/redis/StoreStorageSend.php
@@ -10,7 +10,6 @@ use app\common\model\store_branch_product_exchange\StoreBranchProductExchange;
 use app\common\model\store_product\StoreProduct;
 use app\common\model\store_product_attr_value\StoreProductAttrValue;
 use app\common\model\system_store_storage\SystemStoreStorage;
-use app\common\model\warehouse_product_storege\WarehouseProductStorege;
 use Webman\RedisQueue\Consumer;
 use support\Log;
 use think\facade\Db;

From f5cd98515705adf2d99e102560a2dfeeed84dc86 Mon Sep 17 00:00:00 2001
From: mkm <727897186@qq.com>
Date: Tue, 13 Aug 2024 12:01:56 +0800
Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E5=BA=93?=
 =?UTF-8?q?=E5=AD=98=E7=AE=A1=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98?=
 =?UTF-8?q?=E5=8C=96=E4=BA=86=E5=BA=93=E5=AD=98=E4=B8=8D=E8=B6=B3=E6=97=B6?=
 =?UTF-8?q?=E7=9A=84=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../WarehouseProductLogic.php                 | 38 ++++++++-----------
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php
index 508f1f370..7ee4898b6 100644
--- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php
+++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php
@@ -34,22 +34,22 @@ class WarehouseProductLogic extends BaseLogic
     {
         // Db::startTrans();
         // try {
-        $before_nums=0;
-        $after_nums=0;
+        $before_nums = 0;
+        $after_nums = 0;
         $storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
-        if($storege){
+        if ($storege) {
             if ($params['financial_pm'] == 0) {
-                $after_nums=$storege['nums']-$params['nums'];
-                if($after_nums<0){
+                $after_nums = $storege['nums'] - $params['nums'];
+                if ($after_nums < 0) {
                     throw new BusinessException('库存不足');
                 }
                 WarehouseProductStorege::where('id', $storege['id'])->dec('nums', $params['nums'])->update();
             } else {
-                $after_nums=$storege['nums']+$params['nums'];
+                $after_nums = $storege['nums'] + $params['nums'];
                 WarehouseProductStorege::where('id', $storege['id'])->inc('nums', $params['nums'])->update();
             }
-            $before_nums=$storege['nums'];
-        }else{
+            $before_nums = $storege['nums'];
+        } else {
             WarehouseProductStorege::create([
                 'warehouse_id' => $params['warehouse_id'],
                 'product_id' => $params['product_id'],
@@ -62,7 +62,7 @@ class WarehouseProductLogic extends BaseLogic
             'store_id' => $params['store_id'] ?? 0,
             'product_id' => $params['product_id'],
             'financial_pm' => $params['financial_pm'],
-            'batch' => $batch_count+1,
+            'batch' => $batch_count + 1,
             'nums' => $params['nums'],
             'before_nums' => $before_nums,
             'after_nums' => $after_nums,
@@ -148,21 +148,15 @@ class WarehouseProductLogic extends BaseLogic
         if ($res) {
             $res->delete();
             if ($res['financial_pm'] == 1) {
-                WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id',$res['product_id'])->dec('nums', $res['nums'])->update();
+                WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $res['nums'])->update();
             } elseif ($res['financial_pm'] == 0) {
-                $find = SystemStoreStorage::where(['outbound_id' => $res['id']])->find();
-                if ($find) {
-                    if ($find['status'] == 1) {
-                        $stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock');
-                        if ($stock < $res['nums']) {
-                            self::setError('商品库存不足,无法退回');
-                            return false;
-                        }
-                        StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update();
-                    }
-                    $find->delete();
+                $stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock');
+                if ($stock < $res['nums']) {
+                    self::setError('商品库存不足,无法退回');
+                    return false;
                 }
-                WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id',$res['product_id'])->inc('nums', $res['nums'])->update();
+                StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update();
+                WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->update();
             }
 
             return true;