diff --git a/.env b/.env index a15c551..26273f6 100644 --- a/.env +++ b/.env @@ -6,9 +6,9 @@ DEFAULT_TIMEZONE = Asia/Shanghai [DATABASE] TYPE = mysql HOSTNAME = 127.0.0.1 -DATABASE = youda -USERNAME = youda -PASSWORD = youda +DATABASE = youda_neice +USERNAME = youda_neice +PASSWORD = youda_neice HOSTPORT = 3306 CHARSET = utf8 DEBUG = false diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index c171591..4a17446 100755 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -64,7 +64,13 @@ class Goods extends Base $redis = (new \app\common\server\RedisHelper())->getRedis(); $cache_key = "goods_list_{$type_str}_{$user_id}_{$page}"; $cache_data = $redis->get($cache_key); + $new_data = [ + 'data' => [], + 'last_page' => 0, + ]; + + return $this->renderSuccess('请求成功', $new_data); // 如果缓存存在,直接返回缓存数据 if ($cache_data) { $cached_data = json_decode($cache_data, true); @@ -810,6 +816,7 @@ class Goods extends Base if (empty($user['mobile'])) { return $this->renderError('请先绑定手机号', [], -9); } + return $this->renderError('正在维护中', []); $prize_num = request()->param('prize_num/d', 0); #抽几发 $goods_id = request()->param('goods_id/d', 0); #盒子ID $num = request()->param('goods_num/d', 0); #第几箱 diff --git a/app/api/controller/Index.php b/app/api/controller/Index.php index 9293389..cb2727e 100755 --- a/app/api/controller/Index.php +++ b/app/api/controller/Index.php @@ -41,7 +41,7 @@ class Index extends Base // // unset($tuijian[$key]); // continue; // } - $tuijian_list[] = $advert_value; + // $tuijian_list[] = $advert_value; } } $tuijian = $tuijian_list; @@ -304,12 +304,30 @@ class Index extends Base if (!in_array($type, $validTypes)) { return $this->renderError('无效的排行榜类型'); } + // 设置分页参数 $page = request()->param('page/d', 1); $limit = request()->param('limit/d', 10); - // 初始化排行榜服务类 + + // 获取Redis实例 + $redis = (new \app\common\server\RedisHelper())->getRedis(); + + // 构建缓存键名 + $cacheKey = "rank_list:{$type}:page_{$page}:limit_{$limit}"; + + // 检查缓存中是否有数据 + $cachedData = $redis->get($cacheKey); + if ($cachedData) { + return $this->renderSuccess('请求成功', json_decode($cachedData, true)); + } + + // 缓存中没有数据,从服务获取 $rankService = new \app\common\service\RankService(); $data = $rankService->getRankList($type, $page, $limit); + + // 将数据存入Redis缓存,无过期时间 + $redis->set($cacheKey, json_encode($data)); + // 返回数据 return $this->renderSuccess('请求成功', $data); } diff --git a/app/api/controller/Infinite.php b/app/api/controller/Infinite.php index 53d037f..56203cc 100755 --- a/app/api/controller/Infinite.php +++ b/app/api/controller/Infinite.php @@ -507,6 +507,7 @@ class Infinite extends Base if (empty($user['mobile'])) { return $this->renderError('请先绑定手机号', [], -9); } + return $this->renderError('正在维护中', []); $ad_id = request()->header('adid'); $goods_id = request()->param('goods_id/d', 0); #盒子ID $prize_num = request()->param('prize_num/d', 0); #抽几发 diff --git a/app/api/middleware.php b/app/api/middleware.php index e6c794b..3b23fd3 100755 --- a/app/api/middleware.php +++ b/app/api/middleware.php @@ -10,8 +10,8 @@ return [ // OPTIONS预检请求处理中间件 \app\api\middleware\OptionsRequestMiddleware::class, - // GET请求签名验证中间件 - // \app\api\middleware\SignatureVerifyMiddleware::class, + //请求签名验证中间件 + \app\api\middleware\SignatureVerifyMiddleware::class, // 注意:原来的Allow中间件已被拆分为上面三个专门的中间件,不再需要 // \app\api\middleware\Allow::class, ]; diff --git a/app/api/middleware/SignatureVerifyMiddleware.php b/app/api/middleware/SignatureVerifyMiddleware.php index 88947ee..4854cc2 100644 --- a/app/api/middleware/SignatureVerifyMiddleware.php +++ b/app/api/middleware/SignatureVerifyMiddleware.php @@ -24,7 +24,7 @@ class SignatureVerifyMiddleware /** * Redis键前缀 */ - const REDIS_KEY_PREFIX = 'api_nonce_'; + const REDIS_KEY_PREFIX = 'api_nonce:'; /** * Nonce过期时间(秒) diff --git a/app/common/service/RankService.php b/app/common/service/RankService.php index 39953ea..895fc2e 100644 --- a/app/common/service/RankService.php +++ b/app/common/service/RankService.php @@ -231,15 +231,7 @@ class RankService ->select() ->toArray(); - // // 查询数据 - // $list = Order::where($where) - // ->field('user_id, sum(use_money2) as use_money') - // ->group('user_id') - // ->order('use_money desc') - // ->page($page, $limit) - // ->select() - // ->toArray(); - + // 处理用户信息 $rankList = []; foreach ($list as $index => $item) { @@ -284,7 +276,9 @@ class RankService if ($endTime > 0) { $where[] = ['addtime', '<=', $endTime]; } - + if($limit==10){ + $limit=50; + } // 查询数据 $list = User::where($where) ->field('pid, COUNT(1) as invite_count')