From 6d7edcd628118aec4d9ab9c664aea72372f8aa27 Mon Sep 17 00:00:00 2001 From: shengchanzhe <179998674@qq.com> Date: Fri, 27 Oct 2023 20:41:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index e7364bc1..1e0966d7 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2352,12 +2352,33 @@ class ProductRepository extends BaseRepository } $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) || $orderProduct->is_imported == 1) { - throw new ValidateException('订单商品不存在或已入库'); + if (empty($orderProduct)) { + throw new ValidateException('订单商品不存在'); + } + if( $orderProduct->is_imported == 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; @@ -2370,14 +2391,12 @@ class ProductRepository extends BaseRepository if ($stockIn <= 0) { throw new ValidateException('入库数量不能小于等于0'); } - //111 - ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->where('sku', $sku)->update(['stock'=>$attrValue->stock + $stockIn]); - + $attrValue->stock = $attrValue->stock + $stockIn; + $attrValue->save(); $product->stock = $stockIn + $product->stock; if (!$product->save()) { throw new \Exception('商品库存保存失败', 500); } - $model = new PurchaseRecord(); $data = [ 'order_id' => $params['order_id'] ?? 0, 'order_product_id' => $params['order_product_id'] ?? 0,