package card_info_t_mall_game

import (
	"context"
	"kami/internal/errHandler"
	"kami/internal/model"
	"kami/internal/service"

	"github.com/jinzhu/copier"

	"kami/api/card_info_t_mall_game/v1"

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

func (c *ControllerV1) TMallGameDailyOrderSummary(ctx context.Context, req *v1.TMallGameDailyOrderSummaryReq) (res *v1.TMallGameDailyOrderSummaryRes, err error) {
	orderService := service.RechargeTMallGameOrder()
	res = &v1.TMallGameDailyOrderSummaryRes{}
	total, list, err := orderService.GetOrderSummary(ctx, &model.TMallSummaryListRecordInput{
		TMallGameDailyOrderSummaryReq: *req,
	})
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeInternalError, err, "获取订单统计失败")
		return
	}
	res.Total = total
	err = copier.CopyWithOption(&res.List, &list, copier.Option{IgnoreEmpty: true, DeepCopy: true})
	err = errHandler.WrapError(ctx, gcode.CodeInternalError, err, "转换订单统计数据失败")
	return
}
