mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 13:10:26 +08:00 
			
		
		
		
	优化代码
This commit is contained in:
		@@ -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()
 | 
			
		||||
}
 | 
			
		||||
@@ -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()
 | 
			
		||||
}
 | 
			
		||||
@@ -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()
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
@@ -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")
 | 
			
		||||
}
 | 
			
		||||
@@ -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()
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
@@ -27,8 +27,6 @@ import (
 | 
			
		||||
	_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/db"
 | 
			
		||||
	_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns"
 | 
			
		||||
	_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/tasks"
 | 
			
		||||
	_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/finance"
 | 
			
		||||
	_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/finance/bills"
 | 
			
		||||
	_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/index"
 | 
			
		||||
	_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/log"
 | 
			
		||||
	_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/logout"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user