优化代码

This commit is contained in:
GoEdgeLab
2021-10-22 13:57:04 +08:00
parent b7eb99322f
commit fa0f53d698
6 changed files with 0 additions and 163 deletions

View File

@@ -1,38 +0,0 @@
package bills
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
timeutil "github.com/iwind/TeaGo/utils/time"
"time"
)
type GenerateAction struct {
actionutils.ParentAction
}
func (this *GenerateAction) Init() {
this.Nav("", "", "generate")
}
func (this *GenerateAction) RunGet(params struct{}) {
this.Data["month"] = timeutil.Format("Ym", time.Now().AddDate(0, -1, 0))
this.Show()
}
func (this *GenerateAction) RunPost(params struct {
Month string
Must *actions.Must
}) {
defer this.CreateLogInfo("手动生成上个月(" + params.Month + ")账单")
_, err := this.RPC().UserBillRPC().GenerateAllUserBills(this.AdminContext(), &pb.GenerateAllUserBillsRequest{Month: params.Month})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -1,65 +0,0 @@
package bills
import (
"fmt"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "index")
}
func (this *IndexAction) RunGet(params struct {
PaidFlag int32 `default:"-1"`
UserId int64
Month string
}) {
countResp, err := this.RPC().UserBillRPC().CountAllUserBills(this.AdminContext(), &pb.CountAllUserBillsRequest{})
if err != nil {
this.ErrorPage(err)
return
}
page := this.NewPage(countResp.Count)
this.Data["page"] = page.AsHTML()
billsResp, err := this.RPC().UserBillRPC().ListUserBills(this.AdminContext(), &pb.ListUserBillsRequest{
PaidFlag: params.PaidFlag,
UserId: params.UserId,
Month: params.Month,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
billMaps := []maps.Map{}
for _, bill := range billsResp.UserBills {
var userMap maps.Map = nil
if bill.User != nil {
userMap = maps.Map{
"id": bill.User.Id,
"fullname": bill.User.Fullname,
}
}
billMaps = append(billMaps, maps.Map{
"id": bill.Id,
"isPaid": bill.IsPaid,
"month": bill.Month,
"amount": fmt.Sprintf("%.2f", bill.Amount),
"typeName": bill.TypeName,
"user": userMap,
"description": bill.Description,
})
}
this.Data["bills"] = billMaps
this.Show()
}

View File

@@ -1,22 +0,0 @@
package bills
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeFinance)).
Data("teaMenu", "finance").
// 财务管理
Prefix("/finance/bills").
Get("", new(IndexAction)).
GetPost("/generate", new(GenerateAction)).
EndAll()
})
}

View File

@@ -1,16 +0,0 @@
package finance
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
}
func (this *IndexAction) RunGet(params struct{}) {
// TODO 暂时先跳转到账单页将来做成Dashboard
this.RedirectURL("/finance/bills")
}

View File

@@ -1,20 +0,0 @@
package finance
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeFinance)).
// 财务管理
Prefix("/finance").
Get("", new(IndexAction)).
EndAll()
})
}