wd_refund.go 9.1 KB
package wangdian

import (
	"context"
	"github.com/gogf/gf/encoding/gjson"
	jsoniter "github.com/json-iterator/go"
)

var OrderRefund = new(orderRefund)

type orderRefund struct {
}

type SalesRefundPushReq struct {
	Tid           string             `json:"tid"`
	ShopNo        string             `json:"shop_no"`
	PlatformId    int                `json:"platform_id"`
	RefundNo      int                `json:"refund_no"`
	Type          int                `json:"type"`
	Status        string             `json:"status"`
	RefundFee     float64            `json:"refund_fee"`
	BuyerNick     string             `json:"buyer_nick"`
	RefundTime    string             `json:"refund_time"`
	Reason        string             `json:"reason"`
	Desc          string             `json:"desc"`
	RefundVersion string             `json:"refund_version"`
	OrderList     []*RefundOrderList `json:"order_list"`
}

type RefundOrderList struct {
	Oid string `json:"oid"`
	Num int    `json:"num"`
}

type SalesRefundPushRes struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

/**
创建原始退款单
*/
func (s *orderRefund) SalesRefundPush(ctx context.Context, req *SalesRefundPushReq) (res *SalesRefundPushRes, err error) {
	params := make(map[string]interface{})
	json, _ := jsoniter.MarshalToString(req)
	params["api_refund_list"] = json
	result, err := post(ctx, "/openapi2/sales_refund_push.php", params)
	if nil != err {
		return
	}
	err = gjson.New(result).Scan(&res)
	return
}

type RefundQueryReq struct {
	StartTime   string `json:"start_time"`
	EndTime     string `json:"end_time"`
	PageSize    string `json:"page_size"`
	PageNo      string `json:"page_no"`
	Tid         string `json:"tid"`
	LogisticsNo string `json:"logistics_no"`
	SrcRefundNo string `json:"src_refund_no"`
	RefundNo    string `json:"refund_no"`
}

type RefundQueryRes struct {
	Code       int    `json:"code"`
	Message    string `json:"message"`
	TotalCount string `json:"total_count"`
	Refunds    []struct {
		RefundId             string      `json:"refund_id"`
		RefundNo             string      `json:"refund_no"`
		Created              string      `json:"created"`
		SrcNo                string      `json:"src_no"`
		Type                 string      `json:"type"`
		ProcessStatus        string      `json:"process_status"`
		SwapTradeId          string      `json:"swap_trade_id"`
		Status               string      `json:"status"`
		PayAccount           string      `json:"pay_account"`
		PayNo                string      `json:"pay_no"`
		GoodsAmount          string      `json:"goods_amount"`
		RefundAmount         string      `json:"refund_amount"`
		GuaranteeMode        string      `json:"guarantee_mode"`
		CsStatus             string      `json:"cs_status"`
		SalesTid             string      `json:"sales_tid"`
		PostAmount           string      `json:"post_amount"`
		OtherAmount          string      `json:"other_amount"`
		Paid                 string      `json:"paid"`
		Tid                  string      `json:"tid"`
		SalesTradeId         string      `json:"sales_trade_id"`
		BuyerNick            string      `json:"buyer_nick"`
		ReceiverName         string      `json:"receiver_name"`
		ReceiverAddress      string      `json:"receiver_address"`
		ReceiverTelno        string      `json:"receiver_telno"`
		ReturnName           string      `json:"return_name"`
		ReturnMobile         string      `json:"return_mobile"`
		ReturnTelno          string      `json:"return_telno"`
		ExchangeAmount       string      `json:"exchange_amount"`
		ReturnAddress        string      `json:"return_address"`
		SwapReceiver         string      `json:"swap_receiver"`
		SwapMobile           string      `json:"swap_mobile"`
		SwapTelno            string      `json:"swap_telno"`
		SwapProvince         string      `json:"swap_province"`
		SwapCity             string      `json:"swap_city"`
		SwapDistrict         string      `json:"swap_district"`
		SwapArea             string      `json:"swap_area"`
		SwapAddress          string      `json:"swap_address"`
		RefundTime           string      `json:"refund_time"`
		Remark               string      `json:"remark"`
		Modified             string      `json:"modified"`
		ActualRefundAmount   string      `json:"actual_refund_amount"`
		GuaranteRefundAmount string      `json:"guarante_refund_amount"`
		OuterNo              string      `json:"outer_no"`
		ReturnLogisticsName  string      `json:"return_logistics_name"`
		ReturnLogisticsNo    string      `json:"return_logistics_no"`
		DirectRefundAmount   string      `json:"direct_refund_amount"`
		FinishTime           string      `json:"finish_time"`
		ShopNo               string      `json:"shop_no"`
		ShopName             string      `json:"shop_name"`
		PlatformId           string      `json:"platform_id"`
		ApiOuterNo           string      `json:"api_outer_no"`
		CustomerNo           string      `json:"customer_no"`
		CustomerName         string      `json:"customer_name"`
		SwapZip              interface{} `json:"swap_zip"`
		SwapLogisticsType    string      `json:"swap_logistics_type"`
		SwapLogisticsName    string      `json:"swap_logistics_name"`
		WarehouseNo          string      `json:"warehouse_no"`
		CreatorName          string      `json:"creator_name"`
		SwapWarehouseNo      string      `json:"swap_warehouse_no"`
		RefundReason         string      `json:"refund_reason"`
		SwapTradeNo          string      `json:"swap_trade_no"`
		RefundOrderList      []struct {
			OrderId           string `json:"order_id"`
			RefundId          string `json:"refund_id"`
			Oid               string `json:"oid"`
			Tid               string `json:"tid"`
			ProcessStatus     string `json:"process_status"`
			OrderNum          string `json:"order_num"`
			CostPrice         string `json:"cost_price"`
			Price             string `json:"price"`
			OriginalPrice     string `json:"original_price"`
			Discount          string `json:"discount"`
			Paid              string `json:"paid"`
			RefundNum         string `json:"refund_num"`
			TotalAmount       string `json:"total_amount"`
			RefundOrderAmount string `json:"refund_order_amount"`
			SpecNo            string `json:"spec_no"`
			SpecId            string `json:"spec_id"`
			GoodsName         string `json:"goods_name"`
			SpecName          string `json:"spec_name"`
			SuiteNo           string `json:"suite_no"`
			SuiteName         string `json:"suite_name"`
			SuiteNum          string `json:"suite_num"`
			StockinNum        string `json:"stockin_num"`
			Remark            string `json:"remark"`
			MarketPrice       string `json:"market_price"`
			SpecCode          string `json:"spec_code"`
			IsSnEnable        string `json:"is_sn_enable"`
			GoodsNo           string `json:"goods_no"`
			SalesTid          string `json:"sales_tid"`
		} `json:"refund_order_list"`
	} `json:"refunds"`
}

