// 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 MonthlyAction struct { actionutils.ParentAction } func (this *MonthlyAction) Init() { this.Nav("", "", "monthly") } func (this *MonthlyAction) RunGet(params struct { DayFrom string DayTo string }) { var dayFrom = params.DayFrom var dayTo = params.DayTo if len(dayFrom) == 0 { dayFrom = timeutil.Format("Y-m-01", time.Now().AddDate(0, -12, 0)) } 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().ListUserAccountMonthlyStats(this.AdminContext(), &pb.ListUserAccountMonthlyStatsRequest{ 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{ "month": stat.Month[:4] + "-" + stat.Month[4:6], "income": stat.Income, "expense": stat.Expense, }) } this.Data["stats"] = statMaps this.Show() }