- 新京东到家订单事件中,顺序调用得到新订单信息与手机号(因为超过了1000个店后,只用订单号查手机号要出错)

- 在defsch中异步调用微信发消息
This commit is contained in:
gazebo
2019-03-20 16:30:48 +08:00
parent 02db9f0b4f
commit 4876b7664c
5 changed files with 36 additions and 185 deletions

View File

@@ -151,7 +151,7 @@ func init() {
map[int]*StatusActionConfig{
model.OrderStatusNew: &StatusActionConfig{ // 自动接单
TimerType: scheduler.TimerTypeBaseStatusTime,
Timeout: 1 * time.Second,
Timeout: 10 * time.Millisecond,
TimeoutAction: func(savedOrderInfo *WatchOrderInfo) (err error) {
order := savedOrderInfo.order
mobile := order.ConsigneeMobile
@@ -235,7 +235,9 @@ func (s *DefScheduler) OnOrderNew(order *model.GoodsOrder, isPending bool) (err
if order.Status >= model.OrderStatusNew {
s.resetTimer(savedOrderInfo, nil, isPending)
if !isPending {
weixinmsg.NotifyNewOrder(order)
utils.CallFuncAsync(func() {
weixinmsg.NotifyNewOrder(order)
})
}
}
return err
@@ -248,7 +250,9 @@ func (s *DefScheduler) OnOrderStatusChanged(status *model.OrderStatus, isPending
savedOrderInfo := s.loadSavedOrderFromMap(status, true)
// if status.Status == model.OrderStatusNew {
// if !isPending {
// weixinmsg.NotifyNewOrder(savedOrderInfo.order)
// utils.CallFuncAsync(func() {
// weixinmsg.NotifyNewOrder(savedOrderInfo.order)
// })
// }
// }
s.updateOrderByStatus(savedOrderInfo.order, status)
@@ -358,7 +362,9 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
}
if s.isBillCandidate(order, bill) && order.WaybillVendorID != order.VendorID {
if !isBillAlreadyCandidate || !s.isWaybillCourierSame(savedOrderInfo, bill) {
weixinmsg.NotifyWaybillStatus(bill, order, isBillAlreadyCandidate)
utils.CallFuncAsync(func() {
weixinmsg.NotifyWaybillStatus(bill, order, isBillAlreadyCandidate)
})
}
}
}
@@ -444,7 +450,9 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
}
}
if !isPending {
weixinmsg.NotifyWaybillStatus(bill, order, false)
utils.CallFuncAsync(func() {
weixinmsg.NotifyWaybillStatus(bill, order, false)
})
}
case model.WaybillStatusNeverSend: // 平台不配送,直接创建三方运单
s.resetTimer(savedOrderInfo, bill, isPending)

View File

@@ -16,8 +16,9 @@ import (
// 饿百的评价不是一点一点出来的,而是一下把前一天的全部崩出来。。。
const (
RefreshCommentTime = 36 * time.Hour
RefreshCommentTimeInterval = 60 * time.Minute
RefreshCommentTime = 36 * time.Hour
RefreshCommentTimeInterval = 60 * time.Minute
EBAI_BAD_COMMENTS_MAX_MODIFY_TIME = 24 // 小时
)
func (c *PurchaseHandler) StartRefreshComment() {
@@ -61,7 +62,7 @@ func (c *PurchaseHandler) RefreshComment(fromTime, toTime time.Time) (err error)
Content: utils.Interface2String(result["content"]),
CommentCreatedAt: utils.Str2Time(utils.Interface2String(result["create_time"])),
IsReplied: int8(1 - utils.MustInterface2Int64(result["can_reply"])),
ModifyDuration: 24,
ModifyDuration: EBAI_BAD_COMMENTS_MAX_MODIFY_TIME,
OriginalMsg: string(utils.MustMarshal(result)),
}
// 直接得到的订单是饿了么的,尝试统一成饿百

View File

@@ -9,7 +9,6 @@ import (
"git.rosy.net.cn/baseapi/utils"
"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/tasksch"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
@@ -69,18 +68,21 @@ func (c *PurchaseHandler) GetOrder(orderID string) (order *model.GoodsOrder, err
result2 string
err2 error
)
task := tasksch.NewParallelTask("jd GetOrder", nil, model.AdminName, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, errInner error) {
taskIndex := batchItemList[0].(int)
switch taskIndex {
case 0:
result, err = api.JdAPI.QuerySingleOrder(orderID)
case 1:
result2, err2 = api.JdAPI.GetRealMobile4Order(orderID)
}
return nil, nil
}, []int{0, 1})
task.Run()
task.GetResult(0)
// task := tasksch.NewParallelTask("jd GetOrder", nil, model.AdminName, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, errInner error) {
// taskIndex := batchItemList[0].(int)
// switch taskIndex {
// case 0:
// result, err = api.JdAPI.QuerySingleOrder(orderID)
// case 1:
// result2, err2 = api.JdAPI.GetRealMobile4Order(orderID, "")
// }
// return nil, nil
// }, []int{0, 1})
// task.Run()
// task.GetResult(0)
if result, err = api.JdAPI.QuerySingleOrder(orderID); err == nil {
result2, err2 = api.JdAPI.GetRealMobile4Order(orderID, utils.Interface2String(result["produceStationNo"]))
}
if err == nil {
order = c.Map2Order(result)
if err2 == nil {

View File

@@ -10,6 +10,10 @@ import (
"git.rosy.net.cn/jx-callback/globals/api"
)
const (
JDDJ_BAD_COMMENTS_MAX_MODIFY_TIME = 72 // 小时
)
func (c *PurchaseHandler) onOrderComment2(msg *jdapi.CallbackOrderMsg) (err error) {
intOrderID := utils.Str2Int64(msg.BillID)
result, err := api.JdAPI.GetCommentByOrderId(intOrderID)

View File

@@ -1,164 +0,0 @@
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)
utils.CallFuncAsync(func() {
c.onOrderComment2(msg)
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 { // 如果是直接非差评,忽略
if isNewComment || score <= JX_BAD_COMMENTS_MAX_LEVEL {
comment.Createtime = utils.Timestamp2Str(utils.MustInterface2Int64(result["createTime"].(map[string]interface{})["time"]) / 1000)
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.GetSaleStoreIDFromOrder(order))
if true { //给门店板中间号 order.ConsigneeMobile2 == "" {
comment.Userphone = order.ConsigneeMobile
} else {
comment.Userphone = order.ConsigneeMobile2
}
}
}
} else {
comment.Updatetime = utils.Timestamp2Str(utils.MustInterface2Int64(result["createTime"].(map[string]interface{})["time"]) / 1000)
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 != "" {
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
}
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)
utils.AfterFuncWithRecover(time.Duration(delaySeconds)*time.Second, func() {
if globals.ReallyReplyComment {
err2 := api.JdAPI.OrgReplyComment(intOrderID, jdStoreNo, content, utils.GetAPIOperator(""))
globals.SugarLogger.Debugf("replyOrderComment orderID:%d, error:%v", intOrderID, err2)
}
})
return nil
}