Goods.php
11.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
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
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Validate;
/**
* 商品接口
*/
class Goods extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
protected $uid = '';
public function _initialize()
{
parent::_initialize();
$this->uid = $this->auth->getUserId();
}
/**
* @ApiTitle (商品详情)
* @ApiSummary (商品详情)
* @ApiMethod (GET)
* @ApiRoute (/api/goods/goodsDetail)
*
* @ApiParams (name="goods_id", type="inter", required=true, description="商品id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1574993089",
"data": {
"id": 1,//商品id
"type": 1,
"t_id": 1,
"file": "http://jinglong.springchunjia.cn/uploads/20191127/05d216e117e11bd3de352c155b42eaaa.mp4",//视频路径
"name": "MONENT 动感系列",//商品名称
"name_en": "Monent dynamic series",//商品名称(英文)
"new_price": 2499,//新人价格
"sale_price": 2599,//销售价格
"market_price": 2699,//市场价格
"expense_price": 0,//运费(0:显示包运费标签)
"style": [//商品规格
"主餐匙,茶匙各1件",
"古堡灰"
],
"tag": [//商品标签
"AB级",
"ABX级",
"ABN级"
],
"stock": 100,//商品库存
"introduce": "轻波款,为客厅缀上霞光淡雾",//商品简介
"detail": "",//商品详情(富文本)
"frame": [//视频第一到第六帧图片(无视频返回空数组)
"http://jinglong.springchunjia.cn/uploads/20191127/05d216e117e11bd3de352c155b42eaaa.mp4?vframe/jpg/offset/1",
"http://jinglong.springchunjia.cn/uploads/20191127/05d216e117e11bd3de352c155b42eaaa.mp4?vframe/jpg/offset/2",
"http://jinglong.springchunjia.cn/uploads/20191127/05d216e117e11bd3de352c155b42eaaa.mp4?vframe/jpg/offset/3",
"http://jinglong.springchunjia.cn/uploads/20191127/05d216e117e11bd3de352c155b42eaaa.mp4?vframe/jpg/offset/4",
"http://jinglong.springchunjia.cn/uploads/20191127/05d216e117e11bd3de352c155b42eaaa.mp4?vframe/jpg/offset/5",
"http://jinglong.springchunjia.cn/uploads/20191127/05d216e117e11bd3de352c155b42eaaa.mp4?vframe/jpg/offset/6"
],
"b_type": {//所属品牌(品类则返回空字符串)
"id": 1,//品牌id
"image": "http://jinglong.springchunjia.cn/uploads/20191127/d36d8475bc3bdb999dff26d019c608ed.png",//品牌图片路径
"name": "HEDRMAR1",//品牌名称
"address": "葡萄牙1"//品牌所属地
}
}
})
*/
public function goodsDetail(){
if($this->request->isGet()){
$goods_id = $this->request->get('goods_id');
$rule = config('verify.goods_detail');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['goods_id'=>$goods_id])) {
$this->error($validate->getError());
}
$res = Common::findSoftWhereData('goods',['id'=>$goods_id],'type_name,is_design,is_recommend,sort,image,createtime,updatetime,deletetime,flag,hots,sales',true);
if($res){
if($res['file']){
//图片取视频帧
$frame = [];
for($i=1;$i<7;$i++){
$image_url = $this->auth->absolutionUrlOneFrame($res['file'],$i);
array_push($frame,$image_url);
}
$res['frame'] = $frame;
$res['file'] = $this->auth->absolutionUrlOne($res['file']);
}else{
$res['frame'] = [];
$res['file'] = '';
}
$res['style'] = explode('|',$res['style']);
$res['tag'] = explode('|',$res['tag']);
//所属品牌分类
if($res['type'] == 1){
//查询所属品牌
$b_type = Common::findSoftWhereData('btype',['id'=>$res['t_id']],'id,image,name,address');
$b_type['image'] = $this->auth->absolutionUrlOne($b_type['image']);
$res['b_type'] = $b_type;
}else{
$res['b_type'] = '';
}
//浏览商品增加次数
$goodsModel = new \app\admin\model\Goods();
$goodsModel->where(['id'=>$goods_id])->setInc('hots',1);
}
$this->success('成功',$res);
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (别人也在看商品列表)
* @ApiSummary (别人也在看商品列表)
* @ApiMethod (GET)
* @ApiRoute (/api/goods/otherBrowseGoodsList)
*
* @ApiParams (name="goods_id", type="inter", required=true, description="商品id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1574941706",
"data": {
"data": [
{
"id": 7,//商品id
"image": "http://jinglong.springchunjia.cn/uploads/20191128/8a677f5a0418059bf1b974c50026af13.png",//图片路径
"name": "MONENT 动感系列",//商品名称
"tag": [//商品标签
"日式简约",
"隐秘乡奢",
"家庭情侣"
],
"new_price": 2199,//新人价格(未登录,未购买记录(个人中心返是否有购买记录),显示该字段,另加“新人价”标签)
"sale_price": 2299//销售价格
"expense_price": //运费(0:显示包运费标签)
},
{
"id": 4,
"image": "http://jinglong.springchunjia.cn/uploads/20191128/93971e55b83d1a09c1831f8197514305.png",
"name": "MONENT 动感系列",
"tag": [
"AB级",
"ABX级",
"ABN级"
],
"new_price": 2499,
"sale_price": 2599
},
],
"total_page": 1
}
})
*/
public function otherBrowseGoodsList(){
if($this->request->isGet()){
$goods_id = $this->request->get('goods_id');
$rule = config('verify.goods_detail');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['goods_id'=>$goods_id])) {
$this->error($validate->getError());
}
$result = Common::findSoftWhereData('goods',['id'=>$goods_id],'id,type,t_id');
$where = [];
if($result){
$where['type'] = $result['type'];
$where['t_id'] = $result['t_id'];
$where['id'] = ['<>',$result['id']];
}
$res = Common::selectSoftWhereLimitData('goods',$where,'id,image,name,tag,new_price,sale_price,expense_price');
foreach ($res as &$value){
$value['image'] = $this->auth->absolutionUrlOne($value['image']);
$value['tag'] = explode('|',$value['tag']);
}
$this->success('成功',$res);
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (品类商品列表)
* @ApiSummary (品类商品列表)
* @ApiMethod (GET)
* @ApiRoute (/api/goods/sortGoodsList)
*
* @ApiParams (name="s_id", type="inter", required=true, description="品类分类id")
*
* @ApiParams (name="hots", type="inter", required=false, description="商品热度排序(1:降序,2:升序)")
* @ApiParams (name="sales", type="inter", required=false, description="商品销量排序(1:降序,2:升序)")
* @ApiParams (name="price", type="inter", required=false, description="商品价格排序(1:降序,2:升序)")
*
* @ApiParams (name="page", type="inter", required=true, description="分页页码")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1574941706",
"data": {
"data": [
{
"id": 7,//商品id
"image": "http://jinglong.springchunjia.cn/uploads/20191128/8a677f5a0418059bf1b974c50026af13.png",//图片路径
"name": "MONENT 动感系列",//商品名称
"tag": [//商品标签
"日式简约",
"隐秘乡奢",
"家庭情侣"
],
"style": [//商品规格
"主餐匙,茶匙各1件",
"古堡灰"
],
"new_price": 2199,//新人价格(未登录,未购买记录(个人中心返是否有购买记录),显示该字段,另加“新人价”标签)
"sale_price": 2299//销售价格
"expense_price": //运费(0:显示包运费标签)
},
{
"id": 4,
"image": "http://jinglong.springchunjia.cn/uploads/20191128/93971e55b83d1a09c1831f8197514305.png",
"name": "MONENT 动感系列",
"tag": [
"AB级",
"ABX级",
"ABN级"
],
"new_price": 2499,
"sale_price": 2599
},
],
"total_page": 1
}
})
*/
public function sortGoodsList(){
if($this->request->isGet()){
$s_id = $this->request->get('s_id');
$page = $this->request->get('page');
$rule = config('verify.sort_goods');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['s_id'=>$s_id,'page'=>$page])) {
$this->error($validate->getError());
}
//排序
$hots = $this->request->get('hots');
$sales = $this->request->get('sales');
$price = $this->request->get('price');
$order = 'id desc';
if($hots){
if($hots == 1){
$order = 'hots desc,id desc';
}else if($hots == 2){
$order = 'hots asc';
}
}else if($sales){
if($sales == 1){
$order = 'sales desc,id desc';
}else if($sales == 2){
$order = 'sales asc';
}
}else if($price){
}
$where = ['type'=>0,'t_id'=>$s_id];
$limit = config('verify.goods_limit');
$arr = Common::goodsList($where,$page,$limit,$order);
$this->success('成功',$arr);
}else{
$this->error('请求方式错误');
}
}
}