修复账单与交易接口问题 & 管理员权限的身份限制
This commit is contained in:
@@ -173,6 +173,8 @@ type PageTradeOfUserByAdminReq struct {
|
||||
CreatedAtEnd *time.Time `json:"created_at_end,omitempty"`
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
|
||||
// 创建订单
|
||||
func TradeCreate(c *fiber.Ctx) error {
|
||||
// 检查权限
|
||||
@@ -219,6 +221,8 @@ type TradeCreateReq struct {
|
||||
Recharge *s.UpdateBalanceData `json:"recharge,omitempty"`
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
|
||||
// 完成订单
|
||||
func TradeComplete(c *fiber.Ctx) error {
|
||||
// 检查权限
|
||||
@@ -228,13 +232,13 @@ func TradeComplete(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// 解析请求参数
|
||||
req := new(TradeCompleteReq)
|
||||
if err := g.Validator.ParseBody(c, req); err != nil {
|
||||
var req s.TradeRef
|
||||
if err := g.Validator.ParseBody(c, &req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 检查订单状态
|
||||
err = s.Trade.CompleteTrade(authCtx.User, &req.TradeRef)
|
||||
err = s.Trade.CompleteTrade(authCtx.User, &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -242,10 +246,40 @@ func TradeComplete(c *fiber.Ctx) error {
|
||||
return c.SendStatus(fiber.StatusNoContent)
|
||||
}
|
||||
|
||||
type TradeCompleteReq struct {
|
||||
s.TradeRef
|
||||
// 管理员完成订单
|
||||
func TradeCompleteByAdmin(c *fiber.Ctx) error {
|
||||
// 检查权限
|
||||
_, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeTradeWriteComplete)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 解析请求参数
|
||||
var req struct {
|
||||
s.TradeRef
|
||||
UserID int32 `json:"user_id" validate:"required"`
|
||||
}
|
||||
if err := g.Validator.ParseBody(c, &req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
user, err := s.User.Get(q.Q, req.UserID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 完成订单
|
||||
err = s.Trade.CompleteTrade(user, &req.TradeRef)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusNoContent)
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
|
||||
// 取消订单
|
||||
func TradeCancel(c *fiber.Ctx) error {
|
||||
// 检查权限
|
||||
@@ -274,6 +308,8 @@ type TradeCancelReq struct {
|
||||
s.TradeRef
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
|
||||
// 检查订单
|
||||
func TradeCheck(c *fiber.Ctx) error {
|
||||
// 检查权限:sse 接口暂时不检查权限
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"platform/web/auth"
|
||||
"platform/web/core"
|
||||
g "platform/web/globals"
|
||||
@@ -76,6 +77,12 @@ func PageUserByAdmin(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
for _, user := range users {
|
||||
|
||||
if user.IDNo != nil && len(*user.IDNo) == 18 {
|
||||
var str = *user.IDNo
|
||||
*user.IDNo = str[:6] + "****" + str[len(str)-2:]
|
||||
}
|
||||
|
||||
if user.Admin != nil {
|
||||
user.Admin = &m.Admin{
|
||||
Name: user.Admin.Name,
|
||||
@@ -306,6 +313,9 @@ func UpdateUser(c *fiber.Ctx) error {
|
||||
ContactQQ: &req.ContactQQ,
|
||||
ContactWechat: &req.ContactWechat,
|
||||
})
|
||||
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||
return core.NewBizErr("用户名或邮箱已被占用")
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"platform/pkg/env"
|
||||
"platform/pkg/u"
|
||||
"platform/web/auth"
|
||||
@@ -92,7 +93,7 @@ func CreateWhitelist(c *fiber.Ctx) error {
|
||||
|
||||
ip, err := secureAddr(req.Host)
|
||||
if err != nil {
|
||||
return err
|
||||
return core.NewBizErr("IP 地址无效", err)
|
||||
}
|
||||
|
||||
// 创建白名单
|
||||
@@ -132,7 +133,7 @@ func UpdateWhitelist(c *fiber.Ctx) error {
|
||||
|
||||
ip, err := secureAddr(req.Host)
|
||||
if err != nil {
|
||||
return err
|
||||
return core.NewBizErr("IP 地址无效", err)
|
||||
}
|
||||
|
||||
// 更新白名单
|
||||
@@ -201,7 +202,7 @@ func secureAddr(str string) (*orm.Inet, error) {
|
||||
return nil, err
|
||||
}
|
||||
if !ip.IsGlobalUnicast() && env.RunMode != env.RunModeDev {
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, "IP 地址不可用")
|
||||
return nil, errors.New("IP 地址不可用")
|
||||
}
|
||||
return ip, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user