f
This commit is contained in:
@@ -57,7 +57,7 @@ func (l *AdminBatchUnfreezeAgentCommissionLogic) AdminBatchUnfreezeAgentCommissi
|
||||
// 计算总金额
|
||||
var totalAmount float64
|
||||
for _, commission := range commissions {
|
||||
totalAmount += commission.Amount
|
||||
totalAmount = roundMoney(totalAmount + commission.Amount)
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
@@ -96,16 +96,16 @@ func (l *AdminBatchUnfreezeAgentCommissionLogic) AdminBatchUnfreezeAgentCommissi
|
||||
|
||||
// 累加到对应代理商的钱包数据
|
||||
if wallet, exists := agentWalletMap[commission.AgentId]; exists {
|
||||
wallet.Balance += commission.Amount
|
||||
wallet.FrozenBalance -= commission.Amount
|
||||
wallet.Balance = roundMoney(wallet.Balance + commission.Amount)
|
||||
wallet.FrozenBalance = roundMoney(wallet.FrozenBalance - commission.Amount)
|
||||
} else {
|
||||
// 查询该代理商的钱包
|
||||
wallet, err := l.svcCtx.AgentWalletModel.FindOneByAgentId(ctx, commission.AgentId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wallet.Balance += commission.Amount
|
||||
wallet.FrozenBalance -= commission.Amount
|
||||
wallet.Balance = roundMoney(wallet.Balance + commission.Amount)
|
||||
wallet.FrozenBalance = roundMoney(wallet.FrozenBalance - commission.Amount)
|
||||
agentWalletMap[commission.AgentId] = wallet
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"bdrp-server/app/main/model"
|
||||
"bdrp-server/common/xerr"
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
"bdrp-server/app/main/model"
|
||||
"bdrp-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
@@ -164,7 +164,7 @@ func (l *AdminReviewBankCardWithdrawalLogic) approveBankCardWithdrawal(ctx conte
|
||||
frozenBalanceBefore := wallet.FrozenBalance
|
||||
|
||||
// 更新钱包(减少冻结余额)
|
||||
wallet.FrozenBalance -= record.Amount
|
||||
wallet.FrozenBalance = roundMoney(wallet.FrozenBalance - record.Amount)
|
||||
if err := l.svcCtx.AgentWalletModel.UpdateWithVersion(ctx, session, wallet); err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新钱包失败: %v", err)
|
||||
}
|
||||
@@ -175,14 +175,14 @@ func (l *AdminReviewBankCardWithdrawalLogic) approveBankCardWithdrawal(ctx conte
|
||||
session,
|
||||
wallet.AgentId,
|
||||
model.WalletTransactionTypeWithdraw,
|
||||
-record.Amount, // 变动金额(负数表示减少)
|
||||
wallet.Balance, // 变动前余额(不变)
|
||||
wallet.Balance, // 变动后余额(不变)
|
||||
frozenBalanceBefore, // 变动前冻结余额
|
||||
wallet.FrozenBalance, // 变动后冻结余额
|
||||
record.WithdrawNo, // 关联交易ID
|
||||
0, // 关联用户ID
|
||||
"提现审核通过", // 备注
|
||||
roundMoney(-record.Amount), // 变动金额(负数表示减少)
|
||||
roundMoney(wallet.Balance), // 变动前余额(不变)
|
||||
roundMoney(wallet.Balance), // 变动后余额(不变)
|
||||
roundMoney(frozenBalanceBefore), // 变动前冻结余额
|
||||
roundMoney(wallet.FrozenBalance), // 变动后冻结余额
|
||||
record.WithdrawNo, // 关联交易ID
|
||||
0, // 关联用户ID
|
||||
"提现审核通过", // 备注
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -234,8 +234,8 @@ func (l *AdminReviewBankCardWithdrawalLogic) rejectWithdrawal(ctx context.Contex
|
||||
frozenBalanceBefore := wallet.FrozenBalance
|
||||
|
||||
// 更新钱包(余额增加,冻结余额减少)
|
||||
wallet.Balance += record.Amount
|
||||
wallet.FrozenBalance -= record.Amount
|
||||
wallet.Balance = roundMoney(wallet.Balance + record.Amount)
|
||||
wallet.FrozenBalance = roundMoney(wallet.FrozenBalance - record.Amount)
|
||||
if err := l.svcCtx.AgentWalletModel.UpdateWithVersion(ctx, session, wallet); err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新钱包失败: %v", err)
|
||||
}
|
||||
@@ -246,14 +246,14 @@ func (l *AdminReviewBankCardWithdrawalLogic) rejectWithdrawal(ctx context.Contex
|
||||
session,
|
||||
wallet.AgentId,
|
||||
model.WalletTransactionTypeUnfreeze,
|
||||
record.Amount, // 变动金额(正数表示增加)
|
||||
balanceBefore, // 变动前余额
|
||||
wallet.Balance, // 变动后余额
|
||||
frozenBalanceBefore, // 变动前冻结余额
|
||||
wallet.FrozenBalance, // 变动后冻结余额
|
||||
record.WithdrawNo, // 关联交易ID
|
||||
0, // 关联用户ID
|
||||
"提现拒绝,解冻资金", // 备注
|
||||
roundMoney(record.Amount), // 变动金额(正数表示增加)
|
||||
roundMoney(balanceBefore), // 变动前余额
|
||||
roundMoney(wallet.Balance), // 变动后余额
|
||||
roundMoney(frozenBalanceBefore), // 变动前冻结余额
|
||||
roundMoney(wallet.FrozenBalance), // 变动后冻结余额
|
||||
record.WithdrawNo, // 关联交易ID
|
||||
0, // 关联用户ID
|
||||
"提现拒绝,解冻资金", // 备注
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -295,7 +295,7 @@ func (l *AdminReviewBankCardWithdrawalLogic) completeWithdrawalSuccess(ctx conte
|
||||
frozenBalanceBefore := wallet.FrozenBalance
|
||||
|
||||
// 更新钱包(减少冻结余额)
|
||||
wallet.FrozenBalance -= record.Amount
|
||||
wallet.FrozenBalance = roundMoney(wallet.FrozenBalance - record.Amount)
|
||||
if err := l.svcCtx.AgentWalletModel.UpdateWithVersion(ctx, session, wallet); err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新钱包失败: %v", err)
|
||||
}
|
||||
@@ -306,14 +306,14 @@ func (l *AdminReviewBankCardWithdrawalLogic) completeWithdrawalSuccess(ctx conte
|
||||
session,
|
||||
wallet.AgentId,
|
||||
model.WalletTransactionTypeWithdraw,
|
||||
-record.Amount, // 变动金额(负数表示减少)
|
||||
wallet.Balance, // 变动前余额(不变)
|
||||
wallet.Balance, // 变动后余额(不变)
|
||||
frozenBalanceBefore, // 变动前冻结余额
|
||||
wallet.FrozenBalance, // 变动后冻结余额
|
||||
record.WithdrawNo, // 关联交易ID
|
||||
0, // 关联用户ID
|
||||
"提现成功", // 备注
|
||||
roundMoney(-record.Amount), // 变动金额(负数表示减少)
|
||||
roundMoney(wallet.Balance), // 变动前余额(不变)
|
||||
roundMoney(wallet.Balance), // 变动后余额(不变)
|
||||
roundMoney(frozenBalanceBefore), // 变动前冻结余额
|
||||
roundMoney(wallet.FrozenBalance), // 变动后冻结余额
|
||||
record.WithdrawNo, // 关联交易ID
|
||||
0, // 关联用户ID
|
||||
"提现成功", // 备注
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -365,8 +365,8 @@ func (l *AdminReviewBankCardWithdrawalLogic) completeWithdrawalFailure(ctx conte
|
||||
frozenBalanceBefore := wallet.FrozenBalance
|
||||
|
||||
// 更新钱包(余额增加,冻结余额减少)
|
||||
wallet.Balance += record.Amount
|
||||
wallet.FrozenBalance -= record.Amount
|
||||
wallet.Balance = roundMoney(wallet.Balance + record.Amount)
|
||||
wallet.FrozenBalance = roundMoney(wallet.FrozenBalance - record.Amount)
|
||||
if err := l.svcCtx.AgentWalletModel.UpdateWithVersion(ctx, session, wallet); err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新钱包失败: %v", err)
|
||||
}
|
||||
@@ -377,14 +377,14 @@ func (l *AdminReviewBankCardWithdrawalLogic) completeWithdrawalFailure(ctx conte
|
||||
session,
|
||||
wallet.AgentId,
|
||||
model.WalletTransactionTypeUnfreeze,
|
||||
record.Amount, // 变动金额(正数表示增加)
|
||||
balanceBefore, // 变动前余额
|
||||
wallet.Balance, // 变动后余额
|
||||
frozenBalanceBefore, // 变动前冻结余额
|
||||
wallet.FrozenBalance, // 变动后冻结余额
|
||||
record.WithdrawNo, // 关联交易ID
|
||||
0, // 关联用户ID
|
||||
"提现失败,解冻资金", // 备注
|
||||
roundMoney(record.Amount), // 变动金额(正数表示增加)
|
||||
roundMoney(balanceBefore), // 变动前余额
|
||||
roundMoney(wallet.Balance), // 变动后余额
|
||||
roundMoney(frozenBalanceBefore), // 变动前冻结余额
|
||||
roundMoney(wallet.FrozenBalance), // 变动后冻结余额
|
||||
record.WithdrawNo, // 关联交易ID
|
||||
0, // 关联用户ID
|
||||
"提现失败,解冻资金", // 备注
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"bdrp-server/app/main/api/internal/svc"
|
||||
"bdrp-server/app/main/api/internal/types"
|
||||
@@ -14,6 +15,10 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
func roundMoney(v float64) float64 {
|
||||
return math.Round(v*100) / 100
|
||||
}
|
||||
|
||||
type AdminUpdateAgentWalletBalanceLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
@@ -47,7 +52,8 @@ func (l *AdminUpdateAgentWalletBalanceLogic) AdminUpdateAgentWalletBalance(req *
|
||||
}
|
||||
|
||||
// 计算新余额
|
||||
newBalance := wallet.Balance + req.Amount
|
||||
adjustAmount := roundMoney(req.Amount)
|
||||
newBalance := roundMoney(wallet.Balance + adjustAmount)
|
||||
|
||||
// 校验余额不能为负数
|
||||
if newBalance < 0 {
|
||||
@@ -68,20 +74,20 @@ func (l *AdminUpdateAgentWalletBalanceLogic) AdminUpdateAgentWalletBalance(req *
|
||||
}
|
||||
|
||||
// 创建钱包交易流水记录(手动调整)
|
||||
remark := fmt.Sprintf("管理员手动调整余额,金额: %.2f", req.Amount)
|
||||
remark := fmt.Sprintf("管理员手动调整余额,金额: %.2f", adjustAmount)
|
||||
transErr := l.svcCtx.AgentService.CreateWalletTransaction(
|
||||
transCtx,
|
||||
session,
|
||||
req.AgentId,
|
||||
model.WalletTransactionTypeAdjust,
|
||||
req.Amount, // 变动金额(正数表示增加,负数表示减少)
|
||||
balanceBefore, // 变动前余额
|
||||
wallet.Balance, // 变动后余额
|
||||
frozenBalanceBefore, // 变动前冻结余额
|
||||
wallet.FrozenBalance, // 变动后冻结余额(保持不变)
|
||||
"", // 关联交易ID(无关联)
|
||||
0, // 关联用户ID(无关联)
|
||||
remark, // 备注
|
||||
adjustAmount, // 变动金额(正数表示增加,负数表示减少)
|
||||
roundMoney(balanceBefore), // 变动前余额
|
||||
roundMoney(wallet.Balance), // 变动后余额
|
||||
roundMoney(frozenBalanceBefore), // 变动前冻结余额
|
||||
roundMoney(wallet.FrozenBalance), // 变动后冻结余额(保持不变)
|
||||
"", // 关联交易ID(无关联)
|
||||
0, // 关联用户ID(无关联)
|
||||
remark, // 备注
|
||||
)
|
||||
if transErr != nil {
|
||||
l.Logger.Errorf("创建代理钱包流水记录失败: %+v", transErr)
|
||||
@@ -89,7 +95,7 @@ func (l *AdminUpdateAgentWalletBalanceLogic) AdminUpdateAgentWalletBalance(req *
|
||||
}
|
||||
|
||||
l.Logger.Infof("代理钱包余额变更 - AgentId: %d, 原余额: %.2f, 变更金额: %.2f, 新余额: %.2f",
|
||||
req.AgentId, balanceBefore, req.Amount, wallet.Balance)
|
||||
req.AgentId, roundMoney(balanceBefore), adjustAmount, roundMoney(wallet.Balance))
|
||||
|
||||
return nil
|
||||
})
|
||||
@@ -101,7 +107,7 @@ func (l *AdminUpdateAgentWalletBalanceLogic) AdminUpdateAgentWalletBalance(req *
|
||||
|
||||
resp = &types.AdminUpdateAgentWalletBalanceResp{
|
||||
Success: true,
|
||||
Balance: newBalance,
|
||||
Balance: roundMoney(newBalance),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user