1.4.5.2
This commit is contained in:
109
EdgeAdmin/internal/web/actions/default/finance/orders/index.go
Normal file
109
EdgeAdmin/internal/web/actions/default/finance/orders/index.go
Normal file
@@ -0,0 +1,109 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package orders
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/finance/orders/orderutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "order")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
UserId int64
|
||||
Status string
|
||||
Keyword string
|
||||
}) {
|
||||
this.Data["userId"] = params.UserId
|
||||
this.Data["status"] = params.Status
|
||||
this.Data["keyword"] = params.Keyword
|
||||
|
||||
// 是否支持支付
|
||||
orderConfig, err := orderutils.FindOrderConfig(this.AdminContext())
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["enablePay"] = orderConfig.EnablePay
|
||||
|
||||
// 订单数量
|
||||
countResp, err := this.RPC().UserOrderRPC().CountEnabledUserOrders(this.AdminContext(), &pb.CountEnabledUserOrdersRequest{
|
||||
UserId: params.UserId,
|
||||
Status: params.Status,
|
||||
Keyword: params.Keyword,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countResp.Count
|
||||
var page = this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
// 订单列表
|
||||
ordersResp, err := this.RPC().UserOrderRPC().ListEnabledUserOrders(this.AdminContext(), &pb.ListEnabledUserOrdersRequest{
|
||||
UserId: params.UserId,
|
||||
Status: params.Status,
|
||||
Keyword: params.Keyword,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var orderMaps = []maps.Map{}
|
||||
for _, order := range ordersResp.UserOrders {
|
||||
// user
|
||||
var userMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if order.User != nil {
|
||||
userMap = maps.Map{
|
||||
"id": order.User.Id,
|
||||
"fullname": order.User.Fullname,
|
||||
"username": order.User.Username,
|
||||
}
|
||||
}
|
||||
|
||||
// method
|
||||
var methodMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if order.OrderMethod != nil {
|
||||
methodMap = maps.Map{
|
||||
"id": order.OrderMethod.Id,
|
||||
"name": order.OrderMethod.Name,
|
||||
}
|
||||
}
|
||||
|
||||
orderMaps = append(orderMaps, maps.Map{
|
||||
"code": order.Code,
|
||||
"type": order.Type,
|
||||
"typeName": userconfigs.FindOrderTypeName(order.Type),
|
||||
"status": order.Status,
|
||||
"statusName": userconfigs.FindOrderStatusName(order.Status),
|
||||
"amount": order.Amount,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", order.CreatedAt),
|
||||
"user": userMap,
|
||||
"method": methodMap,
|
||||
})
|
||||
}
|
||||
this.Data["orders"] = orderMaps
|
||||
|
||||
// 所有状态
|
||||
this.Data["statusList"] = userconfigs.FindAllOrderStatusList()
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
//go:build plus
|
||||
|
||||
package orders
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/finance/orders/methods"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/finance/orders/methods/method"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/finance/orders/order"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(plus.NewHelper(plus.ComponentCodeFinance)).
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeFinance)).
|
||||
Data("teaMenu", "finance").
|
||||
Data("teaSubMenu", "orders").
|
||||
|
||||
// 订单列表
|
||||
Prefix("/finance/orders").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/setting", new(SettingAction)).
|
||||
|
||||
// 单个订单
|
||||
Prefix("/finance/orders/order").
|
||||
Get("", new(order.IndexAction)).
|
||||
Post("/finish", new(order.FinishAction)).
|
||||
|
||||
// 支付方式列表
|
||||
Prefix("/finance/orders/methods").
|
||||
Get("", new(methods.IndexAction)).
|
||||
GetPost("/createPopup", new(methods.CreatePopupAction)).
|
||||
|
||||
// 单个支付方式
|
||||
Prefix("/finance/orders/methods/method").
|
||||
Get("", new(method.IndexAction)).
|
||||
GetPost("/update", new(method.UpdateAction)).
|
||||
Post("/delete", new(method.DeleteAction)).
|
||||
|
||||
//
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package methods
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "method")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
this.Data["presetMethods"] = userconfigs.FindAllPresetPayMethods()
|
||||
this.Data["clientTypes"] = userconfigs.FindAllPayClientTypes()
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
Name string
|
||||
Code string
|
||||
Description string
|
||||
ClientType string
|
||||
QrcodeTitle string
|
||||
|
||||
ParentCode string
|
||||
|
||||
// 自定义支付方式
|
||||
Url string
|
||||
|
||||
// Alipay
|
||||
ParamsAlipayAppId string
|
||||
ParamsAlipayPrivateKey string
|
||||
ParamsAlipayAppPublicCert string
|
||||
ParamsAlipayPublicCert string
|
||||
ParamsAlipayRootCert string
|
||||
ParamsAlipayProductCode string
|
||||
ParamsAlipayIsSandbox bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
var methodId int64
|
||||
defer func() {
|
||||
this.CreateLogInfo(codes.OrderMethod_LogCreateOrderMethod, methodId)
|
||||
}()
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入支付方式名称").
|
||||
Field("code", params.Code).
|
||||
Require("请输入支付方式代号").
|
||||
Match("^\\w+$", "代号中只能包含数字、字母和下划线").
|
||||
Field("description", params.Description).
|
||||
Require("请输入支付方式描述")
|
||||
|
||||
// 检查代号是否被占用
|
||||
methodResp, err := this.RPC().OrderMethodRPC().FindEnabledOrderMethodWithCode(this.AdminContext(), &pb.FindEnabledOrderMethodWithCodeRequest{Code: params.Code})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if methodResp.OrderMethod != nil {
|
||||
this.Fail("代号 '" + params.Code + "' 已经被别的支付方式使用,请换一个")
|
||||
}
|
||||
|
||||
var payParams userconfigs.PayMethodParams
|
||||
switch params.ParentCode {
|
||||
case "":
|
||||
params.Must.
|
||||
Field("url", params.Url).
|
||||
Require("请输入支付URL").
|
||||
Match("^(?i)(http|https)://", "请输入正确的支付URL")
|
||||
case userconfigs.PayMethodAlipay:
|
||||
params.Must.
|
||||
Field("paramsAlipayAppId", params.ParamsAlipayAppId).
|
||||
Require("请输入APPID").
|
||||
Field("paramsAlipayPrivateKey", params.ParamsAlipayPrivateKey).
|
||||
Require("请输入私钥").
|
||||
Field("paramsAlipayAppPublicCert", params.ParamsAlipayAppPublicCert).
|
||||
Require("请输入应用公钥证书").
|
||||
Field("paramsAlipayPublicCert", params.ParamsAlipayPublicCert).
|
||||
Require("请输入支付宝公钥证书").
|
||||
Field("paramsAlipayRootCert", params.ParamsAlipayRootCert).
|
||||
Require("请输入支付宝根证书").
|
||||
Field("paramsAlipayProductCode", params.ParamsAlipayProductCode).
|
||||
Require("请输入产品代号")
|
||||
|
||||
payParams = &userconfigs.AlipayPayMethodParams{
|
||||
IsSandbox: params.ParamsAlipayIsSandbox,
|
||||
AppId: params.ParamsAlipayAppId,
|
||||
PrivateKey: params.ParamsAlipayPrivateKey,
|
||||
AppPublicCert: params.ParamsAlipayAppPublicCert,
|
||||
AlipayPublicCert: params.ParamsAlipayPublicCert,
|
||||
AlipayRootCert: params.ParamsAlipayRootCert,
|
||||
ProductCode: params.ParamsAlipayProductCode,
|
||||
}
|
||||
}
|
||||
|
||||
if payParams != nil {
|
||||
err = payParams.Init()
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
payParamsJSON, err := json.Marshal(payParams)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().OrderMethodRPC().CreateOrderMethod(this.AdminContext(), &pb.CreateOrderMethodRequest{
|
||||
Name: params.Name,
|
||||
Code: params.Code,
|
||||
Description: params.Description,
|
||||
Url: params.Url,
|
||||
ParentCode: params.ParentCode,
|
||||
ParamsJSON: payParamsJSON,
|
||||
ClientType: params.ClientType,
|
||||
QrcodeTitle: params.QrcodeTitle,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
methodId = createResp.OrderMethodId
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package methods
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/finance/orders/orderutils"
|
||||
"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("", "", "method")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
// 是否支持支付
|
||||
orderConfig, err := orderutils.FindOrderConfig(this.AdminContext())
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["enablePay"] = orderConfig.EnablePay
|
||||
|
||||
// 所有的支付方式
|
||||
methodsResp, err := this.RPC().OrderMethodRPC().FindAllEnabledOrderMethods(this.AdminContext(), &pb.FindAllEnabledOrderMethodsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var methodMaps = []maps.Map{}
|
||||
for _, method := range methodsResp.OrderMethods {
|
||||
var parentName = ""
|
||||
if len(method.ParentCode) > 0 {
|
||||
var parentMethod = userconfigs.FindPresetPayMethodWithCode(method.ParentCode)
|
||||
if parentMethod != nil {
|
||||
parentName = parentMethod.Name
|
||||
}
|
||||
}
|
||||
|
||||
methodMaps = append(methodMaps, maps.Map{
|
||||
"id": method.Id,
|
||||
"name": method.Name,
|
||||
"code": method.Code,
|
||||
"parentCode": method.ParentCode,
|
||||
"parentName": parentName,
|
||||
"description": method.Description,
|
||||
"url": method.Url,
|
||||
"isOn": method.IsOn,
|
||||
"clientType": method.ClientType,
|
||||
"clientTypeName": userconfigs.FindPayClientTypeName(method.ClientType),
|
||||
})
|
||||
}
|
||||
this.Data["methods"] = methodMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package method
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
MethodId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.OrderMethod_LogDeleteOrderMethod, params.MethodId)
|
||||
|
||||
_, err := this.RPC().OrderMethodRPC().DeleteOrderMethod(this.AdminContext(), &pb.DeleteOrderMethodRequest{OrderMethodId: params.MethodId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package method
|
||||
|
||||
import (
|
||||
"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"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "index")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
MethodId int64
|
||||
}) {
|
||||
methodResp, err := this.RPC().OrderMethodRPC().FindEnabledOrderMethod(this.AdminContext(), &pb.FindEnabledOrderMethodRequest{OrderMethodId: params.MethodId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var method = methodResp.OrderMethod
|
||||
if method == nil {
|
||||
this.NotFound("orderMethod", params.MethodId)
|
||||
return
|
||||
}
|
||||
|
||||
// 父级支付方式和参数
|
||||
var parentCode = method.ParentCode
|
||||
var parentName = ""
|
||||
var payParams any
|
||||
var payNotifyURL = ""
|
||||
if len(parentCode) > 0 {
|
||||
var parentDef = userconfigs.FindPresetPayMethodWithCode(parentCode)
|
||||
if parentDef != nil {
|
||||
parentName = parentDef.Name
|
||||
|
||||
payParams, err = userconfigs.DecodePayMethodParams(parentCode, method.Params)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(parentDef.NotifyURL) > 0 {
|
||||
accessAddrResp, err := this.RPC().UserNodeRPC().FindUserNodeAccessAddr(this.AdminContext(), &pb.FindUserNodeAccessAddrRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var accessAddr = accessAddrResp.AccessAddr
|
||||
payNotifyURL = strings.ReplaceAll(parentDef.NotifyURL, "${baseAddr}", accessAddr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 终端
|
||||
if len(method.ClientType) == 0 {
|
||||
method.ClientType = userconfigs.PayClientTypeAll
|
||||
}
|
||||
var clientTypeName = ""
|
||||
var clientTypeDescription = ""
|
||||
var clientType = userconfigs.FindPayClientType(method.ClientType)
|
||||
if clientType != nil {
|
||||
clientTypeName = clientType.Name
|
||||
clientTypeDescription = clientType.Description
|
||||
}
|
||||
|
||||
this.Data["method"] = maps.Map{
|
||||
"id": method.Id,
|
||||
"name": method.Name,
|
||||
"code": method.Code,
|
||||
"description": method.Description,
|
||||
"secret": method.Secret,
|
||||
"isOn": method.IsOn,
|
||||
|
||||
"parentCode": parentCode,
|
||||
"parentName": parentName,
|
||||
"payNotifyURL": payNotifyURL,
|
||||
"url": method.Url, // 自定义
|
||||
"params": payParams, // 非自定义
|
||||
|
||||
"clientType": method.ClientType,
|
||||
"clientTypeName": clientTypeName,
|
||||
"clientTypeDescription": clientTypeDescription,
|
||||
"qrcodeTitle": method.QrcodeTitle,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package method
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpdateAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdateAction) Init() {
|
||||
this.Nav("", "", "update")
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunGet(params struct {
|
||||
MethodId int64
|
||||
}) {
|
||||
methodResp, err := this.RPC().OrderMethodRPC().FindEnabledOrderMethod(this.AdminContext(), &pb.FindEnabledOrderMethodRequest{OrderMethodId: params.MethodId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var method = methodResp.OrderMethod
|
||||
if method == nil {
|
||||
this.NotFound("orderMethod", params.MethodId)
|
||||
return
|
||||
}
|
||||
|
||||
// 父级支付方式和参数
|
||||
var parentCode = method.ParentCode
|
||||
var parentName = ""
|
||||
var payParams any
|
||||
if len(parentCode) > 0 {
|
||||
var parentDef = userconfigs.FindPresetPayMethodWithCode(parentCode)
|
||||
if parentDef != nil {
|
||||
parentName = parentDef.Name
|
||||
|
||||
payParams, err = userconfigs.DecodePayMethodParams(parentCode, method.Params)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 支持的终端类型
|
||||
this.Data["clientTypes"] = userconfigs.FindAllPayClientTypes()
|
||||
if len(method.ClientType) == 0 {
|
||||
method.ClientType = userconfigs.PayClientTypeAll
|
||||
}
|
||||
|
||||
this.Data["method"] = maps.Map{
|
||||
"id": method.Id,
|
||||
"name": method.Name,
|
||||
"code": method.Code,
|
||||
"description": method.Description,
|
||||
"url": method.Url,
|
||||
"isOn": method.IsOn,
|
||||
"parentCode": method.ParentCode,
|
||||
"parentName": parentName,
|
||||
"params": payParams,
|
||||
"clientType": method.ClientType,
|
||||
"qrcodeTitle": method.QrcodeTitle,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunPost(params struct {
|
||||
MethodId int64
|
||||
Name string
|
||||
Code string
|
||||
Description string
|
||||
IsOn bool
|
||||
ClientType string
|
||||
QrcodeTitle string
|
||||
|
||||
// 自定义支付方式
|
||||
Url string
|
||||
|
||||
// Alipay
|
||||
ParamsAlipayAppId string
|
||||
ParamsAlipayPrivateKey string
|
||||
ParamsAlipayAppPublicCert string
|
||||
ParamsAlipayPublicCert string
|
||||
ParamsAlipayRootCert string
|
||||
ParamsAlipayProductCode string
|
||||
ParamsAlipayIsSandbox bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.OrderMethod_LogUpdateOrderMethod, params.MethodId)
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入支付方式名称").
|
||||
Field("code", params.Code).
|
||||
Require("请输入支付方式代号").
|
||||
Match("^\\w+$", "代号中只能包含数字、字母和下划线").
|
||||
Field("description", params.Description).
|
||||
Require("请输入支付方式描述")
|
||||
|
||||
// 检查代号是否被占用
|
||||
methodWithCodeResp, err := this.RPC().OrderMethodRPC().FindEnabledOrderMethodWithCode(this.AdminContext(), &pb.FindEnabledOrderMethodWithCodeRequest{Code: params.Code})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if methodWithCodeResp.OrderMethod != nil && methodWithCodeResp.OrderMethod.Id != params.MethodId {
|
||||
this.Fail("代号 '" + params.Code + "' 已经被别的支付方式使用,请换一个")
|
||||
}
|
||||
|
||||
// 当前支付方式
|
||||
methodResp, err := this.RPC().OrderMethodRPC().FindEnabledOrderMethod(this.AdminContext(), &pb.FindEnabledOrderMethodRequest{OrderMethodId: params.MethodId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var method = methodResp.OrderMethod
|
||||
if method == nil {
|
||||
this.Fail("找不到要修改的支付方式")
|
||||
}
|
||||
|
||||
var payParams userconfigs.PayMethodParams
|
||||
switch method.ParentCode {
|
||||
case "":
|
||||
params.Must.
|
||||
Field("url", params.Url).
|
||||
Require("请输入支付URL").
|
||||
Match("^(?i)(http|https)://", "请输入正确的支付URL")
|
||||
case userconfigs.PayMethodAlipay:
|
||||
params.Must.
|
||||
Field("paramsAlipayAppId", params.ParamsAlipayAppId).
|
||||
Require("请输入APPID").
|
||||
Field("paramsAlipayPrivateKey", params.ParamsAlipayPrivateKey).
|
||||
Require("请输入私钥").
|
||||
Field("paramsAlipayAppPublicCert", params.ParamsAlipayAppPublicCert).
|
||||
Require("请输入应用公钥证书").
|
||||
Field("paramsAlipayPublicCert", params.ParamsAlipayPublicCert).
|
||||
Require("请输入支付宝公钥证书").
|
||||
Field("paramsAlipayRootCert", params.ParamsAlipayRootCert).
|
||||
Require("请输入支付宝根证书").
|
||||
Field("paramsAlipayProductCode", params.ParamsAlipayProductCode).
|
||||
Require("请输入产品代号")
|
||||
|
||||
payParams = &userconfigs.AlipayPayMethodParams{
|
||||
IsSandbox: params.ParamsAlipayIsSandbox,
|
||||
AppId: params.ParamsAlipayAppId,
|
||||
PrivateKey: params.ParamsAlipayPrivateKey,
|
||||
AppPublicCert: params.ParamsAlipayAppPublicCert,
|
||||
AlipayPublicCert: params.ParamsAlipayPublicCert,
|
||||
AlipayRootCert: params.ParamsAlipayRootCert,
|
||||
ProductCode: params.ParamsAlipayProductCode,
|
||||
}
|
||||
}
|
||||
|
||||
if payParams != nil {
|
||||
err = payParams.Init()
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
payParamsJSON, err := json.Marshal(payParams)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = this.RPC().OrderMethodRPC().UpdateOrderMethod(this.AdminContext(), &pb.UpdateOrderMethodRequest{
|
||||
OrderMethodId: params.MethodId,
|
||||
Name: params.Name,
|
||||
Code: params.Code,
|
||||
Description: params.Description,
|
||||
Url: params.Url,
|
||||
ParamsJSON: payParamsJSON,
|
||||
IsOn: params.IsOn,
|
||||
ClientType: params.ClientType,
|
||||
QrcodeTitle: params.QrcodeTitle,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package order
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type FinishAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *FinishAction) RunPost(params struct {
|
||||
OrderCode string
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.UserOrder_LogFinishUserOrder, params.OrderCode)
|
||||
|
||||
_, err := this.RPC().UserOrderRPC().FinishUserOrder(this.AdminContext(), &pb.FinishUserOrderRequest{Code: params.OrderCode})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package order
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"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"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "order")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
OrderCode string
|
||||
}) {
|
||||
orderResp, err := this.RPC().UserOrderRPC().FindEnabledUserOrder(this.AdminContext(), &pb.FindEnabledUserOrderRequest{Code: params.OrderCode})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var order = orderResp.UserOrder
|
||||
if order == nil {
|
||||
this.ErrorPage(errors.New("order with code '" + params.OrderCode + "' not found"))
|
||||
return
|
||||
}
|
||||
|
||||
// user
|
||||
var userMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if order.User != nil {
|
||||
userMap = maps.Map{
|
||||
"id": order.User.Id,
|
||||
"fullname": order.User.Fullname,
|
||||
"username": order.User.Username,
|
||||
}
|
||||
}
|
||||
|
||||
// method
|
||||
var methodMap = maps.Map{
|
||||
"id": 0,
|
||||
}
|
||||
if order.OrderMethod != nil {
|
||||
methodMap = maps.Map{
|
||||
"id": order.OrderMethod.Id,
|
||||
"name": order.OrderMethod.Name,
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["order"] = maps.Map{
|
||||
"code": order.Code,
|
||||
"type": order.Type,
|
||||
"typeName": userconfigs.FindOrderTypeName(order.Type),
|
||||
"status": order.Status,
|
||||
"statusName": userconfigs.FindOrderStatusName(order.Status),
|
||||
"amount": order.Amount,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", order.CreatedAt),
|
||||
"cancelledTime": timeutil.FormatTime("Y-m-d H:i:s", order.CancelledAt),
|
||||
"finishedTime": timeutil.FormatTime("Y-m-d H:i:s", order.FinishedAt),
|
||||
"isExpired": order.IsExpired,
|
||||
"user": userMap,
|
||||
"method": methodMap,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package orderutils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
)
|
||||
|
||||
// FindOrderConfig 读取订单设置
|
||||
func FindOrderConfig(ctx context.Context) (*userconfigs.UserOrderConfig, error) {
|
||||
rpcClient, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := rpcClient.SysSettingRPC().ReadSysSetting(ctx, &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeUserOrderConfig})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(resp.ValueJSON) == 0 {
|
||||
return userconfigs.DefaultUserOrderConfig(), nil
|
||||
}
|
||||
|
||||
var config = userconfigs.DefaultUserOrderConfig()
|
||||
err = json.Unmarshal(resp.ValueJSON, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
110
EdgeAdmin/internal/web/actions/default/finance/orders/setting.go
Normal file
110
EdgeAdmin/internal/web/actions/default/finance/orders/setting.go
Normal file
@@ -0,0 +1,110 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package orders
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type SettingAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SettingAction) Init() {
|
||||
this.Nav("", "", "setting")
|
||||
}
|
||||
|
||||
func (this *SettingAction) RunGet(params struct{}) {
|
||||
// 配置
|
||||
configResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeUserOrderConfig})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var config = userconfigs.DefaultUserOrderConfig()
|
||||
if len(configResp.ValueJSON) > 0 {
|
||||
err = json.Unmarshal(configResp.ValueJSON, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
this.Data["config"] = config
|
||||
|
||||
// 当前可用支付方式数量
|
||||
methodsResp, err := this.RPC().OrderMethodRPC().FindAllAvailableOrderMethods(this.AdminContext(), &pb.FindAllAvailableOrderMethodsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["hasValidMethods"] = len(methodsResp.OrderMethods) > 0
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *SettingAction) RunPost(params struct {
|
||||
EnablePay bool
|
||||
DisablePageHTML string
|
||||
OrderLifeJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.Finance_LogUpdateUserOrderConfig)
|
||||
|
||||
// 原有配置
|
||||
configResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeUserOrderConfig})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var config = userconfigs.DefaultUserOrderConfig()
|
||||
if len(configResp.ValueJSON) > 0 {
|
||||
err = json.Unmarshal(configResp.ValueJSON, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
config.EnablePay = params.EnablePay
|
||||
config.DisablePageHTML = params.DisablePageHTML
|
||||
|
||||
if len(params.OrderLifeJSON) > 0 {
|
||||
var lifeDuration = &shared.TimeDuration{}
|
||||
err = json.Unmarshal(params.OrderLifeJSON, lifeDuration)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if lifeDuration.Count <= 0 {
|
||||
this.Fail("订单过期时间必须是个有效值")
|
||||
}
|
||||
config.OrderLife = lifeDuration
|
||||
}
|
||||
|
||||
configJSON, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
|
||||
Code: systemconfigs.SettingCodeUserOrderConfig,
|
||||
ValueJSON: configJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user