diff --git a/platformapi/mtpsapi/riderInfo.go b/platformapi/mtpsapi/riderInfo.go index aefe9c7d..10baaaba 100644 --- a/platformapi/mtpsapi/riderInfo.go +++ b/platformapi/mtpsapi/riderInfo.go @@ -4,6 +4,7 @@ const ( DaDaCode = "10002" // 达达配送 FnPsCode = "10004" // 蜂鸟配送 MTPsCode = "10032" // 美团配送 + UUPTCode = "10006" //uu跑腿 DYPsCode = "10018" //抖音配送(小时达) MyselfPsCode = "10015" // 自送 ) diff --git a/platformapi/tiktok_shop/tiktok_api/order.go b/platformapi/tiktok_shop/tiktok_api/order.go index 649e9a54..48786dfc 100644 --- a/platformapi/tiktok_shop/tiktok_api/order.go +++ b/platformapi/tiktok_shop/tiktok_api/order.go @@ -311,6 +311,8 @@ func (a *API) OrderDelivering(param *order_logisticsAdd_request.OrderLogisticsAd request.Param = param result, err := request.Execute(a.accessTokenObj) + globals.SugarLogger.Debugf("订单发货=========:%s", request.GetUrlPath()) + globals.SugarLogger.Debugf("订单发货:=%s", utils.Format4Output(result, false)) if err != nil { return err } diff --git a/platformapi/uuptapi/callback.go b/platformapi/uuptapi/callback.go new file mode 100644 index 00000000..e443351b --- /dev/null +++ b/platformapi/uuptapi/callback.go @@ -0,0 +1,54 @@ +package uuptapi + +import ( + "encoding/json" + "fmt" + "git.rosy.net.cn/baseapi/utils" + "io/ioutil" + "net/http" +) + +const ( + uuCallbackURL = "https://www.jxc4.com/uuCallback" //uu跑腿订单回调地址 +) + +//var ( +// SuccessResponse = &CallbackResponse{ReturnCode: "ok"} +// FailResponse = &CallbackResponse{ReturnCode: "fail"} +//) + +type CallbackResponse struct { + ReturnCode string `json:"return_code"` + ReturnMsg string `json:"return_msg"` +} + +func Err2CallbackResponse(err error) *CallbackResponse { + if err == nil { + return &CallbackResponse{ + ReturnCode: ReturnSuccess, + //ReturnMsg: ReturnSuccessMsg, + } + } + return &CallbackResponse{ + ReturnCode: ReturnFail, + ReturnMsg: utils.Format4Output(err, false), + } +} + +//订单提交后状态变化回调 +func (a *API) WaybillCallback(request *http.Request) (*WaybillCallbackParam, *CallbackResponse) { + resp, err := ioutil.ReadAll(request.Body) + if err != nil { + return nil, Err2CallbackResponse(err) + } + retVal := WaybillCallbackParam{} + if temp, err := json.Marshal(resp); err == nil { + err = json.Unmarshal(temp, &retVal) + } + con := retVal != WaybillCallbackParam{} + if con { + return &retVal, Err2CallbackResponse(nil) + } else { + return nil, Err2CallbackResponse(fmt.Errorf("UU跑腿运单回调信息为空")) + } +} diff --git a/platformapi/uuptapi/uupt_model.go b/platformapi/uuptapi/uupt_model.go index 57a381ca..6b4a0201 100644 --- a/platformapi/uuptapi/uupt_model.go +++ b/platformapi/uuptapi/uupt_model.go @@ -11,20 +11,23 @@ const ( TokenURL = "https://openapi.uupt.com/v2_0/" //沙箱环境 //TokenURL = "http://openapi.test.uupt.com/v2_0/" - RequestPost = "POST" + RequestPost = "POST" + WaybillCallbackURL = "http://callback.jxc4.com/UuPt/UuWaybillCallback" ) const ( + CancelReasonNormal = "其他" + //运单状态 - StateConfirmSuccess = 1 //下单成功 - StateRMGrabsOrder = 3 //跑男抢单 - StateArrivedStore = 4 //已到达 - StatePickUp = 5 //已取件 - StateArrivedDestination = 6 //到达目的地 - StateReceiverGetGoods = 10 //取件人已收货 - StateOrderCancel = -1 //订单取消 + StateConfirmSuccess = "1" //下单成功 + StateRMGrabsOrder = "3" //跑男抢单 + StateArrivedStore = "4" //已到达 + StatePickUp = "5" //已取件 + StateArrivedDestination = "6" //到达目的地 + StateReceiverGetGoods = "10" //取件人已收货 + StateOrderCancel = "-1" //订单取消 //订单小类 - SendTypeHelpMeDeliver = 0 //帮我送 + SendTypeHelpMeDeliver = 0 //帮我送(默认) SendTypeHelpMeBuy = 1 //帮我买 //预约类型 SubscribeTypeRealTime = 0 //实时订单 @@ -51,7 +54,7 @@ const ( ) -var StateUuWaybill = map[int]string{ +var StateUuWaybill = map[string]string{ StateConfirmSuccess: "下单成功", StateRMGrabsOrder: "跑男抢单", StateArrivedStore: "已到达", @@ -106,8 +109,8 @@ type GetOrderPriceReq struct { FromLat string `json:"from_lat"` //发货地址坐标纬度(坐标系为百度地图坐标系) FromLng string `json:"from_lng"` //发货地址坐标经度(坐标系为百度地图坐标系) //非必填 - //FromUserNote string `json:"from_usernote"` //发货详细地址具体门牌号或门店名称 - //ToUserNote string `json:"to_usernote"` //收货人详细地址具体门牌号 + FromUserNote string `json:"from_usernote"` //发货详细地址具体门牌号或门店名称 + ToUserNote string `json:"to_usernote"` //收货人详细地址具体门牌号 //CountyName string `json:"county_name"` //订单所在县级地名称(如金水区就填“金水区”) //SubscribeTime string `json:"subscribe_time"` //预约时间(如:2015-06-18 12:00:00)没有可以传空字符串 //SubscribeType string `json:"subscribe_type"` //预约类型 0实时订单 1预约取件时间 @@ -133,8 +136,10 @@ type GetOrderPriceResp struct { GoodsInsuranceMoney string `json:"goods_insurancemoney"` //商品保价金额 ExpiresIn string `json:"expires_in"` //price_token的过期时间(单位:秒) //非必返回 - PriceToken string `json:"price_token"` //金额令牌,提交订单前必须先计算价格 - BaseRespInfo *BaseRespInfo + PriceToken string `json:"price_token"` //金额令牌,提交订单前必须先计算价格 + FreightMoney string `json:"freight_money"` //跑腿费,此字段废弃可忽略 + CouponID string `json:"couponid"` //优惠券ID,此字段废弃可忽略 + BaseRespInfo } //发布订单请求体 @@ -160,22 +165,26 @@ type AddOrderReq struct { //发布订单返回体 type AddOrderResp struct { - BaseRespInfo *BaseRespInfo - OrderCode string `json:"ordercode"` //订单号 - OriginID string `json:"origin_id"` //第三方对接平台订单id + BaseRespInfo + OrderCode string `json:"ordercode"` //订单号 + OriginID string `json:"origin_id"` //第三方对接平台订单id } -//取消订单 -type CancelOrderReq struct { - BaseRespInfo *BaseRespInfo - OrderCode string `json:"ordercode"` //订单号 - OriginID string `json:"origin_id"` //第三方对接平台订单id +//取消订单返回体 +type CancelOrderResp struct { + BaseRespInfo + OrderCode string `json:"ordercode"` //订单号 + OriginID string `json:"origin_id"` //第三方对接平台订单id } //获取订单详情返回体 type GetOrderDetailResp struct { - BaseRespInfo *BaseRespInfo - OriginID string `json:"origin_id"` //第三方对接平台id + //必返 + OriginID string `json:"origin_id"` //第三方对接平台id + SendType string `json:"send_type"` //订单小类 0帮我送 1帮我买 + DriverLastloc string `json:"driver_lastloc"` //跑男的坐标,百度地图坐标系经纬度(格式:113.71776,34.767501) + //非返回 + BaseRespInfo OrderCode string `json:"order_code"` //uu跑腿订单编号 FromAddress string `json:"from_address"` //发货地址详细地址具体门牌号或门店名称 FromLat string `json:"from_lat"` //发货地址坐标纬度(坐标系为百度地图坐标系) @@ -197,11 +206,17 @@ type GetOrderDetailResp struct { DriverName string `json:"driver_name"` //跑男姓名(跑男接单后) DriverJobNum string `json:"driver_jobnum"` //跑男工号(跑男接单后) DriverMobile string `json:"driver_mobile"` //跑男电话(跑男接单后) - SendType string `json:"send_type"` //订单小类 0帮我送 1帮我买 ExpectedarriveTime string `json:"expectedarrive_time"` //跑男接单后预计到达时间(格式2015-07-01 15:23:56)取货前为到达取货地,取货后为到达收货地 - DriverLastloc string `json:"driver_lastloc"` //跑男的坐标,百度地图坐标系经纬度(格式:113.71776,34.767501) } -//运单提交后的回调 -type CallbackResp struct { +type WaybillCallbackParam struct { + OrderCode string `json:"order_code"` //订单号 + DriverName string `json:"driver_name"` //跑男姓名(跑男接单后) + DriverJobNum string `json:"driver_jobnum"` //跑男工号(跑男接单后) + DriverMobile string `json:"driver_mobile"` //跑男电话(跑男接单后) + State string `json:"state"` //当前状态 1下单成功 3跑男抢单 4已到达 5已取件 6到达目的地 10收件人已收货 -1订单取消 + StateText string `json:"state_text"` //当前状态说明 + OriginID string `json:"origin_id"` //第三方订单号 + DriverPhoto string `json:"driver_photo"` //跑男头像(跑男接单后) + BaseRespInfo } diff --git a/platformapi/uuptapi/uupt_test.go b/platformapi/uuptapi/uupt_test.go index 05b701e7..b58fbb17 100644 --- a/platformapi/uuptapi/uupt_test.go +++ b/platformapi/uuptapi/uupt_test.go @@ -6,7 +6,6 @@ import ( "git.rosy.net.cn/baseapi/utils" "go.uber.org/zap" "testing" - "time" ) var ( @@ -58,6 +57,11 @@ func TestGetWaybillPrice(t *testing.T) { fmt.Println(needPayMoney, priceToken, err) } -func Test(t *testing.T) { - fmt.Println(utils.Int64ToStr(time.Now().Unix() * 1000)) +type tStruct struct { + name string +} + +func Test(t *testing.T) { + a := tStruct{name: "11"} + fmt.Println(a != tStruct{}) } diff --git a/platformapi/uuptapi/uuptapi.go b/platformapi/uuptapi/uuptapi.go index 8036a3e9..d2c23ca9 100644 --- a/platformapi/uuptapi/uuptapi.go +++ b/platformapi/uuptapi/uuptapi.go @@ -13,14 +13,13 @@ import ( ) const ( - BaseURL = "https://openapi.uupt.com/v2_0" - ReturnSuccess = "ok" - ReturnFail = "fail" - signKey = "sign" - secretKey = "secret" - UUOpenID = "8d8464e7c9354c1e88a3f5afa2a7922e" - UUAppID = "55c4542ae60e4d348edcfc93b06dd302" - letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" + BaseURL = "https://openapi.uupt.com/v2_0" + ReturnSuccess = "ok" //返回成功 + ReturnSuccessMsg = "callbackSuccess" + ReturnFail = "fail" //返回失败 + signKey = "sign" + secretKey = "secret" + letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" ) func (a *API) MakeUURequestHead() map[string]interface{} { @@ -81,7 +80,6 @@ func (a *API) AccessAPI(baseUrl, actionApi, method string, bizParams map[string] sendUrl := func() *http.Request { var request *http.Request if method == RequestPost { - //request, _ = http.NewRequest(http.MethodPost, fullPath, strings.NewReader(string(data))) request, _ = http.NewRequest(http.MethodPost, fullPath, strings.NewReader(utils.Map2URLValues(bizParams).Encode())) } else { request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(baseUrl, actionApi, bizParams), nil) diff --git a/platformapi/uuptapi/waybill.go b/platformapi/uuptapi/waybill.go index c0c8fa99..092e43c1 100644 --- a/platformapi/uuptapi/waybill.go +++ b/platformapi/uuptapi/waybill.go @@ -2,24 +2,97 @@ package uuptapi import ( "encoding/json" + "fmt" "git.rosy.net.cn/baseapi/utils" ) //计算订单价格 -func (a *API) GetOrderPrice(req map[string]interface{}) (needPayMoney, priceToken string, err error) { - preOrder := a.MakeUURequestHead() - resp, err := a.AccessAPI(BaseURL, "getorderprice.ashx", RequestPost, utils.MergeMaps(preOrder, req)) +func (a *API) GetOrderPrice(req map[string]interface{}) (*GetOrderPriceResp, error) { + preParam := a.MakeUURequestHead() + resp, err := a.AccessAPI(BaseURL, "getorderprice.ashx", RequestPost, utils.MergeMaps(preParam, req)) + if err != nil { + return nil, err + } + if resp["return_code"] != ReturnSuccess { + return nil, fmt.Errorf("UU跑腿获取运单价格失败:%s", resp["return_msg"]) + } + retVal := GetOrderPriceResp{} + if temp, err := json.Marshal(resp); err == nil { + err = json.Unmarshal(temp, &retVal) + } + con := retVal != GetOrderPriceResp{} + if con { + return &retVal, nil + } else { + return nil, fmt.Errorf("UU跑腿未返回运单价格") + } +} + +//发布订单 +func (a *API) AddOrder(req map[string]interface{}) (orderCode, originID string, err error) { + preParam := a.MakeUURequestHead() + resp, err := a.AccessAPI(BaseURL, "addorder.ashx", RequestPost, utils.MergeMaps(preParam, req)) if err != nil { return "", "", err } - retVal := GetOrderPriceResp{} - if err := json.Unmarshal([]byte(resp["param"].(string)), &retVal); err != nil { - return "", "", err + if resp["return_code"] != ReturnSuccess { + return "", "", fmt.Errorf("UU跑腿发布运单失败:%s", resp["return_msg"]) } - con := retVal == GetOrderPriceResp{} - if !utils.IsNil(retVal) && !con { - needPayMoney = retVal.NeedPayMoney - priceToken = retVal.PriceToken + retVal := AddOrderResp{} + if temp, err := json.Marshal(resp); err == nil { + err = json.Unmarshal(temp, &retVal) + } + con := retVal != AddOrderResp{} + if con { + return retVal.OrderCode, retVal.OriginID, nil + } else { + return "", "", fmt.Errorf("UU跑腿未返回运单ID") + } +} + +//查询订单信息 +func (a *API) GetOrderDetail(orderCode string) (*GetOrderDetailResp, error) { + preParam := a.MakeUURequestHead() + preParam["order_code"] = orderCode + resp, err := a.AccessAPI(BaseURL, "getorderdetail.ashx", RequestPost, preParam) + if err != nil { + return nil, err + } + if resp["return_code"] != ReturnSuccess { + return nil, fmt.Errorf("UU跑腿获取运单详情失败:%s", resp["return_msg"]) + } + retVal := GetOrderDetailResp{} + if temp, err := json.Marshal(resp); err == nil { + err = json.Unmarshal(temp, &retVal) + } + con := retVal != GetOrderDetailResp{} + if con { + return &retVal, nil + } else { + return nil, fmt.Errorf("UU跑腿未返回运单详情") + } +} + +//取消订单 +func (a *API) CancelOrder(orderCode, reason string) error { + preParam := a.MakeUURequestHead() + preParam["order_code"] = orderCode + preParam["reason"] = reason + resp, err := a.AccessAPI(BaseURL, "cancelorder.ashx", RequestPost, preParam) + if err != nil { + return err + } + if resp["return_code"] != ReturnSuccess { + return fmt.Errorf("UU跑腿取消运单失败:%s", resp["return_msg"]) + } + retVal := CancelOrderResp{} + if temp, err := json.Marshal(resp); err == nil { + err = json.Unmarshal(temp, &retVal) + } + con := retVal != CancelOrderResp{} + if con { + return nil + } else { + return fmt.Errorf("UU跑腿未返回取消运单详情") } - return needPayMoney, priceToken, nil }