Files
jx-callback/business/partner/purchase/ebai/order_comment.go

105 lines
4.0 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 ebai
import (
"time"
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
)
// 饿百的评价不是一点一点出来的,而是一下把前一天的全部崩出来。。。
const (
RefreshCommentTime = 36 * time.Hour
RefreshCommentTimeInterval = 60 * time.Minute
EBAI_BAD_COMMENTS_MAX_MODIFY_TIME = 24 // 小时
)
func (c *PurchaseHandler) StartRefreshComment() {
if globals.ReallyCallPlatformAPI {
utils.AfterFuncWithRecover(5*time.Second, func() {
c.refreshCommentOnce()
})
}
}
func (c *PurchaseHandler) refreshCommentOnce() {
c.RefreshComment(time.Now().Add(-RefreshCommentTime), time.Now())
utils.AfterFuncWithRecover(RefreshCommentTimeInterval, func() {
c.refreshCommentOnce()
})
}
func (c *PurchaseHandler) RefreshComment(fromTime, toTime time.Time) (err error) {
globals.SugarLogger.Debugf("RefreshComment fromTime:%s, toTime:%s", utils.Time2Str(fromTime), utils.Time2Str(toTime))
var orderCommentList []*model.OrderComment
stepGap := 24 * time.Hour
stepFromTime := fromTime
for {
stepToTime := stepFromTime.Add(stepGap - time.Second)
if stepToTime.Sub(toTime) > 0 {
stepToTime = toTime
}
if stepToTime.Sub(stepFromTime) == 0 {
break
}
resultList, err2 := api.EbaiAPI.GetEleCommentList(stepFromTime, stepToTime, "", "", ebaiapi.ReplyStatusAll, ebaiapi.CommentLevelAll, ebaiapi.CommentContentAll)
if err = err2; err == nil {
for _, result := range resultList {
orderComment := &model.OrderComment{
VendorOrderID: utils.Interface2String(result["order_id"]),
VendorID: model.VendorIDELM,
UserCommentID: utils.Int64ToStr(utils.MustInterface2Int64(result["comment_id"])),
// VendorStoreID: utils.Int64ToStr(utils.MustInterface2Int64(result["shop_id"])), // 这个shop_id是饿了么ID不是饿百ID
TagList: "",
Score: int8(utils.MustInterface2Int64(result["service_rating"])),
Content: utils.Interface2String(result["content"]),
CommentCreatedAt: utils.Str2Time(utils.Interface2String(result["create_time"])),
IsReplied: int8(1 - utils.MustInterface2Int64(result["can_reply"])),
ModifyDuration: EBAI_BAD_COMMENTS_MAX_MODIFY_TIME,
OriginalMsg: string(utils.MustMarshal(result)),
}
// 直接得到的订单是饿了么的,尝试统一成饿百
if order, err := partner.CurOrderManager.LoadOrder2(orderComment.VendorOrderID, model.VendorIDEBAI); err == nil {
orderComment.VendorOrderID = order.VendorOrderID
orderComment.VendorOrderID2 = order.VendorOrderID2
orderComment.VendorID = model.VendorIDEBAI
orderComment.VendorStoreID = order.VendorStoreID
orderComment.StoreID = jxutils.GetSaleStoreIDFromOrder(order)
orderComment.ConsigneeMobile = order.ConsigneeMobile
} else {
globals.SugarLogger.Infof("RefreshComment, load orderID:%s failed", orderComment.VendorOrderID)
}
orderCommentList = append(orderCommentList, orderComment)
}
} else {
// globals.SugarLogger.Warnf("RefreshComment stepFromTime:%s, stepToTime:%s failed with error:%v", utils.Time2Str(stepFromTime), utils.Time2Str(stepToTime), err)
// break //?
}
if stepToTime.Sub(toTime) == 0 {
break
}
stepFromTime = stepToTime.Add(time.Second)
}
if err == nil && len(orderCommentList) > 0 {
err = partner.CurOrderManager.OnOrderComments(orderCommentList)
}
return err
}
func (c *PurchaseHandler) ReplyOrderComment(ctx *jxcontext.Context, orderComment *model.OrderComment, replyComment string) (err error) {
if orderComment.VendorStoreID != "" && orderComment.UserCommentID != "" {
if globals.ReallyReplyComment {
err = api.EbaiAPI.OrderRatesReply("", utils.Str2Int64(orderComment.VendorStoreID), orderComment.UserCommentID, replyComment)
}
}
return err
}