1
This commit is contained in:
152
platformapi/lakala/lakala_order.go
Normal file
152
platformapi/lakala/lakala_order.go
Normal file
@@ -0,0 +1,152 @@
|
||||
package lakala
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// CreateOrder 创建交易订单
|
||||
func (a *API) CreateOrder(param *CreateOrderReq) (*CreateOrderResp, error) {
|
||||
reqParameter := map[string]interface{}{
|
||||
"req_data": utils.Struct2Map(param, "", false),
|
||||
"version": Version2,
|
||||
"req_time": utils.Time2TimeStrByFormat(time.Now(), TimeFormat),
|
||||
}
|
||||
result, err := a.AccessAPISign(OrderTestUrl, CrateOrderActive, http.MethodPost, "", reqParameter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if result["code"].(string) != Success {
|
||||
return nil, fmt.Errorf(result["msg"].(string))
|
||||
}
|
||||
|
||||
bodyResult, err := json.Marshal(result["resp_data"])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp := &CreateOrderResp{}
|
||||
if err = json.Unmarshal(bodyResult, resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// CloseOrder 订单关单(超时支付订单,主动关闭)
|
||||
func (a *API) CloseOrder(param *CloseOrderReq) (string, error) {
|
||||
if param.OutOrderNo == "" && param.PayOrderNo == "" {
|
||||
return "", fmt.Errorf("out_order_no,pay_order_no 不能同时为空")
|
||||
}
|
||||
|
||||
reqParameter := map[string]interface{}{
|
||||
"req_data": utils.Struct2Map(param, "", false),
|
||||
"version": Version2,
|
||||
"req_time": utils.Time2TimeStrByFormat(time.Now(), TimeFormat),
|
||||
}
|
||||
result, err := a.AccessAPISign(OrderTestUrl, CloseOrderActive, http.MethodPost, "", reqParameter)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if result["code"].(string) != Success {
|
||||
return "", fmt.Errorf(result["msg"].(string))
|
||||
}
|
||||
|
||||
return result["resp_data"].(map[string]string)["order_status"], err
|
||||
}
|
||||
|
||||
// QueryOrder 收银订单查询
|
||||
func (a *API) QueryOrder(outOrderNo string, merchantNo string) (*QueryOrderResp, error) {
|
||||
reqParameter := map[string]interface{}{
|
||||
"req_data": map[string]string{"out_order_no": outOrderNo, "merchant_no": merchantNo, "channel_id": "15"},
|
||||
"version": Version2,
|
||||
"req_time": utils.Time2TimeStrByFormat(time.Now(), TimeFormat),
|
||||
}
|
||||
result, err := a.AccessAPISign(OrderTestUrl, QueryOrderActive, http.MethodPost, "", reqParameter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if result["code"].(string) != Success {
|
||||
return nil, fmt.Errorf(result["msg"].(string))
|
||||
}
|
||||
|
||||
bodyResult, err := json.Marshal(result["resp_data"])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp := &QueryOrderResp{}
|
||||
if err = json.Unmarshal(bodyResult, resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// RefundOrder 订单统一退货
|
||||
func (a *API) RefundOrder(param *RefundOrderReq) (*RefundOrderResp, error) {
|
||||
reqParameter := map[string]interface{}{
|
||||
"req_data": utils.Struct2Map(param, "", false),
|
||||
"version": Version2,
|
||||
"req_time": utils.Time2TimeStrByFormat(time.Now(), TimeFormat),
|
||||
}
|
||||
result, err := a.AccessAPISign(OrderTestUrl, OrderRefundActive, http.MethodPost, "", reqParameter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if result["code"].(string) != Success {
|
||||
return nil, fmt.Errorf(result["msg"].(string))
|
||||
}
|
||||
|
||||
bodyResult, err := json.Marshal(result["resp_data"])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp := &RefundOrderResp{}
|
||||
if err = json.Unmarshal(bodyResult, resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// RefundOrderQuery 订单同一退货查询
|
||||
func (a *API) RefundOrderQuery(param *RefundOrderQueryReq) ([]*RefundOrderQueryResp, error) {
|
||||
if param.OriginOutTradeNo == "" && param.OriginTradeRefNo == "" {
|
||||
return nil, fmt.Errorf("退款流水号/系统参考号必传一个")
|
||||
}
|
||||
reqParameter := map[string]interface{}{
|
||||
"req_data": utils.Struct2Map(param, "", false),
|
||||
"version": Version2,
|
||||
"req_time": utils.Time2TimeStrByFormat(time.Now(), TimeFormat),
|
||||
}
|
||||
result, err := a.AccessAPISign(OrderTestUrl, OrderRefundQueryActive, http.MethodPost, "", reqParameter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if result["code"].(string) != Success {
|
||||
return nil, fmt.Errorf(result["msg"].(string))
|
||||
}
|
||||
|
||||
bodyResult, err := json.Marshal(result["resp_data"].(map[string]interface{})["refund_list"])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp := make([]*RefundOrderQueryResp, 0, 0)
|
||||
if err = json.Unmarshal(bodyResult, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user