Merge remote-tracking branch 'shop/dev' into dev

This commit is contained in:
mkm 2023-05-31 11:59:33 +08:00
commit 8f7da59b5d
3 changed files with 44 additions and 8 deletions

View File

@ -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)); app()->make(UserVisitRepository::class)->searchProduct($this->userInfo ? $this->userInfo['uid'] : 0, $where['keyword'], (int)($where['mer_id'] ?? 0));
} }
} }
if ($rand) { if ($rand) {
$dataKey = 'CloudMerchantSpu_' . $where['mer_id'];
$RedisCacheService = app()->make(RedisCacheService::class); $RedisCacheService = app()->make(RedisCacheService::class);
$exists=$RedisCacheService->exists('CloudMerchantSpu'.$where['mer_id']); $exists = $RedisCacheService->exists($dataKey);
if ($exists){ if (!$exists) {
$Spu_arr=$RedisCacheService->SRANDMEMBER('CloudMerchantSpu'.$where['mer_id'], 10); $productIds = Db::name('cloud_product')->where('mer_id', $where['mer_id'])->where('status', 1)->limit(100)->column('product_id');
$where['product_id'] =$Spu_arr; foreach ($productIds as $productId) {
} else { $RedisCacheService->SADD($dataKey, $productId);
//TODO 后期优化随机查询 }
$where['product_id'] = Db::name('cloud_product')->where('mer_id', $where['mer_id'])->where('status', 1)->orderRand()->limit(10)->column('product_id');
} }
$where['product_id'] = $this->getSpuFromCache($where['mer_id'], $page);
unset($where['mer_id']); unset($where['mer_id']);
} }
$entryMerId = $where['entry_mer_id'] ?? ''; $entryMerId = $where['entry_mer_id'] ?? '';
unset($where['entry_mer_id']); unset($where['entry_mer_id']);
$query = $this->dao->search($where); $query = $this->dao->search($where);
@ -210,6 +213,37 @@ class SpuRepository extends BaseRepository
} }
return compact('count', 'list'); 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) public function getBorderList($list)
{ {
$make = app()->make(StoreActivityRepository::class); $make = app()->make(StoreActivityRepository::class);

View File

@ -18,6 +18,7 @@ use app\common\dao\system\merchant\MerchantDao;
use app\common\dao\system\serve\ServeOrderDao; use app\common\dao\system\serve\ServeOrderDao;
use app\common\model\store\order\StoreOrder; use app\common\model\store\order\StoreOrder;
use app\common\model\store\product\ProductReply; use app\common\model\store\product\ProductReply;
use app\common\model\store\service\StoreService;
use app\common\model\system\merchant\Merchant; use app\common\model\system\merchant\Merchant;
use app\common\repositories\BaseRepository; use app\common\repositories\BaseRepository;
use app\common\repositories\store\coupon\StoreCouponRepository; use app\common\repositories\store\coupon\StoreCouponRepository;
@ -463,6 +464,7 @@ class MerchantRepository extends BaseRepository
{ {
Db::transaction(function () use ($id) { Db::transaction(function () use ($id) {
$this->dao->update($id, ['is_del' => 1]); $this->dao->update($id, ['is_del' => 1]);
StoreService::getInstance()->update(['is_del' => 1], ['mer_id' => $id]);
app()->make(MerchantAdminRepository::class)->deleteMer($id); app()->make(MerchantAdminRepository::class)->deleteMer($id);
Queue::push(ClearMerchantStoreJob::class, ['mer_id' => $id]); Queue::push(ClearMerchantStoreJob::class, ['mer_id' => $id]);
}); });

View File

@ -171,7 +171,7 @@ class Auth extends BaseController
$data['mer_info'] = []; $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) { 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(); $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'] != '') { if ($mer_arr && $mer_arr['mer_avatar'] != '' && $mer_arr['mer_banner'] != '' && $mer_arr['mer_info'] && $mer_arr['service_phone'] != '' && $mer_arr['mer_address'] != '') {