Comment.php
4.76 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
<?php
/**
* Description of YHMApi_App_V1_comment
* app.comment.operate
* @author elkan
*/
class YHMApi_App_V1_Comment extends YHMApi_App_V1_Base {
/**
* 获取商品评论
* @param array $params
* @param string $fileds
* @return array
*/
public static function getListBySkc(array $params, $fileds = '*') {
if (empty($params['product_skc'])) {
return self::result(400, '商品id不能为空');
}
$product_skc = $params['product_skc'];
//默认3条, 可分页
$offset = !empty($params['offset']) ? (int) $params['offset'] : '0';
$num = !empty($params['num']) ? (int) $params['num'] : "3";
//通过skc获取商品
$goodsInfo = YHMProduct_Models_Goods_Client::getOneByProductSkc($product_skc);
if (empty($goodsInfo)) {
return self::result(412, '没有找到该商品');
}
$store_id = $goodsInfo['store_id'];
//总留言数
$total_num = YHMComment_Models_Comment_Client::getCountBySkc($store_id, $product_skc);
//留言列表
$commentlist = YHMComment_Models_Comment_Client::getListBySkc($store_id, $product_skc, $offset, $num);
$retData = array(
'total_num' => $total_num,
'comment_list' => array()
);
foreach ($commentlist as $id => $v) {
//留言内容
$contentData = YHMComment_Models_Comment_Client::getContentById($store_id,$v['id']);
$oneComment = array(
'id' => $v['id'],
'star' => $v['star'],
'content' => $contentData['content'],
'comment_user_info' => self::_getUserInfo($v['uid']),
);
$retData['comment_list'][] = $oneComment;
}
return self::result(200, '获取成功', $retData);
}
/**
* 添加评论
* @param array $params
* @param string $fileds
* @return array
*/
public static function add(array $params, $fileds = '*') {
if (empty($params['product_skc'])) {
return self::result(400, '商品id不能为空');
}
if (empty($params['uid'])) {
return self::result(400, '评论者uid不能为空');
}
if (empty($params['order_code'])) {
return self::result(400, '商品订单号不能为空');
}
if (empty($params['content'])) {
return self::result(400, '内容不能为空');
}
if (empty($params['star'])) {
return self::result(400, '星级不能为空');
}
$goods_info = YHMProduct_Models_Goods_Client::getOneByProductSkc($params ['product_skc']);
//根据uid获取店铺id
$store_id = !empty($params['store_id']) ? (int) $params['store_id'] :(int)$goods_info['store_id'];
//add一条留言返回该id
$id = YHMComment_Models_Comment_Client::add($params['uid'], $params['order_code'], $store_id, $params['product_skc'], $params['star']);
if ($id < 1) {
return self::result(400, "评论失败");
}
//add留言内容
YHMComment_Models_Comment_Client::addContent($store_id, $id, $params['content']);
//修改订单状态
// YHMOrders_Models_Orders_Client::updateOrderStatus($params['order_code'], YHMConfig_Orderstatus::BUYER_COMMENT);
//把最新的订单状态插入操作表
// YHMOrders_Models_Status_Client::setOrderstatus($params['order_code'], YHMConfig_Orderstatus::BUYER_COMMENT, $params['uid']);
//更新订单是否评论
YHMOrders_Models_Orders_Client::UpdateOrderComments($params['order_code'], 1, $params['uid']);
$storeArr= YHMStore_Models_Store_Client::getById($store_id);
$star = YHMComment_Models_Comment_Client::getStarByStore($store_id);
YHMStore_Models_Store_Client::updateStar($storeArr['uid'],$star );
$storeParams = array(
'store_id' => $store_id,
'star' => $star
);
$syncStore = new YHMSearch_Syncstore ();
$syncStore->sync($storeParams);
return self::result(200, '评论成功');
}
/**
* 删除评论
* @param array $params
* @param type $fileds
* @return type
*/
public static function del(array $params, $fileds = '*') {
if (empty($params['id'])) {
return self::result(400, 'id不能为空');
}
$comment = YHMComment_Models_Comment_Client::getOneById($params['id']);
//删除评论信息
YHMComment_Models_Comment_Client::del($comment['store_id'], $params['id']);
//删除评论内容
YHMComment_Models_Comment_Client::delContent($comment['store_id'], $params['id']);
return self::result(200, '删除成功');
}
}