1.4.5.2
This commit is contained in:
94
EdgeUser/internal/web/actions/default/finance/pay/index.go
Normal file
94
EdgeUser/internal/web/actions/default/finance/pay/index.go
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package pay
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/ttlcache"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/rands"
|
||||
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||
"github.com/skip2/go-qrcode"
|
||||
"time"
|
||||
)
|
||||
|
||||
var qrcodeKeySalt = rands.HexString(32)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
Code string
|
||||
From string
|
||||
ReturnURL string
|
||||
}) {
|
||||
this.Data["fromURL"] = params.From
|
||||
this.Data["returnURL"] = params.ReturnURL
|
||||
|
||||
orderResp, err := this.RPC().UserOrderRPC().FindEnabledUserOrder(this.UserContext(), &pb.FindEnabledUserOrderRequest{Code: params.Code})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var order = orderResp.UserOrder
|
||||
if order == nil {
|
||||
this.ErrorPage(errors.New("can not find order with code '" + params.Code + "'"))
|
||||
return
|
||||
}
|
||||
|
||||
var methodMap = maps.Map{
|
||||
"name": "",
|
||||
}
|
||||
var qrcodeKey = ""
|
||||
var qrcodeTitle = ""
|
||||
if order.OrderMethod != nil {
|
||||
methodMap = maps.Map{
|
||||
"name": order.OrderMethod.Name,
|
||||
}
|
||||
|
||||
qrcodeTitle = order.OrderMethod.QrcodeTitle
|
||||
|
||||
if len(qrcodeTitle) == 0 && len(order.OrderMethod.ParentCode) > 0 {
|
||||
var parentDef = userconfigs.FindPresetPayMethodWithCode(order.OrderMethod.ParentCode)
|
||||
if parentDef != nil {
|
||||
qrcodeTitle = parentDef.QRCodeTitle
|
||||
}
|
||||
}
|
||||
|
||||
if order.OrderMethod.ClientType == userconfigs.PayClientTypeMobile {
|
||||
data, err := qrcode.Encode(order.PayURL, qrcode.Medium, 256)
|
||||
if err != nil {
|
||||
this.ErrorPage(errors.New("二维码生成失败:" + err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
qrcodeKey = stringutil.Md5(qrcodeKeySalt + ":order:" + order.Code)
|
||||
ttlcache.DefaultCache.Write(qrcodeKey, data, time.Now().Unix()+600 /** 只保留10分钟,防止内存占用过高 **/)
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["order"] = maps.Map{
|
||||
"code": order.Code,
|
||||
"amount": order.Amount,
|
||||
"canPay": order.CanPay,
|
||||
"payURL": order.PayURL,
|
||||
"typeName": userconfigs.FindOrderTypeName(order.Type),
|
||||
"method": methodMap,
|
||||
"isExpired": order.IsExpired,
|
||||
"status": order.Status,
|
||||
"statusName": userconfigs.FindOrderStatusName(order.Status),
|
||||
"urlQRCodeKey": qrcodeKey,
|
||||
"qrcodeTitle": qrcodeTitle,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
18
EdgeUser/internal/web/actions/default/finance/pay/init.go
Normal file
18
EdgeUser/internal/web/actions/default/finance/pay/init.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package pay
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth("")).
|
||||
Data("teaMenu", "finance").
|
||||
Data("teaSubMenu", "orders").
|
||||
Prefix("/finance/pay").
|
||||
Get("", new(IndexAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user