Initial commit (code only without large binaries)
This commit is contained in:
58
EdgeUser/internal/web/actions/default/finance/bills/pay.go
Normal file
58
EdgeUser/internal/web/actions/default/finance/bills/pay.go
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package bills
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
type PayAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *PayAction) RunPost(params struct {
|
||||
BillId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.UserBill_LogPayUserBill, params.BillId)
|
||||
|
||||
billResp, err := this.RPC().UserBillRPC().FindUserBill(this.UserContext(), &pb.FindUserBillRequest{UserBillId: params.BillId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var bill = billResp.UserBill
|
||||
if bill == nil {
|
||||
this.Fail("找不到要支付的账单")
|
||||
}
|
||||
|
||||
if bill.IsPaid {
|
||||
this.Fail("此账单已支付,不需要重复支付")
|
||||
}
|
||||
|
||||
// 账号余额
|
||||
accountResp, err := this.RPC().UserAccountRPC().FindEnabledUserAccountWithUserId(this.UserContext(), &pb.FindEnabledUserAccountWithUserIdRequest{UserId: this.UserId()})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var account = accountResp.UserAccount
|
||||
if account == nil {
|
||||
this.Fail("当前用户还没有账号")
|
||||
}
|
||||
|
||||
if account.Total < bill.Amount {
|
||||
this.Fail("账号余额不足,当前余额:" + types.String(account.Total) + ",需要支付:" + types.String(bill.Amount))
|
||||
}
|
||||
|
||||
// 支付
|
||||
_, err = this.RPC().UserBillRPC().PayUserBill(this.UserContext(), &pb.PayUserBillRequest{UserBillId: params.BillId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user