IndexController.php
4.6 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
<?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)
{
// 1.首页轮播
$where_banner['status'] = 1;
$final['banner'] = Db::name('Banner')->where($where_banner)
->field("pic")
->order("score desc,create_time desc")->select()->toArray();
// 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. 最新成交
// 4. 合作企业
$where_coo['status'] = 1;
$final['coop'] = Db::name('Cooperation')->where($where_coo)->order("score desc , create_time desc")->field('pic,jump')->select()->toArray();
// 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);
}
}