From 5867fe5895a3d90dac3d2efcbc22da3d1e046860 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 21 Nov 2023 09:37:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index fddaa417..4fc2c7da 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -284,8 +284,9 @@ class ProductRepository extends BaseRepository $spuData['price'] = $settleParams['data']['price']; $spuData['mer_id'] = $merId; $spuData['mer_labels'] = $data['mer_labels']; - Db::transaction(function () use ($id, $data, $productType, $settleParams, $content, $product, $spuData, $merId) { - $this->save($id, $settleParams, $content, $product, $productType); + Db::startTrans(); + try{ + $res=$this->save($id, $settleParams, $content, $product, $productType); // if ($productType == 1) { //秒杀商品 // $dat = $this->setSeckillProduct($data); // app()->make(StoreSeckillActiveRepository::class)->updateByProduct($id, $dat); @@ -300,8 +301,13 @@ class ProductRepository extends BaseRepository if ($data['status'] == 0) { event('product.sell', ['product_id' => [$id]]); } - app()->make(SpuRepository::class)->changeStatus($id, $productType); - }); + app()->make(SpuRepository::class)->changeStatus($id, $productType); + Db::commit(); + return $res; + }catch(\Exception $e){ + Db::rollback(); + return false; + } } public function freeTrial(int $id, array $data, int $merId)