package jd_cookie

import (
	"context"
	"kami/api/jd_cookie/v1"
	"kami/internal/errHandler"
	"kami/internal/service"

	"github.com/gogf/gf/v2/errors/gcode"
	"github.com/gogf/gf/v2/errors/gerror"
)

// ListOrder 订单列表查询
func (c *ControllerV1) ListOrder(ctx context.Context, req *v1.ListOrderReq) (res *v1.ListOrderRes, err error) {
	_, err = service.SysAuth().LoginOnlyIFrame(ctx)
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeNotAuthorized, err, "权限不足")
		return
	}

	list, total, err := service.JdCookie().ListOrder(ctx, req.Page, req.Size, req.Status, req.StartTime, req.EndTime)
	if err != nil {
		return nil, gerror.WrapCode(gcode.CodeInternalError, err, "订单列表查询失败")
	}

	res = &v1.ListOrderRes{
		List:  list,
		Total: total,
	}
	return
}
