From 61188a138007c2f37f17b97384e0a7d8d37f40ad Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 4 Dec 2023 15:27:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index b7375138..3b851fcb 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -239,7 +239,7 @@ class ProductRepository extends BaseRepository $result = $this->dao->create($product); $settleParams = $this->setAttrValue($data, $result->product_id, $productType, 0, $data['mer_id']); - if(isset($data['mer_cate_id']) &&$data['mer_cate_id']!=0){ + if (isset($data['mer_cate_id']) && $data['mer_cate_id'] != 0) { $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $result->product_id, $data['mer_id']); } $settleParams['attr'] = $this->setAttr($data['attr'], $result->product_id); @@ -277,7 +277,9 @@ class ProductRepository extends BaseRepository event('product.update.before', compact('id', 'data', 'merId', 'productType', 'conType')); $spuData = $product = $this->setProduct($data); $settleParams = $this->setAttrValue($data, $id, $productType, 1, $merId); - $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId); + if (isset($data['mer_cate_id']) && $data['mer_cate_id'] != 0 &&$data['mer_cate_id'][0]!=0) { + $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId); + } $settleParams['attr'] = $this->setAttr($data['attr'], $id); $content = [ 'content' => $conType ? json_encode($data['content']) : $data['content'], @@ -287,8 +289,8 @@ class ProductRepository extends BaseRepository $spuData['mer_id'] = $merId; $spuData['mer_labels'] = $data['mer_labels']; Db::startTrans(); - try{ - $res=$this->save($id, $settleParams, $content, $product, $productType); + try { + $res = $this->save($id, $settleParams, $content, $product, $productType); // if ($productType == 1) { //秒杀商品 // $dat = $this->setSeckillProduct($data); // app()->make(StoreSeckillActiveRepository::class)->updateByProduct($id, $dat); @@ -303,10 +305,10 @@ class ProductRepository extends BaseRepository if ($data['status'] == 0) { event('product.sell', ['product_id' => [$id]]); } - app()->make(SpuRepository::class)->changeStatus($id, $productType); - Db::commit(); - return $res; - }catch(\Exception $e){ + app()->make(SpuRepository::class)->changeStatus($id, $productType); + Db::commit(); + return $res; + } catch (\Exception $e) { Db::rollback(); return false; } @@ -525,7 +527,7 @@ class ProductRepository extends BaseRepository { $result = []; foreach ($data as $value) { - if($value['category']){ + if ($value['category']) { $result[] = [ 'product_id' => $productId, 'mer_cate_id' => $value, @@ -790,7 +792,7 @@ class ProductRepository extends BaseRepository unset($data['content']); $data['content'] = $content; // $attr = $this->detailAttr($data['attr']); - $attrValue =$data['attrValue']; + $attrValue = $data['attrValue']; $sku = $this->detailAttrValue($attrValue, null, $data['product_type'], null); $data['sku'] = $sku; @@ -842,7 +844,7 @@ class ProductRepository extends BaseRepository $where['product_type'] = $productType; if (!$merId) $where['is_gift_bag'] = 0; } - if ($productType == 1 ||$productType==98) { + if ($productType == 1 || $productType == 98) { $where['product_type'] = $productType; } if ($productType == 10) { @@ -2356,8 +2358,8 @@ class ProductRepository extends BaseRepository $stockIn = $params['number'] ?? 0; $price = $params['price'] ?? 0; $orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id']) - ->where('product_sku', $params['order_unique'])->find(); - $stockIn=$orderProduct['product_num']; + ->where('product_sku', $params['order_unique'])->find(); + $stockIn = $orderProduct['product_num']; if ($stockIn <= 0) { throw new ValidateException('入库数量不能小于等于0'); } @@ -2377,7 +2379,7 @@ class ProductRepository extends BaseRepository } if ($orderProduct->is_imported == 0) { - $attrValue->stock=$attrValue->stock + $stockIn; + $attrValue->stock = $attrValue->stock + $stockIn; $product->stock = $stockIn + $product->stock; $data = [ 'order_id' => $params['order_id'] ?? 0, @@ -2398,7 +2400,7 @@ class ProductRepository extends BaseRepository $product->save(); Db::commit(); return true; - }else{ + } else { throw new ValidateException('该商品已导入过'); } $stockIn = $orderProduct['product_num'] ?? 0;