f
This commit is contained in:
@@ -85,9 +85,18 @@ func (l *AdminReviewBankCardWithdrawalLogic) AdminReviewBankCardWithdrawal(req *
|
||||
return errors.Wrapf(xerr.NewErrMsg("提现类型不正确"), "提现类型验证失败")
|
||||
}
|
||||
|
||||
// 确认时使用的扣税比例:请求中传入则用传入值,否则默认 6%
|
||||
taxRate := 0.06
|
||||
if req.Action == ReviewActionApprove && req.TaxRate != nil {
|
||||
taxRate = *req.TaxRate
|
||||
if taxRate < 0 || taxRate > 1 {
|
||||
return errors.Wrapf(xerr.NewErrMsg("扣税比例必须在 0~100% 之间"), "扣税比例验证失败")
|
||||
}
|
||||
}
|
||||
|
||||
if req.Action == ReviewActionApprove {
|
||||
// 确认提现
|
||||
return l.approveWithdrawal(ctx, session, record)
|
||||
// 确认提现(可带自定义扣税比例)
|
||||
return l.approveWithdrawal(ctx, session, record, taxRate)
|
||||
} else {
|
||||
// 拒绝提现
|
||||
return l.rejectWithdrawal(ctx, session, record, req.Remark)
|
||||
@@ -102,11 +111,15 @@ func (l *AdminReviewBankCardWithdrawalLogic) AdminReviewBankCardWithdrawal(req *
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// 确认提现
|
||||
func (l *AdminReviewBankCardWithdrawalLogic) approveWithdrawal(ctx context.Context, session sqlx.Session, record *model.AgentWithdrawal) error {
|
||||
// 确认提现(taxRate 为扣税比例,如 0.06 表示 6%)
|
||||
func (l *AdminReviewBankCardWithdrawalLogic) approveWithdrawal(ctx context.Context, session sqlx.Session, record *model.AgentWithdrawal, taxRate float64) error {
|
||||
// 按审核时选择的扣税比例重新计算并更新提现记录与扣税记录
|
||||
if err := l.applyReviewTaxRate(ctx, session, record, taxRate); err != nil {
|
||||
return err
|
||||
}
|
||||
// 根据提现类型执行不同的操作
|
||||
if record.WithdrawType == WithdrawTypeAlipay {
|
||||
// 支付宝提现:先调用支付宝转账接口
|
||||
// 支付宝提现:按更新后的实际到账金额调用支付宝转账
|
||||
return l.approveAlipayWithdrawal(ctx, session, record)
|
||||
} else {
|
||||
// 银行卡提现:直接更新状态为成功(线下转账)
|
||||
@@ -114,6 +127,31 @@ func (l *AdminReviewBankCardWithdrawalLogic) approveWithdrawal(ctx context.Conte
|
||||
}
|
||||
}
|
||||
|
||||
// applyReviewTaxRate 按审核时选择的扣税比例更新提现记录与扣税记录
|
||||
func (l *AdminReviewBankCardWithdrawalLogic) applyReviewTaxRate(ctx context.Context, session sqlx.Session, record *model.AgentWithdrawal, taxRate float64) error {
|
||||
newTaxAmount := record.Amount * taxRate
|
||||
newActualAmount := record.Amount - newTaxAmount
|
||||
|
||||
record.TaxAmount = newTaxAmount
|
||||
record.ActualAmount = newActualAmount
|
||||
if _, err := l.svcCtx.AgentWithdrawalModel.Update(ctx, session, record); err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新提现记录扣税金额失败: %v", err)
|
||||
}
|
||||
|
||||
taxModel, err := l.svcCtx.AgentWithdrawalTaxModel.FindOneByWithdrawalId(ctx, record.Id)
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询扣税记录失败: %v", err)
|
||||
}
|
||||
taxModel.TaxRate = taxRate
|
||||
taxModel.TaxAmount = newTaxAmount
|
||||
taxModel.ActualAmount = newActualAmount
|
||||
taxModel.TaxableAmount = record.Amount
|
||||
if err := l.svcCtx.AgentWithdrawalTaxModel.UpdateWithVersion(ctx, session, taxModel); err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新扣税记录失败: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 确认支付宝提现
|
||||
func (l *AdminReviewBankCardWithdrawalLogic) approveAlipayWithdrawal(ctx context.Context, session sqlx.Session, record *model.AgentWithdrawal) error {
|
||||
// 同步调用支付宝转账
|
||||
|
||||
Reference in New Issue
Block a user