- 自送订单不调用拣货完成API

- 在updateOrderStoreFeature中将order.DeliveryFlag落地
- 发送用户申请取消订单消息(当前只有饿百与京东有此事件)
This commit is contained in:
gazebo
2019-03-22 17:14:09 +08:00
parent 180494ab70
commit 6cc6ee43bf
6 changed files with 90 additions and 29 deletions

View File

@@ -33,19 +33,21 @@ func (c *BaseScheduler) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt
func (c *BaseScheduler) PickupGoods(order *model.GoodsOrder, userName string) (err error) {
globals.SugarLogger.Infof("PickupGoods orderID:%s", order.VendorOrderID)
if order.LockStatus == model.OrderStatusUnknown && order.Status == model.OrderStatusAccepted {
if c.IsReallyCallPlatformAPI {
err = utils.CallFuncLogErrorWithInfo(func() error {
return partner.GetPurchasePlatformFromVendorID(order.VendorID).PickupGoods(order, userName)
}, "PickupGoods orderID:%s", order.VendorOrderID)
}
} else {
if order.LockStatus != model.OrderStatusUnknown || order.Status < model.OrderStatusAccepted {
err = scheduler.ErrOrderStatusIsNotSuitable4CurOperation
globals.SugarLogger.Infof("PickupGoods orderID:%s, status:%d is not suitable", order.VendorOrderID, order.Status)
if (order.DeliveryFlag & model.OrderDeliveryFlagMaskPurcahseDisabled) == 0 {
if order.LockStatus == model.OrderStatusUnknown && order.Status == model.OrderStatusAccepted {
if c.IsReallyCallPlatformAPI {
err = utils.CallFuncLogErrorWithInfo(func() error {
return partner.GetPurchasePlatformFromVendorID(order.VendorID).PickupGoods(order, userName)
}, "PickupGoods orderID:%s", order.VendorOrderID)
}
} else {
err = scheduler.ErrOrderStatusAlreadySatisfyCurOperation
globals.SugarLogger.Debugf("PickupGoods orderID:%s status:%d already ok", order.VendorOrderID, order.Status)
if order.LockStatus != model.OrderStatusUnknown || order.Status < model.OrderStatusAccepted {
err = scheduler.ErrOrderStatusIsNotSuitable4CurOperation
globals.SugarLogger.Infof("PickupGoods orderID:%s, status:%d is not suitable", order.VendorOrderID, order.Status)
} else {
err = scheduler.ErrOrderStatusAlreadySatisfyCurOperation
globals.SugarLogger.Debugf("PickupGoods orderID:%s status:%d already ok", order.VendorOrderID, order.Status)
}
}
}
return err

View File

@@ -136,6 +136,7 @@ func (s *WatchOrderInfo) updateOrderStoreFeature(order *model.GoodsOrder) (err e
if !isNeedSchedule {
order.DeliveryFlag |= model.OrderDeliveryFlagMaskScheduleDisabled
}
_, err = dao.UpdateEntity(db, order, "DeliveryFlag")
globals.SugarLogger.Debugf("updateOrderStoreFeature orderID:%s, s.storeDeliveryType:%d, order.DeliveryFlag:%d", order.VendorOrderID, s.storeDeliveryType, order.DeliveryFlag)
}
return err
@@ -280,6 +281,12 @@ func (s *DefScheduler) OnOrderStatusChanged(status *model.OrderStatus, isPending
} else if status.LockStatus != model.OrderStatusUnknown {
s.stopTimer(savedOrderInfo)
}
} else if status.Status > model.OrderStatusApplyCancel {
globals.SugarLogger.Debugf("OnOrderStatusChanged orderID:%s %s, status:%v", status.VendorOrderID, model.OrderStatusName[status.Status], status)
savedOrderInfo := s.loadSavedOrderFromMap(status, true)
utils.CallFuncAsync(func() {
weixinmsg.NotifyUserApplyCancel(savedOrderInfo.order, status.Remark)
})
}
return err
}

View File

@@ -51,6 +51,7 @@ const (
WX_NORMAL_STORE_MSG_TEMPLATE_ID = "7ngcTFYiUFw66BMzIYntM1tpy-xZkJwlcCT5pVtXwtw"
WX_CHANGE_APPROVED_TEMPLATE_ID = "gIG2olBZtQbjXmp6doNB_dESu60By5xuXYOGxksLv3Y"
WX_CHANGE_REJECTED_TEMPLATE_ID = "tn2QXWi4HtSIwaztmtN6Bb2uzNL-jBxWltCZTDNJuYE"
WS_ORDER_CANCLED_TEMPLATE_ID = "iFozwiCsQdMs7VTiPXoBne45jKIQkoyxdGHSeAExP9U"
)
var (
@@ -273,6 +274,43 @@ func NotifyWaybillStatus(bill *model.Waybill, order *model.GoodsOrder, isBillAlr
return nil
}
func NotifyUserApplyCancel(order *model.GoodsOrder, cancelReason string) (err error) {
globals.SugarLogger.Debugf("NotifyUserApplyCancel orderID:%s", order.VendorOrderID)
if order.VendorID == model.VendorIDELM {
return nil
}
if !model.IsOrderSolid(order) {
globals.SugarLogger.Infof("NotifyUserApplyCancel orderID:%s is not solid", order.VendorOrderID)
return nil
}
data := map[string]interface{}{
"first": map[string]interface{}{
"value": "老板,您有订单申请取消!请及时联系客户处理!",
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword1": map[string]interface{}{
"value": order.VendorOrderID,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword2": map[string]interface{}{
"value": fmt.Sprintf("%s 第%d号订单", model.VendorChineseNames[order.VendorID], order.OrderSeq),
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword3": map[string]interface{}{
"value": cancelReason,
"color": venderColors[order.VendorID],
},
"remark": map[string]interface{}{
"value": order.ConsigneeMobile,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
}
storeID := jxutils.GetSaleStoreIDFromOrder(order)
return SendMsgToStore(storeID, WS_ORDER_CANCLED_TEMPLATE_ID, "", "", data)
}
func PushJDBadCommentToWeiXin(comment *legacymodel.JxBadComments) (err error) {
globals.SugarLogger.Debugf("PushJDBadCommentToWeiXin orderID:%s", comment.OrderId)

View File

@@ -11,7 +11,7 @@ func OnCallbackMsg(msg *ebaiapi.CallbackMsg) (response *ebaiapi.CallbackResponse
orderID := GetOrderIDFromMsg(msg)
jxutils.CallMsgHandler(func() {
switch msg.Cmd {
case ebaiapi.CmdOrderCreate, ebaiapi.CmdOrderStatus:
case ebaiapi.CmdOrderCreate, ebaiapi.CmdOrderStatus, ebaiapi.CmdOrderUserCancel:
response = CurPurchaseHandler.onOrderMsg(msg)
case ebaiapi.CmdOrderDeliveryStatus:
response = CurPurchaseHandler.onWaybillMsg(msg)

View File

@@ -21,8 +21,9 @@ import (
)
const (
acceptOrderDelay = 180 * time.Second
fakePickedUp = "9527"
acceptOrderDelay = 180 * time.Second
fakePickedUp = "9527"
fakeUserApplyCancel = "user_apply_cancel"
)
var (
@@ -30,6 +31,7 @@ var (
ebaiapi.OrderStatusNew: model.OrderStatusNew,
ebaiapi.OrderStatusAccepted: model.OrderStatusAccepted,
fakePickedUp: model.OrderStatusFinishedPickup,
fakeUserApplyCancel: model.OrderStatusApplyCancel,
ebaiapi.OrderStatusCourierAccepted: model.OrderStatusDelivering,
ebaiapi.OrderStatusCourierPickedup: model.OrderStatusDelivering,
ebaiapi.OrderStatusFinished: model.OrderStatusFinished,
@@ -245,21 +247,31 @@ func (c *PurchaseHandler) onOrderNew(msg *ebaiapi.CallbackMsg) (response *ebaiap
}
func (c *PurchaseHandler) callbackMsg2Status(msg *ebaiapi.CallbackMsg) (orderStatus *model.OrderStatus) {
if status, ok := msg.Body["status"]; ok {
vendorStatus := utils.Int64ToStr(utils.MustInterface2Int64(status))
orderID := GetOrderIDFromMsg(msg)
orderStatus = &model.OrderStatus{
VendorOrderID: orderID,
VendorID: model.VendorIDEBAI,
OrderType: model.OrderTypeOrder,
RefVendorOrderID: orderID,
RefVendorID: model.VendorIDEBAI,
VendorStatus: vendorStatus,
Status: c.GetStatusFromVendorStatus(vendorStatus),
StatusTime: utils.Timestamp2Time(msg.Timestamp),
Remark: utils.Interface2String(msg.Body["reason"]),
orderID := GetOrderIDFromMsg(msg)
orderStatus = &model.OrderStatus{
VendorOrderID: orderID,
VendorID: model.VendorIDEBAI,
OrderType: model.OrderTypeOrder,
RefVendorOrderID: orderID,
RefVendorID: model.VendorIDEBAI,
StatusTime: utils.Timestamp2Time(msg.Timestamp),
}
if msg.Cmd == ebaiapi.CmdOrderUserCancel {
cancelType := utils.Int64ToStr(utils.MustInterface2Int64(msg.Body["type"]))
if cancelType == ebaiapi.OrderUserApplyCancel {
orderStatus.VendorStatus = fakeUserApplyCancel
orderStatus.Status = c.GetStatusFromVendorStatus(orderStatus.VendorStatus)
orderStatus.Remark = utils.Interface2String(msg.Body["cancel_reason"])
} else {
orderStatus = nil
}
} else if status, ok := msg.Body["status"]; ok {
vendorStatus := utils.Int64ToStr(utils.MustInterface2Int64(status))
orderStatus.VendorStatus = vendorStatus
orderStatus.Status = c.GetStatusFromVendorStatus(orderStatus.VendorStatus)
orderStatus.Remark = utils.Interface2String(msg.Body["reason"])
} else {
orderStatus = nil
globals.SugarLogger.Infof("ebai callbackMsg2Status can not find status field in msg:%s", utils.Format4Output(msg, false))
}
return orderStatus

View File

@@ -16,7 +16,9 @@ func (c *MtwmController) onCallbackMsg(msgType string) {
msg, callbackResponse := api.MtwmAPI.GetCallbackMsg(c.Ctx.Request)
if callbackResponse == nil {
callbackResponse = mtwm.OnOrderCallbackMsg(msg)
// callbackResponse = mtwmapi.Err2CallbackResponse(nil, "")
if callbackResponse == nil {
callbackResponse = mtwmapi.Err2CallbackResponse(nil, "")
}
}
c.Data["json"] = callbackResponse
c.ServeJSON()