package pddapi

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

const (
	OrderStatusPay       = 0  //-已支付；
	OrderStatus1         = 1  //-已成团；
	OrderStatusTakeOver  = 2  //-确认收货；
	OrderStatusAuditOver = 3  //-审核成功；
	OrderStatusAuditFail = 4  //-审核失败（不可提现）；
	OrderStatusEaring    = 5  //-已经结算 ;
	OrderStatusJuge      = 10 //-已处罚
)

type OrderListRangeGetResult struct {
	LastOrderID string `json:"last_order_id"`
	OrderList   []struct {
		SepMarketFee          int    `json:"sep_market_fee"`
		GoodsPrice            int    `json:"goods_price"`
		SepDuoID              int    `json:"sep_duo_id"`
		PromotionRate         int    `json:"promotion_rate"`
		Type                  int    `json:"type"`
		CatIds                []int  `json:"cat_ids"`
		OrderStatus           int    `json:"order_status"`
		OrderCreateTime       int    `json:"order_create_time"`
		IsDirect              int    `json:"is_direct"`
		OrderGroupSuccessTime int    `json:"order_group_success_time"`
		OrderAmount           int    `json:"order_amount"`
		PriceCompareStatus    int    `json:"price_compare_status"`
		OrderModifyAt         int    `json:"order_modify_at"`
		AuthDuoID             int    `json:"auth_duo_id"`
		CpaNew                int    `json:"cpa_new"`
		GoodsName             string `json:"goods_name"`
		BatchNo               string `json:"batch_no"`
		GoodsQuantity         int    `json:"goods_quantity"`
		GoodsID               int64  `json:"goods_id"`
		SepParameters         string `json:"sep_parameters"`
		SepRate               int    `json:"sep_rate"`
		CustomParameters      string `json:"custom_parameters"`
		GoodsThumbnailURL     string `json:"goods_thumbnail_url"`
		ShareRate             int    `json:"share_rate"`
		PromotionAmount       int    `json:"promotion_amount"`
		OrderPayTime          int    `json:"order_pay_time"`
		GroupID               int64  `json:"group_id"`
		SepPid                string `json:"sep_pid"`
		OrderStatusDesc       string `json:"order_status_desc"`
		ShareAmount           int    `json:"share_amount"`
		GoodsSign             string `json:"goods_sign"`
		OrderSn               string `json:"order_sn"`
		PID                   string `json:"p_id"`
		ZsDuoID               int    `json:"zs_duo_id"`
	} `json:"order_list"`
	RequestID string `json:"request_id"`
}

//查询订单列表
func (a *API) OrderListRangeGet(beginTime, endTime, lastOrderID string, pageSize int) (orderListRangeGetResult *OrderListRangeGetResult, err error) {
	params := map[string]interface{}{
		"start_time": beginTime,
		"end_time":   endTime,
		"page_size":  pageSize,
	}
	if lastOrderID != "" {
		params["last_order_id"] = lastOrderID
	}
	result, err := a.AccessAPI("pdd.ddk.order.list.range.get", false, params)
	if err == nil {
		utils.Map2StructByJson(result["order_list_get_response"], &orderListRangeGetResult, false)
	}
	return orderListRangeGetResult, err
}

type OrderDetailGetResult struct {
	SepMarketFee          int    `json:"sep_market_fee"`
	GoodsPrice            int    `json:"goods_price"`
	SepDuoID              int    `json:"sep_duo_id"`
	CpsSign               string `json:"cps_sign"`
	Pid                   string `json:"pid"`
	PromotionRate         int    `json:"promotion_rate"`
	Type                  int    `json:"type"`
	CatIds                []int  `json:"cat_ids"`
	OrderStatus           int    `json:"order_status"`
	OrderCreateTime       int    `json:"order_create_time"`
	IsDirect              int    `json:"is_direct"`
	OrderGroupSuccessTime int    `json:"order_group_success_time"`
	OrderAmount           int    `json:"order_amount"`
	PriceCompareStatus    int    `json:"price_compare_status"`
	OrderModifyAt         int    `json:"order_modify_at"`
	AuthDuoID             int    `json:"auth_duo_id"`
	CpaNew                int    `json:"cpa_new"`
	GoodsName             string `json:"goods_name"`
	BatchNo               string `json:"batch_no"`
	URLLastGenerateTime   int    `json:"url_last_generate_time"`
	GoodsQuantity         int    `json:"goods_quantity"`
	GoodsID               int64  `json:"goods_id"`
	SepParameters         string `json:"sep_parameters"`
	SepRate               int    `json:"sep_rate"`
	CustomParameters      string `json:"custom_parameters"`
	GoodsThumbnailURL     string `json:"goods_thumbnail_url"`
	ShareRate             int    `json:"share_rate"`
	PromotionAmount       int    `json:"promotion_amount"`
	OrderPayTime          int    `json:"order_pay_time"`
	GroupID               int64  `json:"group_id"`
	SepPid                string `json:"sep_pid"`
	ReturnStatus          int    `json:"return_status"`
	OrderStatusDesc       string `json:"order_status_desc"`
	ShareAmount           int    `json:"share_amount"`
	RequestID             string `json:"request_id"`
	GoodsSign             string `json:"goods_sign"`
	OrderSn               string `json:"order_sn"`
	ZsDuoID               int    `json:"zs_duo_id"`
}

