Wallet与Withdrawal模块:完成分字段重构
核心改造: 1. Wallet模块DTO层全部改为*Cent int64字段 2. Wallet.Entry结构从Amount float64改为AmountCent int64 3. Repository层applyEntry函数使用整数加减,无需浮点运算 4. Withdrawal模块DTO/Request全部改为*Cent字段 5. 所有wallet.AppendEntries调用点改为AmountCent 6. 提现手续费计算改为分单位 技术细节: - 删除了roundWalletMoney函数(不再需要) - toAccountDTO/toLedgerDTO使用*Cent字段 - 最小提现金额:10元=1000分 - 最大提现金额:5000元=500000分 - 编译验证通过 ✅ Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -39,9 +39,9 @@ func (r *Repository) Create(userID uint64, req CreateWithdrawalRequest) (*Withdr
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 计算手续费和实际到账金额
|
||||
fee := req.Amount * WithdrawalFeeRate
|
||||
actualAmount := req.Amount - fee
|
||||
// 计算手续费和实际到账金额(分)
|
||||
feeCent := int64(float64(req.AmountCent) * WithdrawalFeeRate)
|
||||
actualAmountCent := req.AmountCent - feeCent
|
||||
|
||||
// 生成提现单号
|
||||
withdrawNo, err := generateWithdrawNo()
|
||||
@@ -58,9 +58,9 @@ func (r *Repository) Create(userID uint64, req CreateWithdrawalRequest) (*Withdr
|
||||
withdrawal := model.WithdrawalRequest{
|
||||
WithdrawNo: withdrawNo,
|
||||
UserID: userID,
|
||||
Amount: req.Amount,
|
||||
Fee: fee,
|
||||
ActualAmount: actualAmount,
|
||||
AmountCent: req.AmountCent,
|
||||
FeeCent: feeCent,
|
||||
ActualAmountCent: actualAmountCent,
|
||||
PaymentAccountID: &req.PaymentAccountID,
|
||||
AccountType: paymentAccount.AccountType,
|
||||
AccountName: paymentAccount.AccountName,
|
||||
@@ -81,7 +81,7 @@ func (r *Repository) Create(userID uint64, req CreateWithdrawalRequest) (*Withdr
|
||||
if err := wallet.AppendEntries(tx, wallet.Entry{
|
||||
UserID: userID,
|
||||
Direction: "out",
|
||||
Amount: req.Amount,
|
||||
AmountCent: req.AmountCent,
|
||||
BalanceType: "available",
|
||||
BizType: "withdraw_freeze",
|
||||
BizNo: withdrawNo,
|
||||
@@ -89,7 +89,7 @@ func (r *Repository) Create(userID uint64, req CreateWithdrawalRequest) (*Withdr
|
||||
}, wallet.Entry{
|
||||
UserID: userID,
|
||||
Direction: "in",
|
||||
Amount: req.Amount,
|
||||
AmountCent: req.AmountCent,
|
||||
BalanceType: "frozen",
|
||||
BizType: "withdraw_freeze",
|
||||
BizNo: withdrawNo,
|
||||
@@ -179,7 +179,7 @@ func (r *Repository) Cancel(userID, id uint64) error {
|
||||
if err := wallet.AppendEntries(tx, wallet.Entry{
|
||||
UserID: userID,
|
||||
Direction: "out",
|
||||
Amount: withdrawal.Amount,
|
||||
AmountCent: withdrawal.AmountCent,
|
||||
BalanceType: "frozen",
|
||||
BizType: "withdraw_cancel",
|
||||
BizNo: withdrawal.WithdrawNo,
|
||||
@@ -187,7 +187,7 @@ func (r *Repository) Cancel(userID, id uint64) error {
|
||||
}, wallet.Entry{
|
||||
UserID: userID,
|
||||
Direction: "in",
|
||||
Amount: withdrawal.Amount,
|
||||
AmountCent: withdrawal.AmountCent,
|
||||
BalanceType: "available",
|
||||
BizType: "withdraw_cancel",
|
||||
BizNo: withdrawal.WithdrawNo,
|
||||
@@ -292,7 +292,7 @@ func (r *Repository) Review(adminID, id uint64, req ReviewWithdrawalRequest) (*W
|
||||
if err := wallet.AppendEntries(tx, wallet.Entry{
|
||||
UserID: withdrawal.UserID,
|
||||
Direction: "out",
|
||||
Amount: withdrawal.Amount,
|
||||
AmountCent: withdrawal.AmountCent,
|
||||
BalanceType: "frozen",
|
||||
BizType: "withdraw_reject",
|
||||
BizNo: withdrawal.WithdrawNo,
|
||||
@@ -300,7 +300,7 @@ func (r *Repository) Review(adminID, id uint64, req ReviewWithdrawalRequest) (*W
|
||||
}, wallet.Entry{
|
||||
UserID: withdrawal.UserID,
|
||||
Direction: "in",
|
||||
Amount: withdrawal.Amount,
|
||||
AmountCent: withdrawal.AmountCent,
|
||||
BalanceType: "available",
|
||||
BizType: "withdraw_reject",
|
||||
BizNo: withdrawal.WithdrawNo,
|
||||
@@ -351,7 +351,7 @@ func (r *Repository) ConfirmPayment(adminID, id uint64, req ConfirmPaymentReques
|
||||
if err := wallet.AppendEntries(tx, wallet.Entry{
|
||||
UserID: withdrawal.UserID,
|
||||
Direction: "out",
|
||||
Amount: withdrawal.Amount,
|
||||
AmountCent: withdrawal.AmountCent,
|
||||
BalanceType: "frozen",
|
||||
BizType: "withdraw_complete",
|
||||
BizNo: withdrawal.WithdrawNo,
|
||||
@@ -373,22 +373,22 @@ func (r *Repository) ConfirmPayment(adminID, id uint64, req ConfirmPaymentReques
|
||||
// 转换为用户DTO
|
||||
func toDTO(w model.WithdrawalRequest) WithdrawalDTO {
|
||||
return WithdrawalDTO{
|
||||
ID: w.ID,
|
||||
WithdrawNo: w.WithdrawNo,
|
||||
UserID: w.UserID,
|
||||
Amount: w.Amount,
|
||||
Fee: w.Fee,
|
||||
ActualAmount: w.ActualAmount,
|
||||
AccountType: w.AccountType,
|
||||
AccountName: w.AccountName,
|
||||
AccountNo: w.AccountNo,
|
||||
BankName: w.BankName,
|
||||
Status: w.Status,
|
||||
ReviewRemark: w.ReviewRemark,
|
||||
CreatedAt: w.CreatedAt,
|
||||
UpdatedAt: w.UpdatedAt,
|
||||
ReviewedAt: w.ReviewedAt,
|
||||
PaidAt: w.PaidAt,
|
||||
ID: w.ID,
|
||||
WithdrawNo: w.WithdrawNo,
|
||||
UserID: w.UserID,
|
||||
AmountCent: w.AmountCent,
|
||||
FeeCent: w.FeeCent,
|
||||
ActualAmountCent: w.ActualAmountCent,
|
||||
AccountType: w.AccountType,
|
||||
AccountName: w.AccountName,
|
||||
AccountNo: w.AccountNo,
|
||||
BankName: w.BankName,
|
||||
Status: w.Status,
|
||||
ReviewRemark: w.ReviewRemark,
|
||||
CreatedAt: w.CreatedAt,
|
||||
UpdatedAt: w.UpdatedAt,
|
||||
ReviewedAt: w.ReviewedAt,
|
||||
PaidAt: w.PaidAt,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,9 +440,9 @@ func (r *Repository) toDetailDTO(w model.WithdrawalRequest) (*WithdrawalDetailDT
|
||||
UserID: w.UserID,
|
||||
UserNickname: user.Nickname,
|
||||
UserPhone: user.Phone,
|
||||
Amount: w.Amount,
|
||||
Fee: w.Fee,
|
||||
ActualAmount: w.ActualAmount,
|
||||
AmountCent: w.AmountCent,
|
||||
FeeCent: w.FeeCent,
|
||||
ActualAmountCent: w.ActualAmountCent,
|
||||
PaymentAccountID: w.PaymentAccountID,
|
||||
AccountType: w.AccountType,
|
||||
AccountName: w.AccountName,
|
||||
|
||||
Reference in New Issue
Block a user