1
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
package fnpsapi
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
type CallBackInfo struct {
|
||||
AppID string `json:"app_id"`
|
||||
Data string `json:"data"`
|
||||
Salt int `json:"salt"`
|
||||
Signature string `json:"signature"`
|
||||
}
|
||||
|
||||
type WayBillInfo struct {
|
||||
PartnerOrderCode string `json:"partner_order_code"`
|
||||
OrderStatus int `json:"order_status"`
|
||||
PushTime int64 `json:"push_time"`
|
||||
CarrierDriverName string `json:"carrier_driver_name"`
|
||||
CarrierDriverPhone string `json:"carrier_driver_phone"`
|
||||
OpenOrderCode int64 `json:"open_order_code"`
|
||||
PlatformCode string `json:"platform_code"`
|
||||
ErrorScene string `json:"error_scene"`
|
||||
Description string `json:"description"`
|
||||
ErrorCode string `json:"error_code"`
|
||||
DetailDescription string `json:"detail_description"`
|
||||
}
|
||||
|
||||
func (a *API) GetOrderCallbackMsg(data []byte) (orderMsg *WayBillInfo) {
|
||||
callbackInfo := &CallBackInfo{}
|
||||
err := utils.UnmarshalUseNumber(data, callbackInfo)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if err == nil {
|
||||
if str, err := url.QueryUnescape(callbackInfo.Data); err == nil {
|
||||
orderMsg = &WayBillInfo{}
|
||||
if err := utils.UnmarshalUseNumber([]byte(str), orderMsg); err == nil {
|
||||
return orderMsg
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("fn msg faild3 %v", err)
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("fn msg faild2 %v", err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return orderMsg
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
package fnpsapi
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
sigKey = "signature"
|
||||
|
||||
TestURL = "https://exam-anubis.ele.me/anubis-webapi"
|
||||
URL = "https://open-anubis.ele.me/anubis-webapi"
|
||||
tokenAction = "get_access_token"
|
||||
)
|
||||
|
||||
type API struct {
|
||||
accessToken string
|
||||
appID string
|
||||
appSecret string
|
||||
locker sync.RWMutex
|
||||
client *http.Client
|
||||
config *platformapi.APIConfig
|
||||
}
|
||||
|
||||
func (a *API) SetToken(token string) {
|
||||
a.locker.Lock()
|
||||
defer a.locker.Unlock()
|
||||
a.accessToken = token
|
||||
}
|
||||
|
||||
func New(appID, appSecret string, config ...*platformapi.APIConfig) *API {
|
||||
curConfig := platformapi.DefAPIConfig
|
||||
if len(config) > 0 {
|
||||
curConfig = *config[0]
|
||||
}
|
||||
return &API{
|
||||
appID: appID,
|
||||
appSecret: appSecret,
|
||||
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
||||
config: &curConfig,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *API) signParam(params map[string]interface{}) (sig string) {
|
||||
var valueList []string
|
||||
for k, v := range params {
|
||||
if k != sigKey {
|
||||
if str := fmt.Sprint(v); str != "" {
|
||||
valueList = append(valueList, fmt.Sprintf("%s=%s", k, str))
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Sort(sort.StringSlice(valueList))
|
||||
valueList = append(valueList, fmt.Sprintf("secret_key=%s", a.appSecret))
|
||||
sig = strings.Join(valueList, "&")
|
||||
binSig := md5.Sum([]byte(url.QueryEscape(sig)))
|
||||
sig = fmt.Sprintf("%x", binSig)
|
||||
return sig
|
||||
}
|
||||
|
||||
func (a *API) signParam2(params map[string]interface{}) (sig string) {
|
||||
sb := new(strings.Builder)
|
||||
sb.WriteString("app_id=")
|
||||
sb.WriteString(a.appID)
|
||||
sb.WriteString("&access_token=")
|
||||
sb.WriteString(a.accessToken)
|
||||
sb.WriteString("&data=")
|
||||
sb.WriteString(params["data"].(string))
|
||||
sb.WriteString("&salt=")
|
||||
sb.WriteString(utils.Int64ToStr(utils.MustInterface2Int64(params["salt"])))
|
||||
sig = sb.String()
|
||||
binSig := md5.Sum([]byte(sig))
|
||||
sig = fmt.Sprintf("%x", binSig)
|
||||
return sig
|
||||
}
|
||||
|
||||
func (a *API) AccessAPI(action string, url string, bizParams map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) {
|
||||
params := make(map[string]interface{})
|
||||
params["salt"] = GetSalt()
|
||||
params["app_id"] = a.appID
|
||||
if action != tokenAction {
|
||||
data, _ := json.Marshal(bizParams)
|
||||
params["data"] = string(data)
|
||||
signStr := a.signParam2(params)
|
||||
params[sigKey] = signStr
|
||||
} else {
|
||||
signStr := a.signParam(params)
|
||||
params[sigKey] = signStr
|
||||
}
|
||||
data, _ := json.Marshal(params)
|
||||
fullURL := utils.GenerateGetURL(url, action, nil)
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
func() *http.Request {
|
||||
var request *http.Request
|
||||
if isPost {
|
||||
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(string(data)))
|
||||
} else {
|
||||
request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(url, action, params), nil)
|
||||
}
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
return request
|
||||
},
|
||||
a.config,
|
||||
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
|
||||
if jsonResult1 == nil {
|
||||
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
||||
}
|
||||
if err == nil {
|
||||
if utils.MustInterface2Int64(jsonResult1["code"]) != 200 {
|
||||
errLevel = platformapi.ErrLevelGeneralFail
|
||||
err = utils.NewErrorCode(jsonResult1["msg"].(string), utils.Int64ToStr(utils.MustInterface2Int64(jsonResult1["code"])))
|
||||
}
|
||||
retVal = jsonResult1
|
||||
}
|
||||
return errLevel, err
|
||||
})
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
func GetSalt() (salt int) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
return rand.Intn(8999) + 1000
|
||||
}
|
||||
|
||||
type TokenInfo struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
AppID string `json:"app_id"`
|
||||
ExpireTime int64 `json:"expire_time"`
|
||||
}
|
||||
|
||||
func (a *API) GetAccessToken() (tokenInfo *TokenInfo, err error) {
|
||||
result, err := a.AccessAPI(tokenAction, URL, nil, false)
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["data"], &tokenInfo, false)
|
||||
}
|
||||
return tokenInfo, err
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package fnpsapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var (
|
||||
api *API
|
||||
apiv3 *APIv3
|
||||
sugarLogger *zap.SugaredLogger
|
||||
)
|
||||
|
||||
func init() {
|
||||
logger, _ := zap.NewDevelopment()
|
||||
sugarLogger = logger.Sugar()
|
||||
baseapi.Init(sugarLogger)
|
||||
api = New("6a3e2073-1850-413b-9eb7-6c342ec36e1c", "a8248088-a742-4c33-a0db-03aeae00ca7d")
|
||||
api.SetToken("n-606c907a-5117-4c64-bc32-291c3091cabd-w")
|
||||
apiv3 = Newv3("6a3e2073-1850-413b-9eb7-6c342ec36e1c", "a8248088-a742-4c33-a0db-03aeae00ca7d")
|
||||
apiv3.SetTokenv3("n-606c907a-5117-4c64-bc32-291c3091cabd-w")
|
||||
}
|
||||
|
||||
func TestGetAccessToken(t *testing.T) {
|
||||
result, err := api.GetAccessToken()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
package fnpsapi
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
merchantID = "51658"
|
||||
|
||||
URLv3 = "https://open-anubis.ele.me/anubis-webapi/v3/invoke"
|
||||
)
|
||||
|
||||
type APIv3 struct {
|
||||
accessToken string
|
||||
appID string
|
||||
appSecret string
|
||||
|
||||
locker sync.RWMutex
|
||||
client *http.Client
|
||||
config *platformapi.APIConfig
|
||||
}
|
||||
|
||||
func Newv3(appID, appSecret string, config ...*platformapi.APIConfig) *APIv3 {
|
||||
curConfig := platformapi.DefAPIConfig
|
||||
if len(config) > 0 {
|
||||
curConfig = *config[0]
|
||||
}
|
||||
return &APIv3{
|
||||
appID: appID,
|
||||
appSecret: appSecret,
|
||||
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
||||
config: &curConfig,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIv3) SetTokenv3(token string) {
|
||||
a.locker.Lock()
|
||||
defer a.locker.Unlock()
|
||||
a.accessToken = token
|
||||
}
|
||||
|
||||
func (a *APIv3) signParamv3(params map[string]interface{}) (sig string) {
|
||||
var valueList []string
|
||||
for k, v := range params {
|
||||
if k != sigKey {
|
||||
if str := fmt.Sprint(v); str != "" {
|
||||
valueList = append(valueList, fmt.Sprintf("%s=%s", k, str))
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Sort(sort.StringSlice(valueList))
|
||||
sig = strings.Join(valueList, "&")
|
||||
sig = a.appSecret + sig
|
||||
binSig := sha1.Sum([]byte(sig))
|
||||
sig = fmt.Sprintf("%x", binSig)
|
||||
return sig
|
||||
}
|
||||
|
||||
func (a *APIv3) AccessAPIv3(action string, url string, bizParams map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) {
|
||||
params := make(map[string]interface{})
|
||||
params["timestamp"] = time.Now().UnixNano()
|
||||
params["app_id"] = a.appID
|
||||
params["merchant_id"] = merchantID
|
||||
params["version"] = "1.0"
|
||||
params["access_token"] = a.accessToken
|
||||
data, _ := json.Marshal(bizParams)
|
||||
params["business_data"] = string(data)
|
||||
signStr := a.signParamv3(params)
|
||||
params[sigKey] = signStr
|
||||
datas, _ := json.Marshal(params)
|
||||
fullURL := utils.GenerateGetURL(url, action, nil)
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
func() *http.Request {
|
||||
var request *http.Request
|
||||
if isPost {
|
||||
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(string(datas)))
|
||||
} else {
|
||||
request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(url, action, params), nil)
|
||||
}
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
return request
|
||||
},
|
||||
a.config,
|
||||
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
|
||||
if jsonResult1 == nil {
|
||||
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
||||
}
|
||||
if err == nil {
|
||||
if utils.MustInterface2Int64(jsonResult1["code"]) != 200 {
|
||||
errLevel = platformapi.ErrLevelGeneralFail
|
||||
err = utils.NewErrorCode(jsonResult1["msg"].(string), utils.Int64ToStr(utils.MustInterface2Int64(jsonResult1["code"])))
|
||||
}
|
||||
retVal = jsonResult1
|
||||
}
|
||||
return errLevel, err
|
||||
})
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
type PreCreateOrderParam struct {
|
||||
PartnerOrderCode string `json:"partner_order_code"`
|
||||
OutShopCode string `json:"out_shop_code"`
|
||||
OrderType int `json:"order_type"`
|
||||
PositionSource int `json:"position_source"` // 3:高德地图
|
||||
ReceiverAddress string `json:"receiver_address"`
|
||||
ReceiverLongitude float64 `json:"receiver_longitude"`
|
||||
ReceiverLatitude float64 `json:"receiver_latitude"`
|
||||
GoodsTotalAmountCent float64 `json:"goods_total_amount_cent"`
|
||||
GoodsActualAmountCent float64 `json:"goods_actual_amount_cent"`
|
||||
GoodsWeight float64 `json:"goods_weight"`
|
||||
GoodsCount float64 `json:"goods_count"`
|
||||
GoodsItemList []*ItemsJSON2 `json:"goods_item_list"`
|
||||
}
|
||||
|
||||
type ItemsJSON2 struct {
|
||||
ItemName string `json:"item_name"`
|
||||
ItemQuantity int `json:"item_quantity"`
|
||||
ItemAmountCent float64 `json:"item_amount_cent"`
|
||||
ItemActualAmountCent float64 `json:"item_actual_amount_cent"`
|
||||
}
|
||||
|
||||
func (a *APIv3) PreCreateOrder(preCreateOrderParam *PreCreateOrderParam) (queryOrderResult *QueryOrderResult, err error) {
|
||||
result, err := a.AccessAPIv3("preCreateOrder", URLv3, utils.Struct2FlatMap(preCreateOrderParam), true)
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["data"], &queryOrderResult, false)
|
||||
}
|
||||
return queryOrderResult, err
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package fnpsapi
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPreCreateOrder(t *testing.T) {
|
||||
result, err := apiv3.PreCreateOrder(&PreCreateOrderParam{
|
||||
PartnerOrderCode: "2118717546000352",
|
||||
OutShopCode: "667002",
|
||||
OrderType: 1,
|
||||
PositionSource: 3,
|
||||
ReceiverAddress: "徐州市泉山区大润发(欣欣店)一楼咔啦嘟熊童装店",
|
||||
ReceiverLongitude: 117.195360,
|
||||
ReceiverLatitude: 34.201010,
|
||||
GoodsTotalAmountCent: 66.2,
|
||||
GoodsActualAmountCent: 67.2,
|
||||
GoodsWeight: 2.3,
|
||||
GoodsCount: 6,
|
||||
GoodsItemList: []*ItemsJSON2{
|
||||
&ItemsJSON2{
|
||||
ItemName: "巨峰葡萄约500g/份",
|
||||
ItemQuantity: 2,
|
||||
ItemAmountCent: 15.2,
|
||||
ItemActualAmountCent: 15.2,
|
||||
},
|
||||
&ItemsJSON2{
|
||||
ItemName: "[新鲜]苹果150g/个(约150g-250g)",
|
||||
ItemQuantity: 2,
|
||||
ItemAmountCent: 4.3,
|
||||
ItemActualAmountCent: 4.3,
|
||||
},
|
||||
&ItemsJSON2{
|
||||
ItemName: "脆桃 鲜,甜,脆约500g/份",
|
||||
ItemQuantity: 2,
|
||||
ItemAmountCent: 14.6,
|
||||
ItemActualAmountCent: 14.6,
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
package fnpsapi
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
OrderCancelReson1 = 1 // 1:物流原因:订单长时间未分配骑手,
|
||||
OrderCancelReson2 = 2 // 2:物流原因:分配骑手后,骑手长时间未取件 ,
|
||||
OrderCancelReson3 = 3 // 3:物流原因:骑手告知不配送,让取消订单,
|
||||
OrderCancelReson4 = 4 // 4:商品缺货/无法出货/已售完,
|
||||
OrderCancelReson5 = 5 // 5:商户联系不上门店/门店关门了,
|
||||
OrderCancelReson6 = 6 // 6:商户发错单,
|
||||
OrderCancelReson7 = 7 // 7:商户/顾客自身定位错误,
|
||||
OrderCancelReson8 = 8 // 8:商户改其他第三方配送,
|
||||
OrderCancelReson9 = 9 // 9:顾客下错单/临时不想要了,
|
||||
OrderCancelReson10 = 10 // 10:顾客自取/不在家/要求另改时间配送)(0类型已下线)
|
||||
|
||||
OrderStatusAccept = 1 //系统已接单
|
||||
OrderStatusAssigned = 20 //已分配骑手
|
||||
OrderStatusArrived = 80 //已到店
|
||||
OrderStatusDelivering = 2 //配送中
|
||||
OrderStatusDelivered = 3 //已送达
|
||||
OrderStatusException = 5 //异常
|
||||
)
|
||||
|
||||
type CreateOrderParam struct {
|
||||
PartnerRemark string `json:"partner_remark,omitempty"`
|
||||
PartnerOrderCode string `json:"partner_order_code,omitempty"`
|
||||
NotifyURL string `json:"notify_url,omitempty"`
|
||||
OrderType int `json:"order_type,omitempty"`
|
||||
ChainStoreCode string `json:"chain_store_code,omitempty"`
|
||||
TransportInfo *TransportInfo `json:"transport_info,omitempty"`
|
||||
OrderAddTime int64 `json:"order_add_time,omitempty"`
|
||||
OrderTotalAmount float64 `json:"order_total_amount,omitempty"`
|
||||
OrderActualAmount float64 `json:"order_actual_amount,omitempty"`
|
||||
OrderWeight float64 `json:"order_weight,omitempty"`
|
||||
OrderRemark string `json:"order_remark,omitempty"`
|
||||
IsInvoiced int `json:"is_invoiced"`
|
||||
Invoice string `json:"invoice,omitempty"`
|
||||
OrderPaymentStatus int `json:"order_payment_status,omitempty"`
|
||||
OrderPaymentMethod int `json:"order_payment_method,omitempty"`
|
||||
IsAgentPayment int `json:"is_agent_payment"`
|
||||
RequirePaymentPay float64 `json:"require_payment_pay,omitempty"`
|
||||
GoodsCount int `json:"goods_count,omitempty"`
|
||||
RequireReceiveTime int64 `json:"require_receive_time,omitempty"`
|
||||
SerialNumber string `json:"serial_number,omitempty"`
|
||||
ReceiverInfo *ReceiverInfo `json:"receiver_info,omitempty"`
|
||||
ItemsJSON []*ItemsJSON `json:"items_json,omitempty"`
|
||||
OrderSource string `json:"order_source,omitempty"` //饿百订单传109
|
||||
ChannelOrderCode string `json:"channel_order_code,omitempty"`
|
||||
CookingTime int64 `json:"cooking_time,omitempty"`
|
||||
PlatformPaidTime int64 `json:"platform_paid_time,omitempty"`
|
||||
PlatformCreatedTime int64 `json:"platform_created_time,omitempty"`
|
||||
MerchantCode string `json:"merchant_code,omitempty"`
|
||||
}
|
||||
|
||||
type ReceiverInfo struct {
|
||||
ReceiverName string `json:"receiver_name,omitempty"`
|
||||
ReceiverPrimaryPhone string `json:"receiver_primary_phone,omitempty"`
|
||||
ReceiverSecondPhone string `json:"receiver_second_phone,omitempty"`
|
||||
ReceiverAddress string `json:"receiver_address,omitempty"`
|
||||
ReceiverLongitude float64 `json:"receiver_longitude,omitempty"`
|
||||
ReceiverLatitude float64 `json:"receiver_latitude,omitempty"`
|
||||
PositionSource int `json:"position_source,omitempty"`
|
||||
}
|
||||
|
||||
type TransportInfo struct {
|
||||
TransportName string `json:"transport_name,omitempty"`
|
||||
TransportAddress string `json:"transport_address,omitempty"`
|
||||
TransportLongitude float64 `json:"transport_longitude,omitempty"`
|
||||
TransportLatitude float64 `json:"transport_latitude,omitempty"`
|
||||
PositionSource int `json:"position_source,omitempty"`
|
||||
TransportTel string `json:"transport_tel,omitempty"`
|
||||
TransportRemark string `json:"transport_remark,omitempty"`
|
||||
}
|
||||
|
||||
type ItemsJSON struct {
|
||||
ItemID string `json:"item_id,omitempty"`
|
||||
ItemName string `json:"item_name,omitempty"`
|
||||
ItemQuantity int `json:"item_quantity,omitempty"`
|
||||
ItemPrice float64 `json:"item_price"`
|
||||
ItemActualPrice float64 `json:"item_actual_price"`
|
||||
ItemSize int `json:"item_size,omitempty"`
|
||||
ItemRemark string `json:"item_remark,omitempty"`
|
||||
IsNeedPackage int `json:"is_need_package"`
|
||||
IsAgentPurchase int `json:"is_agent_purchase"`
|
||||
AgentPurchasePrice float64 `json:"agent_purchase_price,omitempty"`
|
||||
}
|
||||
|
||||
//https://open.ele.me/documents/%E5%88%9B%E5%BB%BA%E8%9C%82%E9%B8%9F%E8%AE%A2%E5%8D%95
|
||||
func (a *API) CreateOrder(createOrderParam *CreateOrderParam) (err error) {
|
||||
params := utils.Struct2FlatMap(createOrderParam)
|
||||
_, err = a.AccessAPI("v2/order", URL, params, true)
|
||||
return err
|
||||
}
|
||||
|
||||
//order_cancel_reason_code 订单取消原因代码(1:用户取消,2:商家取消)
|
||||
// order_cancel_code 订单取消编码(
|
||||
// 1:物流原因:订单长时间未分配骑手,
|
||||
// 2:物流原因:分配骑手后,骑手长时间未取件 ,
|
||||
// 3:物流原因:骑手告知不配送,让取消订单,
|
||||
// 4:商品缺货/无法出货/已售完, 5:商户联系不上门店/门店关门了, 6:商户发错单,
|
||||
// 7:商户/顾客自身定位错误, 8:商户改其他第三方配送, 9:顾客下错单/临时不想要了,
|
||||
// 10:顾客自取/不在家/要求另改时间配送)(0类型已下线)
|
||||
|
||||
type CancelOrderParam struct {
|
||||
PartnerOrderCode string `json:"partner_order_code,omitempty"`
|
||||
OrderCancelReasonCode int `json:"order_cancel_reason_code,omitempty"`
|
||||
OrderCancelCode int `json:"order_cancel_code,omitempty"`
|
||||
OrderCancelDescription string `json:"order_cancel_description,omitempty"`
|
||||
OrderCancelTime int64 `json:"order_cancel_time,omitempty"`
|
||||
}
|
||||
|
||||
func (a *API) CancelOrder(cancelOrderParam *CancelOrderParam) (err error) {
|
||||
params := utils.Struct2FlatMap(cancelOrderParam)
|
||||
_, err = a.AccessAPI("v2/order/cancel", URL, params, true)
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) ComplaintOrder(cancelOrderParam *CancelOrderParam) (err error) {
|
||||
params := utils.Struct2FlatMap(cancelOrderParam)
|
||||
_, err = a.AccessAPI("v2/order/complaint", URL, params, true)
|
||||
return err
|
||||
}
|
||||
|
||||
type QueryOrderResult struct {
|
||||
AbnormalCode string `json:"abnormal_code"`
|
||||
AbnormalDesc string `json:"abnormal_desc"`
|
||||
CarrierDriverID int `json:"carrier_driver_id"`
|
||||
CarrierDriverName string `json:"carrier_driver_name"`
|
||||
CarrierDriverPhone string `json:"carrier_driver_phone"`
|
||||
ComplaintDescription interface{} `json:"complaintDescription"`
|
||||
ComplaintStatus interface{} `json:"complaintStatus"`
|
||||
EstimateArriveTime int64 `json:"estimate_arrive_time"`
|
||||
EventLogDetails []struct {
|
||||
CarrierDriverName string `json:"carrier_driver_name"`
|
||||
CarrierDriverPhone string `json:"carrier_driver_phone"`
|
||||
OccurTime int64 `json:"occur_time"`
|
||||
OrderStatus int `json:"order_status"`
|
||||
} `json:"event_log_details"`
|
||||
HandleID interface{} `json:"handleId"`
|
||||
OrderID interface{} `json:"orderId"`
|
||||
OrderStatus int `json:"order_status"`
|
||||
OrderTotalDeliveryCost float64 `json:"order_total_delivery_cost"`
|
||||
OrderTotalDeliveryDiscount interface{} `json:"order_total_delivery_discount"`
|
||||
OvertimeCompensationCost float64 `json:"overtime_compensation_cost"`
|
||||
Reason string `json:"reason"`
|
||||
SupportClaims bool `json:"support_claims"`
|
||||
TrackingID int64 `json:"trackingId"`
|
||||
TrackingID2 int64 `json:"tracking_id"`
|
||||
TransportStationID string `json:"transport_station_id"`
|
||||
TransportStationTel string `json:"transport_station_tel"`
|
||||
}
|
||||
|
||||
func (a *API) QueryOrder(partnerOrderCode string) (queryOrderResult *QueryOrderResult, err error) {
|
||||
result, err := a.AccessAPI("v2/order/query", URL, map[string]interface{}{
|
||||
"partner_order_code": partnerOrderCode,
|
||||
}, true)
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["data"], &queryOrderResult, false)
|
||||
}
|
||||
return queryOrderResult, err
|
||||
}
|
||||
|
||||
func (a *API) ComplaintRider(partnerOrderCode string, orderComplaintCode int) (err error) {
|
||||
_, err = a.AccessAPI("v2/order/complaint", URL, map[string]interface{}{
|
||||
"partner_order_code": partnerOrderCode,
|
||||
"order_complaint_code": orderComplaintCode,
|
||||
"order_complaint_time": time.Now().UnixNano() / 1e6,
|
||||
}, true)
|
||||
return err
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package fnpsapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
func TestQueryOrder(t *testing.T) {
|
||||
result, err := api.QueryOrder("134420892247000001")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestCreateOrder(t *testing.T) {
|
||||
params := &CreateOrderParam{
|
||||
PartnerOrderCode: "2140252158517300353",
|
||||
NotifyURL: "https://callback.test.jxc4.com/fn/msg",
|
||||
ChainStoreCode: "667281",
|
||||
OrderType: 1, //即时达
|
||||
TransportInfo: &TransportInfo{
|
||||
TransportName: "测试西南交大店",
|
||||
TransportAddress: "成都市金牛区交大路银桂桥二巷60号",
|
||||
TransportLongitude: 104.047773,
|
||||
TransportLatitude: 30.695838,
|
||||
PositionSource: 3,
|
||||
TransportTel: "18160030913",
|
||||
},
|
||||
OrderAddTime: time.Now().UnixNano() / 1e6,
|
||||
OrderTotalAmount: 12,
|
||||
OrderActualAmount: 10,
|
||||
OrderWeight: 1.2,
|
||||
OrderRemark: utils.FilterMb4("客户电话:18160030913,测试取货失败或配送遇到问题请联系18048531223,禁止未配送直接完成定单!"),
|
||||
IsInvoiced: 0,
|
||||
OrderPaymentStatus: 1,
|
||||
OrderPaymentMethod: 1,
|
||||
IsAgentPayment: 0,
|
||||
GoodsCount: 2,
|
||||
ReceiverInfo: &ReceiverInfo{
|
||||
ReceiverName: "苏尹岚",
|
||||
ReceiverAddress: "武侯大道金色花园A区",
|
||||
ReceiverLongitude: 104.01459,
|
||||
ReceiverLatitude: 30.636258,
|
||||
ReceiverPrimaryPhone: "18160030913",
|
||||
ReceiverSecondPhone: "18160030913",
|
||||
PositionSource: 3,
|
||||
},
|
||||
SerialNumber: "测试1#",
|
||||
}
|
||||
var skuInfo []*ItemsJSON
|
||||
// for _, v := range order.Skus {
|
||||
skuInfo = append(skuInfo, &ItemsJSON{
|
||||
ItemID: "30677",
|
||||
ItemName: "测试商品",
|
||||
ItemQuantity: 1,
|
||||
ItemPrice: 3.6,
|
||||
ItemActualPrice: 2,
|
||||
})
|
||||
// }
|
||||
params.ItemsJSON = skuInfo
|
||||
//要求饿百的订单要传来源
|
||||
// if order.VendorID == model.VendorIDEBAI {
|
||||
// params.OrderSource = "109"
|
||||
// params.ChannelOrderCode = order.VendorOrderID
|
||||
// }
|
||||
err := api.CreateOrder(params)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestComplaintRider(t *testing.T) {
|
||||
err := api.ComplaintRider("2118635456000161", 130)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestCancelOrder(t *testing.T) {
|
||||
err := api.CancelOrder(&CancelOrderParam{
|
||||
PartnerOrderCode: "89296492736359287",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package fnpsapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
StoreNotExist = "门店信息不存在"
|
||||
StoreExist = "该门店已存在"
|
||||
)
|
||||
|
||||
type CreateStoreParam struct {
|
||||
ChainStoreCode string `json:"chain_store_code,omitempty"`
|
||||
ChainStoreName string `json:"chain_store_name,omitempty"`
|
||||
ChainStoreType int `json:"chain_store_type,omitempty"`
|
||||
MerchantCode string `json:"merchant_code,omitempty"`
|
||||
ContactPhone string `json:"contact_phone,omitempty"`
|
||||
Address string `json:"address,omitempty"`
|
||||
PositionSource int `json:"position_source,omitempty"`
|
||||
Longitude string `json:"longitude,omitempty"`
|
||||
Latitude string `json:"latitude,omitempty"`
|
||||
ServiceCode string `json:"service_code,omitempty"`
|
||||
}
|
||||
|
||||
func (a *API) CreateStore(createStoreParam *CreateStoreParam) (err error) {
|
||||
createStoreParam.ServiceCode = "1"
|
||||
params := utils.Struct2FlatMap(createStoreParam)
|
||||
_, err = a.AccessAPI("v2/chain_store", URL, params, true)
|
||||
return err
|
||||
}
|
||||
|
||||
type GetStoreResult struct {
|
||||
ChainStoreCode string `json:"chain_store_code"`
|
||||
ChainStoreName string `json:"chain_store_name"`
|
||||
Address string `json:"address"`
|
||||
Latitude string `json:"latitude"`
|
||||
Longitude string `json:"longitude"`
|
||||
PositionSource int `json:"position_source"`
|
||||
City string `json:"city"`
|
||||
ContactPhone string `json:"contact_phone"`
|
||||
ServiceCode string `json:"service_code"`
|
||||
Status int `json:"status"` //1关店,2开店
|
||||
}
|
||||
|
||||
func (a *API) GetStore(storeID string) (getStoreResult *GetStoreResult, err error) {
|
||||
result, err := a.AccessAPI("v2/chain_store/query", URL, map[string]interface{}{
|
||||
"chain_store_code": []string{storeID},
|
||||
}, true)
|
||||
if err == nil {
|
||||
if data, ok := result["data"].([]interface{}); ok {
|
||||
utils.Map2StructByJson(data[0], &getStoreResult, false)
|
||||
} else {
|
||||
err = fmt.Errorf(result["msg"].(string))
|
||||
}
|
||||
}
|
||||
return getStoreResult, err
|
||||
}
|
||||
|
||||
func IsErrShopNotExist(err error) bool {
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), StoreNotExist) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsErrShopExist(err error) bool {
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), StoreExist) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *API) UpdateStore(createStoreParam *CreateStoreParam) (err error) {
|
||||
params := utils.Struct2FlatMap(createStoreParam)
|
||||
_, err = a.AccessAPI("v2/chain_store/update", URL, params, true)
|
||||
return err
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package fnpsapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
func TestCreateStore(t *testing.T) {
|
||||
err := api.CreateStore(&CreateStoreParam{
|
||||
ChainStoreCode: "667281",
|
||||
ChainStoreName: "测试西南交大店",
|
||||
ChainStoreType: 2,
|
||||
ContactPhone: "18160030913",
|
||||
Address: "成都市金牛区交大路银桂桥二巷60号",
|
||||
PositionSource: 3,
|
||||
Longitude: "104.047773",
|
||||
Latitude: "30.695838",
|
||||
ServiceCode: "1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestGetStore(t *testing.T) {
|
||||
result, err := api.GetStore("667281")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestUpdateStore(t *testing.T) {
|
||||
err := api.UpdateStore(&CreateStoreParam{
|
||||
ChainStoreCode: "667281",
|
||||
Address: "1111111",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -297,10 +297,14 @@ func (a *API) RetailInitData(trackInfo, poiCode, foodCode string, params map[str
|
||||
}
|
||||
|
||||
func (a *API) RetailBatchInitData(trackInfo, poiCode string, foodDataList []map[string]interface{}) (failedFoodList []*AppFoodResult, err error) {
|
||||
globals.SugarLogger.Debugf("=============result := %d", len(foodDataList))
|
||||
result, err := a.AccessAPI2("retail/batchinitdata", false, map[string]interface{}{
|
||||
KeyAppPoiCode: poiCode,
|
||||
"food_data": string(utils.MustMarshal(foodDataList)),
|
||||
}, resultKeyMsg, trackInfo)
|
||||
globals.SugarLogger.Debugf("=============result := %s", utils.Format4Output(result, false))
|
||||
globals.SugarLogger.Debugf("=============err := %v", err)
|
||||
|
||||
if err == nil {
|
||||
failedFoodList, err = handleRetailBatchResult(result)
|
||||
}
|
||||
|
||||
@@ -430,7 +430,6 @@ func (a *API) GetWarehouseByStore(storeID int64) (*warehouse_getWarehouseByStore
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
globals.SugarLogger.Debugf("GetWarehouseByStore response=%s", utils.Format4Output(response, false))
|
||||
if response.Code != RequestSuccessCode {
|
||||
globals.SugarLogger.Debugf("GetWarehouseByStore errMsg=%s", response.LogId+","+response.Msg+","+response.SubMsg)
|
||||
return nil, errors.New(response.LogId + response.Msg + "," + response.SubMsg)
|
||||
|
||||
Reference in New Issue
Block a user