- save jd bad comments in go.
This commit is contained in:
@@ -31,3 +31,28 @@ type JxBackendUser struct {
|
||||
func (*JxBackendUser) TableName() string {
|
||||
return "jxbackenduser"
|
||||
}
|
||||
|
||||
type JxBadComments struct {
|
||||
Id int `orm:"column(id)"`
|
||||
OrderId string `orm:"column(order_id);size(25);unique" description:"订单ID"`
|
||||
Jxstoreid string `orm:"column(jxstoreid);size(11)" description:"京西门店ID"`
|
||||
Userphone string `orm:"column(userphone);size(255);null" description:"评价的用户的联系方式"`
|
||||
Status int `orm:"column(status)" description:"当前评论的状态(0:未解决 1:已解决)"`
|
||||
Createtime string `orm:"column(createtime);size(255);null" description:"评论的创建时间"`
|
||||
Maxmodifytime int `orm:"column(maxmodifytime);null" description:"评论可修改的最大时间"`
|
||||
Score int `orm:"column(score)" description:"评论的星级"`
|
||||
Scorecontent string `orm:"column(scorecontent);size(255);null" description:"评论的内容"`
|
||||
Vendertags string `orm:"column(vendertags);size(255);null" description:"评论的标签"`
|
||||
UpdatedScore int `orm:"column(updated_score);null" description:"更改后的分数"`
|
||||
UpdatedScorecontent string `orm:"column(updated_scorecontent);size(255);null" description:"更改后的评论信息"`
|
||||
UpdatedVendertags string `orm:"column(updated_vendertags);size(255);null" description:"更改后的标签信息"`
|
||||
OrderFlag string `orm:"column(order_flag);size(255);null" description:"订单类别(0:京东 1:美团 2:饿了么)"`
|
||||
Msg string `orm:"column(msg);type(text)" description:"未解决差评的原始信息"`
|
||||
UpdatedMsg string `orm:"column(updated_msg);null" description:"解决后的差评的原始信息"`
|
||||
LastPushTime string `orm:"column(last_push_time);size(255);null" description:"上一次推送的时间"`
|
||||
PushNo int `orm:"column(push_no);null" description:"推送次数"`
|
||||
}
|
||||
|
||||
func (*JxBadComments) TableName() string {
|
||||
return "jx_bad_comments2"
|
||||
}
|
||||
|
||||
@@ -49,6 +49,9 @@ func (c *PurchaseHandler) onOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi
|
||||
if globals.ReallyCallPlatformAPI {
|
||||
freshfood.FreshFoodAPI.JDOrderComment(msg)
|
||||
}
|
||||
if err := c.onOrderComment(msg); err != nil {
|
||||
// return jdapi.Err2CallbackResponse(err, status.VendorStatus)
|
||||
}
|
||||
}
|
||||
err := partner.CurOrderManager.OnOrderStatusChanged(status)
|
||||
// if globals.HandleLegacyJxOrder && err == nil {
|
||||
|
||||
149
business/partner/purchase/jd/order_legacy_comment.go
Normal file
149
business/partner/purchase/jd/order_legacy_comment.go
Normal file
@@ -0,0 +1,149 @@
|
||||
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/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"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 msg:%s", utils.Format4Output(msg, true))
|
||||
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 := &model.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
|
||||
err = 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)
|
||||
comment.OrderFlag = "0"
|
||||
comment.LastPushTime = utils.Time2Str(time.Now())
|
||||
comment.PushNo = 1
|
||||
comment.Maxmodifytime = JDDJ_BAD_COMMENTS_MAX_MODIFY_TIME
|
||||
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 {
|
||||
// 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 err == nil {
|
||||
if isNewComment {
|
||||
globals.SugarLogger.Debug("fuck1")
|
||||
err = dao.CreateEntity(db, comment)
|
||||
} else {
|
||||
globals.SugarLogger.Debug("fuck2")
|
||||
_, err = dao.UpdateEntity(db, comment)
|
||||
}
|
||||
}
|
||||
globals.SugarLogger.Debugf("onOrderComment err:%v", 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))]
|
||||
time.AfterFunc(time.Duration(delaySeconds)*time.Second, func() {
|
||||
utils.CallFuncLogError(func() error {
|
||||
if false { //globals.ReallyCallPlatformAPI {
|
||||
return api.JdAPI.OrgReplyComment(intOrderID, jdStoreNo, content, utils.GetAPIOperator(""))
|
||||
}
|
||||
return nil
|
||||
}, "replyOrderComment %d", intOrderID)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
@@ -13,6 +13,7 @@ func Init() {
|
||||
orm.RegisterDataBase("default", "mysql", beego.AppConfig.String("dbConnectStr"), 30)
|
||||
orm.RegisterModel(new(legacymodel.Config))
|
||||
orm.RegisterModel(new(legacymodel.BlackClient))
|
||||
orm.RegisterModel(new(model.JxBadComments))
|
||||
|
||||
orm.RegisterModel(new(model.GoodsOrder))
|
||||
orm.RegisterModel(new(model.OrderSku))
|
||||
|
||||
Reference in New Issue
Block a user