Files
baseapi/platformapi/ebaiapi/ugc.go
2025-11-20 14:27:08 +08:00

112 lines
3.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package ebaiapi
import (
"time"
"gitrosy.jxc4.com/baseapi/utils"
)
const (
ReplyStatusAll = -1
ReplyStatusNotReplied = 0
ReplyStatusReplied = 1
)
type GoodsComment struct {
CommentID int64 `json:"comment_id"`
Name string `json:"name"`
Rating int `json:"rating"`
RatingContent string `json:"rating_content"`
}
type OrderComment struct {
CommentID int64 `json:"comment_id"`
PackageRating int `json:"package_rating"`
QualityRating int `json:"quality_rating"`
RatingAt int64 `json:"rating_at"`
RatingContent string `json:"rating_content"`
ReplyAt int64 `json:"reply_at"`
ReplyContent string `json:"reply_content"`
ServiceRating int `json:"service_rating"`
}
type ShopOrderComment struct {
AnonymousRating string `json:"anonymous_rating"`
CanEditReply string `json:"can_edit_reply"`
CanReply string `json:"can_reply"`
DishRateList []*GoodsComment `json:"dish_rate_list"`
OrderID int64 `json:"order_id"`
OrderRateList []*OrderComment `json:"order_rate_list"`
}
// 不要使用此接口用OrderCommetGet
func (a *API) OrderRatesGet(shopID string, baiduShopID int64, startTime, endTime time.Time, replyStatus int) (commentList []map[string]interface{}, err error) {
params := a.genShopIDParams(shopID, baiduShopID, 0)
if !utils.IsTimeZero(startTime) {
params["startTime"] = startTime.Unix()
}
if !utils.IsTimeZero(endTime) {
params["endTime"] = endTime.Unix()
}
if replyStatus != ReplyStatusAll {
params["replyStatus"] = replyStatus
}
pageNo := 1
for {
params["page"] = pageNo
result, err := a.AccessAPI("ugc.orderrates.get", params)
if err != nil {
return nil, err
}
data := result.Data.(map[string]interface{})
commentList = append(commentList, utils.Slice2MapSlice(data["comment_list"].([]interface{}))...)
total := int(utils.MustInterface2Int64(data["total"]))
if len(commentList) >= total {
break
}
}
return commentList, err
}
func (a *API) OrderRatesReply(shopID string, baiduShopID int64, commentID, content string) (err error) {
params := a.genShopIDParams(shopID, baiduShopID, 0)
params["comment_id"] = commentID
params["content"] = content
_, err = a.AccessAPI("ugc.reply", params)
return err
}
// 此函数在用户匿名评价时order_id为0还是只有扒网页
func (a *API) OrderCommetGet(shopID string, baiduShopID int64, startTime, endTime time.Time, replyStatus int) (commentList []*ShopOrderComment, err error) {
params := a.genShopIDParams(shopID, baiduShopID, 0)
if !utils.IsTimeZero(startTime) {
params["startTime"] = startTime.Unix()
}
if !utils.IsTimeZero(endTime) {
params["endTime"] = endTime.Unix()
}
if replyStatus != ReplyStatusAll {
params["replyStatus"] = replyStatus
}
pageNo := 1
for {
params["page"] = pageNo
result, err := a.AccessAPI("ugc.ordercomment.get", params)
if err != nil {
return nil, err
}
data := result.Data.(map[string]interface{})
var pageCommentList []*ShopOrderComment
if err = utils.Map2StructByJson(data["comment_list"], &pageCommentList, false); err == nil {
commentList = append(commentList, pageCommentList...)
} else {
break
}
total := int(utils.MustInterface2Int64(data["total"]))
if len(commentList) >= total {
break
}
}
return commentList, err
}