IndexController.php
13.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<?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 app\portal\model\PortalPostModel;
use think\Db;
class IndexController extends HomeBaseController
{
public function index(){
$serverModel = new ServerController();
//统计访问量
$serverModel->statistics();
//banner轮播图
// $coverImg = cache('coverImg');
// if(!$coverImg){
$coverImg = $this->getCoverImg(CityCategoryModel::indexImg,10);
// cache('coverImg',$coverImg);
// }
$this->assign('coverImg',$coverImg);
//星球奇境,城市分类
// $city = cache('res_city');
// if(!$city){
$city[1]['id'] = CityCategoryModel::asia;
$city[2]['id'] = CityCategoryModel::europe;
$city[3]['id'] = CityCategoryModel::africa;
$city[4]['id'] = CityCategoryModel::oceania;
$city[5]['id'] = CityCategoryModel::north;
$city[6]['id'] = CityCategoryModel::south;
$city[20]['id'] = CityCategoryModel::antarctica;
$city[43]['id'] = CityCategoryModel::arctic;
$city_name = $this->getCity(array_column($city,'id'));
foreach($city as &$value){
$k = 0;
foreach($city_name as $value1){
$k += 0;
if($value['id'] == $value1['pid']){
$value['name'][$k]['name'] = $value1['name'];
$value['name'][$k]['id'] = $value1['id'];
$k++;
}
}
}
// cache('res_city', $city);
// }
$this->assign('res_city',$city);
//星享体验
// $month = cache('res_month');
// if(!$month){
$res_month = $this->getMonthArticle();
$month = [];
foreach($res_month['data'] as &$value){
$month[$value['month']]['id'] = $value['id'];
$month[$value['month']]['month'] = $value['month'];
$month[$value['month']]['post_title'] = $value['post_title'];
$month[$value['month']]['index_thumbnail'] = $value['index_thumbnail'];
foreach($res_month['category_name'] as $value1){
if($value['id'] == $value1['post_id']){
$month[$value['month']]['category_name'] = $value1['name'];
}
}
}
// cache('res_month', $month);
// }
$this->assign('res_month',$month);
//星域秀场->首页宣传
// $res_xqyy = cache('res_xqyy');
// if(!$res_xqyy){
// $position = CityCategoryModel::xqyy;
// $field = 'id,more,index_thumbnail';
// $res_xqyy = $this->getVideoIndex($position,$field,1);
// foreach($res_xqyy as &$value){
// $video = json_decode($value['more'],true);
// $value['video'] = $video['video'];
// }
$position = CityCategoryModel::xqyy;
$city_id = CityCategoryModel::syxc;
$field = 'id,more,index_thumbnail';
$res_xqyy = $this->getVideo($position,$city_id,$field,1,1);
foreach($res_xqyy as &$value){
$video = json_decode($value['more'],true);
$value['video'] = $video['video'];
}
if($res_xqyy){
$res_xqyy = $res_xqyy[0];
}
// cache('res_xqyy', $res_xqyy);
// }
$this->assign('res_xqyy',$res_xqyy);
//推广视频
// $res_djxq = cache('res_djxq');
// if(!$res_djxq){
$position = CityCategoryModel::xqyy;
$city_id = CityCategoryModel::djxq;
$field = 'id,more,index_thumbnail';
$res_djxq = $this->getVideo($position,$city_id,$field,1,1);
foreach($res_djxq as &$value){
$video = json_decode($value['more'],true);
$value['video'] = $video['video'];
}
if($res_djxq){
$res_djxq = $res_djxq[0];
}
// cache('res_djxq', $res_djxq);
// }
$this->assign('res_djxq',$res_djxq);
//星域秀场->明星访谈
// $res_mxft = cache('res_mxft');
// if(!$res_mxft){
$position = CityCategoryModel::mxft;
$field = 'id,full_name,position,trade,post_excerpt,thumbnail avatar';
$res_mxft = $this->getChildArticle($position,$field,1);
if($res_mxft){
$res_mxft = $res_mxft[0];
}
// cache('res_mxft',$res_mxft);
// }
$this->assign('res_mxft',$res_mxft);
//星域秀场->星域画廊
// $res_xyhl = cache('res_xyhl');
// if(!$res_xyhl){
$position = CityCategoryModel::xyhl;
$field = 'id,thumbnail';
$res_xyhl = $this->getChildArticle($position,$field,4);
// cache('res_xyhl',$res_xyhl);
// }
$this->assign('res_xyhl',$res_xyhl);
//星探推荐
// $res_xttj = cache('res_xttj');
// if(!$res_xttj){
$position = CityCategoryModel::xttj;
$field = 'id,post_title,price,index_thumbnail,place';
$res_xttj = $this->getParentArticle($position,$field,4);
// cache('res_xttj',$res_xttj);
// }
$this->assign('res_xttj',$res_xttj);
//星际活动
// $res_xjhd = cache('res_xjhd');
// if(!$res_xjhd){
$position = CityCategoryModel::xjhd;
$field = 'id,post_title,thumbnail';
$res_xjhd = $this->getParentArticle($position,$field,2);
// cache('res_xjhd',$res_xjhd);
// }
$this->assign('res_xjhd',$res_xjhd);
$_SESSION['xx_token'] = md5("123456");
return $this->fetch();
}
//根据id获取视频地址(以防止通过链接下载)
public function getVideoById(){
$id = $this->request->param('id');
$video_url = $this->getVideoId($id);
//页面直接输出视频
$filePath = 'http://xingqiu.qiniu.brotop.cn/'.$video_url;
ini_set('memory_limit', '512M');
header("Pragma: public");
header("Expires: 0");
header("Content-Type: application/octet-stream"); //文件mime类型
//header("Content-Disposition: attachment; filename=video11.mp4;" ); //文件名$filename
//header("Content-Length: 83995"); //文件大小$fsize
ob_clean();
flush();
//ob_end_clean();
@readfile($filePath);
}
//根据id获取视频地址
public function getVideoId($id){
$res = Db::name('portal_post')
->where('id',$id)
->field('id,more')
->find();
if($res['more']){
$video = json_decode($res['more'],true);
$video_url = $video['video'];
}else{
$video_url = '';
}
return $video_url;
}
//根据父类查询文章
public function getParentArticle($position,$field,$limit = ''){
$pre = CityCategoryModel::pre;
$limit = empty($limit)?0:$limit;
$category_id = Db::table($pre.'portal_category')
->where('parent_id',$position)
->field('id')
->select()
->toArray();
$c_id = array_column($category_id,'id');
//查询文章id
$post_id = Db::table($pre.'portal_category_post')
->whereIn('category_id',$c_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('delete_time', 0)
->field($field)
->limit($limit)
->order('weigh desc')
->select()
->toArray();
return $res;
}
//根据子类获取文章
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)
->field('post_id')
->select()
->toArray();
$post_id = array_column($post_id,'post_id');
//查询文章
$res = Db::table($pre.'portal_post')
->whereIn('id',$post_id)
->where('delete_time', 0)
->field($field)
->limit($limit)
->order('weigh desc')
->select()
->toArray();
return $res;
}
//获取显示首页视频
public function getVideoIndex($position,$field,$limit=''){
$pre = CityCategoryModel::pre;
$limit = empty($limit)?0:$limit;
$post_id = Db::table($pre.'portal_category_post')
->whereIn('category_id',$position)
->field('post_id')
->select()
->toArray();
$post_id = array_column($post_id,'post_id');
//查询文章
$res = Db::table($pre.'portal_post')
->whereIn('id',$post_id)
->where(['delete_time'=>0,'is_show'=>1])
->field($field)
->limit($limit)
->order('weigh desc')
->select()
->toArray();
return $res;
}
//获取推荐视频
public function getVideo($position,$city_id,$field,$limit='',$extension=''){
$pre = CityCategoryModel::pre;
$limit = empty($limit)?0:$limit;
$post_id = Db::table($pre.'portal_category_post')
->whereIn('category_id',$position)
->field('post_id')
->select()
->toArray();
$post_id = array_column($post_id,'post_id');
//查询文章
if(!empty($extension)){
$where = ['city_id'=>$city_id,'is_show'=>1];
}else{
$where = ['city_id'=>$city_id];
}
$res = Db::table($pre.'portal_post')
->whereIn('id',$post_id)
->where($where)
->where('delete_time', 0)
->field($field)
->limit($limit)
->order('weigh desc')
->select()
->toArray();
return $res;
}
//获取各洲对应的城市
private function getCity($city_ids){
$pre = CityCategoryModel::pre;
$res = Db::table($pre.'city_category')
->whereIn('pid',$city_ids)
->where('is_show',1)
->where('delete_time', 0)
->field('id,pid,name')
->order('weigh desc')
->select()
->toArray();
return $res;
}
//获取封面图
public function getCoverImg($type,$limit){
$res = Db::name('image')
->where(['type'=>$type])
->field('id,image')
->limit($limit)
->order('weigh desc')
->select()
->toArray();
return $res;
}
//根据月份查询文章(星享体验)
private function getMonthArticle(){
$position = CityCategoryModel::xxty;
$pre = CityCategoryModel::pre;
$category_id = Db::table($pre.'portal_category')
->where('parent_id',$position)
->field('id')
->select()
->toArray();
$c_id = array_column($category_id,'id');
//查询文章
$res = Db::name('portal_post')
->alias('p')
->join('portal_category_post c','p.id = c.post_id','LEFT')
->whereIn('c.category_id',$c_id)
->where('p.is_show',1)
->where('p.delete_time', 0)
->field('p.id,p.month,p.post_title,p.index_thumbnail')
->order('weigh desc')
->group('month')
->select()
->toArray();
$arr = [];
if($res){
$post_ids = array_column($res,'id');
$category_name = Db::name('portal_category_post')
->alias('c')
->join('portal_category p','c.category_id = p.id','LEFT')
->whereIn('post_id', $post_ids)
->field('c.post_id,p.name')
->select()
->toArray();
$arr['data'] = $res;
$arr['category_name'] = $category_name;
}
return $arr;
}
//关于我们
public function aboutUs(){
$res = Db::name('about_us')->where('id',1)->find();
$contentModel = new PortalPostModel();
$res['content'] = $contentModel->getPostContentAttr($res['content']);
$this->assign('res',$res);
return $this->fetch();
}
}