IndexController.php
6.8 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
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace api\portal\controller;
use think\Controller;
//use api\portal\model\MemberModel;
//use api\portal\model\UserModel;
//use api\portal\service\PostService;
use think\Db;
use think\Request;
use think\Loader;
/**
* @title 首页接口
* @description 接口说明
* @group 接口分组
*/
class IndexController extends CommonController
{
/**
* @title 首页
* @description 接口说明
* @author 开发者
* @url /api/portal/Index/index
* @method POST
* @param name:chooseType type:int require:1 default: other: desc:类型:1手机站,2PC站
*/
public function index(Request $request)
{
// 推荐人
$getParam = $request->param();
if(!empty($getParam['uid'])){
$where_parent['id'] = $getParam['uid'];
$parent = Db::name('Member')->where($where_parent)->field('id as parent_id,tel as parent_tel')->find();
$final['parent'] = $parent;
}
// 1.首页轮播
$where_banner['status'] = 1;
$final['banner'] = Db::name('Banner')->where($where_banner)
->field("pic")
->order("score desc,create_time desc")->select()->toArray();
foreach ($final['banner'] as $bannerk=>$bannerv){
$final['banner'][$bannerk]['pic'] = cmf_get_image_url($bannerv['pic']);
}
// 2.交易流程
$where_process['status'] = 1;
$where_process['type'] = $request->param('type');
$final['process'] = Db::name('Process')->where($where_process)
->field("content")
->order('create_time desc')
->find();
$final['process']['content'] = htmlspecialchars_decode($final['process']['content']);
// 3. 最新成交
$where_new['status'] = 1;
$final['new'] = Db::name('New')->where($where_new)->order('score desc')->select()->toArray();
// 4. 合作企业
$where_coo['status'] = 1;
$final['coop'] = Db::name('Cooperation')->where($where_coo)->order("score desc , create_time desc")->field('pic,jump')->select()->toArray();
foreach ($final['coop'] as $coopk=>$coopv){
if(empty($member['pic'])){
$pic = "../themes/simpleboot3/public/assets/images/house.jpg";
}else{
$pic = $coopv['pic'];
}
$final['coop'][$coopk]['pic'] = cmf_get_image_url($pic);
}
// 5. 文章
$where_cate['c.delete_time'] = 0;
$where_cate['c.status'] = 1;
$where_cate['j.status'] = 1;
// 分类
$connect = Db::name('PortalCategoryPost')->alias('j')
->where($where_cate)
->join("PortalCategory c",'c.id = j.category_id')
// ->join("PortalPost p",'p.id = j.post_id')
// ->group('j.category_id')
->field("j.id as jid ,j.post_id,j.category_id,c.name")
->select()->toArray();
$cate_arr = array();
$post_arr = array();
$connect_arr = array();
// 处理分类id
foreach ($connect as $conk=>$conv){
$cate_arr[] = $conv['category_id'];
$post_arr[] = $conv['post_id'];
$connect_arr[$conk]['category_id'] = $conv['category_id'];
$connect_arr[$conk]['post_id'] = $conv['post_id'];
}
$cate_arr = array_values(array_unique($cate_arr));
// 查询分类
$where_cateNext['id'] = array('in',$cate_arr);
$cateNext_list = Db::name('PortalCategory')->where($where_cateNext)->field('id,name')->select()->toArray();
// 查文章
$where_arr['post_status'] = 1;
$where_arr['id'] = array('in',$post_arr);
$artcile = Db::name('PortalPost')
->where($where_arr)
->field('id,post_title')
->order("create_time desc")
->select()->toArray();
$middle =array();
// 拼数组
// 循环关联
foreach ($connect_arr as $conNextk=>$conNextv){
// 循环类
foreach ($cateNext_list as $catNextk=>$catNextv){
$middle[$catNextk]['id'] = $catNextv['id'];
$middle[$catNextk]['name'] = $catNextv['name'];
// 循环文章
foreach ($artcile as $artNextk=>$artNextv){
if($conNextv['category_id'] == $catNextv['id']){
// $key = $catNextv['name'];
if($conNextv['post_id'] == $artNextv['id']){
// $middle[$key][$artNextk]['title'] = $artNextv['post_title'];
// $middle[$key][$artNextk]['id'] = $artNextv['id'];
$middle[$catNextk]['list'][$artNextk]['id'] = $artNextv['id'];
$middle[$catNextk]['list'][$artNextk]['title'] = $artNextv['post_title'];
}
}
}
}
}
$final['article'] = $middle;
$this->apiResponse('1','成功',$final);
}
/**
* @title 两分钟视频
* @description 接口说明
* @author 开发者
* @url /api/portal/Index/video
* @method POST
*/
public function video(){
$where_video['status'] = 1;
$find = Db::name('Video')->where($where_video)->order('create_time desc')->find();
$this->apiResponse('1','成功',$find);
}
/**
* @title 首页二维码
* @description 接口说明
* @author 开发者
* @url /api/portal/Index/code
* @method POST
*/
public function code(){
$where_video['status'] = 1;
$find = Db::name('Qrcode')->where($where_video)->order('create_time desc')->select()->toArray();
if($find){
foreach ($find as $k=>$v){
$find[$k]['path'] = cmf_get_image_url($v['path']);
}
}
$this->apiResponse('1','成功',$find);
}
/**
* @title 首页推广
* @description 接口说明
* @author 开发者
* @url /api/portal/Index/share
* @method POST
*/
public function share(){
$where_push['status'] = 1;
$list = Db::name('Push')->where($where_push)->find();
$final['content'] = $list;
$this->apiResponse('1','成功',$final);
}
}