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 { //有商品有规格