Classification.php
22.0 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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
<?php
namespace app\api\controller;
use app\api\model\Category;
use app\api\model\Goods;
use app\api\model\GoodsSpec;
use app\api\model\GoodsSpecRel;
use app\common\controller\Api;
use think\Config;
use think\Db;
/**
* 分类页面
*/
class Classification extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* @ApiTitle (分类列表)
* @ApiSummary (分类按钮页面左侧分类列表 其他页面切换到分类页面id不传值 分类页面点击分类id传值 后台返回高亮显示)
* @ApiMethod (POST)
* @ApiParams (name=id, type=integer, required=false, description="分类id")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
'data':[
{
"id": 4,
"name": "电子产品",
"is_myself": "0", 0不高亮1高亮
"image_text": ""
},
{
"id": 6,
"name": "水果",
"is_myself": "0",
"image_text": ""
}
]
})
*/
public function sort()
{
$id = $this->request->post('id', 0);
$model = new Category();
$list = $model->field('id,name')->order('weigh desc')->select();
foreach ($list as $key => &$value) {
$value['is_myself'] = $value['id'] == $id ? '1' : '0';
}
$this->success('分类列表', $list);
}
/**
* @ApiTitle (分类列表商品)
* @ApiSummary (分类按钮页面右侧商品列表 初次点击分类页面可不传分类id值)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=false, description="token")
* @ApiParams (name=sort_id, type=integer, required=false, description="分类id")
* @ApiParams (name=page, type=integer, required=false, description="页数")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
'data':{
"list": {
"total": 4, 总条数
"per_page": 10,每页数量
"current_page": 1,当前页
"last_page": 1,最后一页
"data": [
{
"goods_id": 21,
"goods_name": "小米Mix3",
"price": "100.00",
"line_price": "1000.00",划线价
"image_text": "图片路径",
"stock_num": 68, 商品总库存
}
]
},
"image": "广告图"
}
})
*/
public function sortGoodsList()
{
$sort_id = $this->request->post('sort_id', 0);
$page = $this->request->post('page', 1);
$model = new Goods();
if ($sort_id > 0) {
$list = $model
->where('is_delete', '0')
->where('category_id', $sort_id)
->where('goods_status', '10')
->field('goods_id,spec_type,goods_name,image')
->paginate(10, false, ['page' => $page])
->each(function ($item, $key) {
if ($this->auth->isLogin()) {
$item['cart_number'] = Db::name('cart')
->where('user_id', $this->auth->id)
->where('goods_id', $item['goods_id'])
->sum('number');
} else {
$item['cart_number'] = 0;
}
$goods_spec = Db::name('litestore_goods_spec')
->where('goods_id', $item['goods_id'])
->find();
$item['price'] = $goods_spec['goods_price'];
$item['line_price'] = $goods_spec['line_price'];
//判断是否打折
$item['is_discount'] = 'is';
if ($goods_spec['goods_price'] == $goods_spec['line_price']) {
$item['is_discount'] = 'no';
}
$item['discount'] = $goods_spec['discount'];
// 总库存
$item->append(['stock_num']);
});
} else {
$list = $model
->where('is_delete', '0')
->where('goods_status', '10')
->field('goods_id,goods_name,image')
->paginate(10, false, ['page' => $page])
->each(function ($item, $key) {
if ($this->auth->isLogin()) {
$item['cart_number'] = Db::name('cart')
->where('user_id', $this->auth->id)
->where('goods_id', $item['goods_id'])
->sum('number');
} else {
$item['cart_number'] = 0;
}
$goods_spec = Db::name('litestore_goods_spec')
->where('goods_id', $item['goods_id'])
->find();
$item['price'] = $goods_spec['goods_price'];
$item['line_price'] = $goods_spec['line_price'];
//判断是否打折
$item['is_discount'] = 'is';
if ($goods_spec['goods_price'] == $goods_spec['line_price']) {
$item['is_discount'] = 'no';
}
$item['discount'] = $goods_spec['discount'];
// 总库存
$item->append(['stock_num']);
});
}
$this->success('分类商品列表', ['list' => $list, 'image' => cdnurl(Config::get('site.advert'), true)]);
}
/**
* @ApiTitle (商品规格)
* @ApiMethod (POST)
* @ApiParams (name=goods_id, type=integer, required=true, description="商品id")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
'data':{
// 规格组合完毕的列表
// 如果sku是空数组 为单规格商品 只需要用list的值
"list": [
{
"goods_spec_id": 103, // 规格列表id
"goods_id": 22,
"goods_no": "SNHW001",
"goods_price": "4499.00",
"line_price": "0.00",
"stock_num": 941, // 库存
"goods_sales": 58,
"goods_weight": 500,
"spec_sku_id": "44_46", // 搜索字段 组合sku里面的id搜索 从小到大排序
"spec_image": "",
"create_time": 1542784591,
"update_time": 1543242861
}
],
// 规格展示的列表
"sku": [
{
"name": "颜色",
"second": [
{
"id": 44,
"name": "亮黑色"
}
]
},
{
"name": "内存",
"second": [
{
"id": 46,
"name": "6GB+64GB"
}
]
}
]
}
})
*/
public function goodsSku()
{
$goods_id = $this->request->post('goods_id');
$goodsspecrelmodel = new GoodsSpecRel();
$list = $goodsspecrelmodel
->where('goods_id', $goods_id)
->select();
$array = [];
$goods = \app\api\model\Goods::get($goods_id);
if ($goods['spec_type'] == 20) {
foreach ($list as $key => $value) {
if (!isset($array[$value['spec_id']])) {
$array[$value['spec_id']]['name'] = Db::name('litestore_spec')
->where('id', $value['spec_id'])
->value('spec_name');
}
$spec_value = Db::name('litestore_spec_value')
->where('id', $value['spec_value_id'])
->value('spec_value');
$array[$value['spec_id']]['second'][] = [
'id' => $value['spec_value_id'],
'name' => $spec_value,
];
}
$array = array_values($array);
}
$goods_spec = GoodsSpec::all(['goods_id' => $goods_id]);
$this->success('商品规格', ['list' => $goods_spec, 'sku' => $array]);
}
/**
* @ApiTitle (分类商品——二开)
* @ApiParams (name=sort_id, type=integer, required=false, description="分类id")
* @ApiParams (name=page, type=integer, required=false, description="页数")
* @ApiMethod (POST)
* @ApiReturn ({
"code": 1,
"msg": "分类商品列表",
"time": "1650252313",
"data": {
"list": {
"total": 2,
"per_page": 10,
"current_page": 1,
"last_page": 1,
"data": [
{
"goods_id": 41, //商品id
"goods_name": "黑人超白竹炭牙膏", //商品名称
"image": "/uploads/20220401/ff35da0c6cd2789f1f671d8ce1600b5d.png", //商品图
"cart_number": 0, //购物车数量
"price": "9.00", //折扣价格
"line_price": "10.00", //划线价
"is_discount": "is", //是否打折 is=打折(显示折扣) no= 未打折(不显示折扣)
"discount": "", //折扣
"goods_sku_list": [ //商品sku
{
"goods_spec_id": 273, //sku id
"goods_id": 41, //商品id
"goods_no": "4891338025416", //商品编号
"goods_price": "9.00", //折扣价
"line_price": "10.00", //划线价
"stock_num": 100, //库存
"goods_sales": 0,
"goods_weight": 0.09, //重量
"spec_sku_id": "",
"spec_image": "",
"create_time": 1648795163,
"update_time": 1648795163,
"discount": "" //折扣
}
],
"goods_sku": [], //sku值
"image_text": "http://temporaryfood.qiniu.broing.cn/uploads/20220401/ff35da0c6cd2789f1f671d8ce1600b5d.png",
"images_text": [],
"down_image_text": "",
"four_image_text": [],
"detail_image_text": [],
"stock_num": 100
},
{
"goods_id": 46,
"goods_name": "宇宙无敌",
"image": "/uploads/20220415/88ede89dc926c7556d4caeec2def0cb5.jpg",
"cart_number": 0,
"price": "150.00",
"line_price": "150.00",
"is_discount": "no",
"discount": "3.3折",
"goods_sku_list": [
{
"goods_spec_id": 309,
"goods_id": 46,
"goods_no": "wzry20220415",
"goods_price": "150.00",
"line_price": "150.00",
"stock_num": 2000,
"goods_sales": 0,
"goods_weight": 0,
"spec_sku_id": "2",
"spec_image": "http://temporaryfood.qiniu.broing.cn/uploads/20220415/12ccfc9ce3ab739b7468210e1cb03b34.jpg",
"create_time": 1650010750,
"update_time": 1650010750,
"discount": "3.3折"
},
{
"goods_spec_id": 310,
"goods_id": 46,
"goods_no": "wzry20220415",
"goods_price": "50.00",
"line_price": "150.00",
"stock_num": 2000,
"goods_sales": 0,
"goods_weight": 0,
"spec_sku_id": "3",
"spec_image": "http://temporaryfood.qiniu.broing.cn/uploads/20220415/4c51cd16c74d566e501b3dc32f4af563.jpg",
"create_time": 1650010750,
"update_time": 1650010750,
"discount": "3.3折"
},
{
"goods_spec_id": 311,
"goods_id": 46,
"goods_no": "wzry20220415",
"goods_price": "50.00",
"line_price": "150.00",
"stock_num": 2000,
"goods_sales": 0,
"goods_weight": 0,
"spec_sku_id": "4",
"spec_image": "http://temporaryfood.qiniu.broing.cn/uploads/20220415/88ede89dc926c7556d4caeec2def0cb5.jpg",
"create_time": 1650010750,
"update_time": 1650010750,
"discount": "3.3折"
},
{
"goods_spec_id": 312,
"goods_id": 46,
"goods_no": "wzry20220415",
"goods_price": "50.00",
"line_price": "150.00",
"stock_num": 2000,
"goods_sales": 0,
"goods_weight": 0,
"spec_sku_id": "5",
"spec_image": "http://temporaryfood.qiniu.broing.cn/uploads/20220415/6e3683dac095dd567fc527de8a2a7ba6.jpg",
"create_time": 1650010750,
"update_time": 1650010750,
"discount": "3.3折"
}
],
"goods_sku": [
{
"name": "分路",
"second": [
{
"id": 2,
"name": "上路"
},
{
"id": 3,
"name": "中路"
},
{
"id": 4,
"name": "下路"
},
{
"id": 5,
"name": "打野"
}
]
}
],
"image_text": "http://temporaryfood.qiniu.broing.cn/uploads/20220415/88ede89dc926c7556d4caeec2def0cb5.jpg",
"images_text": [],
"down_image_text": "",
"four_image_text": [],
"detail_image_text": [],
"stock_num": 8000
}
]
},
"image": "http://temporaryfood.qiniu.broing.cn/uploads/20220114/95d210316c68dcc4d4c13f5b605ca463.jpg"
}
})
*/
public function goods_list()
{
$sort_id = $this->request->param('sort_id', 0);
$page = $this->request->post('page', 1);
$model = new Goods();
if ($sort_id > 0) {
$list = $model
->where('is_delete', '0')
->where('category_id', $sort_id)
->where('goods_status', '10')
->field('goods_id,spec_type,goods_name,image')
->paginate(10, false, ['page' => $page])
->each(function (&$item) {
if ($this->auth->isLogin()) {
$item['cart_number'] = Db::name('cart')
->where('user_id', $this->auth->id)
->where('goods_id', $item['goods_id'])
->sum('number');
} else {
$item['cart_number'] = 0;
}
$goods_spec = Db::name('litestore_goods_spec')
->where('goods_id', $item['goods_id'])
->find();
$item['price'] = $goods_spec['goods_price'];
$item['line_price'] = $goods_spec['line_price'];
//判断是否打折
$item['is_discount'] = 'is';
if ($goods_spec['goods_price'] == $goods_spec['line_price']) {
$item['is_discount'] = 'no';
}
$item['discount'] = $goods_spec['discount'];
// 总库存
$item->append(['stock_num']);
//商品sku
$goodsspecrelmodel = new GoodsSpecRel();
$list = $goodsspecrelmodel
->where('goods_id', $item['goods_id'])
->select();
$array = [];
$goods = \app\api\model\Goods::get($item['goods_id']);
if ($goods['spec_type'] == 20) {
foreach ($list as $key => $value) {
if (!isset($array[$value['spec_id']])) {
$array[$value['spec_id']]['name'] = Db::name('litestore_spec')
->where('id', $value['spec_id'])
->value('spec_name');
}
$spec_value = Db::name('litestore_spec_value')
->where('id', $value['spec_value_id'])
->value('spec_value');
$array[$value['spec_id']]['second'][] = [
'id' => $value['spec_value_id'],
'name' => $spec_value,
];
}
$array = array_values($array);
}
$goods_spec = GoodsSpec::all(['goods_id' => $item['goods_id']]);
foreach ($goods_spec as &$spec_value) {
//规格下的购物车数量
$spec_value['cart_number'] = Db::name('cart')
->where(['goods_id' => $spec_value['goods_id'], 'sku_id' => $spec_value['goods_spec_id'], 'user_id' => $this->auth->id])
->value('number');
//判断是否打折
$spec_value['is_discount'] = 'is';
if ($spec_value['goods_price'] == $spec_value['line_price']) {
$spec_value['is_discount'] = 'no';
}
}
$item['goods_sku_list'] = $goods_spec;
$item['goods_sku'] = $array;
});
} else {
$list = $model
->where('is_delete', '0')
->where('goods_status', '10')
->field('goods_id,goods_name,spec_type,image')
->paginate(10, false, ['page' => $page])
->each(function (&$item) {
if ($this->auth->isLogin()) {
$item['cart_number'] = Db::name('cart')
->where('user_id', $this->auth->id)
->where('goods_id', $item['goods_id'])
->sum('number');
} else {
$item['cart_number'] = 0;
}
$goods_spec = Db::name('litestore_goods_spec')
->where('goods_id', $item['goods_id'])
->find();
$item['price'] = $goods_spec['goods_price'];
$item['line_price'] = $goods_spec['line_price'];
//判断是否打折
$item['is_discount'] = 'is';
if ($goods_spec['goods_price'] == $goods_spec['line_price']) {
$item['is_discount'] = 'no';
}
$item['discount'] = $goods_spec['discount'];
// 总库存
$item->append(['stock_num']);
//商品sku
$goodsspecrelmodel = new GoodsSpecRel();
$list = $goodsspecrelmodel
->where('goods_id', $item['goods_id'])
->select();
$array = [];
$goods = \app\api\model\Goods::get($item['goods_id']);
if ($goods['spec_type'] == 20) {
foreach ($list as $key => $value) {
if (!isset($array[$value['spec_id']])) {
$array[$value['spec_id']]['name'] = Db::name('litestore_spec')
->where('id', $value['spec_id'])
->value('spec_name');
}
$spec_value = Db::name('litestore_spec_value')
->where('id', $value['spec_value_id'])
->value('spec_value');
$array[$value['spec_id']]['second'][] = [
'id' => $value['spec_value_id'],
'name' => $spec_value,
];
}
$array = array_values($array);
}
$goods_spec = GoodsSpec::all(['goods_id' => $item['goods_id']]);
foreach ($goods_spec as &$spec_value) {
//规格下的购物车数量
$spec_value['cart_number'] = Db::name('cart')
->where(['goods_id' => $spec_value['goods_id'], 'sku_id' => $spec_value['goods_spec_id'], 'user_id' => $this->auth->id])
->value('number');
//判断是否打折
$spec_value['is_discount'] = 'is';
if ($spec_value['goods_price'] == $spec_value['line_price']) {
$spec_value['is_discount'] = 'no';
}
}
$item['goods_sku_list'] = $goods_spec;
$item['goods_sku'] = $array;
});
}
$this->success('分类商品列表', ['list' => $list, 'image' => cdnurl(Config::get('site.advert'), true)]);
}
/**
* @ApiTitle (商品分类——二开)
* @ApiMethod (POST)
* @ApiReturn ({
"code": 1,
"msg": "ok",
"time": "1650251148",
"data": [
{
"id": 22, //分类id
"name": "RIO 3度白桃白兰地味鸡尾酒", //分类名称
"category_cart_number": 0, //该分类下的用户加入购物车的数量,未登录时为0
"image_text": ""
},
{
"id": 21,
"name": "冷制品",
"category_cart_number": 0,
"image_text": ""
},
{
"id": 20,
"name": "饮料",
"category_cart_number": 0,
"image_text": ""
},
{
"id": 13,
"name": "悠闲零食",
"category_cart_number": 0,
"image_text": ""
},
{
"id": 14,
"name": "酒水",
"category_cart_number": 0,
"image_text": ""
},
{
"id": 15,
"name": "乳品烘培",
"category_cart_number": 0,
"image_text": ""
},
{
"id": 16,
"name": "粮油调味",
"category_cart_number": 0,
"image_text": ""
},
{
"id": 17,
"name": "生活百货",
"category_cart_number": 0,
"image_text": ""
},
{
"id": 19,
"name": "日化类",
"category_cart_number": 0,
"image_text": ""
}
]
})
*/
public function category_list()
{
$model = new Category();
$list = $model->field('id,name')->order('weigh desc')->select();
foreach ($list as $key => &$value) {
$model = new Goods();
if ($this->auth->isLogin()) {
$goods_list = $model
->where('is_delete', '0')
->where('category_id', $value['id'])
->where('goods_status', '10')
->field('goods_id')
->select()->toArray();
//如果该分类下没商品,则分类下购物车数量为零
if (empty($goods_list)) {
$value['category_cart_number'] = 0;
continue;
}
foreach ($goods_list as &$item) {
$value['category_cart_number'] = Db::name('cart')
->where('user_id', $this->auth->id)
// ->where('goods_id', $item['goods_id'])
->where('category_id', $value['id'])
->sum('number');
}
} else {
$value['category_cart_number'] = 0;
}
}
$this->success('ok', $list);
}
}