chore: 同步管理端构建与余额模块调整

- 更新 soul-admin dist 构建产物
- 调整 soul-api balance 路由与模型文件

Made-with: Cursor
This commit is contained in:
卡若
2026-03-17 16:12:04 +08:00
parent e222d254be
commit b625fd5aa1
11 changed files with 946 additions and 1900 deletions

File diff suppressed because one or more lines are too long

927
soul-admin/dist/assets/index-BJTFaSuJ.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -4,8 +4,8 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>管理后台 - Soul创业派对</title>
<script type="module" crossorigin src="/assets/index--Y8yZ41S.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-CKdDSrMs.css">
<script type="module" crossorigin src="/assets/index-BJTFaSuJ.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-dmhT0dvT.css">
</head>
<body>
<div id="root"></div>

View File

@@ -21,7 +21,7 @@ import { ReferralSettingsPage } from '@/pages/referral-settings/ReferralSettings
import { Pagination } from '@/components/ui/Pagination'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Card, CardContent } from '@/components/ui/card'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import {
Dialog,

View File

@@ -61,8 +61,8 @@ func BalanceTransactionsGet(c *gin.Context) {
out := make([]gin.H, 0, len(list))
for _, t := range list {
orderID := ""
if t.OrderID != nil {
orderID = *t.OrderID
if t.RelatedOrder != nil {
orderID = *t.RelatedOrder
}
out = append(out, gin.H{
"id": t.ID, "type": t.Type, "amount": t.Amount,
@@ -127,16 +127,14 @@ func BalanceRechargeConfirmPost(c *gin.Context) {
}
// 幂等:检查是否已处理
var cnt int64
tx.Model(&model.BalanceTransaction{}).Where("order_id = ? AND type = ?", req.OrderSn, "recharge").Count(&cnt)
tx.Model(&model.BalanceTransaction{}).Where("related_order = ? AND type = ?", req.OrderSn, "recharge").Count(&cnt)
if cnt > 0 {
return nil // 已处理,直接成功
return nil
}
// 增加余额
tx.Exec("INSERT INTO user_balances (user_id, balance, updated_at) VALUES (?, 0, NOW()) ON DUPLICATE KEY UPDATE balance = balance + ?, updated_at = NOW()", order.UserID, order.Amount)
txID := fmt.Sprintf("bt_%d", time.Now().UnixNano()%100000000000)
tx.Create(&model.BalanceTransaction{
ID: txID, UserID: order.UserID, Type: "recharge", Amount: order.Amount,
OrderID: &req.OrderSn, CreatedAt: time.Now(),
UserID: order.UserID, Type: "recharge", Amount: order.Amount,
RelatedOrder: &req.OrderSn, CreatedAt: time.Now(),
})
return nil
})
@@ -246,10 +244,9 @@ func BalanceConsumePost(c *gin.Context) {
if err := tx.Create(&order).Error; err != nil {
return err
}
txID := fmt.Sprintf("bt_%d", time.Now().UnixNano()%100000000000)
tx.Create(&model.BalanceTransaction{
ID: txID, UserID: req.UserID, Type: "consume", Amount: -amount,
OrderID: &orderSn, CreatedAt: now,
UserID: req.UserID, Type: "consume", Amount: -amount,
RelatedOrder: &orderSn, CreatedAt: now,
})
// 激活权益
if req.ProductType == "fullbook" {
@@ -298,9 +295,8 @@ func BalanceRefundPost(c *gin.Context) {
return fmt.Errorf("余额不足")
}
tx.Model(&model.UserBalance{}).Where("user_id = ?", req.UserID).Update("balance", gorm.Expr("balance - ?", req.Amount))
txID := fmt.Sprintf("bt_%d", time.Now().UnixNano()%100000000000)
tx.Create(&model.BalanceTransaction{
ID: txID, UserID: req.UserID, Type: "refund", Amount: -req.Amount,
UserID: req.UserID, Type: "refund", Amount: -req.Amount,
CreatedAt: time.Now(),
})
return nil
@@ -330,8 +326,8 @@ func AdminUserBalanceGet(c *gin.Context) {
transactions := make([]gin.H, 0, len(list))
for _, t := range list {
orderID := ""
if t.OrderID != nil {
orderID = *t.OrderID
if t.RelatedOrder != nil {
orderID = *t.RelatedOrder
}
transactions = append(transactions, gin.H{
"id": t.ID, "type": t.Type, "amount": t.Amount,
@@ -375,9 +371,8 @@ func AdminUserBalanceAdjust(c *gin.Context) {
return fmt.Errorf("调整后余额不能为负,当前余额 %.2f", ub.Balance)
}
tx.Exec("INSERT INTO user_balances (user_id, balance, updated_at) VALUES (?, 0, NOW()) ON DUPLICATE KEY UPDATE balance = ?, updated_at = NOW()", userID, newBalance)
txID := fmt.Sprintf("bt_adj_%d", time.Now().UnixNano()%100000000000)
return tx.Create(&model.BalanceTransaction{
ID: txID, UserID: userID, Type: "admin_adjust", Amount: req.Amount,
UserID: userID, Type: "admin_adjust", Amount: req.Amount,
CreatedAt: time.Now(),
}).Error
})
@@ -401,10 +396,9 @@ func ConfirmBalanceRechargeByOrder(db *gorm.DB, order *model.Order) error {
return nil // 已处理,幂等
}
tx.Exec("INSERT INTO user_balances (user_id, balance, updated_at) VALUES (?, 0, NOW()) ON DUPLICATE KEY UPDATE balance = balance + ?, updated_at = NOW()", order.UserID, order.Amount)
txID := fmt.Sprintf("bt_%d", time.Now().UnixNano()%100000000000)
return tx.Create(&model.BalanceTransaction{
ID: txID, UserID: order.UserID, Type: "recharge", Amount: order.Amount,
OrderID: &orderSn, CreatedAt: time.Now(),
UserID: order.UserID, Type: "recharge", Amount: order.Amount,
RelatedOrder: &orderSn, CreatedAt: time.Now(),
}).Error
})
}

View File

@@ -1,24 +0,0 @@
package model
import "time"
// UserBalance 对应表 user_balances
type UserBalance struct {
UserID string `gorm:"column:user_id;primaryKey;size:50"`
Balance float64 `gorm:"column:balance;type:decimal(10,2);default:0"`
UpdatedAt time.Time `gorm:"column:updated_at"`
}
func (UserBalance) TableName() string { return "user_balances" }
// BalanceTransaction 对应表 balance_transactions
type BalanceTransaction struct {
ID string `gorm:"column:id;primaryKey;size:50"`
UserID string `gorm:"column:user_id;size:50"`
Type string `gorm:"column:type;size:20"` // recharge, consume, refund, gift
Amount float64 `gorm:"column:amount;type:decimal(10,2)"`
OrderID *string `gorm:"column:order_id;size:50"`
CreatedAt time.Time `gorm:"column:created_at"`
}
func (BalanceTransaction) TableName() string { return "balance_transactions" }

View File

@@ -100,6 +100,7 @@ func Setup(cfg *config.Config) *gin.Engine {
admin.GET("/orders", handler.OrdersList)
admin.GET("/gift-pay-requests", handler.AdminGiftPayRequestsList)
admin.GET("/user/track", handler.UserTrackGet)
admin.GET("/track/stats", handler.AdminTrackStats)
}
// ----- 鉴权 -----