From b944a03a1a1b3e783aa04d369306cd003c2bf16c Mon Sep 17 00:00:00 2001 From: muzi_ys <1099438829@qq.com> Date: Sun, 7 Aug 2022 21:33:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=BD=AE=E6=92=AD=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Advert.php | 10 ++++++++-- app/admin/controller/SystemConfig.php | 2 ++ app/admin/view/advert/info.html | 9 ++++++++- app/admin/view/article/comment.html | 2 +- app/common/model/AdvertInfo.php | 1 + app/index/common.php | 21 ++++++++++++++------- public/template/default/pc/index/index.html | 5 +++-- public/template/default/pc/js/index.js | 4 +--- 8 files changed, 38 insertions(+), 16 deletions(-) diff --git a/app/admin/controller/Advert.php b/app/admin/controller/Advert.php index b162be4..fc1f717 100644 --- a/app/admin/controller/Advert.php +++ b/app/admin/controller/Advert.php @@ -155,8 +155,9 @@ class Advert extends AuthController * @author 木子的忧伤 * @date 2021-02-19 11:53 */ - public function info() + public function info($id = '') { + if (!$id) return app("json")->fail("参数有误,Id为空!"); return $this->fetch(); } @@ -173,6 +174,7 @@ class Advert extends AuthController public function infoList(Request $request) { $where = Util::postMore([ + ['id', ''], ['title', ''], ['start_time', ''], ['end_time', ''], @@ -260,12 +262,16 @@ class Advert extends AuthController if (is_array($data['cover_path'])) $data['cover_path'] = $data['cover_path'][0]; $data['user_id'] = $this->adminId;//默认修改你 if (filter_var($data['url'], FILTER_VALIDATE_URL) === false) return app("json")->fail("链接地址不合法"); + $info = aModel::find($data['advert_id']); + if (!$info){ + return app("json")->fail("广告组id错误"); + } if ($id == "") { $res = tModel::create($data); } else { $res = tModel::update($data, ['id' => $id]); } - cache(Data::DATA_ADVERT . '_' . $data['advert_id'], null);//清除缓存 + cache(Data::DATA_ADVERT . '_' . $info['alias'], null);//清除缓存 return $res ? app("json")->success("操作成功", 'code') : app("json")->fail("操作失败"); } } \ No newline at end of file diff --git a/app/admin/controller/SystemConfig.php b/app/admin/controller/SystemConfig.php index c930d4e..4ef8ec4 100644 --- a/app/admin/controller/SystemConfig.php +++ b/app/admin/controller/SystemConfig.php @@ -15,6 +15,7 @@ use Psr\SimpleCache\InvalidArgumentException; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; +use think\facade\Cache; /** * 系统配置 @@ -66,6 +67,7 @@ class SystemConfig extends AuthController $commonPath = config("cache.runtime") . "/cache/"; $indexPath = config("cache.runtime") . "/index/"; $apiPath = config("cache.runtime") . "/api/"; + Cache::clear(); if (remove_cache($adminPath) && remove_cache($indexPath) && remove_cache($apiPath) && remove_cache($commonPath)) return app("json")->success("操作成功"); return app("json")->error("操作失败"); } diff --git a/app/admin/view/advert/info.html b/app/admin/view/advert/info.html index b3381d4..4b8da36 100644 --- a/app/admin/view/advert/info.html +++ b/app/admin/view/advert/info.html @@ -68,9 +68,10 @@ {include file="public/footer"/} \ No newline at end of file diff --git a/app/admin/view/article/comment.html b/app/admin/view/article/comment.html index bdd945d..0b0a9d7 100644 --- a/app/admin/view/article/comment.html +++ b/app/admin/view/article/comment.html @@ -83,7 +83,7 @@ var id = GetQueryString("id"); $('#tb_departments').bootstrapTable({ classes: 'table table-bordered table-hover table-striped', - url: '/admin/article/commentList?id=' + id, + url: '/admin/article/commentList?document_id=' + id, method: 'post', dataType: 'json', // 因为本示例中是跨域的调用,所以涉及到ajax都采用jsonp, uniqueId: 'id', diff --git a/app/common/model/AdvertInfo.php b/app/common/model/AdvertInfo.php index 4a5f7c2..f00068d 100644 --- a/app/common/model/AdvertInfo.php +++ b/app/common/model/AdvertInfo.php @@ -28,6 +28,7 @@ class AdvertInfo extends BaseModel public static function systemPage($where): array { $model = new self; + if ($where['id'] != '') $model = $model->where("advert_id", "=", $where['id']); if ($where['title'] != '') $model = $model->where("title|url", "like", "%$where[title]%"); if ($where['start_time'] != '') $model = $model->where("create_time", ">", strtotime($where['start_time'] . " 00:00:00")); if ($where['end_time'] != '') $model = $model->where("create_time", "<", strtotime($where['end_time'] . " 23:59:59")); diff --git a/app/index/common.php b/app/index/common.php index 26c5f92..082b595 100644 --- a/app/index/common.php +++ b/app/index/common.php @@ -567,7 +567,7 @@ function tpl_get_friend_link($type, $row) /** * 广告 * @param $type - * @param $row + * @param int $row * @return array|mixed|object|App|Collection|Db[] * @throws DataNotFoundException * @throws DbException @@ -575,9 +575,9 @@ function tpl_get_friend_link($type, $row) * @author 木子的忧伤 * @date 2021-07-26 23:24 */ -function tpl_get_advert($type, $row) +function tpl_get_advert($type, int $row = 5) { - $advertList = cache(Data::DATA_ADVERT . '_' . $type .'_'. $row); + $advertList = cache(Data::DATA_ADVERT . '_' . $type); if ($advertList === null) { $advertList = (new Advert())->alias("a") ->leftJoin("advert_info i",'a.id = i.advert_id') @@ -586,8 +586,8 @@ function tpl_get_advert($type, $row) ->where('a.status', 1) ->where('i.status', 1) ->order('sort desc') - ->limit($row) - ->select(); + ->select() + ->toArray(); //处理文件cdn信息 foreach ($advertList as $key => &$item) { if (empty($item['cover_path'])){ @@ -595,9 +595,16 @@ function tpl_get_advert($type, $row) } $item['cover_path'] = file_cdn($item['cover_path']); } - cache(Data::DATA_ADVERT . '_' . $type .'_'. $row, $advertList); + unset($item); + if (!empty($advertList)){ + cache(Data::DATA_ADVERT . '_' . $type, $advertList); + } } - return $advertList; + //如果获取行数为空则取默认值 + if (!$row){ + $row = 5; + } + return array_slice($advertList,0,$row); } /** diff --git a/public/template/default/pc/index/index.html b/public/template/default/pc/index/index.html index e6a5fd0..d8a1592 100644 --- a/public/template/default/pc/index/index.html +++ b/public/template/default/pc/index/index.html @@ -34,6 +34,7 @@