From 3408ccb75235821cab3b8d5b2f3dd4060e85a9a4 Mon Sep 17 00:00:00 2001 From: yin5th <541304803@qq.com> Date: Mon, 17 Oct 2022 15:03:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=88=97=E8=A1=A8=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E3=80=81=E5=AA=92=E4=BD=93=E6=8A=A5=E9=81=93=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/Index.php | 3 +- app/model/Article.php | 68 +++++++++++++++++++++++++++++++++++++ view/article/news_list.html | 2 ++ view/page/activity.html | 27 +++++++++++---- 4 files changed, 93 insertions(+), 7 deletions(-) diff --git a/app/controller/Index.php b/app/controller/Index.php index 6ad0812..da7bd20 100755 --- a/app/controller/Index.php +++ b/app/controller/Index.php @@ -65,7 +65,8 @@ class Index extends Base // 案例 private function cases() { - $casesList = CasesModel::where('home', 1)->order('sort', 'desc')->order('id', 'desc')->select(); + $casesList = CasesModel::where('home', 1)->order('sort', 'desc') + ->order('id', 'desc')->limit(4)->select(); $this->data['casesList'] = $casesList; } diff --git a/app/model/Article.php b/app/model/Article.php index e87ffb3..456b841 100755 --- a/app/model/Article.php +++ b/app/model/Article.php @@ -212,6 +212,74 @@ class Article extends Base ->paginate($paginate, false); } + /** + * @param array $where + * @return \think\Paginator + * @throws \think\db\exception\DbException + */ + public static function getListByWhere(array $where) + { + $categoryId = $where['category_id']; + $per = $where['size']; + $keyword = $where['keyword'] ?? ''; + $param = $where['param'] ?? []; + $status = $where['status'] ?? -1; + $orderList = $where['order'] ?? ['sort' => 'desc']; + $onlyChild = $where['only_child'] ?? true; + $whereList = $where['where'] ?? []; + + $whereMap = []; + $pageParam = []; + + if (!empty($whereList)) { + foreach ($whereList as $w) { + $whereMap[] = $w; + } + } + + if (is_numeric($categoryId) && $categoryId > 0) { + $children = Category::getChildrenByParentId($categoryId, $onlyChild); + if (!empty($children)) { + $categoryIds = [$categoryId]; + foreach ($children as $child) { + if ($child['model_id'] == Model::MODEL_ARTICLE) { + $categoryIds[] = $child['id']; + } + } + $whereMap[] = ['category_id', 'in', $categoryIds]; + } else { + $whereMap[] = ['category_id', '=', $categoryId]; + } + $pageParam['category_id'] = $categoryId; + } + if (!empty($keyword)) { + $whereMap[] = ['title', 'like', '%'.$keyword.'%']; + $pageParam['keyword'] = $keyword; + } + if (is_array($param) && count($param) > 0) { + $pageParam['param'] = $param; + foreach ($param as $vo) { + if (in_array($vo, ['top', 'hot', 'recommend', 'is_prev'], true)) { + $whereMap[] = ["{$vo}", '=', 1]; + } + } + } + $paginate = [ + 'list_rows' => $per, + 'query' => $pageParam + ]; + + return self::with(["archivesCategory"]) + ->when(count($whereMap) > 0, function ($query) use ($whereMap) { + $query->where($whereMap); + }) + ->when($status != -1, function ($query) use ($status) { + $query->where('status', $status); + }) + ->order($orderList) + ->paginate($paginate, false); + } + //获取文章涉及到的图片 public static function getFilesInUse() { diff --git a/view/article/news_list.html b/view/article/news_list.html index 019e083..7e8cd2f 100755 --- a/view/article/news_list.html +++ b/view/article/news_list.html @@ -40,6 +40,7 @@ if (!$topNews->isEmpty()) {
{foreach $items as $item} + {if $item['id'] != ($topNews['id'] ?? 0)}
{$item.title}
@@ -56,6 +57,7 @@ if (!$topNews->isEmpty()) {
+ {/if} {/foreach} diff --git a/view/page/activity.html b/view/page/activity.html index 57db23e..fb2ea7f 100755 --- a/view/page/activity.html +++ b/view/page/activity.html @@ -3,7 +3,11 @@ use app\model\Article; use app\model\Category; $childrenMenu = Category::getChildrenByParentId($topCategoryId); -$items = Article::getList(Category::CATEGORY_BRAND_ACTIVITY, $category['number'] ?? 4); +$where = []; +$where['category_id'] = Category::CATEGORY_BRAND_ACTIVITY; +$where['size'] = $category['number'] ?? 4; +$where['where'] = [['is_prev', '=',0]]; +$items = Article::getListByWhere($where); $previewList = Article::getList(Category::CATEGORY_BRAND_ACTIVITY, 10, null, ['is_prev']); {/php} @@ -16,8 +20,11 @@ $previewList = Article::getList(Category::CATEGORY_BRAND_ACTIVITY, 10, null, ['i

{$blocks['brand_activity']['value']}

{$blocks['brand_activity']['title']}
+ {foreach $items as $k => $item} + {if $k%4==0} +
- {foreach $items as $item} + {/if}
{$item.title}
@@ -26,8 +33,8 @@ $previewList = Article::getList(Category::CATEGORY_BRAND_ACTIVITY, 10, null, ['i 查看详情查看详情
- {/foreach} -
+ {/foreach} + {if $k%3 == 0 || ($k == count($items) - 1)}{/if} @@ -79,6 +86,10 @@ $previewList = Article::getList(Category::CATEGORY_BRAND_ACTIVITY, 10, null, ['i } let html = ''; $.each(res.data, function (index, item) { + console.log(index,'sdfdasfs') + if (index%4 === 0) { + html += `
`; + } html += `
${item.title}
@@ -89,10 +100,14 @@ $previewList = Article::getList(Category::CATEGORY_BRAND_ACTIVITY, 10, null, ['i
`; + if (index === 3 || index=== (res.data.length - 1)) { + html += ``; + } }) page++; - that.data('page', page) - $('.activities-list').append(html); + that.data('page', page); + $('.brand-activities').append(html); + html = ''; return false; } })