From f4b8f0716009c8f1c4183e1421fa27c2470fe9f2 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 20 May 2023 16:29:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=95=86=E5=93=81=E7=9A=84?= =?UTF-8?q?=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/product/SpuDao.php | 3 +++ .../repositories/store/product/SpuRepository.php | 10 ++++++++-- app/controller/api/store/product/StoreSpu.php | 2 +- app/listener/ProductCreate.php | 16 ++++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/common/dao/store/product/SpuDao.php b/app/common/dao/store/product/SpuDao.php index 8a437bf3..b85b3e6d 100644 --- a/app/common/dao/store/product/SpuDao.php +++ b/app/common/dao/store/product/SpuDao.php @@ -52,6 +52,9 @@ class SpuDao extends BaseDao $query->when(isset($where['is_del']) && $where['is_del'] !== '',function($query)use($where){ $query->where('P.is_del',$where['is_del']); }) + ->when(isset($where['product_id']) && $where['product_id'] !== '',function($query)use($where){ + $query->where('P.product_id','in',$where['product_id']); + }) ->when(isset($where['mer_id']) && $where['mer_id'] !== '',function($query)use($where){ $query->where('P.mer_id',$where['mer_id']); }) diff --git a/app/common/repositories/store/product/SpuRepository.php b/app/common/repositories/store/product/SpuRepository.php index 83951b66..a46ef148 100644 --- a/app/common/repositories/store/product/SpuRepository.php +++ b/app/common/repositories/store/product/SpuRepository.php @@ -161,9 +161,15 @@ class SpuRepository extends BaseRepository { $where['spu_status'] = 1; $where['mer_status'] = 1; + $RedisCacheService = app()->make(RedisCacheService::class); + $exists=$RedisCacheService->exists('CloudMerchanSpu'.$where['mer_id']); + if ($exists){ + $Spu_arr=$RedisCacheService->SRANDMEMBER('CloudMerchanSpu'.$where['mer_id'], 10); + $where['product_id'] =$Spu_arr; + } $query = $this->dao->search($where); - $count = $query->count(); + $count = 0; // $Sql=$query->page($page, $limit)->setOption('field', [])->field($this->productFiled)->fetchSql(true); $query->with([ 'merchant' => function ($query) { @@ -171,7 +177,7 @@ class SpuRepository extends BaseRepository }, 'issetCoupon', ]); - $list = $query->page($page, $limit)->setOption('field', [])->field($this->productFiled)->orderRaw('rand()')->select(); + $list = $query->setOption('field', [])->field($this->productFiled)->orderRaw('rand()')->select(); $append = ['stop_time','svip_price','show_svip_info','is_svip_price']; $list->append($append); diff --git a/app/controller/api/store/product/StoreSpu.php b/app/controller/api/store/product/StoreSpu.php index 31a2dc67..f7ab95ce 100644 --- a/app/controller/api/store/product/StoreSpu.php +++ b/app/controller/api/store/product/StoreSpu.php @@ -102,7 +102,7 @@ class StoreSpu extends BaseController ]); if ($where['action']) unset($where['product_type']); $category_id=Db::name('merchant')->where('mer_id',$id)->value('category_id'); - $mer_id=Db::name('merchant')->where('category_id',$category_id)->where('type_id',11)->value('mer_id'); + $mer_id=Db::name('merchant')->where('mer_state',1)->where('status',1)->where('category_id',$category_id)->where('type_id',11)->value('mer_id'); if (!$mer_id){ return app('json')->success(['count'=>0,'list'=>[]]); diff --git a/app/listener/ProductCreate.php b/app/listener/ProductCreate.php index 0057054a..fa580678 100644 --- a/app/listener/ProductCreate.php +++ b/app/listener/ProductCreate.php @@ -3,6 +3,7 @@ declare (strict_types=1); namespace app\listener; +use crmeb\services\RedisCacheService; use think\facade\Db; use think\facade\Log; @@ -12,6 +13,9 @@ class ProductCreate public function handle($event) { $merchant=Db::name('merchant')->where('mer_id',$event['product']['mer_id'])->find(); + if ($merchant['type_id']==11){ + $this->CloudMerchanSpu($merchant,$event); + } if ($merchant['type_id']==13 ||$merchant['type_id']==11){ return false; } @@ -58,6 +62,18 @@ class ProductCreate return false; } + public function CloudMerchanSpu($data,$event){ + $RedisCacheService = app()->make(RedisCacheService::class); + $exists=$RedisCacheService->exists('CloudMerchanSpu'.$data['mer_id']); + if ($exists){ + $RedisCacheService->SADD ('CloudMerchanSpu'.$data['mer_id'], $event['product']['product_id']); + }else{ + $Spu_arr=Db::name('store_spu')->where('mer_id',$data['mer_id'])->where('status',1)->column('product_id'); + foreach ($Spu_arr as $k=>$v){ + $RedisCacheService->SADD ('CloudMerchanSpu'.$data['mer_id'], $v); + } + } + } public function AddProduct($mer_id,$product_find,$event){ $datas=[ 'mer_id'=>$mer_id,