1
This commit is contained in:
@@ -276,33 +276,38 @@ func (d DeliveryHandler) GetRiderInfo(orderId string, deliveryId int64, mtPeison
|
||||
}
|
||||
|
||||
// OnWaybillMsg 配送状态更改回调
|
||||
func OnWaybillMsg(msg *sfps2.RiderStatus) (resp *sfps2.CallbackResponse) {
|
||||
func OnWaybillMsg(urlIndex string, msg interface{}) (resp *sfps2.CallbackResponse) {
|
||||
order := GetWaybillByStatus(urlIndex, msg)
|
||||
//order := &model.Waybill{
|
||||
// VendorWaybillID: msg.SFOrderID,
|
||||
// WaybillVendorID: model.VendorIDSFPS,
|
||||
// VendorOrderID: msg.ShopOrderID,
|
||||
// CourierName: msg.OperatorName,
|
||||
// CourierMobile: msg.OperatorPhone,
|
||||
// VendorStatus: utils.Int2Str(msg.OrderStatus),
|
||||
// StatusTime: utils.Timestamp2Time(int64(msg.PushTime)),
|
||||
// Remark: msg.StatusDesc,
|
||||
//}
|
||||
|
||||
order := &model.Waybill{
|
||||
VendorWaybillID: msg.SFOrderID,
|
||||
WaybillVendorID: model.VendorIDSFPS,
|
||||
VendorOrderID: msg.ShopOrderID,
|
||||
CourierName: msg.OperatorName,
|
||||
CourierMobile: msg.OperatorPhone,
|
||||
VendorStatus: utils.Int2Str(msg.OrderStatus),
|
||||
StatusTime: utils.Timestamp2Time(int64(msg.PushTime)),
|
||||
Remark: msg.StatusDesc,
|
||||
}
|
||||
if msg.PushTime == 0 {
|
||||
order.StatusTime = time.Now()
|
||||
}
|
||||
//获取实时订单信息
|
||||
sfOrder, err := api.SfPsAPI.GetOrderStatus(msg.SFOrderID)
|
||||
sfOrder, err := api.SfPsAPI.GetOrderStatus(order.VendorWaybillID)
|
||||
if err != nil {
|
||||
return sfps2.Err2CallbackResponse(err)
|
||||
}
|
||||
if order.CourierMobile == "" {
|
||||
order.CourierName = sfOrder.RiderName
|
||||
}
|
||||
if order.CourierName == "" {
|
||||
order.CourierMobile = sfOrder.RiderPhone
|
||||
}
|
||||
|
||||
//+0.2
|
||||
sfTotalPrice := utils.Float64TwoInt(sfOrder.TotalPrice) + utils.WayBillDeliveryMarkUp
|
||||
sfActualPrice := utils.Float64TwoInt64(sfOrder.RealPayMoney)
|
||||
|
||||
var good *model.GoodsOrder
|
||||
sql := `SELECT * FROM goods_order WHERE vendor_order_id = ? ORDER BY order_created_at DESC LIMIT 1 OFFSET 0`
|
||||
sqlParams := []interface{}{msg.ShopOrderID}
|
||||
sqlParams := []interface{}{order.VendorOrderID}
|
||||
dao.GetRow(dao.GetDB(), &good, sql, sqlParams)
|
||||
order.OrderVendorID = good.VendorID
|
||||
|
||||
@@ -325,7 +330,7 @@ func OnWaybillMsg(msg *sfps2.RiderStatus) (resp *sfps2.CallbackResponse) {
|
||||
case sfps2.OrderStatusFinished:
|
||||
order.DesiredFee = int64(sfTotalPrice)
|
||||
order.Status = model.WaybillStatusDelivered
|
||||
case sfps2.OrderStatusOrderCancel:
|
||||
case sfps2.OrderStatusOrderCancel, sfps2.OrderStatusRiderCancel:
|
||||
order.Status = model.WaybillStatusCanceled
|
||||
case sfps2.OrderStatusError:
|
||||
order.Status = model.WaybillStatusDeliverFailed // 22
|
||||
@@ -399,6 +404,59 @@ func OnWaybillExceptSF(msg *sfps2.RiderException) (retVal *sfps2.CallbackRespons
|
||||
return retVal
|
||||
}
|
||||
|
||||
// GetWaybillByStatus 根据orderStatus 获取waybill结构
|
||||
func GetWaybillByStatus(urlIndex string, msg interface{}) *model.Waybill {
|
||||
waybill := &model.Waybill{}
|
||||
switch urlIndex {
|
||||
case sfps2.UrlIndexRiderStatus, sfps2.UrlIndexSFCancel:
|
||||
retVal := msg.(sfps2.RiderStatus)
|
||||
waybill = &model.Waybill{
|
||||
VendorWaybillID: retVal.SFOrderID,
|
||||
WaybillVendorID: model.VendorIDSFPS,
|
||||
VendorOrderID: retVal.ShopOrderID,
|
||||
CourierName: retVal.OperatorName,
|
||||
CourierMobile: retVal.OperatorPhone,
|
||||
VendorStatus: utils.Int2Str(retVal.OrderStatus),
|
||||
StatusTime: utils.Timestamp2Time(int64(retVal.PushTime)),
|
||||
Remark: retVal.StatusDesc,
|
||||
}
|
||||
if retVal.PushTime == 0 {
|
||||
waybill.StatusTime = time.Now()
|
||||
}
|
||||
case sfps2.UrlIndexRiderRecall:
|
||||
retVal := msg.(sfps2.RiderRecall)
|
||||
waybill = &model.Waybill{
|
||||
VendorWaybillID: retVal.SFOrderID,
|
||||
WaybillVendorID: model.VendorIDSFPS,
|
||||
VendorOrderID: retVal.ShopOrderID,
|
||||
VendorStatus: utils.Int2Str(retVal.OrderStatus),
|
||||
StatusTime: utils.Timestamp2Time(int64(retVal.PushTime)),
|
||||
Remark: retVal.StatusDesc,
|
||||
}
|
||||
if retVal.PushTime == 0 {
|
||||
waybill.StatusTime = time.Now()
|
||||
}
|
||||
case sfps2.UrlIndexOrderComplete:
|
||||
retVal := msg.(sfps2.OrderComplete)
|
||||
waybill = &model.Waybill{
|
||||
VendorWaybillID: retVal.SFOrderID,
|
||||
WaybillVendorID: model.VendorIDSFPS,
|
||||
VendorOrderID: retVal.ShopOrderID,
|
||||
CourierName: retVal.OperatorName,
|
||||
VendorStatus: utils.Int2Str(retVal.OrderStatus),
|
||||
StatusTime: utils.Timestamp2Time(int64(retVal.PushTime)),
|
||||
Remark: retVal.StatusDesc,
|
||||
}
|
||||
if retVal.PushTime == 0 {
|
||||
waybill.StatusTime = time.Now()
|
||||
}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
return waybill
|
||||
}
|
||||
|
||||
// GetVendorSource 辅助函数
|
||||
//获取订单来源标识符
|
||||
func GetVendorSource(vendorID int) (source string) {
|
||||
|
||||
@@ -15,16 +15,18 @@ type SFPSController struct {
|
||||
|
||||
func (c *SFPSController) SfOrder() {
|
||||
if c.Ctx.Input.Method() == http.MethodPost {
|
||||
msg, callbackResponse := api.SfPsAPI.GetRiderStatusCallback(c.Ctx.Request)
|
||||
msg, callbackResponse := api.SfPsAPI.GetCallbackUrlIndex(c.Ctx.Request)
|
||||
if callbackResponse.ErrorCode == -1 {
|
||||
c.Data["error_code"] = -1
|
||||
c.ServeJSON()
|
||||
return
|
||||
}
|
||||
// 订单回调
|
||||
callbackResponse = sfps.OnWaybillMsg(msg)
|
||||
c.Data["error_code"] = callbackResponse
|
||||
c.ServeJSON()
|
||||
for k, v := range msg {
|
||||
callbackResponse = sfps.OnWaybillMsg(k, v)
|
||||
c.Data["error_code"] = callbackResponse
|
||||
c.ServeJSON()
|
||||
}
|
||||
} else {
|
||||
c.Abort("404")
|
||||
}
|
||||
@@ -32,7 +34,6 @@ func (c *SFPSController) SfOrder() {
|
||||
|
||||
// SfAbnormal 异常回调
|
||||
func (c *FnController) SfAbnormal() {
|
||||
|
||||
if c.Ctx.Input.Method() == http.MethodPost {
|
||||
msg, callbackResponse := api.SfPsAPI.GetRiderExceptionCallback(c.Ctx.Request)
|
||||
if callbackResponse.ErrorCode == -1 {
|
||||
|
||||
Reference in New Issue
Block a user