From f8b060c1e7c285a36cbba0f08eb1bab028e010c3 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 31 May 2023 10:20:00 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=95=86=E6=88=B7?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E5=88=A0=E9=99=A4store=5Fservice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/system/merchant/MerchantRepository.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index 393d8d43..79315a36 100644 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -18,6 +18,7 @@ use app\common\dao\system\merchant\MerchantDao; use app\common\dao\system\serve\ServeOrderDao; use app\common\model\store\order\StoreOrder; use app\common\model\store\product\ProductReply; +use app\common\model\store\service\StoreService; use app\common\model\system\merchant\Merchant; use app\common\repositories\BaseRepository; use app\common\repositories\store\coupon\StoreCouponRepository; @@ -463,6 +464,7 @@ class MerchantRepository extends BaseRepository { Db::transaction(function () use ($id) { $this->dao->update($id, ['is_del' => 1]); + StoreService::getInstance()->update(['is_del' => 1], ['mer_id' => $id]); app()->make(MerchantAdminRepository::class)->deleteMer($id); Queue::push(ClearMerchantStoreJob::class, ['mer_id' => $id]); }); From 7ed8a2ea48299da29b63e67d7b2b6f562bfc07a5 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 31 May 2023 10:22:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=95=86=E6=88=B7?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E5=88=A0=E9=99=A4store=5Fservice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index a15a9af2..971cbc4f 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -171,7 +171,7 @@ class Auth extends BaseController $data['mer_info'] = []; // 判断是否是商户,并且有没有完善信息 //这里有点小问题以后要修改 - $store_service = Db::name('store_service')->where('uid', $data['uid'])->find(); + $store_service = Db::name('store_service')->where('uid', $data['uid'])->where('is_del', 0)->find(); if ($store_service) { $mer_arr = Db::name('merchant')->where('mer_id', $store_service['mer_id'])->where('is_del', 0)->where('status', 1)->field('type_id,mer_avatar,mer_banner,mer_info,category_id,service_phone,mer_address,uid,mer_name')->find(); if ($mer_arr && $mer_arr['mer_avatar'] != '' && $mer_arr['mer_banner'] != '' && $mer_arr['mer_info'] && $mer_arr['service_phone'] != '' && $mer_arr['mer_address'] != '') { From 3fa65222ee6c657c3304e39b30dab96e464885ff Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 31 May 2023 11:12:52 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=9A=8F=E6=9C=BA?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E4=BA=91=E4=BB=93=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/SpuRepository.php | 48 ++++++++++++++++--- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/app/common/repositories/store/product/SpuRepository.php b/app/common/repositories/store/product/SpuRepository.php index 1939abaa..ed5ec943 100644 --- a/app/common/repositories/store/product/SpuRepository.php +++ b/app/common/repositories/store/product/SpuRepository.php @@ -177,18 +177,21 @@ class SpuRepository extends BaseRepository app()->make(UserVisitRepository::class)->searchProduct($this->userInfo ? $this->userInfo['uid'] : 0, $where['keyword'], (int)($where['mer_id'] ?? 0)); } } + if ($rand) { + $dataKey = 'CloudMerchantSpu_' . $where['mer_id']; $RedisCacheService = app()->make(RedisCacheService::class); - $exists=$RedisCacheService->exists('CloudMerchantSpu'.$where['mer_id']); - if ($exists){ - $Spu_arr=$RedisCacheService->SRANDMEMBER('CloudMerchantSpu'.$where['mer_id'], 10); - $where['product_id'] =$Spu_arr; - } else { - //TODO 后期优化随机查询 - $where['product_id'] = Db::name('cloud_product')->where('mer_id', $where['mer_id'])->where('status', 1)->orderRand()->limit(10)->column('product_id'); + $exists = $RedisCacheService->exists($dataKey); + if (!$exists) { + $productIds = Db::name('cloud_product')->where('mer_id', $where['mer_id'])->where('status', 1)->limit(100)->column('product_id'); + foreach ($productIds as $productId) { + $RedisCacheService->SADD($dataKey, $productId); + } } + $where['product_id'] = $this->getSpuFromCache($where['mer_id'], $page); unset($where['mer_id']); } + $entryMerId = $where['entry_mer_id'] ?? ''; unset($where['entry_mer_id']); $query = $this->dao->search($where); @@ -210,6 +213,37 @@ class SpuRepository extends BaseRepository } return compact('count', 'list'); } + + /** + * 从缓存中随机取出不重复数据 + * @param $merId + * @param $page + * @return array + */ + public function getSpuFromCache($merId, $page): array + { + $dataKey = 'CloudMerchantSpu_' . $merId; + $takenKey = 'CloudMerchantSpuTakenProductIds_' . $merId . '_page_'. $page; + $RedisCacheService = app()->make(RedisCacheService::class); + if (!$RedisCacheService->exists($takenKey)) { + $productIds = $RedisCacheService->sRandMember($dataKey, 10); + } else { + $keys = $RedisCacheService->sDiff($dataKey, $takenKey); + $number = min(count($keys), 10); + if ($number <= 0) { + return []; + } + $indexes = array_rand($keys, $number); + $productIds = []; + foreach ($indexes as $index) { + $productIds[] = $keys[$index]; + } + } + $RedisCacheService->sAdd($takenKey, ...$productIds); + $RedisCacheService->expire($takenKey, 60); + return $productIds; + } + public function getBorderList($list) { $make = app()->make(StoreActivityRepository::class);