StarController.php
6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\HomeBaseController;
use app\portal\model\CityCategoryModel;
use think\Db;
//星球奇境
class StarController extends HomeBaseController
{
private $index_limit = 16;//首页分页
private $more_limit = 8;//更多列表分页
public function index(){
//按照城市查询
$city_id = $this->request->param('city_id');
$position['city_id'] = $city_id;
//星球故事
$position['category_id'] = CityCategoryModel::xqgs;
$field = 'id,thumbnail,post_excerpt,more';
$res_xqgs = $this->getChildArticle($position,$field,1);
foreach($res_xqgs as &$value){
$video = json_decode($value['more'],true);
$value['audio'] = $video['audio'];
}
$this->assign('res_xqgs',$res_xqgs);
//网红美景
$position['category_id'] = CityCategoryModel::whmj;
$field = 'id,thumbnail,post_title,post_hits,post_favorites';
$res_whmj = $this->getChildArticle($position,$field,$this->index_limit);
$this->assign('res_whmj',$res_whmj);
//异域珍馐
$position['category_id'] = CityCategoryModel::yyzx;
$field = 'id,thumbnail,post_title';
$res_yyzx = $this->getChildArticle($position,$field,$this->index_limit);
$this->assign('res_yyzx',$res_yyzx);
//良宿美寝
$position['category_id'] = CityCategoryModel::lsmq;
$field = 'id,thumbnail,post_title';
$res_lsmj = $this->getChildArticle($position,$field,$this->index_limit);
$this->assign('res_lsmj',$res_lsmj);
//活力生态
$position['category_id'] = CityCategoryModel::hlst;
$field = 'id,thumbnail,post_title,post_excerpt';
$res_hlst = $this->getChildArticle($position,$field,$this->index_limit);
$this->assign('res_hlst',$res_hlst);
//便利出行
$position['category_id'] = CityCategoryModel::blcx;
$field = 'id,thumbnail';
$res_blcx = $this->getChildArticle($position,$field,$this->index_limit);
$this->assign('res_blcx',$res_blcx);
return $this->fetch();
}
//根据子类获取文章
public function getChildArticle($position,$field,$limit=''){
$pre = CityCategoryModel::pre;
$limit = empty($limit)?0:$limit;
$post_id = Db::table($pre.'portal_category_post')
->whereIn('category_id',$position['category_id'])
->field('post_id')
->select()
->toArray();
$post_id = array_column($post_id,'post_id');
//查询文章
$res = Db::table($pre.'portal_post')
->whereIn('id',$post_id)
->where('city_id',$position['city_id'])
->where('delete_time', 0)
->field($field)
->limit($limit)
->order('weigh desc')
->select()
->toArray();
return $res;
}
//根据子类获取文章分页
public function getChildArticlePage($position,$field,$page){
$pre = CityCategoryModel::pre;
$limit = $this->more_limit;
$post_id = Db::table($pre.'portal_category_post')
->whereIn('category_id',$position['category_id'])
->field('post_id')
->select()
->toArray();
$post_id = array_column($post_id,'post_id');
//查询文章
$res = Db::table($pre.'portal_post')
->whereIn('id',$post_id)
->where('city_id',$position['city_id'])
->where('delete_time', 0)
->field($field)
->page($page,$limit)
->order('weigh desc')
->select()
->toArray();
return $res;
}
//网红美景更多
public function getMoreScenery(){
$page = $this->request->param('page',1,'intval');
$position['category_id'] = CityCategoryModel::whmj;
$field = 'id,thumbnail,post_title,post_hits,post_favorites';
$res = $this->getChildArticlePage($position,$field,$page);
$this->assign('res',$res);
}
//异域珍馐更多
public function getMoreFood(){
$page = $this->request->param('page',1,'intval');
$position['category_id'] = CityCategoryModel::yyzx;
$field = 'id,thumbnail,post_title,post_hits,post_favorites';
$res_top = $this->getChildArticle($position,$field,2);
$res = $this->getChildArticlePage($position,$field,$page);
$this->assign('res_top',$res_top);
$this->assign('res',$res);
}
//良宿美寝更多
public function getMoreHotel(){
$page = $this->request->param('page',1,'intval');
$position['category_id'] = CityCategoryModel::lsmq;
$field = 'id,thumbnail,post_title';
$res = $this->getChildArticlePage($position,$field,$page);
$this->assign('res',$res);
}
//活力生态更多
public function getMoreEcology(){
$page = $this->request->param('page',1,'intval');
$position['category_id'] = CityCategoryModel::hlst;
$field = 'id,thumbnail,post_title,post_excerpt';
$res = $this->getChildArticlePage($position,$field,$page);
$this->assign('res',$res);
}
//便利出行更多
public function getMoreTravel(){
$page = $this->request->param('page',1,'intval');
$position['category_id'] = CityCategoryModel::blcx;
$field = 'id,thumbnail,post_title,post_excerpt';
$res = $this->getChildArticlePage($position,$field,$page);
$this->assign('res',$res);
}
}