//查询订单详情
func (a *API) OrderDetailGet(orderID string) (orderDetailGetResult *OrderDetailGetResult, err error) {
	params := map[string]interface{}{
		"order_sn": orderID,
	}
	result, err := a.AccessAPI("pdd.ddk.order.detail.get", false, params)
	if err == nil {
		utils.Map2StructByJson(result["order_detail_response"], &orderDetailGetResult, false)
	}
	return orderDetailGetResult, err
}

type OrderListIncrementGetResult struct {
	SepMarketFee          int    `json:"sep_market_fee"`
	GoodsPrice            int    `json:"goods_price"`
	SepDuoID              int    `json:"sep_duo_id"`
	PromotionRate         int    `json:"promotion_rate"`
	Type                  int    `json:"type"`
	CatIds                []int  `json:"cat_ids"`
	OrderStatus           int    `json:"order_status"`
	OrderCreateTime       int    `json:"order_create_time"`
	OrderSettleTime       int    `json:"order_settle_time"`
	IsDirect              int    `json:"is_direct"`
	OrderGroupSuccessTime int    `json:"order_group_success_time"`
	OrderAmount           int    `json:"order_amount"`
	PriceCompareStatus    int    `json:"price_compare_status"`
	OrderModifyAt         int    `json:"order_modify_at"`
	AuthDuoID             int    `json:"auth_duo_id"`
	CpaNew                int    `json:"cpa_new"`
	GoodsName             string `json:"goods_name"`
	BatchNo               string `json:"batch_no"`
	GoodsQuantity         int    `json:"goods_quantity"`
	GoodsID               int64  `json:"goods_id"`
	SepParameters         string `json:"sep_parameters"`
	SepRate               int    `json:"sep_rate"`
	CustomParameters      string `json:"custom_parameters"`
	GoodsThumbnailURL     string `json:"goods_thumbnail_url"`
	ShareRate             int    `json:"share_rate"`
	PromotionAmount       int    `json:"promotion_amount"`
	OrderPayTime          int    `json:"order_pay_time"`
	GroupID               int64  `json:"group_id"`
	SepPid                string `json:"sep_pid"`
	FailReason            string `json:"fail_reason"`
	OrderStatusDesc       string `json:"order_status_desc"`
	ShareAmount           int    `json:"share_amount"`
	OrderID               string `json:"order_id"`
	GoodsSign             string `json:"goods_sign"`
	OrderSn               string `json:"order_sn"`
	PID                   string `json:"p_id"`
	ZsDuoID               int    `json:"zs_duo_id"`
	OrderReceiveTime      int    `json:"order_receive_time"`
}

//查询订单列表2
func (a *API) OrderListIncrementGet(start_update_time, end_update_time int64, page, pageSize int) (orderListIncrementGetResult []*OrderListIncrementGetResult, err error) {
	params := map[string]interface{}{
		"start_update_time": start_update_time,
		"end_update_time":   end_update_time,
		"page":              page,
		"page_size":         pageSize,
		"return_count":      false,
	}
	result, err := a.AccessAPI("pdd.ddk.order.list.increment.get", false, params)
	if err == nil {
		utils.Map2StructByJson(result["order_list_get_response"].(map[string]interface{})["order_list"], &orderListIncrementGetResult, false)
	}
	return orderListIncrementGetResult, err
}
