1.4.5.2
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
// 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()
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// 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()
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//go:build plus
|
||||
|
||||
package income
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(plus.NewHelper(plus.ComponentCodeFinance)).
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeFinance)).
|
||||
Data("teaMenu", "finance").
|
||||
Data("teaSubMenu", "income").
|
||||
|
||||
// 财务管理
|
||||
Prefix("/finance/income").
|
||||
Get("", new(IndexAction)).
|
||||
Get("/monthly", new(MonthlyAction)).
|
||||
Get("/daily", new(DailyAction)).
|
||||
|
||||
//
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// 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()
|
||||
}
|
||||
Reference in New Issue
Block a user