SeriesController.php
7.3 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
<?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 api\home\controller;
use cmf\controller\RestBaseController;
use think\Db;
use think\Validate;
use app\portal\model\PortalPostModel;
/**
* @title 产品系列
*/
class SeriesController extends RestBaseController
{
/**
* @title 产品系列分类
* @description 接口说明
* @author 开发者
* @url /api/home/series/seriesType
* @method GET
*
* @param name:language type:string require:0 default: other desc:语言切换(英文传递此字段(en),中文无需传递)
*
* @return data:一级分类@
* @data id:一级分类id thumbnail:图片路径 name:一级分类名称 children:子类@
* @children id:二级分类id thumbnail:图片路径 name:二级分类名称
*/
public function seriesType(){
$language = $this->request->param('language');
if(isset($language) && !empty($language)){
//英文
$field_type = 'id,pid,thumbnail,name_en name';
}else{
//中文
$field_type = 'id,pid,thumbnail,name';
}
$parent_res = CommonController::findSeriesType($field_type);
$this->success('成功',['data'=>$parent_res]);
}
/**
* @title 产品系列列表(一级分类查找)
* @description 接口说明
* @author 开发者
* @url /api/home/series/seriesListByParent
* @method GET
*
* @param name:language type:string require:0 default: other desc:语言切换(英文传递此字段(en),中文无需传递)
* @param name:parent_id type:inter require:1 default: other desc:一级分类id
* @param name:page type:inter require:1 default: other desc:分页页码
*
* @return data:产品系列列表@
* @data id:产品系列id thumbnail:图片路径 title:系列名称
*
* @return count_page:总页码
*/
public function seriesListByParent(){
$language = $this->request->param('language');
$parent_id = $this->request->param('parent_id');//二级分类id
$page = $this->request->param('page');//分页
//验证
$rule = config('site.parent_id');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['parent_id'=>$parent_id,'page'=>$page])) {
$this->error($validate->getError());
}
if(isset($language) && !empty($language)){
//英文
$field_series = 'id,thumbnail,title_en title';
}else{
//中文
$field_series = 'id,thumbnail,title';
}
//查找二级分类
$type = CommonController::selectData('type',['pid'=>$parent_id],'id');
$children_ids = array_column($type,'id');
$limit = CommonController::series_limit;
$res = Db::name('series')
->whereIn('t_id',$children_ids);
$data = $res->field($field_series)
->page($page,$limit)
->order('id desc')
->select()
->toArray();
$count = $res->count()/$limit;
$count_page = ceil($count/$limit);
$this->success('成功',['data'=>$data,'count_page'=>$count_page]);
}
/**
* @title 产品系列列表(二级分类查找)
* @description 接口说明
* @author 开发者
* @url /api/home/series/seriesListBySon
* @method GET
*
* @param name:language type:string require:0 default: other desc:语言切换(英文传递此字段(en),中文无需传递)
* @param name:children_id type:inter require:1 default: other desc:二级分类id
* @param name:page type:inter require:1 default: other desc:分页页码
*
* @return data:产品系列列表@
* @data id:产品系列id thumbnail:图片路径 title:系列名称
*
* @return count_page:总页码
*/
public function seriesListBySon(){
$language = $this->request->param('language');
$children_id = $this->request->param('children_id');//二级分类id
$page = $this->request->param('page');//分页
//验证
$rule = config('site.children_id');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['children_id'=>$children_id,'page'=>$page])) {
$this->error($validate->getError());
}
if(isset($language) && !empty($language)){
//英文
$field_series = 'id,thumbnail,title_en title';
}else{
//中文
$field_series = 'id,thumbnail,title';
}
$limit = CommonController::series_limit;
$res = Db::name('series')
->where(['t_id'=>$children_id]);
$data = $res->field($field_series)
->page($page,$limit)
->order('id desc')
->select()
->toArray();
$count = $res->count()/$limit;
$count_page = ceil($count/$limit);
$this->success('成功',['data'=>$data,'count_page'=>$count_page]);
}
/**
* @title 产品系列详情
* @description 接口说明
* @author 开发者
* @url /api/home/series/seriesDetail
* @method GET
*
* @param name:language type:string require:0 default: other desc:语言切换(英文传递此字段(en),中文无需传递)
* @param name:series_id type:inter require:1 default: other desc:产品系列id
*
* @return data:产品系列列表@
* @data id:产品系列id thumbnail:图片路径 title:系列名称 detail:详情(富文本) hotline:电话咨询
*
* @return parent_name:一级分类名称
*/
public function seriesDetail(){
$language = $this->request->param('language');
$series_id = $this->request->param('series_id');//列表id
//验证
$rule = config('site.series_id');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['series_id'=>$series_id])) {
$this->error($validate->getError());
}
if(isset($language) && !empty($language)){
//英文
$field_series = 'id,t_id,thumbnail,title_en title,detail_en detail,hotline';
$flag = 'name_en name';
}else{
//中文
$field_series = 'id,t_id,thumbnail,title,detail,hotline';
$flag = 'name';
}
$res = CommonController::findData('series',['id'=>$series_id],$field_series);
//查找父类名称
$pid = CommonController::findData('type',['id'=>$res['t_id']],'pid');
$parent_name = CommonController::findData('type',['id'=>$pid['pid']],$flag);
if($res){
$contentModel = new PortalPostModel();
$res['detail'] = $contentModel->getPostContentAttr($res['detail']);
}
$this->success('成功',['data'=>$res,'parent_name'=>$parent_name['name']]);
}
}