This commit is contained in:
hero920103 committed 2026-10-19 01:13:17 +08:00
1 parent 5718a00e31
commit 1850ac640e
226 files changed
+37772 -12071

No files matched your search

+8 -20
View File
@@ -3,13 +3,13 @@ package controllers
import (
"context"
"encoding/json"
"fmt"
"io"
"strconv"
"strings"
"time"
"server/models"
"server/pkg/identity"
"server/pkg/jwtutil"
"server/services/payment"
@@ -24,22 +24,7 @@ type BackendPaymentController struct {
}
func (c *BackendPaymentController) backendClaims() (*jwtutil.Claims, error) {
auth := c.Ctx.Request.Header.Get("Authorization")
if auth == "" {
return nil, fmt.Errorf("未登录")
}
parts := strings.SplitN(auth, " ", 2)
if len(parts) != 2 || parts[0] != "Bearer" {
return nil, fmt.Errorf("认证信息格式错误")
}
claims, err := jwtutil.ParseToken(parts[1])
if err != nil {
return nil, fmt.Errorf("无效的token")
}
if claims.UserType != "backend" {
return nil, fmt.Errorf("无权访问")
}
return claims, nil
return identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndBackend)
}
func (c *BackendPaymentController) jsonErr(httpStatus, bizCode int, msg string) {
@@ -80,7 +65,8 @@ func (c *BackendPaymentController) tenantName() string {
// Channels GET /backend/payment/channels 收银台可用渠道(已启用且参数完整)
func (c *BackendPaymentController) Channels() {
if _, err := c.backendClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}
var rows []models.PlatformPaymentChannel
@@ -119,7 +105,8 @@ func (c *BackendPaymentController) Channels() {
func (c *BackendPaymentController) Create() {
claims, err := c.backendClaims()
if err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}
body, _ := io.ReadAll(c.Ctx.Request.Body)
@@ -191,7 +178,8 @@ func (c *BackendPaymentController) Create() {
// Query GET /backend/payment/query/:payNo 查询支付单(仅本租户)
func (c *BackendPaymentController) Query() {
if _, err := c.backendClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
code := identity.Status(err)
c.jsonErr(code, code, err.Error())
return
}
payNo := c.Ctx.Input.Param(":payNo")