- refactor platform apis.

This commit is contained in:
gazebo
2018-06-18 11:47:20 +08:00
parent db287fb025
commit 03574f0f9d
7 changed files with 220 additions and 42 deletions

View File

@@ -0,0 +1,86 @@
package jdapi
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"git.rosy.net.cn/baseapi/platform/common"
)
type JDCallbackResponse struct {
Code string `json:"code"`
Msg string `json:"msg"`
Data string `json:"data"`
}
type JDOrderMsg struct {
Id int `json:"-"` // 用于传递Jdorder的主键值减少一次读库操作
BillId string `json:"billId"`
StatusId string `json:"statusId"`
Timestamp string `json:"timestamp"`
}
type JDDeliveryStatusMsg struct {
OrderId string
DeliveryStatusTime string
DeliveryManNo string
DeliveryManName string
DeliveryManPhone string
DeliveryCarrierNo string
DeliveryCarrierName string
DeliveryStatus int
Remark string
FailType string
CreatePin string
OpTime int64
InputTime string
}
var (
SuccessResponse = &JDCallbackResponse{Code: "0", Msg: "success", Data: ""}
)
func (j *JDAPI) unmarshalData(strData string, msg interface{}) (callbackResponse *JDCallbackResponse) {
err := json.Unmarshal([]byte(strData), msg)
if err != nil {
return &JDCallbackResponse{
Code: JDerrorCodeAbnormalParam,
Msg: fmt.Sprintf(common.CBErrMsgUnmarshal, strData, err),
Data: strData,
}
}
return nil
}
func (j *JDAPI) GetOrderMsg(request *http.Request) (msg *JDOrderMsg, callbackResponse *JDCallbackResponse) {
msg = new(JDOrderMsg)
jdParamJSON := request.FormValue(JD_PARAM_JSON)
callbackResponse = j.unmarshalData(jdParamJSON, msg)
if callbackResponse != nil {
return nil, callbackResponse
}
return msg, nil
}
func (j *JDAPI) GetOrderDeliveryMsg(request *http.Request) (msg *JDDeliveryStatusMsg, callbackResponse *JDCallbackResponse) {
msg = new(JDDeliveryStatusMsg)
jdParamJSON := request.FormValue(JD_PARAM_JSON)
jdParamJSON2, err := url.QueryUnescape(jdParamJSON)
if err != nil {
return nil, &JDCallbackResponse{
Code: JDerrorCodeAbnormalParam,
Msg: fmt.Sprintf(common.CBErrMsgUnescape, jdParamJSON, err),
Data: jdParamJSON,
}
}
jdParamJSON = jdParamJSON2
callbackResponse = j.unmarshalData(jdParamJSON, msg)
if callbackResponse != nil {
return nil, callbackResponse
}
return msg, nil
}

View File

@@ -24,6 +24,10 @@ const (
maxRetryCountWhenReachLimited = 10
)
const (
JD_PARAM_JSON = "jd_param_json"
)
const (
// JDErrorCodeSuccess 操作成功
JDErrorCodeSuccess = "0"

View File

@@ -4,35 +4,6 @@ import (
"git.rosy.net.cn/baseapi/utils"
)
type JDOrderMsgResponse struct {
Code string `json:"code"`
Msg string `json:"msg"`
Data string `json:"data"`
}
type JDOrderMsg struct {
Id int `json:"-"` // 用于传递Jdorder的主键值减少一次读库操作
BillId string `json:"billId"`
StatusId string `json:"statusId"`
Timestamp string `json:"timestamp"`
}
type JDDeliveryStatusMsg struct {
OrderId string
DeliveryStatusTime string
DeliveryManNo string
DeliveryManName string
DeliveryManPhone string
DeliveryCarrierNo string
DeliveryCarrierName string
DeliveryStatus int
Remark string
FailType string
CreatePin string
OpTime int64
InputTime string
}
const (
JdOrderStatusNew = "32000"
JdOrderStatusAdjust = "33080"