Files
waf-platform/EdgeAdmin/internal/web/actions/default/finance/bills/index.go

94 lines
2.3 KiB
Go

package bills
import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
"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{
PaidFlag: params.PaidFlag,
UserId: params.UserId,
Month: params.Month,
})
if err != nil {
this.ErrorPage(err)
return
}
var 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
}
var 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,
"username": bill.User.Username,
}
}
var month = bill.Month
var dayFrom = bill.DayFrom
var dayTo = bill.DayTo
if len(month) == 6 {
month = month[:4] + "-" + month[4:]
}
if len(dayFrom) == 8 {
dayFrom = dayFrom[:4] + "-" + dayFrom[4:6] + "-" + dayFrom[6:]
}
if len(dayTo) == 8 {
dayTo = dayTo[:4] + "-" + dayTo[4:6] + "-" + dayTo[6:]
}
billMaps = append(billMaps, maps.Map{
"id": bill.Id,
"isPaid": bill.IsPaid,
"month": month,
"dayFrom": dayFrom,
"dayTo": dayTo,
"amount": numberutils.FormatFloat(bill.Amount, 2),
"typeName": bill.TypeName,
"user": userMap,
"description": bill.Description,
"code": bill.Code,
"canPay": bill.CanPay,
"pricePeriodName": userconfigs.PricePeriodName(bill.PricePeriod),
"pricePeriod": bill.PricePeriod,
"isOverdue": bill.IsOverdue,
})
}
this.Data["bills"] = billMaps
this.Show()
}