72 lines
2.7 KiB
Go
72 lines
2.7 KiB
Go
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/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 = 4 * time.Hour
|
|
RefreshCommentTimeInterval = 10 * time.Minute
|
|
)
|
|
|
|
func (c *PurchaseHandler) StartRefreshComment() {
|
|
c.RefreshComment(time.Now().Add(-RefreshCommentTime), time.Now())
|
|
time.AfterFunc(RefreshCommentTimeInterval, func() {
|
|
c.StartRefreshComment()
|
|
})
|
|
}
|
|
|
|
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
|
|
}
|
|
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.VendorIDEBAI,
|
|
UserCommentID: utils.Interface2String(result["comment_id"]),
|
|
VendorStoreID: utils.Int64ToStr(utils.MustInterface2Int64(result["shop_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: 24,
|
|
OriginalMsg: string(utils.MustMarshal(result)),
|
|
}
|
|
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
|
|
}
|
|
}
|
|
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) {
|
|
return api.EbaiAPI.OrderRatesReply("", utils.Str2Int64(orderComment.VendorStoreID), orderComment.UserCommentID, replyComment)
|
|
}
|