feat: add payout account review flow
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/errorx"
|
||||
@@ -864,7 +865,8 @@ func (s *creator) ListPayoutAccounts(ctx context.Context, tenantID, userID int64
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list, err := models.PayoutAccountQuery.WithContext(ctx).Where(models.PayoutAccountQuery.TenantID.Eq(tid)).Find()
|
||||
tbl, q := models.PayoutAccountQuery.QueryContext(ctx)
|
||||
list, err := q.Where(tbl.TenantID.Eq(tid)).Find()
|
||||
if err != nil {
|
||||
return nil, errorx.ErrDatabaseError.WithCause(err)
|
||||
}
|
||||
@@ -872,11 +874,15 @@ func (s *creator) ListPayoutAccounts(ctx context.Context, tenantID, userID int64
|
||||
var data []creator_dto.PayoutAccount
|
||||
for _, v := range list {
|
||||
data = append(data, creator_dto.PayoutAccount{
|
||||
ID: v.ID,
|
||||
Type: v.Type,
|
||||
Name: v.Name,
|
||||
Account: v.Account,
|
||||
Realname: v.Realname,
|
||||
ID: v.ID,
|
||||
Type: string(v.Type),
|
||||
Name: v.Name,
|
||||
Account: v.Account,
|
||||
Realname: v.Realname,
|
||||
Status: v.Status,
|
||||
StatusDescription: v.Status.Description(),
|
||||
ReviewedAt: s.formatTime(v.ReviewedAt),
|
||||
ReviewReason: v.ReviewReason,
|
||||
})
|
||||
}
|
||||
return data, nil
|
||||
@@ -892,10 +898,11 @@ func (s *creator) AddPayoutAccount(ctx context.Context, tenantID, userID int64,
|
||||
pa := &models.PayoutAccount{
|
||||
TenantID: tid,
|
||||
UserID: uid,
|
||||
Type: form.Type,
|
||||
Type: consts.PayoutAccountType(form.Type),
|
||||
Name: form.Name,
|
||||
Account: form.Account,
|
||||
Realname: form.Realname,
|
||||
Status: consts.PayoutAccountStatusPending,
|
||||
}
|
||||
if err := models.PayoutAccountQuery.WithContext(ctx).Create(pa); err != nil {
|
||||
return errorx.ErrDatabaseError.WithCause(err)
|
||||
@@ -909,9 +916,8 @@ func (s *creator) RemovePayoutAccount(ctx context.Context, tenantID, userID, id
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = models.PayoutAccountQuery.WithContext(ctx).
|
||||
Where(models.PayoutAccountQuery.ID.Eq(id), models.PayoutAccountQuery.TenantID.Eq(tid)).
|
||||
Delete()
|
||||
tbl, q := models.PayoutAccountQuery.QueryContext(ctx)
|
||||
_, err = q.Where(tbl.ID.Eq(id), tbl.TenantID.Eq(tid)).Delete()
|
||||
if err != nil {
|
||||
return errorx.ErrDatabaseError.WithCause(err)
|
||||
}
|
||||
@@ -925,7 +931,7 @@ func (s *creator) Withdraw(ctx context.Context, tenantID, userID int64, form *cr
|
||||
}
|
||||
uid := userID
|
||||
|
||||
// Validate User Real-name Status
|
||||
// 校验用户实名认证状态,未通过不允许提现。
|
||||
user, err := models.UserQuery.WithContext(ctx).Where(models.UserQuery.ID.Eq(uid)).First()
|
||||
if err != nil {
|
||||
return errorx.ErrDatabaseError.WithCause(err)
|
||||
@@ -939,19 +945,25 @@ func (s *creator) Withdraw(ctx context.Context, tenantID, userID int64, form *cr
|
||||
return errorx.ErrBadRequest.WithMsg("金额无效")
|
||||
}
|
||||
|
||||
// Validate Payout Account
|
||||
account, err := models.PayoutAccountQuery.WithContext(ctx).
|
||||
Where(models.PayoutAccountQuery.ID.Eq(form.AccountID), models.PayoutAccountQuery.TenantID.Eq(tid)).
|
||||
First()
|
||||
// 校验收款账户可用性与审核状态。
|
||||
tbl, q := models.PayoutAccountQuery.QueryContext(ctx)
|
||||
account, err := q.Where(tbl.ID.Eq(form.AccountID), tbl.TenantID.Eq(tid)).First()
|
||||
if err != nil {
|
||||
return errorx.ErrRecordNotFound.WithMsg("收款账户不存在")
|
||||
}
|
||||
if account.Status != consts.PayoutAccountStatusApproved {
|
||||
reason := strings.TrimSpace(account.ReviewReason)
|
||||
if account.Status == consts.PayoutAccountStatusRejected && reason != "" {
|
||||
return errorx.ErrPreconditionFailed.WithMsg("收款账户审核未通过:" + reason)
|
||||
}
|
||||
return errorx.ErrPreconditionFailed.WithMsg("收款账户未审核通过")
|
||||
}
|
||||
|
||||
// 将收款账户快照写入订单,便于超管审核与打款核对。
|
||||
snapshotPayload, err := json.Marshal(fields.OrdersWithdrawalSnapshot{
|
||||
Method: form.Method,
|
||||
AccountID: account.ID,
|
||||
AccountType: account.Type,
|
||||
AccountType: string(account.Type),
|
||||
AccountName: account.Name,
|
||||
Account: account.Account,
|
||||
AccountRealname: account.Realname,
|
||||
@@ -1032,6 +1044,13 @@ func (s *creator) getTenantID(ctx context.Context, tenantID, userID int64) (int6
|
||||
return t.ID, nil
|
||||
}
|
||||
|
||||
func (s *creator) formatTime(t time.Time) string {
|
||||
if t.IsZero() {
|
||||
return ""
|
||||
}
|
||||
return t.Format(time.RFC3339)
|
||||
}
|
||||
|
||||
func (s *creator) validateContentAssets(
|
||||
ctx context.Context,
|
||||
tx *models.Query,
|
||||
|
||||
Reference in New Issue
Block a user