Goods.php
20.5 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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
<?php
namespace app\api\controller;
use addons\shopro\exception\Exception;
/**
* 商品接口
*/
class Goods extends Base
{
protected $noNeedLogin = ['index', 'detail', 'lists', 'activity', 'seckillList', 'grouponList', 'store'];
protected $noNeedRight = ['*'];
/**
* @ApiInternal
* 测试
*/
public function index()
{
// 测试,下面代码可删除
// $redis = $this->getRedis();
// $redis->HSET('aaaaa', 'bbb', 'smallnews');
// // 获取活动集合
// $hashList = $redis->ZRANGE('aaaaa', 0, 999999999);
// var_dump($hashList);
// $user = \addons\shopro\model\User::where('id', 57)->find();
// $user->notify(
// new \addons\shopro\notifications\Order([
// // 'order' => \addons\shopro\model\Order::where('id', 359)->find(),
// // 'item' => \addons\shopro\model\OrderItem::where('id', 390)->find(),
// 'order' => \addons\shopro\model\Order::where('id', 349)->find(),
// 'item' => \addons\shopro\model\OrderItem::where('id', 380)->find(),
// 'event' => 'order_sended'
// ])
// );
// $user = \addons\shopro\model\User::where('id', 2)->find();
// $user->notify(
// new \addons\shopro\notifications\Aftersale([
// 'aftersale' => \addons\shopro\model\OrderAftersale::get(6),
// 'order' => \addons\shopro\model\Order::get(115),
// 'aftersaleLog' => \addons\shopro\model\OrderAftersaleLog::get(9),
// 'event' => 'aftersale_change'
// ])
// );
// $user = \addons\shopro\model\User::where('id', 2)->find();
// $user->notify(
// new \addons\shopro\notifications\Wallet([
// 'apply' => \addons\shopro\model\UserWalletApply::get(1),
// 'event' => 'wallet_apply'
// ])
// );
// $user = \addons\shopro\model\User::where('id', 2)->find();
// $user->notify(
// new \addons\shopro\notifications\Wallet([
// 'walletLog' => \addons\shopro\model\UserWalletLog::get(1),
// 'event' => 'wallet_change'
// ])
// );
// $user = \addons\shopro\model\User::where('id', 2)->find();
// $user->notify(
// new \addons\shopro\notifications\store\Order([
// 'store' => \addons\shopro\model\Store::get(1),
// 'order' => \addons\shopro\model\Order::get(83),
// 'event' => 'store_order_new'
// ])
// );
}
/**
* @ApiWeigh (97)
* @ApiTitle (商品详情)
* @ApiSummary (商品详情)
* @ApiMethod (GET)
*
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=id, type=inter, required=true, description="商品ID")
*
* @ApiReturn({
"code": 1,
"msg": "商品详情",
"time": "1607678789",
"data": {
"id": 1, //商品ID
"type": "normal",
"title": "测试商品", //商品名称
"subtitle": "测试啊", //副标题
"weigh": 0,
"category_ids": "3",
"image": "http://www.ant.top/assets/img/qrcode.png", //商品主图
"images": [ //轮播图
"http://www.ant.top/uploads/20201211/ceaf516172280f5da413fb020bf777c9.png"
],
"params": [{
"title": "50",
"content": "123"
}],
"content": "", //详情
"price": "0.01", //现价
"original_price": "10000.00", //划线价
"is_sku": 0, //是否多规格:0=否,1=是
"likes": 0, //收藏数量
"views": 2, //浏览量
"sales": 0, //销量
"show_sales": 0, //显示销量
"service_ids": "",
"dispatch_type": "express",
"dispatch_ids": "1",
"deletetime": null,
"activity": { //活动信息
"id": 7,
"title": "秒杀测试",
"type": "seckill",
"richtext_id": 0,
"richtext_title": "",
"starttime": 1607616000,
"endtime": 1607702400,
"rules": {
"limit_buy": "1",
"order_auto_close": "",
"activity_auto_close": ""
}
},
"activity_type": "seckill",
"sku_price": [{ //规格信息
"id": 1,
"goods_sku_ids": null,
"goods_id": 1,
"weigh": 0,
"image": null,
"stock": 20,
"sales": 0,
"sn": "",
"weight": 0,
"price": "0.01",
"goods_sku_text": null,
"status": "up",
"activity_type": "seckill",
"activity_id": 7,
"item_goods_sku_price": {
"id": 4,
"activity_id": 7,
"sku_price_id": 1,
"goods_id": 1,
"stock": 20,
"sales": 0,
"price": "0.01",
"status": "up"
},
"goods_sku_id_arr": [
""
]
}],
"stock": 20,
"favorite": null,
"dispatch_type_arr": [
"express"
],
"service": [{ //服务标签
"id": 4, //标签ID
"name": "极速退款", //名称
"image": "http://api.7wpp.com/uploads/20200222/57d971eb5984317ee794e531ea0f9207.png", //图片
"description": "超快无审核退款流程" //描述
}],
"sku": [{ //规格
"id": 1,
"name": "颜色", //一级规格名称
"pid": 0,
"goods_id": 4,
"weigh": 0,
"content": [{ //二级规格
"id": 2, //规格ID
"name": "黄色", //名称
"pid": 1,
"goods_id": 4,
"weigh": 0
}]
}],
"coupons": []
}
})
*/
public function detail()
{
$id = $this->request->get('id');
$detail = \addons\shopro\model\Goods::getGoodsDetail($id);
// 记录足记
\addons\shopro\model\UserView::addView($detail);
$sku_price = $detail['sku_price']; // 处理过的规格
// tp bug json_encode 或者 toArray 的时候 sku_price 会重新查询数据库,导致被处理过的规格又还原回去了
$detail = json_decode(json_encode($detail), true);
$detail['sku_price'] = $sku_price;
$this->success('商品详情', $detail);
}
/**
* @ApiWeigh (99)
* @ApiTitle (商品列表)
* @ApiSummary (商品列表)
* @ApiMethod (GET)
*
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=order, type=string, required=false, description="排序:{'defaultOrder':0,'priceOrder':0,'salesOrder':1,'newProdcutOrder':0},defaultOrder为1=默认,priceOrder为1=价格从低到高,priceOrder为2=从高到低,salesOrder为1=销量,newProdcutOrder为1=最新上架")
* @ApiParams (name=keyword, type=string, required=false, description="搜索关键字")
* @ApiParams (name=category_id, type=inter, required=false, description="分类ID")
* @ApiParams (name=page, type=inter, required=false, description="分页页码")
*
* @ApiReturn({
"code": 1,
"msg": "商品列表",
"time": "1607675191",
"data": {
"total": 2,
"per_page": 10,
"current_page": 1,
"last_page": 1,
"data": [{
"id": 1, //商品ID
"type": "normal", //类型:nomal=正常,hidden=隐藏
"title": "测试商品", //商品名称
"subtitle": "测试啊", //商品小名称
"weigh": 0, //权重
"category_ids": "3", //所属分类ID
"image": "http://www.ant.top/assets/img/qrcode.png", //商品主图
"price": "0.01", //现价
"original_price": "10000.00", //划线价格
"is_sku": 0, //是否多规格:0=否,1=是
"likes": 0, //收藏人数
"views": 2, //浏览人数
"sales": 0, //销量
"show_sales": 0, //显示销量
"dispatch_type": "express", //发货方式:express=物流快递
"dispatch_ids": "1", //发货模板ID
"deletetime": null,
"activity": { //活动
"id": 7, //活动ID
"title": "秒杀测试", //活动名称
"type": "seckill", //活动类型:seckill=秒杀,groupon=拼团
"richtext_id": 0,
"richtext_title": "",
"starttime": 1607616000,
"endtime": 1607702400,
"rules": {
"limit_buy": "1",
"order_auto_close": "",
"activity_auto_close": ""
}
},
"activity_type": "seckill", //活动类型:seckill=秒杀,groupon=拼团
"sku_price": [{ //规格价格
"id": 1, //规格价格ID
"goods_sku_ids": null, //商品规格ID集合
"goods_id": 1, //商品ID
"weigh": 0,
"image": null, //规格图片
"stock": 20, //库存
"sales": 0, //销量
"sn": "",
"weight": 0,
"price": "0.01", //价格
"goods_sku_text": null, //中文规格
"status": "up", //状态:up=上架
"activity_type": "seckill", //活动类型:seckill=秒杀,grupon=拼团
"activity_id": 7, //活动ID
"item_goods_sku_price": {
"id": 4,
"activity_id": 7,
"sku_price_id": 1,
"goods_id": 1,
"stock": 20,
"sales": 0,
"price": "0.01",
"status": "up"
},
"goods_sku_id_arr": [
""
]
}],
"stock": 20, //库存
"dispatch_type_arr": [
"express"
]
}]
}
})
*/
public function lists()
{
$params = $this->request->get();
$data = \addons\shopro\model\Goods::getGoodsList($params);
$this->success('商品列表', $data);
}
/**
* @ApiInternal
* 获取商品支持的 自提点
*/
public function store()
{
$params = $this->request->get();
$data = \addons\shopro\model\Goods::getGoodsStore($params);
$this->success('自提列表', $data);
}
/**
* @ApiWeigh (95)
* @ApiTitle (秒杀列表)
* @ApiSummary (秒杀列表)
* @ApiMethod (GET)
*
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=type, type=string, required=false, description="类型:all=全部,ing=进行中,nostart=未开始,ended=已结束,tomorrow=明日预告")
*
* @ApiReturn({
"code": 1,
"msg": "秒杀商品列表",
"time": "1607734877",
"data": {
"total": 1, //数据总数
"per_page": 10,
"current_page": 1,
"last_page": 1,
"data": [{
"id": 1, //商品ID
"type": "normal",
"title": "测试商品", //标题
"subtitle": "测试啊", //副标题
"weigh": 0,
"category_ids": "3", //所属分类ID
"image": "http://www.ant.top/assets/img/qrcode.png", //商品主图
"price": "0.01", //商品价格
"original_price": "10000.00", //原价
"is_sku": 0,
"likes": 0,
"views": 3,
"sales": 0, //销量
"show_sales": 0, //显示销量
"dispatch_type": "express",
"dispatch_ids": "1",
"deletetime": null,
"activity": {
"id": 7, //活动ID
"title": "秒杀测试", //活动标题
"type": "seckill", //活动类型:seckill=秒杀,groupon=拼团
"richtext_id": 0,
"richtext_title": "",
"starttime": 1607616000,
"endtime": 1607702400,
"rules": {
"limit_buy": "1", //每人限购件数
"order_auto_close": "",
"activity_auto_close": ""
}
},
"activity_type": "seckill",
"sku_price": [{
"id": 1,
"goods_sku_ids": null,
"goods_id": 1,
"weigh": 0,
"image": null,
"stock": 20,
"sales": 0,
"sn": "",
"weight": 0,
"price": "0.01",
"goods_sku_text": null,
"status": "up",
"activity_type": "seckill",
"activity_id": 7,
"item_goods_sku_price": {
"id": 4,
"activity_id": 7,
"sku_price_id": 1,
"goods_id": 1,
"stock": 20,
"sales": 0,
"price": "0.01",
"status": "up"
},
"goods_sku_id_arr": [
""
]
}],
"stock": 20,
"dispatch_type_arr": [
"express"
]
}]
}
})
*/
public function seckillList() {
$params = $this->request->get();
$this->success('秒杀商品列表', \addons\shopro\model\Goods::getSeckillGoodsList($params));
}
/**
* @ApiWeigh (93)
* @ApiTitle (拼团列表)
* @ApiSummary (拼团列表)
* @ApiMethod (GET)
*
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=type, type=string, required=false, description="类型:all=全部,ing=进行中,nostart=未开始,ended=已结束,tomorrow=明日预告")
*
* @ApiReturn({
"code": 1,
"msg": "拼团商品列表",
"time": "1608039147",
"data": {
"total": 1, //数据总数
"per_page": 10,
"current_page": 1,
"last_page": 1,
"data": [{
"id": 2, //商品ID
"type": "normal",
"title": "测试商品2", //商品标题
"subtitle": "测试啊啊", //商品副标题
"weigh": 0,
"category_ids": "3",
"image": "http://www.ant.top/uploads/20201211/8894d62100f2f920ffb2f38063b63f2d.jpg", //商品主图
"price": "0.02", //现价
"original_price": "1000.00", //原价
"is_sku": 0, //是否多规格:0=否,1=是
"likes": 0,
"views": 1,
"sales": 0,
"show_sales": 0, //显示销量
"dispatch_type": "express",
"dispatch_ids": "1",
"deletetime": null,
"activity": {
"id": 9, //活动ID
"title": "拼团测试", //活动标题
"type": "groupon", //活动类型:seckill=秒杀,groupon=拼团
"richtext_id": 0,
"richtext_title": "",
"starttime": 1607616000,
"endtime": 1607702400,
"rules": { //活动规则
"limit_buy": "1", //每人限购件数
"order_auto_close": "",
"activity_auto_close": "",
"team_num": "2", //成团人数
"is_alone": "0", //是否允许单独购买
"is_fictitious": "0",
"fictitious_num": "",
"valid_time": "",
"team_card": "0"
}
},
"activity_type": "groupon",
"groupon_price": "0.01",
"sku_price": [{
"id": 2,
"goods_sku_ids": null,
"goods_id": 2,
"weigh": 0,
"image": null,
"stock": 10,
"sales": 0,
"sn": "",
"weight": 0,
"price": "0.02",
"goods_sku_text": null,
"status": "up",
"groupon_price": "0.01",
"activity_type": "groupon",
"activity_id": 9,
"item_goods_sku_price": {
"id": 5,
"activity_id": 9,
"sku_price_id": 2,
"goods_id": 2,
"stock": 10,
"sales": 0,
"price": "0.01",
"status": "up"
},
"goods_sku_id_arr": [
""
]
}],
"stock": 10,
"dispatch_type_arr": [
"express"
]
}]
}
})
*/
public function grouponList() {
$params = $this->request->get();
$this->success('拼团商品列表', \addons\shopro\model\Goods::getGrouponGoodsList($params));
}
/**
* @ApiInternal
* 活动列表
*/
public function activity()
{
$activity_id = $this->request->get('activity_id');
$activity = \addons\shopro\model\Activity::get($activity_id);
if (!$activity) {
throw new Exception('活动不存在', -1);
}
$goods = \addons\shopro\model\Goods::getGoodsList(['goods_ids' => $activity->goods_ids]);
$activity->goods = $goods;
$this->success('活动列表', $activity);
}
/**
* @ApiWeigh (93)
* @ApiTitle (收藏或取消收藏)
* @ApiSummary (收藏或取消收藏)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=goods_id, type=inter, required=false, description="商品ID")
* @ApiParams (name=goods_ids, type=inter, required=false, description="商品ID集合,批量删除时可用")
*
* @ApiReturn({
"code": 1,
"msg": "收藏成功|取消收藏",
"time": "1608039147",
"data": null
})
*/
public function favorite()
{
$params = $this->request->post();
$result = \addons\shopro\model\UserFavorite::edit($params);
$this->success($result ? '收藏成功' : '取消收藏', $result);
}
/**
* @ApiInternal
* 商品收藏列表
*/
public function favoriteList()
{
$data = \addons\shopro\model\UserFavorite::getGoodsList();
$this->success('商品收藏列表', $data);
}
/**
* @ApiInternal
* 浏览记录删除
*/
public function viewDelete()
{
$params = $this->request->post();
$result = \addons\shopro\model\UserView::del($params);
$this->success('删除成功', $result);
}
/**
* @ApiInternal
* 浏览记录列表
*/
public function viewList()
{
$data = \addons\shopro\model\UserView::getGoodsList();
$this->success('商品浏览列表', $data);
}
}