package service

import (
	"fmt"
	"gadmin/config"
	"gadmin/internal/admin/forms"
	"gadmin/internal/gorm/model"
	"gadmin/internal/gorm/query"

	"strings"
)

var TreasureChest = new(sTreasureChest)

type sTreasureChest struct{}

// QueryTreasureLog 统计宝物碎片信息
func (s *sTreasureChest) QueryTreasureChestList(params forms.TreasureChestReportReq) (result []*model.ReportDayTreasureChest, err error) {
	rdb := query.Use(config.DB).ReportDayTreasureChest

	m := rdb.Where(rdb.Date.Gte(params.Day), rdb.Date.Lt(params.EndDay)).Order(rdb.Date.Desc())

	if params.ServerId > 0 {
		m = m.Where(rdb.ServerID.Eq(int32(params.ServerId)))
	}

	result, err = m.Find()
	if err != nil {
		return
	}

	fmt.Println("=====", result)

	for _, v := range result {
		v.Date = strings.ReplaceAll(v.Date, "T00:00:00+08:00", "")
	}
	return
}
