diff --git a/platformapi/dadaapi/notify.go b/platformapi/dadaapi/notify.go new file mode 100644 index 00000000..0333b88c --- /dev/null +++ b/platformapi/dadaapi/notify.go @@ -0,0 +1,58 @@ +package dadaapi + +import "git.rosy.net.cn/baseapi/utils" + +const ( + MessageTypeRidderCancel = 1 +) + +type RidderCancelNotify struct { + OrderID string `json:"orderId"` + DadaOrderID int64 `json:"dadaOrderId"` + CancelReason string `json:"cancelReason"` +} + +type RidderCancelConfirm struct { + OrderID string `json:"orderId"` + DadaOrderID int64 `json:"dadaOrderId"` + IsConfirm int `json:"isConfirm"` +} + +type NotifyMsg struct { + MessageType int `json:"messageType"` + MessageBody string `json:"messageBody"` + CreateTime int64 `json:"createTime"` + + MessageObj *RidderCancelNotify `json:"messageObj"` +} + +type NotifyResponse struct { + Status string `json:"status"` +} + +var ( + SuccessNotifyResponse = &NotifyResponse{Status: "ok"} + FailedNotifyResponse = &NotifyResponse{Status: "fail"} +) + +func (a *API) GetNotifyMsg(data []byte) (msg *NotifyMsg, notifyResponse *NotifyResponse) { + err := utils.UnmarshalUseNumber(data, &msg) + if err == nil { + err = utils.UnmarshalUseNumber([]byte(msg.MessageBody), &msg.MessageObj) + } + if err != nil { + notifyResponse = FailedNotifyResponse + } + return msg, notifyResponse +} + +// 消息确认 +// http://newopen.imdada.cn/#/development/file/merchantConfirm?_k=gqkja3 +func (a *API) ConfirmRidderCancel(orderID string, dadaOrderID int64, isConfirm bool) (err error) { + _, err = a.AccessAPI("message/confirm", utils.Struct2FlatMap(&RidderCancelConfirm{ + OrderID: orderID, + DadaOrderID: dadaOrderID, + IsConfirm: utils.Bool2Int(isConfirm), + })) + return err +}