Goods.php
4.9 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
<?php
namespace app\api\controller;
use app\api\model\GoodsComment;
use app\api\model\GoodsSpec;
use app\api\model\GoodsSpecRel;
use app\common\controller\Api;
use think\Db;
/**
* 商品页面
*/
class Goods extends Api
{
protected $noNeedRight = ['*'];
protected $noNeedLogin = ['*'];
/**
* @ApiTitle (商品详情)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=goods_id, type=integer, required=true, description="商品id")
* @ApiReturn ({
'code':'1',
'msg':'商品详情'
'data':{
"goods_id": 22,商品id
"goods_name": "Mate 20 华为 HUAWEI ",
"spec_type": "20", 10=单规格20=多规格
"brand": null, 品牌
"makefor": null, 进口国产
"packing": null, 包装方式
"keep": null, 保存条件
"number": null, 编号
"price_description": null, 价格说明
"sales_actual": 64, 销量
"price": "4499.00", 价格
"line_price": "0.00", 划线价
"images_text": [
轮播图
],
"down_image_text": "底部图",
"four_image_text": [
四宫格图
]
}
})
*/
public function goodsDetail()
{
$goods_id = $this->request->post('goods_id');
$goodsmodel = new \app\api\model\Goods();
if (!is_numeric($goods_id)){
$this->error('商品id不合法');
}
$goods = $goodsmodel::get($goods_id);
$goods_spec = Db::name('litestore_goods_spec')->where('goods_id',$goods['goods_id'])->find();
$goods['price'] = $goods_spec['goods_price'];
$goods['line_price'] = $goods_spec['line_price'];
$this->success('商品详情',$goods);
}
/**
* @ApiTitle (商品详情页评价)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=goods_id, type=integer, required=true, description="商品id")
* @ApiReturn ({
'code':'1',
'msg':'商品详情页评价'
'data':{
"comment_number": 1, 评价数量
"comment": {
"id": 1,
"user_id": null,
"goods_id": 22,
"comment": "12121212", 评论内容
"images": "1asdasd",
"score": null,
"createtime": null,
"status": "normal",
"images_text": [
评价图片数组
"http://temporaryfood.com1asdasd"
]
}
"user": {
"id": 1,
"nickname": "admin",
"avatar_text": "用户头像",
}
}
})
*/
public function goodsDetailComment()
{
$goods_id = $this->request->post('goods_id');
if (!is_numeric($goods_id)){
$this->error('商品id不合法');
}
$model = new GoodsComment();
$goods = [];
$goods['comment_number'] = $model->where('status','normal')->count();
$goods['comment'] = $model
->with(['user'])
->where('goods_id',$goods_id)
->where('status','normal')
->order('id','desc')
->find();
$goods['comment']->getRelation('user')->visible(['id','nickname']);
$this->success('商品详情页评价',$goods);
}
/**
* @ApiTitle (商品评价列表)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=goods_id, type=integer, required=true, description="商品id")
* @ApiParams (name=page, type=integer, required=false, description="页数")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
'data':{
"total": 1,
"per_page": 10,
"current_page": 1,
"last_page": 1,
"data": [
{
"id": 1,
"user_id": 1,
"goods_id": 22,
"comment": "12121212",
"images": "1asdasd",
"score": null,
"createtime": null,
"status": "normal",
"user": {
"id": 1,
"nickname": "admin",
"avatar_text": ""
},
"images_text": [
"http://temporaryfood.com1asdasd"
],
"createtime_text": ""
}
]
}
})
*/
public function goodsComment()
{
$goods_id = $this->request->post('goods_id');
$page = $this->request->post('page');
$model = new \app\api\model\GoodsComment();
if (!is_numeric($goods_id)){
$this->error('商品id不合法');
}
$lists = $model
->with(['user'])
->where('goods_id',$goods_id)
->order('id','desc')
->paginate(10,false,['page'=>$page])
->each(function ($item,$key){
$item->getRelation('user')->visible(['id','nickname']);
});
$this->success('商品规格',$lists);
}
}