Files
jx-callback/business/partner/purchase/jd/order_legacy_comment.go

165 lines
6.4 KiB
Go

package jd
import (
"math/rand"
"time"
"git.rosy.net.cn/baseapi/platformapi/jdapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/weixinmsg"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"github.com/astaxie/beego/orm"
)
const (
COMMENT_NOT_RESOLVED = 0 //未解决的差评状态
COMMENT_RESOLVED = 1 //已解决的差评状态
JDDJ_BAD_COMMENTS_MAX_MODIFY_TIME = 72 // 小时
JX_BAD_COMMENTS_MAX_LEVEL = 2
COMMENTS_SCORE_ONE_ORTWO_BEGIN_DELAY_TIME = 1 * 60 //评论回复一星或二星回复延迟开始时间区间
COMMENTS_SCORE_ONE_ORTWO_END_DELAY_TIME = 3 * 60 //评论回复一星或二星回复延迟结束时间区间
COMMENTS_SCORE_THREE_BEGIN_DELAY_TIME = 2 * 60 //评论回复三星回复延迟开始时间区间
COMMENTS_SCORE_THREE_END_DELAY_TIME = 4 * 60 //评论回复三星回复延迟结束时间区间
COMMENTS_SCORE_FOUR_ORFIVE_BEGIN_DELAY_TIME = 2 * 60 //评论回复四星或五星回复延迟开始时间区间
COMMENTS_SCORE_FOUR_ORFIVE_END_DELAY_TIME = 5 * 60 //评论回复四星或五星回复延迟结束时间区间
)
type tReplyConfig struct {
delayGapBegin int
delayGapEnd int
comments []string
}
var (
replyConfig = map[int]*tReplyConfig{
1: &tReplyConfig{
delayGapBegin: COMMENTS_SCORE_ONE_ORTWO_BEGIN_DELAY_TIME,
delayGapEnd: COMMENTS_SCORE_ONE_ORTWO_END_DELAY_TIME,
comments: []string{
"非常抱歉让您没有得到十分满意的购物体验,我们会及时与您联系进行确认并解决问题!",
},
},
3: &tReplyConfig{
delayGapBegin: COMMENTS_SCORE_THREE_BEGIN_DELAY_TIME,
delayGapEnd: COMMENTS_SCORE_THREE_END_DELAY_TIME,
comments: []string{
"感谢您对我们的肯定,祝您生活愉快!欢迎再次光临,谢谢!",
"感谢您对京西菜市的关照,我们会更加精益求精。",
"感谢您的光临,您的支持是我们前进的动力!",
},
},
4: &tReplyConfig{
delayGapBegin: COMMENTS_SCORE_FOUR_ORFIVE_BEGIN_DELAY_TIME,
delayGapEnd: COMMENTS_SCORE_FOUR_ORFIVE_END_DELAY_TIME,
comments: []string{
"感谢您的信赖!我们会不断提升菜品质量以及优质的服务,期待与您的再次相遇!",
"感谢您的支持,愿您天天好心情!",
"感谢您的认可!您的支持是我们前进的动力。",
"感谢您的肯定与支持!我们会坚持把最好的服务带给您,期待和您的再次相遇!",
},
},
}
)
func (c *PurchaseHandler) onOrderComment(msg *jdapi.CallbackOrderMsg) (err error) {
globals.SugarLogger.Debugf("onOrderComment orderID:%s", msg.BillID)
go func() error {
intOrderID := utils.Str2Int64(msg.BillID)
result, err := api.JdAPI.GetCommentByOrderId(intOrderID)
if err == nil {
globals.SugarLogger.Debugf("onOrderComment comment:%s", utils.Format4Output(result, true))
comment := &legacymodel.JxBadComments{
OrderId: msg.BillID,
}
db := dao.GetDB()
err := dao.GetEntity(db, comment, "OrderId")
if err == nil || err == orm.ErrNoRows {
score := int(utils.MustInterface2Int64(result["score4"]))
isNewComment := false
if err == orm.ErrNoRows {
isNewComment = true
if result["orgCommentContent"] == nil {
c.replyOrderComment(intOrderID, utils.Int64ToStr(utils.MustInterface2Int64(result["storeId"])), score)
}
}
if score <= JX_BAD_COMMENTS_MAX_LEVEL || !isNewComment { // 如果是直接非差评,忽略
comment.Createtime = utils.Timestamp2Str(utils.MustInterface2Int64(result["createTime"].(map[string]interface{})["time"]) / 1000)
if isNewComment || score <= JX_BAD_COMMENTS_MAX_LEVEL {
comment.Msg = string(utils.MustMarshal(result))
comment.Score = score
comment.Scorecontent = utils.Interface2String(result["score4Content"])
comment.Vendertags = string(utils.MustMarshal(result["venderTags"]))
comment.Status = COMMENT_NOT_RESOLVED
if isNewComment {
comment.OrderFlag = "0"
comment.LastPushTime = utils.Time2Str(time.Now())
comment.PushNo = 1
comment.Maxmodifytime = JDDJ_BAD_COMMENTS_MAX_MODIFY_TIME
order, err2 := partner.CurOrderManager.LoadOrder(msg.BillID, model.VendorIDJD)
if err = err2; err == nil {
comment.Jxstoreid = utils.Int2Str(jxutils.GetJxStoreIDFromOrder(order))
comment.Userphone = order.ConsigneeMobile
}
}
} else {
comment.UpdatedMsg = string(utils.MustMarshal(result))
comment.UpdatedScore = score
comment.UpdatedScorecontent = utils.Interface2String(result["score4Content"])
comment.UpdatedVendertags = string(utils.MustMarshal(result["venderTags"]))
comment.Status = COMMENT_RESOLVED
}
if score <= JX_BAD_COMMENTS_MAX_LEVEL && comment.Jxstoreid != "" {
if globals.ReallyCallPlatformAPI {
weixinmsg.PushJDBadCommentToWeiXin(comment)
}
}
if err == nil {
if isNewComment {
err = dao.CreateEntity(db, comment)
} else {
_, err = dao.UpdateEntity(db, comment)
}
}
}
}
}
if err != nil {
globals.SugarLogger.Warnf("onOrderComment orderID:%s failed with error:%v", msg.BillID, err)
}
return err
}()
return err
}
func (c *PurchaseHandler) replyOrderComment(intOrderID int64, jdStoreNo string, score int) (err error) {
if score <= 2 {
score = 1
} else if score >= 5 {
score = 4
}
config := replyConfig[score]
delaySeconds := config.delayGapBegin + rand.Intn(config.delayGapEnd-config.delayGapBegin)
content := config.comments[rand.Intn(len(config.comments))]
globals.SugarLogger.Debugf("replyOrderComment orderID:%d, delaySeconds:%d, content:%s", intOrderID, delaySeconds, content)
time.AfterFunc(time.Duration(delaySeconds)*time.Second, func() {
// err2 := utils.CallFuncLogError(func() error {
// if globals.ReallyCallPlatformAPI {
// return api.JdAPI.OrgReplyComment(intOrderID, jdStoreNo, content, utils.GetAPIOperator(""))
// }
// return nil
// }, "replyOrderComment %d", intOrderID)
err2 := api.JdAPI.OrgReplyComment(intOrderID, jdStoreNo, content, utils.GetAPIOperator(""))
globals.SugarLogger.Debugf("replyOrderComment orderID:%d, error:%v", intOrderID, err2)
})
return nil
}