package ali_logistics_query

import (
	"errors"
	"git.rosy.net.cn/baseapi/utils"
	"net/http"
)

// GetLogisticsInfo 阿里云免费案例用完了,未充值续费
func (a *API) GetLogisticsInfo(logisticsNumber string) (*OrderDetail, error) {
	if len(logisticsNumber) == 0 {
		return nil, errors.New("参数不能为空")
	}
	param := make(map[string]interface{}, 1)
	param["number"] = logisticsNumber

	result, err := a.AccessAPI(BastUrl, GetOrderDetailApi, http.MethodGet, param)
	if err != nil {
		return nil, err
	}

	var detail *GetOrderDetail
	if err := utils.Map2StructByJson(result, &detail, false); err != nil {
		return nil, err
	}

	if detail.Code != 200 || !detail.Success {
		return nil, errors.New(detail.Msg)
	}

	return detail.Data, nil

}
