美团评价自动回复
This commit is contained in:
@@ -417,7 +417,7 @@ func PushJDBadCommentToWeiXin(comment *legacymodel.JxBadComments, isBadComment b
|
||||
orderInfo = fmt.Sprintf("%s第%d号订单, %s", model.VendorChineseNames[int(utils.Str2Int64WithDefault(comment.OrderFlag, 0))], order.OrderSeq, comment.OrderId)
|
||||
consigneeName = order.ConsigneeName
|
||||
} else {
|
||||
orderInfo = fmt.Sprintf("%s订单, %s", model.VendorChineseNames[int(utils.Str2Int64WithDefault(comment.OrderFlag, 0))], comment.OrderId)
|
||||
orderInfo = fmt.Sprintf("%s订单, %s", model.VendorChineseNames[int(utils.Str2Int64WithDefault(comment.OrderFlag, 0))] /*comment.OrderId*/, "")
|
||||
}
|
||||
data := map[string]interface{}{
|
||||
"first": map[string]interface{}{
|
||||
|
||||
@@ -183,10 +183,12 @@ func GetStoresMapList(db *DaoDB, vendorIDs, storeIDs []int, status, isSync int,
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
FROM store_map t1
|
||||
JOIN store t2 ON t2.id = t1.store_id AND t2.deleted_at = ?
|
||||
WHERE t1.deleted_at = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND t1.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
|
||||
@@ -22,12 +22,10 @@ const (
|
||||
)
|
||||
|
||||
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())
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
@@ -16,18 +17,16 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
RefreshCommentTime = 36 * time.Hour
|
||||
RefreshCommentTime = 3 * 24 * time.Hour // 此值必须大于24小时
|
||||
RefreshCommentTimeInterval = 60 * time.Minute
|
||||
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())
|
||||
@@ -37,21 +36,48 @@ func (c *PurchaseHandler) refreshCommentOnce() {
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) RefreshComment(fromTime, toTime time.Time) (err error) {
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
storeMapList, err2 := dao.GetStoresMapList(dao.GetDB(), []int{model.VendorIDMTWM}, nil, model.StoreStatusAll, model.StoreIsSyncAll, "")
|
||||
storeMapList, err2 := dao.GetStoresMapList(dao.GetDB(), []int{model.VendorIDMTWM}, nil, model.StoreStatusAll, model.StoreIsSyncYes, "")
|
||||
if err = err2; err != nil {
|
||||
return err
|
||||
}
|
||||
task := tasksch.NewParallelTask("mtwm RefreshComment", nil, jxcontext.AdminCtx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeMap := batchItemList[0].(*model.StoreMap)
|
||||
startDateStr := time.Now().Format("20060102")
|
||||
endDateStr := time.Now().Add(-RefreshCommentTime).Format("20060102")
|
||||
endDateStr := time.Now().Add(-24 * time.Hour).Format("20060102")
|
||||
startDateStr := time.Now().Add(-RefreshCommentTime).Format("20060102")
|
||||
commentList, err2 := api.MtwmAPI.CommentQuery(storeMap.VendorStoreID, startDateStr, endDateStr, 0, 0, mtwmapi.CommentReplyStatusAll)
|
||||
|
||||
var orderCommentList []*model.OrderComment
|
||||
if err = err2; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return commentList, nil
|
||||
for _, mtwmComment := range commentList {
|
||||
createdTime, err := utils.TryStr2Time(mtwmComment.CommentTime)
|
||||
if err == nil {
|
||||
orderComment := &model.OrderComment{
|
||||
VendorOrderID: utils.Int64ToStr(mtwmComment.CommentID), // 美团评价不能得到订单号,以评价ID代替
|
||||
VendorID: model.VendorIDMTWM,
|
||||
UserCommentID: utils.Int64ToStr(mtwmComment.CommentID),
|
||||
VendorStoreID: storeMap.VendorStoreID,
|
||||
TagList: mtwmComment.CommentLables,
|
||||
Score: int8(mtwmComment.FoodCommentScore),
|
||||
ModifyDuration: BAD_COMMENTS_MAX_MODIFY_TIME,
|
||||
OriginalMsg: string(utils.MustMarshal(mtwmComment)),
|
||||
IsReplied: int8(mtwmComment.ReplyStatus),
|
||||
}
|
||||
if orderComment.IsReplied == 0 {
|
||||
orderComment.Content = mtwmComment.CommentContent
|
||||
orderComment.CommentCreatedAt = createdTime
|
||||
} else {
|
||||
orderComment.Content = mtwmComment.AddComment
|
||||
if updatedTime, err := utils.TryStr2Time(mtwmComment.CommentTime); err == nil {
|
||||
orderComment.CommentCreatedAt = updatedTime
|
||||
}
|
||||
}
|
||||
orderCommentList = append(orderCommentList, orderComment)
|
||||
}
|
||||
}
|
||||
return orderCommentList, nil
|
||||
}, storeMapList)
|
||||
task.Run()
|
||||
resultList, err2 := task.GetResult(0)
|
||||
@@ -60,19 +86,17 @@ func (c *PurchaseHandler) RefreshComment(fromTime, toTime time.Time) (err error)
|
||||
}
|
||||
var orderCommentList []*model.OrderComment
|
||||
for _, result := range resultList {
|
||||
mtwmComment := result.(*mtwmapi.OrderComment)
|
||||
orderComment := &model.OrderComment{
|
||||
VendorID: model.VendorIDMTWM,
|
||||
TagList: mtwmComment.CommentLables,
|
||||
Score: int8(mtwmComment.FoodCommentScore),
|
||||
}
|
||||
orderComment := result.(*model.OrderComment)
|
||||
orderCommentList = append(orderCommentList, orderComment)
|
||||
}
|
||||
if len(orderCommentList) > 0 {
|
||||
err = partner.CurOrderManager.OnOrderComments(orderCommentList)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) ReplyOrderComment(ctx *jxcontext.Context, orderComment *model.OrderComment, replyComment string) (err error) {
|
||||
globals.SugarLogger.Debugf("mtwm ReplyOrderComment, orderComment:%s, replyComment:%s", utils.Format4Output(orderComment, true), replyComment)
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
err = api.MtwmAPI.CommentAddReply(orderComment.VendorStoreID, utils.Str2Int64(orderComment.UserCommentID), replyComment)
|
||||
}
|
||||
|
||||
2
main.go
2
main.go
@@ -21,6 +21,7 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/misc"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasks"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/ebai"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"git.rosy.net.cn/jx-callback/globals/api2"
|
||||
@@ -66,6 +67,7 @@ func Init() {
|
||||
|
||||
if globals.IsProductEnv() {
|
||||
ebai.CurPurchaseHandler.StartRefreshComment()
|
||||
mtwm.CurPurchaseHandler.StartRefreshComment()
|
||||
}
|
||||
misc.Init()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user