- 达达与美团配送的接口修改为较正式参数

This commit is contained in:
gazebo
2019-07-23 09:12:33 +08:00
parent 7ac11981b3
commit 7242dd435e
9 changed files with 255 additions and 81 deletions

View File

@@ -57,9 +57,10 @@ var (
)
const (
DeliveryServiceCodeRapid = 4011
DeliveryServiceCodeIntime = 4012
DeliveryServiceCodeTogether = 4013
DeliveryServiceCodeSuperRapid = 4002 // 飞速达
DeliveryServiceCodeRapid = 4011 // 快速达
DeliveryServiceCodeIntime = 4012 // 及时达
DeliveryServiceCodeTogether = 4013 // 集中送
)
const (
@@ -73,8 +74,8 @@ const (
)
const (
CoordinateTypeMars = 0
CoordinateTypeBaidu = 1
CoordinateTypeMars = 0 // 火星坐标(高德,腾讯地图均采用火星坐标),此为默认项
CoordinateTypeBaidu = 1 // 百度坐标
)
// 错误码
@@ -97,6 +98,21 @@ const (
CancelReasonRideerOther = 399
)
const (
ShopStatusAuditRejected = 10 // 审核驳回
ShopStatusAuditPassed = 20 // 审核通过
ShopStatusCreateSuccess = 30 // 创建成功
ShopStatusOnline = 40 // 上线可发单
)
const (
ShopCategoryMarket = 120 // 生活超市
ShopCategoryMarketConvenience = 120001 // 便利店
ShopCategoryFruit = 150 // 生鲜果蔬
ShopCategoryFruitFruit = 150001 // 果蔬
)
type OrderInfoCommon struct {
DeliveryID int64
MtPeisongID string
@@ -148,10 +164,40 @@ type GoodsItem struct {
GoodPrice float64 `json:"goodPrice"`
GoodUnit string `json:"goodUnit"`
}
type GoodsDetail struct {
Goods []*GoodsItem `json:"goods"`
}
type BusinessHour struct {
BeginTime string `json:"beginTime"`
EndTime string `json:"endTime"`
}
type ShopInfo struct {
ShopID string `json:"shop_id,omitempty"`
ShopName string `json:"shop_name,omitempty"`
Category int `json:"category,omitempty"`
SecondCategory int `json:"second_category,omitempty"`
ContactName string `json:"contact_name,omitempty"`
ContactPhone string `json:"contact_phone,omitempty"`
ContactEmail string `json:"contact_email,omitempty"`
ShopAddress string `json:"shop_address,omitempty"`
ShopAddressDetail string `json:"shop_address_detail,omitempty"`
ShopLng int `json:"shop_lng,omitempty"`
ShopLat int `json:"shop_lat,omitempty"`
CoordinateType int `json:"coordinate_type"`
DeliveryServiceCodes string `json:"delivery_service_codes,omitempty"`
BusinessHours string `json:"business_hours,omitempty"`
// 以下为查询专有的
City int `json:"city,omitempty"`
DeliveryHours string `json:"delivery_hours,omitempty"`
Prebook int `json:"prebook,omitempty"`
PrebookOutOfBizTime int `json:"prebook_out_of_biz_time,omitempty"`
PrebookPeriod string `json:"prebook_period,omitempty"`
}
type API struct {
appKey string
secret string
@@ -198,14 +244,11 @@ func (a *API) AccessAPI(action string, params map[string]interface{}) (retVal *R
panic("params is nil!")
}
params2 := make(url.Values)
for k, v := range params {
params2[k] = []string{fmt.Sprint(v)}
}
params2["appkey"] = []string{a.appKey}
params2["timestamp"] = []string{utils.Int64ToStr(utils.GetCurTimestamp())}
params2["version"] = []string{"1.0"}
params2[signKey] = []string{a.signParams(params2)}
params2 := utils.Map2URLValues(params)
params2.Set("appkey", a.appKey)
params2.Set("timestamp", utils.Int64ToStr(utils.GetCurTimestamp()))
params2.Set("version", "1.0")
params2.Set(signKey, a.signParams(params2))
// baseapi.SugarLogger.Debug(params2.Encode())
err = platformapi.AccessPlatformAPIWithRetry(a.client,
@@ -286,6 +329,25 @@ func (a *API) CancelOrder(deliveryId int64, mtPeiSongId string, cancelReasonId i
}
}
func (a *API) ShopCreate(shopInfo *ShopInfo) (status int, err error) {
params := utils.Struct2MapByJson(shopInfo)
result, err := a.AccessAPI("shop/create", params)
if err == nil {
status = int(utils.Interface2Int64WithDefault(result.Data["status"], 0))
}
return status, err
}
func (a *API) ShopQuery(shopID string) (shopInfo *ShopInfo, err error) {
result, err := a.AccessAPI("shop/query", map[string]interface{}{
"shop_id": shopID,
})
if err == nil {
err = utils.Map2StructByJson(result.Data, &shopInfo, false)
}
return shopInfo, err
}
func (a *API) simulateOrderBehavior(action string, deliveryId int64, mtPeiSongId string) (err error) {
params := map[string]interface{}{
"delivery_id": deliveryId,