56 lines
1.2 KiB
Go
56 lines
1.2 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"
|
|
)
|
|
|
|
type DailyAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *DailyAction) Init() {
|
|
this.Nav("", "", "monthly")
|
|
}
|
|
|
|
func (this *DailyAction) RunGet(params struct {
|
|
Month string
|
|
}) {
|
|
if len(params.Month) == 0 {
|
|
params.Month = timeutil.Format("Y-m")
|
|
}
|
|
|
|
this.Data["month"] = params.Month
|
|
|
|
var dayFrom = params.Month + "-01"
|
|
var dayTo = params.Month + "-32"
|
|
|
|
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 {
|
|
if stat.Day > timeutil.Format("Ymd") {
|
|
continue
|
|
}
|
|
|
|
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()
|
|
}
|