From d7b7a0e0b989514dbcc0f2c17c8ca04d0ed62519 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 7 Jun 2023 18:13:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=EF=BC=8C=E5=BA=97=E9=93=BA=E4=BA=91=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/store/product/StoreSpu.php | 2 ++ app/listener/CloudProduct.php | 20 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/controller/api/store/product/StoreSpu.php b/app/controller/api/store/product/StoreSpu.php index e404246f..0b838992 100644 --- a/app/controller/api/store/product/StoreSpu.php +++ b/app/controller/api/store/product/StoreSpu.php @@ -62,6 +62,8 @@ class StoreSpu extends BaseController $where['is_gift_bag'] = 0; $where['product_type'] = 0; $where['order'] = $where['order'] ?: 'star'; + $where['mer_ids'] = Merchant::getInstance()->where('type_id', Merchant::TypeStore) + ->where(['status' => 1, 'mer_state' => 1, 'is_del' => 0])->column('mer_id'); if ($where['is_trader'] != 1) unset($where['is_trader']); $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo); return app('json')->success($data); diff --git a/app/listener/CloudProduct.php b/app/listener/CloudProduct.php index 6cd39b54..d666cb47 100644 --- a/app/listener/CloudProduct.php +++ b/app/listener/CloudProduct.php @@ -13,19 +13,29 @@ class CloudProduct public function handle($event) { - $categoryId = Merchant::getDB()->where('mer_id', $event['source_mer_id'])->value('category_id'); - $cloudMerchant = Merchant::getDB()->where(['type_id' => Merchant::TypeCloudWarehouse, 'category_id' => $categoryId, 'status' => 1, 'mer_state' => 1])->value('mer_id'); + $sourceMerchant = Merchant::getDB()->where('mer_id', $event['source_mer_id'])->field('category_id,type_id')->find(); + if ($sourceMerchant['type_id'] != Merchant::TypeStore) { + return true; + } + $cloudMerchant = Merchant::getDB()->where(['type_id' => Merchant::TypeCloudWarehouse, 'category_id' => $sourceMerchant['category_id'], 'status' => 1, 'mer_state' => 1])->value('mer_id'); if ($cloudMerchant) { - $list = []; + /** @var CloudProductDao $repo */ + $repo = app()->make(CloudProductDao::class); foreach ($event['product_id'] as $productId) { - $list[] = [ + $values = [ 'mer_id' => $cloudMerchant, 'source_mer_id' => $event['source_mer_id'], 'product_id' => $productId, 'status' => $event['status'], + 'create_time' => date('Y-m-d H:i:s'), ]; + $exist = $repo->get($productId); + if (!$exist) { + $repo->create($values); + } else { + $repo->update((int)$productId, $values); + } } - app()->make(CloudProductDao::class)->saveAll($list); $RedisCacheService = app()->make(RedisCacheService::class); foreach ($event['product_id'] as $productId) { if ($event['status'] == 1) {