|
@@ -40,30 +40,36 @@ class Goods extends Api |
|
@@ -40,30 +40,36 @@ class Goods extends Api |
40
|
"price": "4499.00", 价格
|
40
|
"price": "4499.00", 价格
|
41
|
"line_price": "0.00", 划线价
|
41
|
"line_price": "0.00", 划线价
|
42
|
"images_text": [
|
42
|
"images_text": [
|
43
|
- 轮播图
|
43
|
+ 轮播图
|
44
|
],
|
44
|
],
|
45
|
"down_image_text": "底部图",
|
45
|
"down_image_text": "底部图",
|
46
|
"four_image_text": [
|
46
|
"four_image_text": [
|
47
|
- 四宫格图
|
47
|
+ 四宫格图
|
48
|
]
|
48
|
]
|
49
|
}
|
49
|
}
|
50
|
})
|
50
|
})
|
51
|
*/
|
51
|
*/
|
52
|
public function goodsDetail()
|
52
|
public function goodsDetail()
|
53
|
{
|
53
|
{
|
54
|
- $goods_id = $this->request->post('goods_id');
|
54
|
+ $goods_id = $this->request->post('goods_id');
|
55
|
$goodsmodel = new \app\api\model\Goods();
|
55
|
$goodsmodel = new \app\api\model\Goods();
|
56
|
- if (!is_numeric($goods_id)){
|
56
|
+ if (!is_numeric($goods_id)) {
|
57
|
$this->error('商品id不合法');
|
57
|
$this->error('商品id不合法');
|
58
|
}
|
58
|
}
|
59
|
- $goods = $goodsmodel::get($goods_id);
|
|
|
60
|
- $goods_spec = Db::name('litestore_goods_spec')->where('goods_id',$goods['goods_id'])->find();
|
|
|
61
|
- $goods['price'] = $goods_spec['goods_price'];
|
59
|
+ $goods = $goodsmodel::get($goods_id);
|
|
|
60
|
+ $goods_spec = Db::name('litestore_goods_spec')->where('goods_id', $goods['goods_id'])->find();
|
|
|
61
|
+ $goods['price'] = $goods_spec['goods_price'];
|
62
|
$goods['line_price'] = $goods_spec['line_price'];
|
62
|
$goods['line_price'] = $goods_spec['line_price'];
|
|
|
63
|
+ //判断是否打折
|
|
|
64
|
+ $goods['is_discount'] = 'is';
|
|
|
65
|
+ if ($goods_spec['goods_price'] == $goods_spec['line_price']) {
|
|
|
66
|
+ $goods['is_discount'] = 'no';
|
|
|
67
|
+ }
|
|
|
68
|
+ $goods['discount'] = $goods_spec['discount'];
|
63
|
// 产地
|
69
|
// 产地
|
64
|
- $makerfor_list = ['1' => '国产','2' => '进口'];
|
70
|
+ $makerfor_list = ['1' => '国产', '2' => '进口'];
|
65
|
$goods['makefor'] = isset($makerfor_list[$goods['makefor']]) ? $makerfor_list[$goods['makefor']] : '未知';
|
71
|
$goods['makefor'] = isset($makerfor_list[$goods['makefor']]) ? $makerfor_list[$goods['makefor']] : '未知';
|
66
|
- $this->success('商品详情',$goods);
|
72
|
+ $this->success('商品详情', $goods);
|
67
|
}
|
73
|
}
|
68
|
|
74
|
|
69
|
|
75
|
|
|
@@ -118,36 +124,42 @@ class Goods extends Api |
|
@@ -118,36 +124,42 @@ class Goods extends Api |
118
|
*/
|
124
|
*/
|
119
|
public function goodsSku()
|
125
|
public function goodsSku()
|
120
|
{
|
126
|
{
|
121
|
- $goods_id = $this->request->post('goods_id');
|
127
|
+ $goods_id = $this->request->param('goods_id');
|
122
|
$goodsspecrelmodel = new GoodsSpecRel();
|
128
|
$goodsspecrelmodel = new GoodsSpecRel();
|
123
|
- $list = $goodsspecrelmodel
|
|
|
124
|
- ->where('goods_id',$goods_id)
|
129
|
+ $list = $goodsspecrelmodel
|
|
|
130
|
+ ->where('goods_id', $goods_id)
|
125
|
->select();
|
131
|
->select();
|
126
|
- $array = [];
|
|
|
127
|
- $goods = \app\api\model\Goods::get($goods_id);
|
|
|
128
|
- if ($goods['spec_type'] == 20){
|
|
|
129
|
- foreach ($list as $key => $value){
|
|
|
130
|
- if (!isset($array[$value['spec_id']])){
|
132
|
+ $array = [];
|
|
|
133
|
+ $goods = \app\api\model\Goods::get($goods_id);
|
|
|
134
|
+ if ($goods['spec_type'] == 20) {
|
|
|
135
|
+ foreach ($list as $key => $value) {
|
|
|
136
|
+ if (!isset($array[$value['spec_id']])) {
|
131
|
$array[$value['spec_id']]['name'] = Db::name('litestore_spec')
|
137
|
$array[$value['spec_id']]['name'] = Db::name('litestore_spec')
|
132
|
- ->where('id',$value['spec_id'])
|
138
|
+ ->where('id', $value['spec_id'])
|
133
|
->value('spec_name');
|
139
|
->value('spec_name');
|
134
|
}
|
140
|
}
|
135
|
- $spec_value =Db::name('litestore_spec_value')
|
|
|
136
|
- ->where('id',$value['spec_value_id'])
|
141
|
+ $spec_value = Db::name('litestore_spec_value')
|
|
|
142
|
+ ->where('id', $value['spec_value_id'])
|
137
|
->value('spec_value');
|
143
|
->value('spec_value');
|
138
|
$array[$value['spec_id']]['second'][] = [
|
144
|
$array[$value['spec_id']]['second'][] = [
|
139
|
- 'id' => $value['spec_value_id'],
|
|
|
140
|
- 'name' => $spec_value
|
145
|
+ 'id' => $value['spec_value_id'],
|
|
|
146
|
+ 'name' => $spec_value,
|
141
|
];
|
147
|
];
|
142
|
}
|
148
|
}
|
143
|
$array = array_values($array);
|
149
|
$array = array_values($array);
|
144
|
}
|
150
|
}
|
145
|
- $goods_spec = GoodsSpec::all(['goods_id'=>$goods_id]);
|
|
|
146
|
- $this->success('商品规格',['list'=>$goods_spec,'sku'=>$array]);
|
151
|
+ $goods_spec = GoodsSpec::all(['goods_id' => $goods_id]);
|
|
|
152
|
+ foreach ($goods_spec as &$value) {
|
|
|
153
|
+ //判断是否打折
|
|
|
154
|
+ $value['is_discount'] = 'is';
|
|
|
155
|
+ if ($value['goods_price'] == $value['line_price']) {
|
|
|
156
|
+ $value['is_discount'] = 'no';
|
|
|
157
|
+ }
|
|
|
158
|
+ }
|
|
|
159
|
+ $this->success('商品规格', ['list' => $goods_spec, 'sku' => $array]);
|
147
|
}
|
160
|
}
|
148
|
|
161
|
|
149
|
|
162
|
|
150
|
-
|
|
|
151
|
/**
|
163
|
/**
|
152
|
* @ApiTitle (商品详情页评价)
|
164
|
* @ApiTitle (商品详情页评价)
|
153
|
* @ApiMethod (POST)
|
165
|
* @ApiMethod (POST)
|
|
@@ -158,23 +170,23 @@ class Goods extends Api |
|
@@ -158,23 +170,23 @@ class Goods extends Api |
158
|
'data':{
|
170
|
'data':{
|
159
|
"comment_number": 1, 评价数量
|
171
|
"comment_number": 1, 评价数量
|
160
|
"comment": {
|
172
|
"comment": {
|
161
|
- "id": 1,
|
|
|
162
|
- "user_id": null,
|
|
|
163
|
- "goods_id": 22,
|
|
|
164
|
- "comment": "12121212", 评论内容
|
|
|
165
|
- "images": "1asdasd",
|
|
|
166
|
- "score": null,
|
|
|
167
|
- "createtime": null,
|
|
|
168
|
- "status": "normal",
|
|
|
169
|
- "images_text": [
|
|
|
170
|
- 评价图片数组
|
|
|
171
|
- "http://temporaryfood.com1asdasd"
|
|
|
172
|
- ]
|
173
|
+ "id": 1,
|
|
|
174
|
+ "user_id": null,
|
|
|
175
|
+ "goods_id": 22,
|
|
|
176
|
+ "comment": "12121212", 评论内容
|
|
|
177
|
+ "images": "1asdasd",
|
|
|
178
|
+ "score": null,
|
|
|
179
|
+ "createtime": null,
|
|
|
180
|
+ "status": "normal",
|
|
|
181
|
+ "images_text": [
|
|
|
182
|
+ 评价图片数组
|
|
|
183
|
+ "http://temporaryfood.com1asdasd"
|
|
|
184
|
+ ]
|
173
|
}
|
185
|
}
|
174
|
"user": {
|
186
|
"user": {
|
175
|
- "id": 1,
|
|
|
176
|
- "nickname": "admin",
|
|
|
177
|
- "avatar_text": "用户头像",
|
187
|
+ "id": 1,
|
|
|
188
|
+ "nickname": "admin",
|
|
|
189
|
+ "avatar_text": "用户头像",
|
178
|
}
|
190
|
}
|
179
|
}
|
191
|
}
|
180
|
})
|
192
|
})
|
|
@@ -182,21 +194,21 @@ class Goods extends Api |
|
@@ -182,21 +194,21 @@ class Goods extends Api |
182
|
public function goodsDetailComment()
|
194
|
public function goodsDetailComment()
|
183
|
{
|
195
|
{
|
184
|
$goods_id = $this->request->post('goods_id');
|
196
|
$goods_id = $this->request->post('goods_id');
|
185
|
- if (!is_numeric($goods_id)){
|
197
|
+ if (!is_numeric($goods_id)) {
|
186
|
$this->error('商品id不合法');
|
198
|
$this->error('商品id不合法');
|
187
|
}
|
199
|
}
|
188
|
- $model = new GoodsComment();
|
|
|
189
|
- $goods = [];
|
|
|
190
|
- $goods['comment_number'] = $model->where('goods_id',$goods_id)->where('status','normal')->count();
|
|
|
191
|
- $table_name = $model->getTable();
|
|
|
192
|
- $goods['comment'] = $model
|
|
|
193
|
- ->with(['user'])
|
|
|
194
|
- ->where($table_name.'.goods_id',$goods_id)
|
|
|
195
|
- ->where($table_name.'.status','normal')
|
|
|
196
|
- ->order($table_name.'.id','desc')
|
|
|
197
|
- ->find()??[];
|
|
|
198
|
- if ($goods['comment'])$goods['comment']->getRelation('user')->visible(['id','nickname']);
|
|
|
199
|
- $this->success('商品详情页评价',$goods);
|
200
|
+ $model = new GoodsComment();
|
|
|
201
|
+ $goods = [];
|
|
|
202
|
+ $goods['comment_number'] = $model->where('goods_id', $goods_id)->where('status', 'normal')->count();
|
|
|
203
|
+ $table_name = $model->getTable();
|
|
|
204
|
+ $goods['comment'] = $model
|
|
|
205
|
+ ->with(['user'])
|
|
|
206
|
+ ->where($table_name . '.goods_id', $goods_id)
|
|
|
207
|
+ ->where($table_name . '.status', 'normal')
|
|
|
208
|
+ ->order($table_name . '.id', 'desc')
|
|
|
209
|
+ ->find() ?? [];
|
|
|
210
|
+ if ($goods['comment']) $goods['comment']->getRelation('user')->visible(['id', 'nickname']);
|
|
|
211
|
+ $this->success('商品详情页评价', $goods);
|
200
|
}
|
212
|
}
|
201
|
|
213
|
|
202
|
|
214
|
|
|
@@ -209,50 +221,50 @@ class Goods extends Api |
|
@@ -209,50 +221,50 @@ class Goods extends Api |
209
|
'code':'1',
|
221
|
'code':'1',
|
210
|
'msg':'返回成功'
|
222
|
'msg':'返回成功'
|
211
|
'data':{
|
223
|
'data':{
|
212
|
- "total": 1,
|
|
|
213
|
- "per_page": 10,
|
|
|
214
|
- "current_page": 1,
|
|
|
215
|
- "last_page": 1,
|
|
|
216
|
- "data": [
|
|
|
217
|
- {
|
|
|
218
|
- "id": 1,
|
|
|
219
|
- "user_id": 1,
|
|
|
220
|
- "goods_id": 22,
|
|
|
221
|
- "comment": "12121212",
|
|
|
222
|
- "images": "1asdasd",
|
|
|
223
|
- "score": null,
|
|
|
224
|
- "createtime": null,
|
|
|
225
|
- "status": "normal",
|
|
|
226
|
- "user": {
|
|
|
227
|
- "id": 1,
|
|
|
228
|
- "nickname": "admin",
|
|
|
229
|
- "avatar_text": ""
|
|
|
230
|
- },
|
|
|
231
|
- "images_text": [
|
|
|
232
|
- "http://temporaryfood.com1asdasd"
|
|
|
233
|
- ],
|
|
|
234
|
- "createtime_text": ""
|
|
|
235
|
- }
|
|
|
236
|
- ]
|
224
|
+ "total": 1,
|
|
|
225
|
+ "per_page": 10,
|
|
|
226
|
+ "current_page": 1,
|
|
|
227
|
+ "last_page": 1,
|
|
|
228
|
+ "data": [
|
|
|
229
|
+ {
|
|
|
230
|
+ "id": 1,
|
|
|
231
|
+ "user_id": 1,
|
|
|
232
|
+ "goods_id": 22,
|
|
|
233
|
+ "comment": "12121212",
|
|
|
234
|
+ "images": "1asdasd",
|
|
|
235
|
+ "score": null,
|
|
|
236
|
+ "createtime": null,
|
|
|
237
|
+ "status": "normal",
|
|
|
238
|
+ "user": {
|
|
|
239
|
+ "id": 1,
|
|
|
240
|
+ "nickname": "admin",
|
|
|
241
|
+ "avatar_text": ""
|
|
|
242
|
+ },
|
|
|
243
|
+ "images_text": [
|
|
|
244
|
+ "http://temporaryfood.com1asdasd"
|
|
|
245
|
+ ],
|
|
|
246
|
+ "createtime_text": ""
|
|
|
247
|
+ }
|
|
|
248
|
+ ]
|
237
|
}
|
249
|
}
|
238
|
})
|
250
|
})
|
239
|
*/
|
251
|
*/
|
240
|
public function goodsComment()
|
252
|
public function goodsComment()
|
241
|
{
|
253
|
{
|
242
|
$goods_id = $this->request->post('goods_id');
|
254
|
$goods_id = $this->request->post('goods_id');
|
243
|
- $page = $this->request->post('page');
|
|
|
244
|
- $model = new \app\api\model\GoodsComment();
|
|
|
245
|
- if (!is_numeric($goods_id)){
|
255
|
+ $page = $this->request->post('page');
|
|
|
256
|
+ $model = new \app\api\model\GoodsComment();
|
|
|
257
|
+ if (!is_numeric($goods_id)) {
|
246
|
$this->error('商品id不合法');
|
258
|
$this->error('商品id不合法');
|
247
|
}
|
259
|
}
|
248
|
$lists = $model
|
260
|
$lists = $model
|
249
|
->with(['user'])
|
261
|
->with(['user'])
|
250
|
- ->where('goods_id',$goods_id)
|
|
|
251
|
- ->order('id','desc')
|
|
|
252
|
- ->paginate(10,false,['page'=>$page])
|
|
|
253
|
- ->each(function ($item,$key){
|
|
|
254
|
- $item->getRelation('user')->visible(['id','nickname']);
|
262
|
+ ->where('goods_id', $goods_id)
|
|
|
263
|
+ ->order('id', 'desc')
|
|
|
264
|
+ ->paginate(10, false, ['page' => $page])
|
|
|
265
|
+ ->each(function ($item, $key) {
|
|
|
266
|
+ $item->getRelation('user')->visible(['id', 'nickname']);
|
255
|
});
|
267
|
});
|
256
|
- $this->success('商品规格',$lists);
|
268
|
+ $this->success('商品规格', $lists);
|
257
|
}
|
269
|
}
|
258
|
} |
270
|
} |