This commit is contained in:
suyl
2021-08-19 10:49:14 +08:00
parent 97127128e4
commit a4277ff92a
3 changed files with 96 additions and 44 deletions

View File

@@ -1736,3 +1736,23 @@ func QueryOrdersForManageState(db *DaoDB, storeID, vendorID, status int, fromTim
err = GetRows(db, &userCoupons, sql, sqlParams) err = GetRows(db, &userCoupons, sql, sqlParams)
return userCoupons, err return userCoupons, err
} }
func GetOrderStoreIDs(db *DaoDB, beginAt, endAt time.Time, vendorID int) (storeIDs []int, err error) {
var (
stores []*model.Store
)
sql := `
SELECT DISTINCT IF(store_id = 0, jx_store_id, store_id) id
FROM goods_order
WHERE order_created_at > ? AND order_created_at < ?
AND vendor_id = ?
AND status = ?
`
sqlParams := []interface{}{beginAt, endAt, vendorID, model.OrderStatusFinished}
if err = GetRows(db, &stores, sql, sqlParams); err == nil {
for _, v := range stores {
storeIDs = append(storeIDs, v.ID)
}
}
return storeIDs, err
}

View File

@@ -1,9 +1,9 @@
package ebai package ebai
import ( import (
"git.rosy.net.cn/jx-callback/business/model/dao"
"time" "time"
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
@@ -47,40 +47,71 @@ func (c *PurchaseHandler) RefreshComment(fromTime, toTime time.Time) (err error)
if stepToTime.Sub(stepFromTime) == 0 { if stepToTime.Sub(stepFromTime) == 0 {
break break
} }
resultList, err2 := api.EbaiAPI.GetEleCommentList(stepFromTime, stepToTime, "", "", ebaiapi.ReplyStatusAll, ebaiapi.CommentLevelAll, ebaiapi.CommentContentAll) storeIDs, _ := dao.GetOrderStoreIDs(dao.GetDB(), stepFromTime, stepToTime, model.VendorIDEBAI)
if err = err2; err == nil { for _, v := range storeIDs {
for _, result := range resultList { if commentList, err := api.EbaiAPI.OrderCommetGet(utils.Int2Str(v), 0, stepToTime, stepToTime, 0); err == nil {
orderComment := &model.OrderComment{ for _, comment := range commentList {
VendorOrderID: utils.Interface2String(result["order_id"]), if comment.OrderID != 0 && comment.AnonymousRating == "0" && comment.CanReply == "1" {
VendorID: model.VendorIDELM, orderComment := &model.OrderComment{
UserCommentID: utils.Int64ToStr(utils.MustInterface2Int64(result["comment_id"])), VendorOrderID: utils.Int64ToStr(comment.OrderID),
// VendorStoreID: utils.Int64ToStr(utils.MustInterface2Int64(result["shop_id"])), // 这个shop_id是饿了么ID不是饿百ID VendorID: model.VendorIDEBAI,
TagList: "", UserCommentID: utils.Int64ToStr(comment.OrderRateList[0].CommentID),
Score: int8(utils.MustInterface2Int64(result["service_rating"])), TagList: "",
Content: utils.Interface2String(result["content"]), Score: int8(comment.OrderRateList[0].ServiceRating),
CommentCreatedAt: utils.Str2Time(utils.Interface2String(result["create_time"])), Content: comment.OrderRateList[0].RatingContent,
IsReplied: int8(1 - utils.MustInterface2Int64(result["can_reply"])), CommentCreatedAt: utils.Timestamp2Time(comment.OrderRateList[0].RatingAt),
ModifyDuration: EBAI_BAD_COMMENTS_MAX_MODIFY_TIME, IsReplied: int8(utils.Str2Int(comment.AnonymousRating)),
OriginalMsg: string(utils.MustMarshal(result)), ModifyDuration: EBAI_BAD_COMMENTS_MAX_MODIFY_TIME,
} OriginalMsg: string(utils.MustMarshal(comment)),
// 直接得到的订单是饿了么的,尝试统一成饿百 }
if order, err := partner.CurOrderManager.LoadOrder2(orderComment.VendorOrderID, model.VendorIDEBAI); err == nil { // 直接得到的订单是饿了么的,尝试统一成饿百
orderComment.VendorOrderID = order.VendorOrderID if order, err := partner.CurOrderManager.LoadOrder(orderComment.VendorOrderID, model.VendorIDEBAI); err == nil {
orderComment.VendorOrderID2 = order.VendorOrderID2 orderComment.VendorOrderID = order.VendorOrderID
orderComment.VendorID = model.VendorIDEBAI orderComment.VendorOrderID2 = order.VendorOrderID2
orderComment.VendorID = model.VendorIDEBAI
orderComment.VendorStoreID = order.VendorStoreID orderComment.VendorStoreID = order.VendorStoreID
orderComment.StoreID = jxutils.GetSaleStoreIDFromOrder(order) orderComment.StoreID = jxutils.GetSaleStoreIDFromOrder(order)
orderComment.ConsigneeMobile = order.ConsigneeMobile orderComment.ConsigneeMobile = order.ConsigneeMobile
} else { } else {
globals.SugarLogger.Infof("RefreshComment, load orderID:%s failed", orderComment.VendorOrderID) globals.SugarLogger.Infof("RefreshComment, load orderID:%s failed", orderComment.VendorOrderID)
}
orderCommentList = append(orderCommentList, orderComment)
}
} }
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 //?
} }
//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)
// }
//}
if stepToTime.Sub(toTime) == 0 { if stepToTime.Sub(toTime) == 0 {
break break
} }
@@ -92,7 +123,7 @@ func (c *PurchaseHandler) RefreshComment(fromTime, toTime time.Time) (err error)
return err return err
} }
func (c *PurchaseHandler) ReplyOrderComment(ctx *jxcontext.Context, vendorOrgCode string,orderComment *model.OrderComment, replyComment string) (err error) { func (c *PurchaseHandler) ReplyOrderComment(ctx *jxcontext.Context, vendorOrgCode string, orderComment *model.OrderComment, replyComment string) (err error) {
if orderComment.VendorStoreID != "" && orderComment.UserCommentID != "" { if orderComment.VendorStoreID != "" && orderComment.UserCommentID != "" {
if globals.EnableEbaiStoreWrite { if globals.EnableEbaiStoreWrite {
err = api.EbaiAPI.OrderRatesReply("", utils.Str2Int64(orderComment.VendorStoreID), orderComment.UserCommentID, replyComment) err = api.EbaiAPI.OrderRatesReply("", utils.Str2Int64(orderComment.VendorStoreID), orderComment.UserCommentID, replyComment)

View File

@@ -43,17 +43,18 @@ func formalizeTagList(mtwmTagList string) (outTagList string) {
} }
func (c *PurchaseHandler) RefreshComment(fromTime, toTime time.Time) (err error) { func (c *PurchaseHandler) RefreshComment(fromTime, toTime time.Time) (err error) {
storeMapList, err2 := dao.GetStoresMapList(dao.GetDB(), []int{model.VendorIDMTWM}, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, "", "", "") //storeMapList, err2 := dao.GetStoresMapList(dao.GetDB(), []int{model.VendorIDMTWM}, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, "", "", "")
if err = err2; err != nil { //if err = err2; err != nil {
return err // return err
} //}
endDateStr := time.Now().Add(-24 * time.Hour).Format("20060102")
startDateStr := time.Now().Add(-RefreshCommentTime).Format("20060102")
storeIDs, _ := dao.GetOrderStoreIDs(dao.GetDB(), utils.Str2Time(startDateStr), utils.Str2Time(endDateStr), model.VendorIDMTWM)
task := tasksch.NewParallelTask("mtwm RefreshComment", nil, jxcontext.AdminCtx, task := tasksch.NewParallelTask("mtwm RefreshComment", nil, jxcontext.AdminCtx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeMap := batchItemList[0].(*model.StoreMap) storeID := batchItemList[0].(int)
endDateStr := time.Now().Add(-24 * time.Hour).Format("20060102") storeDetail, _ := dao.GetStoreDetail(dao.GetDB(), storeID, model.VendorIDMTWM, "")
startDateStr := time.Now().Add(-RefreshCommentTime).Format("20060102") commentList, err2 := getAPI(storeDetail.VendorOrgCode, storeID, storeDetail.VendorStoreID).CommentQuery(storeDetail.VendorStoreID, startDateStr, endDateStr, 0, 0, mtwmapi.CommentReplyStatusNotReplied)
commentList, err2 := getAPI(storeMap.VendorOrgCode, storeMap.StoreID, storeMap.VendorStoreID).CommentQuery(storeMap.VendorStoreID, startDateStr, endDateStr, 0, 0, mtwmapi.CommentReplyStatusAll)
var orderCommentList []*model.OrderComment var orderCommentList []*model.OrderComment
if err = err2; err != nil { if err = err2; err != nil {
return nil, err return nil, err
@@ -65,13 +66,13 @@ func (c *PurchaseHandler) RefreshComment(fromTime, toTime time.Time) (err error)
VendorOrderID: utils.Int64ToStr(mtwmComment.CommentID), // 美团评价不能得到订单号以评价ID代替 VendorOrderID: utils.Int64ToStr(mtwmComment.CommentID), // 美团评价不能得到订单号以评价ID代替
VendorID: model.VendorIDMTWM, VendorID: model.VendorIDMTWM,
UserCommentID: utils.Int64ToStr(mtwmComment.CommentID), UserCommentID: utils.Int64ToStr(mtwmComment.CommentID),
VendorStoreID: storeMap.VendorStoreID, VendorStoreID: storeDetail.VendorStoreID,
TagList: formalizeTagList(mtwmComment.CommentLables), TagList: formalizeTagList(mtwmComment.CommentLables),
Score: int8(mtwmComment.FoodCommentScore), Score: int8(mtwmComment.FoodCommentScore),
ModifyDuration: BAD_COMMENTS_MAX_MODIFY_TIME, ModifyDuration: BAD_COMMENTS_MAX_MODIFY_TIME,
OriginalMsg: string(utils.MustMarshal(mtwmComment)), OriginalMsg: string(utils.MustMarshal(mtwmComment)),
IsReplied: int8(mtwmComment.ReplyStatus), IsReplied: int8(mtwmComment.ReplyStatus),
StoreID: storeMap.StoreID, StoreID: storeDetail.ID,
} }
if orderComment.IsReplied == 0 { if orderComment.IsReplied == 0 {
orderComment.Content = mtwmComment.CommentContent orderComment.Content = mtwmComment.CommentContent
@@ -86,7 +87,7 @@ func (c *PurchaseHandler) RefreshComment(fromTime, toTime time.Time) (err error)
} }
} }
return orderCommentList, nil return orderCommentList, nil
}, storeMapList) }, storeIDs)
task.Run() task.Run()
resultList, err2 := task.GetResult(0) resultList, err2 := task.GetResult(0)
if err = err2; err != nil { if err = err2; err != nil {