Files
jx-callback/controllers/dada_order.go
苏尹岚 ac2bb2bcfe aa
2021-03-30 10:19:36 +08:00

55 lines
1.5 KiB
Go

package controllers
import (
"net/http"
"git.rosy.net.cn/baseapi/platformapi/dadaapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/partner/delivery/dada"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
beego "github.com/astaxie/beego/adapter"
)
// Operations about ELMOrder
type DadaDeliveryController struct {
beego.Controller
}
func (c *DadaDeliveryController) Msg() {
if c.Ctx.Input.Method() == http.MethodPost {
obj, callbackResponse := api.DadaAPI.GetOrderCallbackMsg(c.Ctx.Input.RequestBody)
if callbackResponse == nil {
callbackResponse = dada.OnWaybillMsg(obj)
}
if callbackResponse != nil && callbackResponse.Code != 200 {
c.CustomAbort(callbackResponse.Code, string(utils.MustMarshal(callbackResponse)))
} else {
c.Data["json"] = callbackResponse
c.ServeJSON()
}
} else {
c.Abort("404")
}
}
func (c *DadaDeliveryController) Notify() {
if c.Ctx.Input.Method() == http.MethodPost {
obj, notifyResponse := api.DadaAPI.GetNotifyMsg(c.Ctx.Input.RequestBody)
if notifyResponse == nil && obj.MessageObj != nil {
err := api.DadaAPI.ConfirmRidderCancel(obj.MessageObj.OrderID, obj.MessageObj.DadaOrderID, true)
if err != nil {
notifyResponse = dadaapi.FailedNotifyResponse
}
globals.SugarLogger.Debugf("dada notify, obj:%s, err:%v", utils.Format4Output(obj, false), err)
}
if notifyResponse == nil {
notifyResponse = dadaapi.SuccessNotifyResponse
}
c.Data["json"] = notifyResponse
c.ServeJSON()
} else {
c.Abort("404")
}
}