From 79d4d3adb97cdddcfd8062122dbc4af6ff0dd46d Mon Sep 17 00:00:00 2001 From: shengchanzhe <179998674@qq.com> Date: Fri, 27 Oct 2023 21:11:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=87=87=E8=B4=AD=E5=85=A5?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 91 +++++++++---------- 1 file changed, 45 insertions(+), 46 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 289e4f31..7d7a6145 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2328,20 +2328,60 @@ class ProductRepository extends BaseRepository Db::startTrans(); try { $supplierMerId = 0; + $model = new PurchaseRecord(); if (empty($params['product_id']) && !empty($params['order_product_id'])) { //有商品无规格或者无商品无规格,导入商品和规格 $product = $this->getWhere(['source_product_id' => $params['order_product_id'], 'mer_id' => $merId]); + $sku = ProductAttrValue::where('product_id', $params['order_product_id'])->where('unique', $params['order_unique'])->value('sku'); + $attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->where('sku', $sku)->find(); if (!empty($product)) { - $unique = $this->importAttrValue($params['order_product_id'], $product->toArray(), $params['order_unique']); - if (!$unique) { - throw new \Exception('商品规格导入出错', 500); + $stockIn = $params['number'] ?? 0; + $price = $params['price'] ?? 0; + if (!empty($params['order_id'])) { + //采购、委托订单导入 + $orderMerId = StoreOrder::where('order_id', $params['order_id'])->value('mer_id'); + $orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id'])->where('product_sku', $params['order_unique'])->find(); + if (empty($orderProduct)) { + $unique = $this->importAttrValue($params['order_product_id'], $product->toArray(), $params['order_unique']); + if (!$unique) { + throw new \Exception('商品规格导入出错', 500); + } + } + if( $orderProduct->is_imported == 1){ + if($stockIn==0){ + $stockIn=1; + } + ProductAttrValue::where('mer_id', $merId) + ->where('product_id', $params['product_id'])->where('unique', $params['unique']) + ->update(['stock'=>$attrValue->stock + $stockIn]); + $data = [ + 'order_id' => $params['order_id'] ?? 0, + 'order_product_id' => $params['order_product_id'] ?? 0, + 'product_id' => $product->product_id, + 'number' => $stockIn, + 'order_unique' => $params['order_unique'] ?? '', + 'unique' => $attrValue['unique'], + 'price' => $price, + 'mer_id' => $product->mer_id, + 'supplier_mer_id' => $supplierMerId, + ]; + if (!$model->save($data)) { + throw new \Exception('入库失败', 500); + } + return true; + } + $stockIn = $orderProduct['product_num'] ?? 0; + $price = $orderProduct['product_price'] ?? 0; + $supplierMerId = $orderMerId ?? 0; + // 如果是委托商品入库后就成为供应链商家的采购类型商品 + if ($orderProduct['product_type'] == 99) { + $product->product_type = 98; + } } } else { $productId = $this->import($params['order_product_id'], request()->userInfo()); $product = $this->get($productId); } - $sku = ProductAttrValue::where('product_id', $params['order_product_id'])->where('unique', $params['order_unique'])->value('sku'); - $attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->where('sku', $sku)->find(); } else { //有商品有规格 $product = $this->get($params['product_id']); @@ -2350,47 +2390,6 @@ class ProductRepository extends BaseRepository if (!$product || !$attrValue) { throw new DataNotFoundException('商品或规格不存在'); } - $stockIn = $params['number'] ?? 0; - $price = $params['price'] ?? 0; - $model = new PurchaseRecord(); - if (!empty($params['order_id'])) { - //采购、委托订单导入 - $orderMerId = StoreOrder::where('order_id', $params['order_id'])->value('mer_id'); - $orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id'])->where('product_sku', $params['order_unique'])->find(); - if (empty($orderProduct)) { - throw new ValidateException('订单商品不存在'); - } - if( $orderProduct->is_imported == 1){ - if($stockIn==0){ - $stockIn=1; - } - ProductAttrValue::where('mer_id', $merId) - ->where('product_id', $params['product_id'])->where('unique', $params['unique']) - ->update(['stock'=>$attrValue->stock + $stockIn]); - $data = [ - 'order_id' => $params['order_id'] ?? 0, - 'order_product_id' => $params['order_product_id'] ?? 0, - 'product_id' => $product->product_id, - 'number' => $stockIn, - 'order_unique' => $params['order_unique'] ?? '', - 'unique' => $attrValue['unique'], - 'price' => $price, - 'mer_id' => $product->mer_id, - 'supplier_mer_id' => $supplierMerId, - ]; - if (!$model->save($data)) { - throw new \Exception('入库失败', 500); - } - return true; - } - $stockIn = $orderProduct['product_num'] ?? 0; - $price = $orderProduct['product_price'] ?? 0; - $supplierMerId = $orderMerId ?? 0; - // 如果是委托商品入库后就成为供应链商家的采购类型商品 - if ($orderProduct['product_type'] == 99) { - $product->product_type = 98; - } - } if ($stockIn <= 0) { throw new ValidateException('入库数量不能小于等于0'); }