重构增加模型枚举值定义
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"log/slog"
|
||||
"platform/web/auth"
|
||||
client2 "platform/web/domains/client"
|
||||
m "platform/web/models"
|
||||
q "platform/web/queries"
|
||||
s "platform/web/services"
|
||||
@@ -188,7 +189,7 @@ func protect(c *fiber.Ctx, grant s.OauthGrantType, clientId, clientSecret string
|
||||
return nil, s.ErrOauthUnauthorizedClient
|
||||
}
|
||||
case s.OauthGrantTypeClientCredentials:
|
||||
if !client.GrantClient || client.Spec != 3 {
|
||||
if !client.GrantClient || client.Spec != int32(client2.SpecWeb) || client.Spec != int32(client2.SpecTrusted) {
|
||||
return nil, s.ErrOauthUnauthorizedClient
|
||||
}
|
||||
case s.OauthGrantTypeRefreshToken:
|
||||
@@ -202,7 +203,7 @@ func protect(c *fiber.Ctx, grant s.OauthGrantType, clientId, clientSecret string
|
||||
}
|
||||
|
||||
// 如果客户端是 confidential,验证 client_secret,失败返回错误
|
||||
if client.Spec == 3 {
|
||||
if client.Spec == int32(client2.SpecWeb) || client.Spec == int32(client2.SpecTrusted) {
|
||||
if clientSecret == "" {
|
||||
return nil, s.ErrOauthInvalidRequest
|
||||
}
|
||||
@@ -215,7 +216,7 @@ func protect(c *fiber.Ctx, grant s.OauthGrantType, clientId, clientSecret string
|
||||
auth.Locals(c, &auth.Context{
|
||||
Payload: auth.Payload{
|
||||
Id: client.ID,
|
||||
Type: auth.PayloadClientConfidential,
|
||||
Type: auth.PayloadSecuredServer,
|
||||
Name: client.Name,
|
||||
Avatar: client.Icon,
|
||||
},
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"platform/web/auth"
|
||||
"platform/web/core"
|
||||
channel2 "platform/web/domains/channel"
|
||||
q "platform/web/queries"
|
||||
s "platform/web/services"
|
||||
"time"
|
||||
@@ -90,7 +91,7 @@ func ListChannels(c *fiber.Ctx) error {
|
||||
type CreateChannelReq struct {
|
||||
ResourceId int32 `json:"resource_id" validate:"required"`
|
||||
AuthType s.ChannelAuthType `json:"auth_type" validate:"required"`
|
||||
Protocol s.ChannelProtocol `json:"protocol" validate:"required"`
|
||||
Protocol channel2.Protocol `json:"protocol" validate:"required"`
|
||||
Count int `json:"count" validate:"required"`
|
||||
Prov string `json:"prov"`
|
||||
City string `json:"city"`
|
||||
@@ -98,7 +99,7 @@ type CreateChannelReq struct {
|
||||
}
|
||||
|
||||
type CreateChannelRespItem struct {
|
||||
Proto s.ChannelProtocol `json:"-"`
|
||||
Proto channel2.Protocol `json:"-"`
|
||||
Host string `json:"host"`
|
||||
Port int32 `json:"port"`
|
||||
Username *string `json:"username,omitempty"`
|
||||
@@ -198,7 +199,7 @@ func RemoveChannels(c *fiber.Ctx) error {
|
||||
// 检查权限
|
||||
authCtx, err := auth.Protect(c, []auth.PayloadType{
|
||||
auth.PayloadUser,
|
||||
auth.PayloadClientConfidential,
|
||||
auth.PayloadSecuredServer,
|
||||
}, []string{})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"platform/pkg/u"
|
||||
"platform/web/auth"
|
||||
"platform/web/core"
|
||||
resource2 "platform/web/domains/resource"
|
||||
trade2 "platform/web/domains/trade"
|
||||
q "platform/web/queries"
|
||||
s "platform/web/services"
|
||||
"time"
|
||||
@@ -115,10 +117,10 @@ func AllResource(c *fiber.Ctx) error {
|
||||
q.Resource.UserID.Eq(authContext.Payload.Id),
|
||||
q.Resource.Active.Is(true),
|
||||
q.Resource.Where(
|
||||
pss.Type.Eq(1),
|
||||
pss.Type.Eq(int32(resource2.PssTypeTime)),
|
||||
pss.Expire.Gte(core.LocalDateTime(time.Now())),
|
||||
).Or(
|
||||
pss.Type.Eq(2),
|
||||
pss.Type.Eq(int32(resource2.PssTypeCount)),
|
||||
pss.Quota.GtCol(pss.Used),
|
||||
),
|
||||
q.Resource.Where(
|
||||
@@ -174,7 +176,7 @@ func PrepareResourceByAlipay(c *fiber.Ctx) error {
|
||||
c.Context(),
|
||||
&req.CreateResourceData,
|
||||
authContext.Payload.Id,
|
||||
s.TransactionMethodAlipay,
|
||||
trade2.MethodAlipay,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -206,7 +208,7 @@ func PrepareResourceByWechat(c *fiber.Ctx) error {
|
||||
c.Context(),
|
||||
&req.CreateResourceData,
|
||||
authContext.Payload.Id,
|
||||
s.TransactionMethodWeChat,
|
||||
trade2.MethodWeChat,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -235,7 +237,7 @@ func CreateResourceByAlipay(c *fiber.Ctx) error {
|
||||
// 验证支付结果
|
||||
result, err := s.Transaction.VerifyTransaction(c.Context(), &s.TransactionVerifyData{
|
||||
TradeNo: req.TradeNo,
|
||||
Method: s.TransactionMethodAlipay,
|
||||
Method: trade2.MethodAlipay,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -266,7 +268,7 @@ func CreateResourceByWechat(c *fiber.Ctx) error {
|
||||
// 验证支付结果
|
||||
result, err := s.Transaction.VerifyTransaction(c.Context(), &s.TransactionVerifyData{
|
||||
TradeNo: req.TradeNo,
|
||||
Method: s.TransactionMethodWeChat,
|
||||
Method: trade2.MethodWeChat,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
trade2 "platform/web/domains/trade"
|
||||
g "platform/web/globals"
|
||||
q "platform/web/queries"
|
||||
s "platform/web/services"
|
||||
@@ -65,17 +66,17 @@ func AlipayCallback(c *fiber.Ctx) error {
|
||||
Payment: payment,
|
||||
Time: paidAt,
|
||||
}
|
||||
switch trade.Type {
|
||||
switch trade2.Type(trade.Type) {
|
||||
|
||||
// 余额充值
|
||||
case 2:
|
||||
case trade2.TypeRecharge:
|
||||
err := s.User.RechargeConfirm(c.Context(), notification.OutTradeNo, verified)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 购买产品
|
||||
case 1:
|
||||
case trade2.TypePurchase:
|
||||
err = s.Resource.CompleteResource(c.Context(), notification.OutTradeNo, verified)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -84,20 +85,21 @@ func AlipayCallback(c *fiber.Ctx) error {
|
||||
|
||||
// 支付关闭
|
||||
case string(alipay.TradeStatusClosed):
|
||||
switch trade.Type {
|
||||
switch trade2.Type(trade.Type) {
|
||||
|
||||
// 购买产品
|
||||
case 1:
|
||||
case trade2.TypePurchase:
|
||||
|
||||
cancelAt, err := time.Parse("2006-01-02 15:04:05", notification.GmtClose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.Resource.CancelResource(c.Context(), notification.OutTradeNo, cancelAt, s.TransactionMethodAlipay)
|
||||
err = s.Resource.CancelResource(c.Context(), notification.OutTradeNo, cancelAt, trade2.MethodAlipay)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,14 +177,14 @@ func WechatPayCallback(c *fiber.Ctx) error {
|
||||
switch {
|
||||
|
||||
// 余额充值
|
||||
case trade.Type == 2:
|
||||
case trade.Type == int32(trade2.TypeRecharge):
|
||||
err := s.User.RechargeConfirm(c.Context(), *content.OutTradeNo, verified)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 购买产品
|
||||
case trade.Type == 1:
|
||||
case trade.Type == int32(trade2.TypePurchase):
|
||||
err = s.Resource.CompleteResource(c.Context(), *content.OutTradeNo, verified)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -3,6 +3,7 @@ package handlers
|
||||
import (
|
||||
"platform/web/auth"
|
||||
"platform/web/core"
|
||||
trade2 "platform/web/domains/trade"
|
||||
m "platform/web/models"
|
||||
q "platform/web/queries"
|
||||
s "platform/web/services"
|
||||
@@ -180,8 +181,8 @@ func RechargePrepareAlipay(c *fiber.Ctx) error {
|
||||
Subject: "账户充值 - " + strconv.FormatFloat(req.Amount, 'f', 2, 64) + "元",
|
||||
Amount: req.Amount,
|
||||
ExpireAt: time.Now().Add(30 * time.Minute),
|
||||
Type: s.TransactionTypeRecharge,
|
||||
Method: s.TransactionMethodAlipay,
|
||||
Type: trade2.TypeRecharge,
|
||||
Method: trade2.MethodAlipay,
|
||||
})
|
||||
return err
|
||||
})
|
||||
@@ -212,7 +213,7 @@ func RechargeConfirmAlipay(c *fiber.Ctx) error {
|
||||
// 验证支付结果
|
||||
result, err := s.Transaction.VerifyTransaction(c.Context(), &s.TransactionVerifyData{
|
||||
TradeNo: req.TradeNo,
|
||||
Method: s.TransactionMethodAlipay,
|
||||
Method: trade2.MethodAlipay,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -247,8 +248,8 @@ func RechargePrepareWechat(c *fiber.Ctx) error {
|
||||
Subject: "账户充值 - " + strconv.FormatFloat(req.Amount, 'f', 2, 64) + "元",
|
||||
Amount: req.Amount,
|
||||
ExpireAt: time.Now().Add(30 * time.Minute),
|
||||
Type: s.TransactionTypeRecharge,
|
||||
Method: s.TransactionMethodWeChat,
|
||||
Type: trade2.TypeRecharge,
|
||||
Method: trade2.MethodWeChat,
|
||||
})
|
||||
return err
|
||||
})
|
||||
@@ -281,7 +282,7 @@ func RechargeConfirmWechat(c *fiber.Ctx) error {
|
||||
// 验证支付结果
|
||||
result, err := s.Transaction.VerifyTransaction(c.Context(), &s.TransactionVerifyData{
|
||||
TradeNo: req.TradeNo,
|
||||
Method: s.TransactionMethodWeChat,
|
||||
Method: trade2.MethodWeChat,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -18,7 +18,7 @@ type VerifierReq struct {
|
||||
func SmsCode(c *fiber.Ctx) error {
|
||||
|
||||
_, err := auth.Protect(c, []auth.PayloadType{
|
||||
auth.PayloadClientConfidential,
|
||||
auth.PayloadSecuredServer,
|
||||
}, []string{})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user