From 3f1546e7b2b48d866d52c07809c5c8f7cd3e9b4d Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 28 Oct 2023 16:55:16 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=87=E8=B4=AD=E5=85=A5=E5=BA=93=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 3c5303a6..e5d3c578 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2325,19 +2325,20 @@ class ProductRepository extends BaseRepository */ public function stockIn($merId, $params) { - /**感觉有问题 最好在优化一下结构 */ Db::startTrans(); try { $supplierMerId = 0; $model = new PurchaseRecord(); + $stockIn = $params['number'] ?? 0; + $price = $params['price'] ?? 0; + if($stockIn==0){ + $stockIn=1; + } 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)) { - $stockIn = $params['number'] ?? 0; - $price = $params['price'] ?? 0; + $attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->find(); if (!empty($params['order_id'])) { //采购、委托订单导入 $orderMerId = StoreOrder::where('order_id', $params['order_id'])->value('mer_id'); @@ -2349,9 +2350,7 @@ class ProductRepository extends BaseRepository } } if( $orderProduct->is_imported == 1){ - if($stockIn==0){ - $stockIn=1; - } + ProductAttrValue::where('mer_id', $merId) ->where('product_id', $product['product_id']) ->update(['stock'=>$attrValue->stock + $stockIn]); @@ -2383,6 +2382,8 @@ class ProductRepository extends BaseRepository } else { $productId = $this->import($params['order_product_id'], request()->userInfo()); $product = $this->get($productId); + $attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $productId)->find(); + } } else { //有商品有规格