IndexController.php
5.7 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
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\home\controller;
use cmf\controller\RestBaseController;
use think\Db;
use think\Validate;
/**
* @title 首页
*/
class IndexController extends RestBaseController
{
/**
* @title 首页
* @description 接口说明
* @author 开发者
* @url /api/home/index/index
* @method GET
*
* @param name:language type:string require:0 default: other desc:语言切换(英文传递此字段(en),中文无需传递)
*
* @return rotation:轮播图@
* @rotation id:轮播图id thumbnail:图片路径 thumbnail_mobile:移动图片路径 link:立即查看链接
*
* @return about:关于我们@!
* @about id:关于我们id thumbnail:图片路径 introduce:简介
*
* @return type:我们的产品@
* @type id:产品id thumbnail:图片路径 name:分类名称 children_name:分类子名称
*
* @return advantage:我们的优势@
* @advantage id:优势id title:标题 introduce:简介
*
* @return contact:联系我们@!
* @contact id:联系我们id address:地址 mobile:电话 phone:手机 wx:微信 email:邮箱
*/
public function index(){
$language = $this->request->param('language');
$arr = [];
//轮播图
$res_rotation = CommonController::selectNoPositionData('rotation','id,thumbnail,thumbnail_mobile,link');
$arr['rotation'] = $res_rotation;
//关于我们
if(isset($language) && !empty($language)){
//英文
$field_about = 'id,thumbnail,introduce_en introduce';
}else{
//中文
$field_about = 'id,thumbnail,introduce';
}
$res_about = CommonController::findData('about',['id'=>1],$field_about);
$arr['about'] = $res_about;
//我们的产品(系列)
if(isset($language) && !empty($language)){
//英文
$field_type = 'id,pid,thumbnail,name_en name';
$flag = 'name';
}else{
//中文
$field_type = 'id,pid,thumbnail,name';
$flag = 'name';
}
$res_type = CommonController::getSeriesType($field_type,$flag);
$arr['type'] = $res_type;
//我们的优势
if(isset($language) && !empty($language)){
//英文
$field_advantage = 'id,title_en title,introduce_en introduce';
}else{
//中文
$field_advantage = 'id,title,introduce';
}
$res_advantage = CommonController::selectLimitData('advantage',$field_advantage,3);
$arr['advantage'] = $res_advantage;
//联系我们
if(isset($language) && !empty($language)){
//英文
$field_contact = 'id,address_en address,mobile,phone,wx,email';
}else{
//中文
$field_contact = 'id,address,mobile,phone,wx,email';
}
$res_contact = CommonController::findData('contact',['id'=>1],$field_contact);
$arr['contact'] = $res_contact;
$this->success('成功',$arr);
}
/**
* @title 七牛云域名
* @description 接口说明
* @author 开发者
* @url /api/home/index/qiNiuDomain
* @method GET
*
* @return domain:七牛云域名
*/
public function qiNiuDomain(){
//七牛域名
$arr['domain'] = CommonController::domain;
$this->success('成功',$arr);
}
/**
* @title 搜索产品系列(若没有数据提示:暂无数据,请联系客服)
* @description 接口说明
* @author 开发者
* @url /api/home/index/searchSeriesList
* @method GET
*
* @param name:language type:string require:0 default: other desc:语言切换(英文传递此字段(en),中文无需传递)
* @param name:keyword type:string require:1 default: other desc:关键字
* @param name:page type:inter require:1 default: other desc:分页页码
*
* @return data:产品系列列表@
* @data id:产品系列id thumbnail:图片路径 title:系列名称
*
* @return count_page:总页码
*/
public function searchSeriesList(){
$language = $this->request->param('language');
$keyword = $this->request->param('keyword');
$page = $this->request->param('page');//分页
//验证
$rule = config('site.search');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['keyword'=>$keyword,'page'=>$page])) {
$this->error($validate->getError());
}
if(isset($language) && !empty($language)){
//英文
$field_series = 'id,thumbnail,title_en title';
$where = ['title_en'=>['like','%'.$keyword.'%']];
}else{
//中文
$field_series = 'id,thumbnail,title';
$where = ['title'=>['like','%'.$keyword.'%']];
}
//查找二级分类
$limit = CommonController::series_limit;
$data = Db::name('series')
->where($where)->field($field_series)
->page($page,$limit)
->order('id desc')
->select()
->toArray();
$count = Db::name('series')->where($where)->count();
$count_page = ceil($count/$limit);
$this->success('成功',['data'=>$data,'count_page'=>$count_page]);
}
}