package jdapi

import "git.rosy.net.cn/baseapi/utils"

// 新版订单金额拆分接口
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=182&apiid=4d1494c5e7ac4679bfdaaed950c5bc7f
func (a *API) QueryOassBussMoney(orderId string) ([]map[string]interface{}, error) {
	jdParams := map[string]interface{}{
		"orderId": orderId,
	}
	result, err := a.AccessAPINoPage("oassBussService/queryOassBussMoney", jdParams, nil, nil, genNoPageResultParser("errorCode", "errorInfos", "data", "0"))
	if err != nil {
		return nil, err
	}
	return utils.Slice2MapSlice(result.([]interface{})), nil
}

type CheckAfsBillResult struct {
	AfsID                     int     `json:"afsId"`
	AfsSource                 int     `json:"afsSource"`
	AfsType                   int     `json:"afsType"`
	BillOrderType             int     `json:"billOrderType"`
	DiffLessCommision         float64 `json:"diffLessCommision"`
	FreightBill               int     `json:"freightBill"`
	FreightCommissionBill     int     `json:"freightCommissionBill"`
	GiftcardBill              int     `json:"giftcardBill"`
	GiftcardBillStatus        int     `json:"giftcardBillStatus"`
	GoodsBill                 int     `json:"goodsBill"`
	GoodsCommissionBill       int     `json:"goodsCommissionBill"`
	GoogsSettlementStatus     int     `json:"googsSettlementStatus"`
	MarketBill                int     `json:"marketBill"`
	MarketSettlementStatus    int     `json:"marketSettlementStatus"`
	MarketingServiceFee       int     `json:"marketingServiceFee"`
	MarketingServiceFeeStatus int     `json:"marketingServiceFeeStatus"`
	OrderID                   int64   `json:"orderId"`
	PackageBill               int     `json:"packageBill"`
}

// 查询订单售后计费明细接口
// https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=182&apiid=4a0b2f16ae884695876aab70e79783ee
func (a *API) CheckAfsBill(orderId string) (checkAfsBillResult []*CheckAfsBillResult, err error) {
	jdParams := map[string]interface{}{
		"orderId": orderId,
	}
	result, err := a.AccessAPINoPage("bill/checkAfsBill", jdParams, nil, nil, genNoPageResultParser("code", "msg", "result", "200"))
	if err == nil {
		utils.Map2StructByJson(result, &checkAfsBillResult, false)
	}
	return checkAfsBillResult, nil
}

// 分页查询结算单
// http://opendj.jd.com/staticnew/widgets/resources.html?groupid=182&apiid=3c6214051ba04226afc021d7b86f83f9
func (a *API) GetSettleOrderList(orderId string) (checkAfsBillResult []*CheckAfsBillResult, err error) {
	jdParams := map[string]interface{}{
		"finishTimeStart": "20210722",
		"finishTimeEnd":   "20210723",
	}
	result, err := a.AccessAPINoPage("settle/getSettleOrderList", jdParams, nil, nil, genNoPageResultParser("code", "msg", "result", "200"))
	if err == nil {
		utils.Map2StructByJson(result, &checkAfsBillResult, false)
	}
	return checkAfsBillResult, nil
}
