diff --git a/app/admin/controller/store_product/StoreProductController.php b/app/admin/controller/store_product/StoreProductController.php index f494ea82..4e6121f9 100644 --- a/app/admin/controller/store_product/StoreProductController.php +++ b/app/admin/controller/store_product/StoreProductController.php @@ -124,6 +124,18 @@ class StoreProductController extends BaseAdminController return $this->success('复制成功', [], 1, 1); } + /** + * @notes 复制商品到仓库 + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function copyWarehouse() + { + $params = $this->request->post(); + StoreProductLogic::copyWarehouse($params); + return $this->success('复制成功', [], 1, 1); + } + /** * 商品导入到门店 */ diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 7a78e02d..744e0c9b 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -462,4 +462,32 @@ class StoreProductLogic extends BaseLogic // } // } } + + /** + * 复制商品到仓库 + * @param $params + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function copyWarehouse($params) + { + $exist = WarehouseProductStorege::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id']])->find(); + if ($exist) { + throw new BusinessException('该商品已存在该仓库'); + } + $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty(); + if (!$storeProduct) { + throw new BusinessException('商品不存在'); + } + $data = [ + 'warehouse_id' => $params['warehouse_id'], + 'product_id' => $params['product_id'], + 'nums' => 0, + 'total_price' => 0 + ]; + WarehouseProductStorege::create($data); + } + }