Evaluate.php
5.8 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
<?php
namespace app\api\controller;
use app\api\model\OrderDetail;
use app\api\model\OrderInfo;
use app\common\controller\Api;
use function GuzzleHttp\Psr7\uri_for;
use think\Db;
use think\Validate;
use think\Config;
/**
* 评价接口
*/
class Evaluate extends Api
{
protected $evaluateModel;
protected function _initialize()
{
parent::_initialize();
$this->evaluateModel = new \app\api\model\Evaluate;
}
/**
* @ApiTitle (获取商品评价)
* @ApiSummary (获取商品评价)
* @ApiMethod (POST)
* @ApiRoute (/api/evaluate/getGoodsEvaluate)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=goods_id, type=string, required=true, description="商品id")
* @ApiParams (name=page, type=string, required=false, description="页数")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587472510",
"data": {
"total": 1,
"list": [
{
"content": "content", 评论内容
"images": [
"http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png" 评论图片
],
"createtime": "2020-04-20", 评论日期
"avatar": "avatar", 用户头像
"nickname": "admin" 用户昵称
}
]
}
})
*/
public function getGoodsEvaluate(){
$goods_id = $this->request->param('goods_id');
if (!$goods_id) $this->error('缺少参数 goods_id!');
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
$where['e.goods_id'] = $goods_id;
$data = $this->evaluateModel->selectPageData($where,$page,$limit);
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (添加商品评价)
* @ApiSummary (添加商品评价)
* @ApiMethod (POST)
* @ApiRoute (/api/evaluate/addGoodsEvaluate)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=goods_id, type=string, required=true, description="商品id")
* @ApiParams (name=images, type=string, required=false, description="图片 例1.jpg,2.jpg")
* @ApiParams (name=content, type=string, required=true, description="评价内容")
* @ApiParams (name=type, type=string, required=true, description="类型:1=普通商品,2=积分商品")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587472510",
"data": {}
})
*/
public function addGoodsEvaluate(){
$userId = $this->getUserId();
$data = $this->request->param();
$data['user_id'] = $userId;
$validate = new Validate([
'goods_id' => 'require',
'content' => 'require',
'type' => 'require',
]);
$validate->message([
'goods_id' => '缺少参数 goods_id!',
'content' => '缺少参数 content!',
'type' => '缺少参数 type!',
]);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$data = $this->evaluateModel->save($data);
$this->success('SUCCESS');
}
/**
* @ApiTitle (添加商品评价(批量))
* @ApiSummary (添加商品评价(批量))
* @ApiMethod (POST)
* @ApiRoute (/api/evaluate/addAllGoodsEvaluate)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=data, type=string, required=true, description="[['goods_id=>1,'content'=>1,'images'=>1,'type'=>1],['goods_id=>1,'content'=>1,'images'=>1,'type'=>1]]")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587472510",
"data":
})
*/
public function addAllGoodsEvaluate(){
$userId = $this->getUserId();
$data = $this->request->param();
if (empty($data)) $this->error('缺少参数 data!');
$validate = new Validate([
'goods_id' => 'require',
'content' => 'require',
'type' => 'require',
]);
$validate->message([
'goods_id' => '缺少参数 goods_id!',
'content' => '缺少参数 content!',
'type' => '缺少参数 type!',
]);
foreach ($data as $k=>$v){
if (!$validate->check($v)) {
$this->error($validate->getError());
}
$data[$k]['user_id'] = $userId;
}
$res = $this->evaluateModel->saveAll($data);
if ($res) $this->success('SUCCESS');
else $this->success('ERROR');
}
/**
* @ApiTitle (商品评价页)
* @ApiSummary (商品评价页)
* @ApiMethod (POST)
* @ApiRoute (/api/evaluate/goodsEvaluate)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=order_detail_id, type=string, required=true, description="订单子表id")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587472510",
"data": {
{
"id": 3,
"goods_name": "Japanese black cattle", 商品名称
"type": "1" 类型:1=普通商品,2=积分商品
},
{
"id": 4,
"goods_name": "EMP ",
"type": "2"
}
}
})
*/
public function goodsEvaluate(){
$orderInfoModel = new OrderInfo();
$userId = $this->getUserId();
$order_detail_id = $this->request->param('order_detail_id');
if (empty($order_detail_id)) $this->error('缺少参数 order_detail_id!');
if ($this->lang == 'ch') $field = 'id,ch_goods_name goods_name,type';
else $field = 'id,en_goods_name goods_name,type';
$data = $orderInfoModel->where('order_detail_id',$order_detail_id)->field($field)->select();
$this->success('SUCCESS',$data);
}
}