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