add bank
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/xerr"
|
||||
"qnc-server/pkg/lzkit/lzUtils"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -25,6 +27,11 @@ type ApplyWithdrawalLogic struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
const (
|
||||
withdrawMethodAlipay int64 = 1
|
||||
withdrawMethodBankCard int64 = 2
|
||||
)
|
||||
|
||||
func NewApplyWithdrawalLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApplyWithdrawalLogic {
|
||||
return &ApplyWithdrawalLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
@@ -65,6 +72,32 @@ func (l *ApplyWithdrawalLogic) ApplyWithdrawal(req *types.ApplyWithdrawalReq) (r
|
||||
if req.Amount <= 0 {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("提现金额必须大于0"), "")
|
||||
}
|
||||
if req.WithdrawMethod != withdrawMethodAlipay && req.WithdrawMethod != withdrawMethodBankCard {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("提现方式不支持"), "")
|
||||
}
|
||||
if strings.TrimSpace(req.PayeeName) == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("收款人姓名不能为空"), "")
|
||||
}
|
||||
|
||||
if req.WithdrawMethod == withdrawMethodAlipay {
|
||||
if strings.TrimSpace(req.PayeeAccount) == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("支付宝账号不能为空"), "")
|
||||
}
|
||||
} else {
|
||||
if strings.TrimSpace(req.BankName) == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("开户行不能为空"), "")
|
||||
}
|
||||
bankCardNo := strings.TrimSpace(req.BankCardNo)
|
||||
if bankCardNo == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("银行卡号不能为空"), "")
|
||||
}
|
||||
if !regexp.MustCompile(`^\d{13,19}$`).MatchString(bankCardNo) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("银行卡号格式不正确"), "")
|
||||
}
|
||||
if !regexp.MustCompile(`^1[3-9]\d{9}$`).MatchString(strings.TrimSpace(req.BankReservedMobile)) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("银行预留手机号格式不正确"), "")
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 获取钱包信息
|
||||
wallet, err := l.svcCtx.AgentWalletModel.FindOneByAgentId(l.ctx, agent.Id)
|
||||
@@ -85,9 +118,9 @@ func (l *ApplyWithdrawalLogic) ApplyWithdrawal(req *types.ApplyWithdrawalReq) (r
|
||||
}
|
||||
|
||||
// 7. 生成提现单号
|
||||
withdrawNo := fmt.Sprintf("WD%d%d", time.Now().Unix(), agent.Id)
|
||||
withdrawNo := fmt.Sprintf("WD%d%s", time.Now().Unix(), agent.Id)
|
||||
|
||||
// 8. 使用事务处理提现申请
|
||||
// 8. 使用事务处理提现申请(申请时冻结余额,审核通过后扣减冻结余额)
|
||||
var withdrawalId string
|
||||
err = l.svcCtx.AgentWalletModel.Trans(l.ctx, func(transCtx context.Context, session sqlx.Session) error {
|
||||
// 8.1 冻结余额
|
||||
@@ -99,15 +132,19 @@ func (l *ApplyWithdrawalLogic) ApplyWithdrawal(req *types.ApplyWithdrawalReq) (r
|
||||
|
||||
// 8.2 创建提现记录
|
||||
withdrawal := &model.AgentWithdrawal{
|
||||
Id: uuid.New().String(),
|
||||
AgentId: agent.Id,
|
||||
WithdrawNo: withdrawNo,
|
||||
PayeeAccount: req.PayeeAccount,
|
||||
PayeeName: req.PayeeName,
|
||||
Amount: req.Amount,
|
||||
ActualAmount: taxInfo.ActualAmount,
|
||||
TaxAmount: taxInfo.TaxAmount,
|
||||
Status: 1, // 处理中(待审核)
|
||||
Id: uuid.New().String(),
|
||||
AgentId: agent.Id,
|
||||
WithdrawNo: withdrawNo,
|
||||
WithdrawMethod: req.WithdrawMethod,
|
||||
PayeeAccount: strings.TrimSpace(req.PayeeAccount),
|
||||
PayeeName: strings.TrimSpace(req.PayeeName),
|
||||
BankName: strings.TrimSpace(req.BankName),
|
||||
BankCardNo: strings.TrimSpace(req.BankCardNo),
|
||||
BankReservedMobile: strings.TrimSpace(req.BankReservedMobile),
|
||||
Amount: req.Amount,
|
||||
ActualAmount: taxInfo.ActualAmount,
|
||||
TaxAmount: taxInfo.TaxAmount,
|
||||
Status: 1, // 待审核
|
||||
}
|
||||
|
||||
_, err := l.svcCtx.AgentWithdrawalModel.Insert(transCtx, session, withdrawal)
|
||||
|
||||
@@ -82,16 +82,20 @@ func (l *GetWithdrawalListLogic) GetWithdrawalList(req *types.GetWithdrawalListR
|
||||
}
|
||||
|
||||
list = append(list, types.WithdrawalItem{
|
||||
Id: withdrawal.Id,
|
||||
WithdrawalNo: withdrawal.WithdrawNo,
|
||||
Amount: withdrawal.Amount,
|
||||
TaxAmount: withdrawal.TaxAmount,
|
||||
ActualAmount: withdrawal.ActualAmount,
|
||||
Status: withdrawal.Status,
|
||||
PayeeAccount: withdrawal.PayeeAccount,
|
||||
PayeeName: withdrawal.PayeeName,
|
||||
Remark: remark,
|
||||
CreateTime: withdrawal.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
Id: withdrawal.Id,
|
||||
WithdrawalNo: withdrawal.WithdrawNo,
|
||||
WithdrawMethod: withdrawal.WithdrawMethod,
|
||||
Amount: withdrawal.Amount,
|
||||
TaxAmount: withdrawal.TaxAmount,
|
||||
ActualAmount: withdrawal.ActualAmount,
|
||||
Status: withdrawal.Status,
|
||||
PayeeAccount: withdrawal.PayeeAccount,
|
||||
PayeeName: withdrawal.PayeeName,
|
||||
BankName: withdrawal.BankName,
|
||||
BankCardNo: withdrawal.BankCardNo,
|
||||
BankReservedMobile: withdrawal.BankReservedMobile,
|
||||
Remark: remark,
|
||||
CreateTime: withdrawal.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
"qnc-server/app/main/model"
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/xerr"
|
||||
@@ -61,37 +62,40 @@ func (l *RealNameAuthLogic) RealNameAuth(req *types.RealNameAuthReq) (resp *type
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("手机号与代理注册手机号不匹配"), "")
|
||||
}
|
||||
|
||||
// 3. 验证验证码
|
||||
encryptedMobile, err := crypto.EncryptMobile(req.Mobile, l.svcCtx.Config.Encrypt.SecretKey)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "加密手机号失败, %v", err)
|
||||
}
|
||||
redisKey := fmt.Sprintf("realName:%s", encryptedMobile)
|
||||
cacheCode, err := l.svcCtx.Redis.Get(redisKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("验证码已过期"), "")
|
||||
// 3. 开发环境下跳过验证码和三要素核验
|
||||
if os.Getenv("ENV") != "development" {
|
||||
// 3.1 验证验证码
|
||||
encryptedMobile, err := crypto.EncryptMobile(req.Mobile, l.svcCtx.Config.Encrypt.SecretKey)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "加密手机号失败, %v", err)
|
||||
}
|
||||
redisKey := fmt.Sprintf("realName:%s", encryptedMobile)
|
||||
cacheCode, err := l.svcCtx.Redis.Get(redisKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("验证码已过期"), "")
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "读取验证码失败, %v", err)
|
||||
}
|
||||
if cacheCode != req.Code {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("验证码不正确"), "")
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "读取验证码失败, %v", err)
|
||||
}
|
||||
if cacheCode != req.Code {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("验证码不正确"), "")
|
||||
}
|
||||
|
||||
// 4. 三要素核验(姓名、身份证号、手机号)
|
||||
verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(service.ThreeFactorVerificationRequest{
|
||||
Name: req.Name,
|
||||
IDCard: req.IdCard,
|
||||
Mobile: req.Mobile,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "三要素核验失败: %v", err)
|
||||
}
|
||||
if !verification.Passed {
|
||||
if verification.Err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg(verification.Err.Error()), "三要素核验不通过")
|
||||
// 3.2 三要素核验(姓名、身份证号、手机号)
|
||||
verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(service.ThreeFactorVerificationRequest{
|
||||
Name: req.Name,
|
||||
IDCard: req.IdCard,
|
||||
Mobile: req.Mobile,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "三要素核验失败: %v", err)
|
||||
}
|
||||
if !verification.Passed {
|
||||
if verification.Err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg(verification.Err.Error()), "三要素核验不通过")
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("三要素核验不通过"), "")
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("三要素核验不通过"), "")
|
||||
}
|
||||
|
||||
// 5. 检查是否已有实名认证记录
|
||||
|
||||
Reference in New Issue
Block a user