/**
查询退换管理
*/
func (s *orderRefund) RefundQuery(ctx context.Context, req *RefundQueryReq) (res *RefundQueryRes, err error) {

	result, err := post(ctx, "/openapi2/refund_query.php", req)
	if nil != err {
		return
	}
	err = gjson.New(result).Scan(&res)
	return
}

type StockRefundLogisticsQueryReq struct {
	StartTime   string `json:"start_time"`
	EndTime     string `json:"end_time"`
	PageSize    string `json:"page_size"`
	PageNo      string `json:"page_no"`
	LogisticsNo string `json:"logistics_no"`
}

type StockRefundLogisticsQueryRes struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Trades  []struct {
		RecId            string `json:"rec_id"`
		ShopNo           string `json:"shop_no"`
		Tid              string `json:"tid"`
		LogisticsType    string `json:"logistics_type"`
		LogisticsNo      string `json:"logistics_no"`
		DeliveryTerm     string `json:"delivery_term"`
		ConsignTime      string `json:"consign_time"`
		Oids             string `json:"oids"`
		IsPartSync       string `json:"is_part_sync"`
		PlatformId       string `json:"platform_id"`
		TradeId          string `json:"trade_id"`
		LogisticsNameErp string `json:"logistics_name_erp"`
		LogisticsCodeErp string `json:"logistics_code_erp"`
		LogisticsName    string `json:"logistics_name"`
	} `json:"trades"`
}

/**
查询退货物流单号
*/
func (s *orderRefund) StockRefundLogisticsQuery(ctx context.Context, req *StockRefundLogisticsQueryReq) (res *StockRefundLogisticsQueryRes, err error) {

	result, err := post(ctx, "/openapi2/stock_refund_logistics_query.php", req)
	if nil != err {
		return
	}
	err = gjson.New(result).Scan(&res)
	return
}

type StockinRefundPushReq struct {
	RefundNo      string `json:"refund_no"`
	OuterNo       string `json:"outer_no"`
	WarehouseNo   string `json:"warehouse_no"`
	LogisticsCode string `json:"logistics_code"`
	DetailList    []struct {
		SpecNo       string  `json:"spec_no"`
		StockinNum   int     `json:"stockin_num"`
		BatchNo      string  `json:"batch_no"`
		StockinPrice float64 `json:"stockin_price"`
	} `json:"detail_list"`
}

type StockinRefundPushRes struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

/**
创建退货入库单
*/
func (s *orderRefund) StockinRefundPush(ctx context.Context, req *StockinRefundPushReq) (res *StockinRefundPushRes, err error) {

	result, err := post(ctx, "/openapi2/stockin_refund_push.php", req)
	if nil != err {
		return
	}
	err = gjson.New(result).Scan(&res)
	return
}