GoodsComment.php
5.1 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
<?php
namespace app\api\controller;
/**
* 商品评价接口
*/
class GoodsComment extends Base
{
protected $noNeedLogin = ['index', 'type'];
protected $noNeedRight = ['*'];
/**
* @ApiWeigh (99)
* @ApiTitle (评价列表)
* @ApiSummary (评价列表)
* @ApiMethod (GET)
*
* @ApiParams (name=goods_id, type=inter, required=true, description="商品ID")
* @ApiParams (name=type, type=string, required=false, description="评价类型:all=全部,images=有图,good=好评,moderate=中评,bad=差评")
*
* @ApiReturn({
"code": 1,
"msg": "评价列表",
"time": "1609221855",
"data": {
"total": 1, //数据总数
"per_page": 10,
"current_page": 1,
"last_page": 1,
"data": [{
"id": 1,
"goods_id": 6,
"order_id": 17,
"order_item_id": 19,
"user_id": 1,
"level": 5,
"content": "还行吧", //评价内容
"images": [ //评价图片
"https://yixiaoxian.qiniu.broing.cn/uploads/20201229/5c088559ebcc3f0ffcda663f04dfbeb2.png"
],
"video": null, //评价视频
"status": "show",
"admin_id": 0,
"reply_content": null,
"replytime": null,
"createtime": "2020-12-29", //评价时间
"updatetime": 1609221767,
"deletetime": null,
"user": { //评价用户
"id": 1, //用户ID
"nickname": "wn", //昵称
"avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/C8dW9GFDHAy3wwnZwoqibeNciaN6jUZXp6QCrtjehdF3GyHickt9oiaDSibMBhATtF7f19w4AgpcQIR1Mibwu1pjYKEA/132", //头像
"url": "/u/1"
}
}]
}
})
*/
public function index()
{
$params = $this->request->get();
$goodsComments = \addons\shopro\model\GoodsComment::getList($params);
$this->success('评价列表', $goodsComments);
}
/**
* @ApiWeigh (97)
* @ApiTitle (筛选类型)
* @ApiSummary (筛选类型)
* @ApiMethod (GET)
*
* @ApiParams (name=goods_id, type=inter, required=true, description="商品ID")
*
* @ApiReturn({
"code": 1,
"msg": "领取成功",
"time": "1607911049",
"data": {
"user_id": 1, //用户ID
"coupons_id": "2", //优惠券ID
"createtime": 1607911050, //领取时间戳
"id": "1" //领取ID
}
})
*/
public function type() {
$goods_id = $this->request->get('goods_id', 0);
$type = array_values(\addons\shopro\model\GoodsComment::$typeAll);
foreach ($type as $key => $val) {
// 只查询 count 比查出来所有评论,在判断状态要快
$comment = \addons\shopro\model\GoodsComment::where('goods_id', $goods_id);
if ($val['code'] != 'all') {
$comment = $comment->{$val['code']}();
}
$comment = $comment->count();
$type[$key]['num'] = $comment;
}
$this->success('筛选类型', $type);
}
/**
* @ApiWeigh (95)
* @ApiTitle (我的评价)
* @ApiSummary (我的评价)
* @ApiMethod (GET)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的token")
*
* @ApiReturn({
"code": 1,
"msg": "我的评价",
"time": "1609221855",
"data": {
"total": 1, //数据总数
"per_page": 10,
"current_page": 1,
"last_page": 1,
"data": [{
"id": 1,
"goods_id": 6,
"order_id": 17,
"order_item_id": 19,
"user_id": 1,
"level": 5,
"content": "还行吧", //评价内容
"images": [ //评价图片
"https://yixiaoxian.qiniu.broing.cn/uploads/20201229/5c088559ebcc3f0ffcda663f04dfbeb2.png"
],
"video": null, //评价视频
"status": "show",
"admin_id": 0,
"reply_content": null,
"replytime": null,
"createtime": "2020-12-29", //评价时间
"updatetime": 1609221767,
"deletetime": null,
"user": { //评价用户
"id": 1, //用户ID
"nickname": "wn", //昵称
"avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/C8dW9GFDHAy3wwnZwoqibeNciaN6jUZXp6QCrtjehdF3GyHickt9oiaDSibMBhATtF7f19w4AgpcQIR1Mibwu1pjYKEA/132", //头像
"url": "/u/1"
}
}]
}
})
*/
public function myComment()
{
$params = $this->request->get();
$goodsComments = \addons\shopro\model\GoodsComment::getMyList($params);
$this->success('我的评价', $goodsComments);
}
}