From f6d50d8d98a726ca0d13084ae1d56927d3927eed Mon Sep 17 00:00:00 2001 From: gitfjn <2860488097@qq.com> Date: Mon, 22 Dec 2025 21:26:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=8E=E5=B8=82=E6=9F=A5=E8=AF=A2=E5=88=97?= =?UTF-8?q?=E8=A1=A8=20=E8=BD=AE=E6=92=AD=E5=9B=BE=20=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/php.xml | 2 +- .idea/vcs.xml | 1 - application/api/controller/Ad.php | 5 ++ application/api/controller/City.php | 28 +++++++++++ application/api/server/CityService.php | 28 +++++++++++ composer.json | 2 +- config/cache.php | 66 +++++++++++++++++--------- 7 files changed, 106 insertions(+), 26 deletions(-) diff --git a/.idea/php.xml b/.idea/php.xml index d4632d26..f7571ed3 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -73,7 +73,7 @@ - + diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 28fefc54..94a25f7f 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,6 +2,5 @@ - \ No newline at end of file diff --git a/application/api/controller/Ad.php b/application/api/controller/Ad.php index f01e85e8..d9aed756 100644 --- a/application/api/controller/Ad.php +++ b/application/api/controller/Ad.php @@ -9,6 +9,11 @@ use think\Db; class Ad extends ApiBase { public $like_not_need_login = ['lists','channel','label','add_comost','add_comost','list_comost','follow_comost','comost_add','label_edit','comost_info','notice','position','position_list','vode_type','video_list','video_info','user_wages','user_wages_add','user_leave','fine','recruit','last_leave','last_fine','notice_list','leave','auth']; + + /** + * @return void + * 广告图片展示 + */ public function lists() { $pid = $this->request->get('pid'); diff --git a/application/api/controller/City.php b/application/api/controller/City.php index e69de29b..1d07068c 100644 --- a/application/api/controller/City.php +++ b/application/api/controller/City.php @@ -0,0 +1,28 @@ +cityService = new CityService(); + } + public function index() + { + $array = $this->cityService->list(); + return $this->_success($array); + } +} \ No newline at end of file diff --git a/application/api/server/CityService.php b/application/api/server/CityService.php index e69de29b..beb8fe2b 100644 --- a/application/api/server/CityService.php +++ b/application/api/server/CityService.php @@ -0,0 +1,28 @@ +has($cacheKey)) { + return Cache::store('redis')->get($cacheKey); + } + //查询市级名称 + $data = Db::name('dev_region') + ->order('id', 'asc') + ->field('id,parent_id,name') + ->where('level',1) + ->select(); + if ($data) { + Cache::store('redis')->set($cacheKey, $data); + } + return $data; + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index ea2a64e1..a0f9ce56 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.0.0", + "php": ">=7.4", "topthink/framework": "5.1.*", "topthink/think-captcha": "2.0.*", "overtrue/wechat": "~4.0", diff --git a/config/cache.php b/config/cache.php index 8f8b7f5c..5b3258e1 100644 --- a/config/cache.php +++ b/config/cache.php @@ -1,29 +1,49 @@ -// +---------------------------------------------------------------------- - -// +---------------------------------------------------------------------- -// | 缓存设置 -// +---------------------------------------------------------------------- use think\facade\Env; return [ - // 驱动方式 - 'type' => Env::get('cache.type','File'), - // 缓存保存目录 - 'path' => '', - // 缓存前缀 - 'prefix' => 'like_shop_', - // 缓存有效期 0表示永久缓存 - 'expire' => 0, - 'port' =>Env::get('cache.port','6379'), + // 缓存配置为文件类型 + 'type' => 'complex', - 'host' => Env::get('cache.host','like-redis'), + // 默认缓存配置 + 'default' => [ + // 驱动方式 + 'type' => 'File', + // 缓存保存目录 + 'path' => '', + // 缓存前缀 + 'prefix' => 'like_shop_', + // 缓存有效期 0表示永久缓存 + 'expire' => 0, + ], + + // Redis缓存配置 + 'redis' => [ + // 驱动方式 + 'type' => 'redis', + // Redis服务器地址 + 'host' => Env::get('cache.host','127.0.0.1'), + // Redis服务器端口 + 'port' => Env::get('cache.port','6379'), + // Redis连接密码(留空表示无密码) + 'password' => Env::get('cache.pwd',''), + // Redis数据库索引(0-15,默认为0) + 'select' => Env::get('cache.select', 0), + // 连接超时时间(秒,0表示不限制) + 'timeout' => Env::get('cache.timeout', 0), + // 是否使用长连接(true=长连接,false=短连接) + 'persistent' => Env::get('cache.persistent', true), + // 缓存前缀,用于区分不同应用或环境的缓存 + 'prefix' => 'like_shop_redis_', + // 缓存有效期(秒),0表示永久缓存 + 'expire' => Env::get('cache.expire', 0), + ], + + // File缓存配置 + 'file' => [ + 'type' => 'File', + 'path' => '', + 'prefix' => 'like_shop_file_', + 'expire' => 0, + ], ];