59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
|
|
package income
|
|
|
|
import (
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
"github.com/iwind/TeaGo/maps"
|
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
|
"time"
|
|
)
|
|
|
|
type IndexAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *IndexAction) Init() {
|
|
this.Nav("", "", "daily")
|
|
}
|
|
|
|
func (this *IndexAction) RunGet(params struct {
|
|
DayFrom string
|
|
DayTo string
|
|
}) {
|
|
var dayFrom = params.DayFrom
|
|
var dayTo = params.DayTo
|
|
if len(dayFrom) == 0 {
|
|
dayFrom = timeutil.Format("Y-m-d", time.Now().AddDate(0, 0, -14))
|
|
}
|
|
if len(dayTo) == 0 {
|
|
dayTo = timeutil.Format("Y-m-d")
|
|
}
|
|
if dayFrom > dayTo {
|
|
dayFrom, dayTo = dayTo, dayFrom
|
|
}
|
|
this.Data["dayFrom"] = dayFrom
|
|
this.Data["dayTo"] = dayTo
|
|
|
|
statsResp, err := this.RPC().UserAccountDailyStatRPC().ListUserAccountDailyStats(this.AdminContext(), &pb.ListUserAccountDailyStatsRequest{
|
|
DayFrom: dayFrom,
|
|
DayTo: dayTo,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
var statMaps = []maps.Map{}
|
|
for _, stat := range statsResp.Stats {
|
|
statMaps = append(statMaps, maps.Map{
|
|
"day": stat.Day[:4] + "-" + stat.Day[4:6] + "-" + stat.Day[6:],
|
|
"income": stat.Income,
|
|
"expense": stat.Expense,
|
|
})
|
|
}
|
|
this.Data["stats"] = statMaps
|
|
|
|
this.Show()
|
|
}
|