- avoid manually build map in CreateOrderByShop.
This commit is contained in:
@@ -21,6 +21,7 @@ type JDOrderMsg struct {
|
|||||||
BillId string `json:"billId"`
|
BillId string `json:"billId"`
|
||||||
StatusId string `json:"statusId"`
|
StatusId string `json:"statusId"`
|
||||||
Timestamp string `json:"timestamp"`
|
Timestamp string `json:"timestamp"`
|
||||||
|
Remark string `json:"remark"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type JDDeliveryStatusMsg struct {
|
type JDDeliveryStatusMsg struct {
|
||||||
@@ -77,13 +78,18 @@ func (j *JDAPI) CheckRequestValidation(request *http.Request) (callbackResponse
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *JDAPI) GetOrderMsg(request *http.Request) (msg *JDOrderMsg, callbackResponse *JDCallbackResponse) {
|
func (j *JDAPI) getCommonOrderMsg(request *http.Request, needDecode bool) (msg *JDOrderMsg, callbackResponse *JDCallbackResponse) {
|
||||||
if callbackResponse = j.CheckRequestValidation(request); callbackResponse != nil {
|
if callbackResponse = j.CheckRequestValidation(request); callbackResponse != nil {
|
||||||
return nil, callbackResponse
|
return nil, callbackResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = new(JDOrderMsg)
|
msg = new(JDOrderMsg)
|
||||||
jdParamJSON := request.FormValue(JD_PARAM_JSON)
|
jdParamJSON := request.FormValue(JD_PARAM_JSON)
|
||||||
|
if needDecode {
|
||||||
|
if jdParamJSON2, err := url.QueryUnescape(jdParamJSON); err == nil {
|
||||||
|
jdParamJSON = jdParamJSON2
|
||||||
|
}
|
||||||
|
}
|
||||||
callbackResponse = j.unmarshalData(jdParamJSON, msg)
|
callbackResponse = j.unmarshalData(jdParamJSON, msg)
|
||||||
if callbackResponse != nil {
|
if callbackResponse != nil {
|
||||||
return nil, callbackResponse
|
return nil, callbackResponse
|
||||||
@@ -91,6 +97,14 @@ func (j *JDAPI) GetOrderMsg(request *http.Request) (msg *JDOrderMsg, callbackRes
|
|||||||
return msg, nil
|
return msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *JDAPI) GetOrderMsg(request *http.Request) (msg *JDOrderMsg, callbackResponse *JDCallbackResponse) {
|
||||||
|
return j.getCommonOrderMsg(request, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *JDAPI) GetOrderApplyCancelMsg(request *http.Request) (msg *JDOrderMsg, callbackResponse *JDCallbackResponse) {
|
||||||
|
return j.getCommonOrderMsg(request, true)
|
||||||
|
}
|
||||||
|
|
||||||
func (j *JDAPI) GetOrderDeliveryMsg(request *http.Request) (msg *JDDeliveryStatusMsg, callbackResponse *JDCallbackResponse) {
|
func (j *JDAPI) GetOrderDeliveryMsg(request *http.Request) (msg *JDDeliveryStatusMsg, callbackResponse *JDCallbackResponse) {
|
||||||
if callbackResponse = j.CheckRequestValidation(request); callbackResponse != nil {
|
if callbackResponse = j.CheckRequestValidation(request); callbackResponse != nil {
|
||||||
return nil, callbackResponse
|
return nil, callbackResponse
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatih/structs"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi"
|
"git.rosy.net.cn/baseapi"
|
||||||
"git.rosy.net.cn/baseapi/platform/common"
|
"git.rosy.net.cn/baseapi/platform/common"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
@@ -105,20 +107,20 @@ type MTPSResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MtpsCreateOrderByShopInfo struct {
|
type MtpsCreateOrderByShopInfo struct {
|
||||||
DeliveryId int64
|
DeliveryId int64 `structs:"delivery_id"`
|
||||||
OrderId string
|
OrderId string `structs:"order_id"`
|
||||||
ShopId string
|
ShopId string `structs:"shop_id"`
|
||||||
DeliveryServiceCode int
|
DeliveryServiceCode int `structs:"delivery_service_code"`
|
||||||
ReceiverName string
|
ReceiverName string `structs:"receiver_name"`
|
||||||
ReceiverAddress string
|
ReceiverAddress string `structs:"receiver_address"`
|
||||||
ReceiverPhone string
|
ReceiverPhone string `structs:"receiver_phone"`
|
||||||
ReceiverLng int
|
ReceiverLng int `structs:"receiver_lng"`
|
||||||
ReceiverLat int
|
ReceiverLat int `structs:"receiver_lat"`
|
||||||
CoordinateType int
|
CoordinateType int `structs:"coordinate_type"`
|
||||||
GoodsValue float64
|
GoodsValue float64 `structs:"goods_value"`
|
||||||
GoodsWeight float64
|
GoodsWeight float64 `structs:"goods_weight"`
|
||||||
ExpectedDeliveryTime int64
|
ExpectedDeliveryTime int64 `structs:"expected_delivery_time"`
|
||||||
OrderType int
|
OrderType int `structs:"order_type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MTPSAPI struct {
|
type MTPSAPI struct {
|
||||||
@@ -215,30 +217,15 @@ func (m *MTPSAPI) result2OrderResponse(result *MTPSResult) (order *MtpsOrderResp
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *MTPSAPI) CreateOrderByShop(basicParams *MtpsCreateOrderByShopInfo, addParams map[string]interface{}) (order *MtpsOrderResponse, err error) {
|
func (m *MTPSAPI) CreateOrderByShop(basicParams *MtpsCreateOrderByShopInfo, addParams map[string]interface{}) (order *MtpsOrderResponse, err error) {
|
||||||
params := make(map[string]interface{})
|
params := structs.Map(basicParams)
|
||||||
params["delivery_id"] = basicParams.DeliveryId
|
|
||||||
params["order_id"] = basicParams.OrderId
|
|
||||||
params["shop_id"] = basicParams.ShopId
|
|
||||||
params["delivery_service_code"] = basicParams.DeliveryServiceCode
|
|
||||||
params["receiver_name"] = basicParams.ReceiverName
|
|
||||||
params["receiver_address"] = basicParams.ReceiverAddress
|
|
||||||
params["receiver_phone"] = basicParams.ReceiverPhone
|
|
||||||
params["receiver_lng"] = basicParams.ReceiverLng
|
|
||||||
params["receiver_lat"] = basicParams.ReceiverLat
|
|
||||||
params["coordinate_type"] = basicParams.CoordinateType
|
|
||||||
params["goods_value"] = strconv.FormatFloat(basicParams.GoodsValue, 'f', 2, 64)
|
params["goods_value"] = strconv.FormatFloat(basicParams.GoodsValue, 'f', 2, 64)
|
||||||
params["goods_weight"] = strconv.FormatFloat(basicParams.GoodsWeight, 'f', 2, 64)
|
params["goods_weight"] = strconv.FormatFloat(basicParams.GoodsWeight, 'f', 2, 64)
|
||||||
params["expected_delivery_time"] = basicParams.ExpectedDeliveryTime
|
allParams := utils.MergeMaps(params, addParams)
|
||||||
params["order_type"] = basicParams.OrderType
|
|
||||||
if addParams != nil {
|
|
||||||
for k, v := range addParams {
|
|
||||||
params[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if params["order_type"] != utils.Int2Str(OrderTypeBook) {
|
if params["order_type"] != utils.Int2Str(OrderTypeBook) {
|
||||||
delete(params, "expected_delivery_time")
|
delete(params, "expected_delivery_time")
|
||||||
}
|
}
|
||||||
if result, err := m.AccessMTPS("order/createByShop", params); err != nil {
|
if result, err := m.AccessMTPS("order/createByShop", allParams); err != nil {
|
||||||
baseapi.SugarLogger.Debugf("result:%v", result)
|
baseapi.SugarLogger.Debugf("result:%v", result)
|
||||||
return nil, utils.NewErrorIntCode(err.Error(), result.Code)
|
return nil, utils.NewErrorIntCode(err.Error(), result.Code)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -176,6 +176,18 @@ func MustInterface2Int64(data interface{}) int64 {
|
|||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MustInterface2Float64(data interface{}) float64 {
|
||||||
|
dataNumber, ok := data.(json.Number)
|
||||||
|
if !ok {
|
||||||
|
panic(fmt.Sprintf("error when convert:%v", data))
|
||||||
|
}
|
||||||
|
retVal, err := dataNumber.Float64()
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
return retVal
|
||||||
|
}
|
||||||
|
|
||||||
func MergeMaps(firstMap map[string]interface{}, otherMaps ...map[string]interface{}) (retVal map[string]interface{}) {
|
func MergeMaps(firstMap map[string]interface{}, otherMaps ...map[string]interface{}) (retVal map[string]interface{}) {
|
||||||
retVal = make(map[string]interface{})
|
retVal = make(map[string]interface{})
|
||||||
allMaps := append(otherMaps, firstMap)
|
allMaps := append(otherMaps, firstMap)
|
||||||
|
|||||||
Reference in New Issue
Block a user