feat(withdrawal): 增加提现审核对账与历史记录
This commit is contained in:
@@ -37,13 +37,9 @@ func (r *Repository) AdminList(ctx context.Context, query AdminListQuery) (*Admi
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
items := make([]WithdrawalDetailDTO, 0, len(withdrawals))
|
items, err := r.toAdminListItems(ctx, withdrawals)
|
||||||
for _, w := range withdrawals {
|
if err != nil {
|
||||||
dto, err := r.toDetailDTO(ctx, w)
|
return nil, err
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
items = append(items, *dto)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &AdminPaginatedResult{
|
return &AdminPaginatedResult{
|
||||||
|
|||||||
@@ -59,6 +59,108 @@ type WithdrawalDetailDTO struct {
|
|||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithdrawalListItemDTO 是后台提现分页列表使用的轻量 DTO。
|
||||||
|
// 收款二维码、完整收款账号、审核和打款详情只在打开详情时查询。
|
||||||
|
type WithdrawalListItemDTO struct {
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
WithdrawNo string `json:"withdraw_no"`
|
||||||
|
UserID uint64 `json:"user_id"`
|
||||||
|
DistributionSiteID uint64 `json:"distribution_site_id"`
|
||||||
|
DistributionSiteName string `json:"distribution_site_name"`
|
||||||
|
UserNickname string `json:"user_nickname"`
|
||||||
|
UserPhone string `json:"user_phone"`
|
||||||
|
AmountCent int64 `json:"amount_cent"`
|
||||||
|
FeeCent int64 `json:"fee_cent"`
|
||||||
|
ActualAmountCent int64 `json:"actual_amount_cent"`
|
||||||
|
AccountType string `json:"account_type"`
|
||||||
|
AccountName string `json:"account_name"`
|
||||||
|
AccountNo string `json:"account_no"`
|
||||||
|
BankName string `json:"bank_name"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithdrawalReviewSummaryDTO 汇总审核员核对提现时最关心的用户财务口径。
|
||||||
|
// wallet_actual_income_cent 汇总普通钱包结算订单及站内钱包提号的有效结算额;
|
||||||
|
// platform_managed_income_cent 汇总平台代管订单和平台代管提号的线下结算额。
|
||||||
|
// reconcile_difference_amount_cent = 钱包收入 - 已打款 - 待处理提现。
|
||||||
|
type WithdrawalReviewSummaryDTO struct {
|
||||||
|
OwnerOrderCount int64 `json:"owner_order_count"`
|
||||||
|
OwnerPickupCount int64 `json:"owner_pickup_count"`
|
||||||
|
FinalizedOrderCount int64 `json:"finalized_order_count"`
|
||||||
|
WalletActualIncomeCent int64 `json:"wallet_actual_income_cent"`
|
||||||
|
PickupIncomeCent int64 `json:"pickup_income_cent"`
|
||||||
|
WalletPickupIncomeCent int64 `json:"wallet_pickup_income_cent"`
|
||||||
|
PlatformManagedPickupIncomeCent int64 `json:"platform_managed_pickup_income_cent"`
|
||||||
|
PlatformManagedIncomeCent int64 `json:"platform_managed_income_cent"`
|
||||||
|
WithdrawalCount int64 `json:"withdrawal_count"`
|
||||||
|
WithdrawnAmountCent int64 `json:"withdrawn_amount_cent"`
|
||||||
|
PendingWithdrawalAmountCent int64 `json:"pending_withdrawal_amount_cent"`
|
||||||
|
RejectedWithdrawalCount int64 `json:"rejected_withdrawal_count"`
|
||||||
|
ReconcileDifferenceAmountCent int64 `json:"reconcile_difference_amount_cent"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WithdrawalReviewOrderDTO struct {
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
OrderNo string `json:"order_no"`
|
||||||
|
ListingNo string `json:"listing_no"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
SettlementStatus string `json:"settlement_status"`
|
||||||
|
SettlementMode string `json:"settlement_mode"`
|
||||||
|
RentAmountCent int64 `json:"rent_amount_cent"`
|
||||||
|
OwnerActualIncomeCent *int64 `json:"owner_actual_income_cent,omitempty"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
SettledAt *time.Time `json:"settled_at,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WithdrawalReviewPickupDTO struct {
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
PickupNo string `json:"pickup_no"`
|
||||||
|
ListingNo string `json:"listing_no"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
SettlementMode string `json:"settlement_mode"`
|
||||||
|
OfflineSettlementStatus string `json:"offline_settlement_status"`
|
||||||
|
SettleAmountCent int64 `json:"settle_amount_cent"`
|
||||||
|
SettleAdjustmentCent int64 `json:"settle_adjustment_cent"`
|
||||||
|
EffectiveSettleAmountCent int64 `json:"effective_settle_amount_cent"`
|
||||||
|
CompletedAt *time.Time `json:"completed_at,omitempty"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WithdrawalReviewHistoryDTO struct {
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
WithdrawNo string `json:"withdraw_no"`
|
||||||
|
AmountCent int64 `json:"amount_cent"`
|
||||||
|
FeeCent int64 `json:"fee_cent"`
|
||||||
|
ActualAmountCent int64 `json:"actual_amount_cent"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
ReviewedAt *time.Time `json:"reviewed_at,omitempty"`
|
||||||
|
PaidAt *time.Time `json:"paid_at,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WithdrawalReviewContextQuery struct {
|
||||||
|
OrderPage int `form:"order_page"`
|
||||||
|
PickupPage int `form:"pickup_page"`
|
||||||
|
WithdrawalPage int `form:"withdrawal_page"`
|
||||||
|
PageSize int `form:"page_size"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WithdrawalReviewContextDTO struct {
|
||||||
|
Summary WithdrawalReviewSummaryDTO `json:"summary"`
|
||||||
|
Orders []WithdrawalReviewOrderDTO `json:"orders"`
|
||||||
|
OrderPage int `json:"order_page"`
|
||||||
|
OrderPageSize int `json:"order_page_size"`
|
||||||
|
Pickups []WithdrawalReviewPickupDTO `json:"pickups"`
|
||||||
|
PickupPage int `json:"pickup_page"`
|
||||||
|
PickupPageSize int `json:"pickup_page_size"`
|
||||||
|
Withdrawals []WithdrawalReviewHistoryDTO `json:"withdrawals"`
|
||||||
|
WithdrawalPage int `json:"withdrawal_page"`
|
||||||
|
WithdrawalPageSize int `json:"withdrawal_page_size"`
|
||||||
|
}
|
||||||
|
|
||||||
type CreateWithdrawalRequest struct {
|
type CreateWithdrawalRequest struct {
|
||||||
PaymentAccountID uint64 `json:"payment_account_id" binding:"required"`
|
PaymentAccountID uint64 `json:"payment_account_id" binding:"required"`
|
||||||
AmountCent int64 `json:"amount_cent" binding:"required,gt=0"`
|
AmountCent int64 `json:"amount_cent" binding:"required,gt=0"`
|
||||||
@@ -82,10 +184,10 @@ type PaginatedResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AdminPaginatedResult struct {
|
type AdminPaginatedResult struct {
|
||||||
Items []WithdrawalDetailDTO `json:"items"`
|
Items []WithdrawalListItemDTO `json:"items"`
|
||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
Page int `json:"page"`
|
Page int `json:"page"`
|
||||||
PageSize int `json:"page_size"`
|
PageSize int `json:"page_size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminListQuery struct {
|
type AdminListQuery struct {
|
||||||
|
|||||||
@@ -140,6 +140,25 @@ func (h *Handler) AdminFindByID(c *gin.Context) {
|
|||||||
response.OK(c, withdrawal)
|
response.OK(c, withdrawal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) AdminReviewContext(c *gin.Context) {
|
||||||
|
id, ok := parseID(c)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var query WithdrawalReviewContextQuery
|
||||||
|
if err := c.ShouldBindQuery(&query); err != nil {
|
||||||
|
response.BadRequest(c, "请求参数错误")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
result, err := h.service.AdminReviewContext(c.Request.Context(), id, query)
|
||||||
|
if err != nil {
|
||||||
|
writeError(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.OK(c, result)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Handler) Review(c *gin.Context) {
|
func (h *Handler) Review(c *gin.Context) {
|
||||||
adminID, ok := currentAdminID(c)
|
adminID, ok := currentAdminID(c)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
@@ -32,6 +32,75 @@ func toDTO(w model.WithdrawalRequest) WithdrawalDTO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// toAdminListItems 批量装配提现分页列表依赖的用户和站点信息,避免每条记录分别查库。
|
||||||
|
func (r *Repository) toAdminListItems(ctx context.Context, withdrawals []model.WithdrawalRequest) ([]WithdrawalListItemDTO, error) {
|
||||||
|
items := make([]WithdrawalListItemDTO, 0, len(withdrawals))
|
||||||
|
if len(withdrawals) == 0 {
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
userIDs := make([]uint64, 0, len(withdrawals))
|
||||||
|
siteIDs := make([]uint64, 0, len(withdrawals))
|
||||||
|
seenUsers := make(map[uint64]struct{}, len(withdrawals))
|
||||||
|
seenSites := make(map[uint64]struct{}, len(withdrawals))
|
||||||
|
for _, withdrawal := range withdrawals {
|
||||||
|
if _, ok := seenUsers[withdrawal.UserID]; !ok {
|
||||||
|
seenUsers[withdrawal.UserID] = struct{}{}
|
||||||
|
userIDs = append(userIDs, withdrawal.UserID)
|
||||||
|
}
|
||||||
|
if withdrawal.DistributionSiteID > 0 {
|
||||||
|
if _, ok := seenSites[withdrawal.DistributionSiteID]; !ok {
|
||||||
|
seenSites[withdrawal.DistributionSiteID] = struct{}{}
|
||||||
|
siteIDs = append(siteIDs, withdrawal.DistributionSiteID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
usersByID := make(map[uint64]model.User, len(userIDs))
|
||||||
|
var users []model.User
|
||||||
|
if err := r.db.WithContext(ctx).Select("id, nickname, phone").Where("id IN ?", userIDs).Find(&users).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, user := range users {
|
||||||
|
usersByID[user.ID] = user
|
||||||
|
}
|
||||||
|
|
||||||
|
sitesByID := make(map[uint64]model.DistributionSite, len(siteIDs))
|
||||||
|
if len(siteIDs) > 0 {
|
||||||
|
var sites []model.DistributionSite
|
||||||
|
if err := r.db.WithContext(ctx).Select("id, site_name").Where("id IN ?", siteIDs).Find(&sites).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, site := range sites {
|
||||||
|
sitesByID[site.ID] = site
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, withdrawal := range withdrawals {
|
||||||
|
user := usersByID[withdrawal.UserID]
|
||||||
|
site := sitesByID[withdrawal.DistributionSiteID]
|
||||||
|
items = append(items, WithdrawalListItemDTO{
|
||||||
|
ID: withdrawal.ID,
|
||||||
|
WithdrawNo: withdrawal.WithdrawNo,
|
||||||
|
UserID: withdrawal.UserID,
|
||||||
|
DistributionSiteID: withdrawal.DistributionSiteID,
|
||||||
|
DistributionSiteName: site.SiteName,
|
||||||
|
UserNickname: user.Nickname,
|
||||||
|
UserPhone: user.Phone,
|
||||||
|
AmountCent: withdrawal.AmountCent,
|
||||||
|
FeeCent: withdrawal.FeeCent,
|
||||||
|
ActualAmountCent: withdrawal.ActualAmountCent,
|
||||||
|
AccountType: withdrawal.AccountType,
|
||||||
|
AccountName: withdrawal.AccountName,
|
||||||
|
AccountNo: withdrawal.AccountNo,
|
||||||
|
BankName: withdrawal.BankName,
|
||||||
|
Status: withdrawal.Status,
|
||||||
|
CreatedAt: withdrawal.CreatedAt,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
// 转换为管理员详细DTO
|
// 转换为管理员详细DTO
|
||||||
|
|
||||||
// 转换为管理员详细DTO
|
// 转换为管理员详细DTO
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"hfb_sys/backend/internal/database"
|
"hfb_sys/backend/internal/database"
|
||||||
"hfb_sys/backend/internal/model"
|
"hfb_sys/backend/internal/model"
|
||||||
@@ -11,6 +12,7 @@ import (
|
|||||||
"hfb_sys/backend/pkg/crypto"
|
"hfb_sys/backend/pkg/crypto"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type withdrawalFixture struct {
|
type withdrawalFixture struct {
|
||||||
@@ -31,6 +33,12 @@ func newWithdrawalFixture(t *testing.T) withdrawalFixture {
|
|||||||
&model.WithdrawalRequest{},
|
&model.WithdrawalRequest{},
|
||||||
&model.WalletAccount{},
|
&model.WalletAccount{},
|
||||||
&model.WalletLedger{},
|
&model.WalletLedger{},
|
||||||
|
&model.RentalListing{},
|
||||||
|
&model.RentalOrder{},
|
||||||
|
&model.GameAccount{},
|
||||||
|
&model.AdminPickup{},
|
||||||
|
&model.AdminPickupFinancialAdjustment{},
|
||||||
|
&model.DistributionSite{},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
t.Fatalf("migrate fixture: %v", err)
|
t.Fatalf("migrate fixture: %v", err)
|
||||||
}
|
}
|
||||||
@@ -62,6 +70,205 @@ func newWithdrawalFixture(t *testing.T) withdrawalFixture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type withdrawalQueryCounter struct {
|
||||||
|
logger.Interface
|
||||||
|
count int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *withdrawalQueryCounter) Trace(_ context.Context, _ time.Time, fc func() (string, int64), _ error) {
|
||||||
|
c.count++
|
||||||
|
fc()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAdminListUsesBatchQueries(t *testing.T) {
|
||||||
|
f := newWithdrawalFixture(t)
|
||||||
|
for i := 0; i < 5; i++ {
|
||||||
|
item := model.WithdrawalRequest{
|
||||||
|
WithdrawNo: "WD-BATCH-" + string(rune('A'+i)),
|
||||||
|
UserID: f.userID,
|
||||||
|
AmountCent: int64(1000 + i),
|
||||||
|
ActualAmountCent: int64(1000 + i),
|
||||||
|
AccountType: "bank",
|
||||||
|
AccountName: "Test User",
|
||||||
|
AccountNo: "****0000",
|
||||||
|
Status: "pending",
|
||||||
|
}
|
||||||
|
if err := f.db.Create(&item).Error; err != nil {
|
||||||
|
t.Fatalf("create withdrawal: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
counter := &withdrawalQueryCounter{Interface: logger.Default.LogMode(logger.Silent)}
|
||||||
|
repo := NewRepository(f.db.Session(&gorm.Session{Logger: counter}), f.repo.walletRepo, f.repo.encryptor)
|
||||||
|
result, err := repo.AdminList(context.Background(), AdminListQuery{Page: 1, Size: 20})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("AdminList failed: %v", err)
|
||||||
|
}
|
||||||
|
if len(result.Items) != 5 {
|
||||||
|
t.Fatalf("AdminList items = %d, want 5", len(result.Items))
|
||||||
|
}
|
||||||
|
if counter.count > 4 {
|
||||||
|
t.Fatalf("AdminList queries = %d, want batch queries (<=4)", counter.count)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAdminReviewContextSummarizesIncomeAndHistory(t *testing.T) {
|
||||||
|
f := newWithdrawalFixture(t)
|
||||||
|
renter := model.User{Phone: "13800000002", Nickname: "renter", Status: "active"}
|
||||||
|
if err := f.db.Create(&renter).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
account := model.GameAccount{OwnerID: f.userID, ServerRegion: "cn", LoginPlatform: "pc", Title: "审核订单"}
|
||||||
|
if err := f.db.Create(&account).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
listing := model.RentalListing{ListingNo: "202610280362", AccountID: account.ID, OwnerID: f.userID, Status: "active"}
|
||||||
|
if err := f.db.Create(&listing).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
orders := []model.RentalOrder{
|
||||||
|
{OrderNo: "RO-WALLET", ListingID: listing.ID, AccountID: account.ID, OwnerID: f.userID, RenterID: renter.ID, Status: "completed", SettlementStatus: "settled", SettlementMode: "owner_wallet", RentAmountCent: 1000, OwnerRentAmountCent: 700},
|
||||||
|
{OrderNo: "RO-PLATFORM", ListingID: listing.ID, AccountID: account.ID, OwnerID: f.userID, RenterID: renter.ID, Status: "completed", SettlementStatus: "arbitrated", SettlementMode: "platform_managed", RentAmountCent: 200, OwnerRentAmountCent: 100, OfflineSettlementStatus: "settled", OfflineSettlementAmountCent: 100},
|
||||||
|
{OrderNo: "RO-OPEN", ListingID: listing.ID, AccountID: account.ID, OwnerID: f.userID, RenterID: renter.ID, Status: "renting", SettlementStatus: "unsettled", SettlementMode: "owner_wallet"},
|
||||||
|
}
|
||||||
|
for i := range orders {
|
||||||
|
if err := f.db.Create(&orders[i]).Error; err != nil {
|
||||||
|
t.Fatalf("create order: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
orderID := orders[0].ID
|
||||||
|
ledgers := []model.WalletLedger{
|
||||||
|
{LedgerNo: "WL-OWNER-INCOME", UserID: f.userID, OrderID: &orderID, Direction: "in", AmountCent: 700, BalanceType: "available", BizType: "owner_income", BizNo: "RO-WALLET"},
|
||||||
|
{LedgerNo: "WL-DEPOSIT-COMP", UserID: f.userID, OrderID: &orderID, Direction: "in", AmountCent: 50, BalanceType: "available", BizType: "deposit_compensation", BizNo: "RO-WALLET"},
|
||||||
|
}
|
||||||
|
if err := f.db.Create(&ledgers).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
pickups := []model.AdminPickup{
|
||||||
|
{PickupNo: "PK-WALLET", ListingID: listing.ID, AccountID: account.ID, OwnerID: f.userID, AdminID: f.adminID, Status: "completed", SettlementMode: "owner_wallet", SettleAmountCent: 200, CompletedAt: &now},
|
||||||
|
{PickupNo: "PK-PLATFORM", ListingID: listing.ID, AccountID: account.ID, OwnerID: f.userID, AdminID: f.adminID, Status: "completed", SettlementMode: "platform_managed", SettleAmountCent: 100, OfflineSettlementStatus: "settled", CompletedAt: &now},
|
||||||
|
}
|
||||||
|
if err := f.db.Create(&pickups).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
adjustments := []model.AdminPickupFinancialAdjustment{
|
||||||
|
{PickupID: pickups[0].ID, SettleDeltaCent: 50, SettlementMode: "owner_wallet", Status: "settled", Reason: "补款", CreatedBy: f.adminID},
|
||||||
|
{PickupID: pickups[1].ID, SettleDeltaCent: 20, SettlementMode: "platform_managed", Status: "settled", Reason: "补款", CreatedBy: f.adminID},
|
||||||
|
}
|
||||||
|
if err := f.db.Create(&adjustments).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
withdrawals := []model.WithdrawalRequest{
|
||||||
|
{WithdrawNo: "WD-CURRENT", UserID: f.userID, AmountCent: 300, ActualAmountCent: 300, AccountType: "bank", AccountName: "Test User", AccountNo: "****0000", Status: "pending", CreatedAt: now},
|
||||||
|
{WithdrawNo: "WD-PAID", UserID: f.userID, AmountCent: 300, ActualAmountCent: 300, AccountType: "bank", AccountName: "Test User", AccountNo: "****0000", Status: "completed", CreatedAt: now.Add(-time.Hour)},
|
||||||
|
{WithdrawNo: "WD-REJECTED", UserID: f.userID, AmountCent: 100, ActualAmountCent: 100, AccountType: "bank", AccountName: "Test User", AccountNo: "****0000", Status: "rejected", CreatedAt: now.Add(-2 * time.Hour)},
|
||||||
|
}
|
||||||
|
if err := f.db.Create(&withdrawals).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
contextDTO, err := f.repo.AdminReviewContext(context.Background(), withdrawals[0].ID, WithdrawalReviewContextQuery{PageSize: 10})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("AdminReviewContext failed: %v", err)
|
||||||
|
}
|
||||||
|
summary := contextDTO.Summary
|
||||||
|
if summary.OwnerOrderCount != 3 || summary.FinalizedOrderCount != 2 {
|
||||||
|
t.Fatalf("order summary = %+v", summary)
|
||||||
|
}
|
||||||
|
if summary.OwnerPickupCount != 2 || summary.PickupIncomeCent != 370 {
|
||||||
|
t.Fatalf("pickup summary = %+v", summary)
|
||||||
|
}
|
||||||
|
if summary.WalletPickupIncomeCent != 250 || summary.PlatformManagedPickupIncomeCent != 120 {
|
||||||
|
t.Fatalf("pickup income summary = %+v", summary)
|
||||||
|
}
|
||||||
|
if summary.WalletActualIncomeCent != 1000 || summary.PlatformManagedIncomeCent != 220 {
|
||||||
|
t.Fatalf("income summary = %+v", summary)
|
||||||
|
}
|
||||||
|
if summary.WithdrawalCount != 3 || summary.WithdrawnAmountCent != 300 || summary.PendingWithdrawalAmountCent != 300 || summary.RejectedWithdrawalCount != 1 {
|
||||||
|
t.Fatalf("withdrawal summary = %+v", summary)
|
||||||
|
}
|
||||||
|
if summary.ReconcileDifferenceAmountCent != 400 {
|
||||||
|
t.Fatalf("reconcile difference = %d, want 400", summary.ReconcileDifferenceAmountCent)
|
||||||
|
}
|
||||||
|
if len(contextDTO.Orders) != 3 || contextDTO.Orders[0].ListingNo != listing.ListingNo {
|
||||||
|
t.Fatalf("review orders = %+v", contextDTO.Orders)
|
||||||
|
}
|
||||||
|
if len(contextDTO.Pickups) != 2 || contextDTO.Pickups[0].ListingNo != listing.ListingNo {
|
||||||
|
t.Fatalf("review pickups = %+v", contextDTO.Pickups)
|
||||||
|
}
|
||||||
|
if len(contextDTO.Withdrawals) != 3 || contextDTO.Withdrawals[0].WithdrawNo != "WD-CURRENT" {
|
||||||
|
t.Fatalf("review withdrawals = %+v", contextDTO.Withdrawals)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAdminReviewContextScopesIncomeByWithdrawalSite(t *testing.T) {
|
||||||
|
f := newWithdrawalFixture(t)
|
||||||
|
siteA := model.DistributionSite{SiteCode: "audit-a", SiteName: "审核站A", Domain: "a.example.com", Status: "active"}
|
||||||
|
siteB := model.DistributionSite{SiteCode: "audit-b", SiteName: "审核站B", Domain: "b.example.com", Status: "active"}
|
||||||
|
if err := f.db.Create(&siteA).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := f.db.Create(&siteB).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
renter := model.User{Phone: "13800000003", Nickname: "renter-site", Status: "active"}
|
||||||
|
if err := f.db.Create(&renter).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
account := model.GameAccount{OwnerID: f.userID, ServerRegion: "cn", LoginPlatform: "pc", Title: "分站审核"}
|
||||||
|
if err := f.db.Create(&account).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
listingA := model.RentalListing{ListingNo: "SITE-A-LISTING", AccountID: account.ID, OwnerID: f.userID, Status: "active", DistributionSiteID: &siteA.ID}
|
||||||
|
listingB := model.RentalListing{ListingNo: "SITE-B-LISTING", AccountID: account.ID, OwnerID: f.userID, Status: "active", DistributionSiteID: &siteB.ID}
|
||||||
|
if err := f.db.Create(&listingA).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := f.db.Create(&listingB).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
orderA := model.RentalOrder{OrderNo: "RO-SITE-A", ListingID: listingA.ID, AccountID: account.ID, OwnerID: f.userID, RenterID: renter.ID, Status: "completed", SettlementStatus: "settled", SettlementMode: "owner_wallet", DistributionSiteID: &siteA.ID}
|
||||||
|
orderB := model.RentalOrder{OrderNo: "RO-SITE-B", ListingID: listingB.ID, AccountID: account.ID, OwnerID: f.userID, RenterID: renter.ID, Status: "completed", SettlementStatus: "settled", SettlementMode: "owner_wallet", DistributionSiteID: &siteB.ID}
|
||||||
|
if err := f.db.Create(&orderA).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := f.db.Create(&orderB).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := f.db.Create(&[]model.WalletLedger{
|
||||||
|
{LedgerNo: "WL-SITE-A", UserID: f.userID, DistributionSiteID: siteA.ID, OrderID: &orderA.ID, Direction: "in", AmountCent: 100, BalanceType: "available", BizType: "owner_income", BizNo: orderA.OrderNo},
|
||||||
|
{LedgerNo: "WL-SITE-B", UserID: f.userID, DistributionSiteID: siteB.ID, OrderID: &orderB.ID, Direction: "in", AmountCent: 999, BalanceType: "available", BizType: "owner_income", BizNo: orderB.OrderNo},
|
||||||
|
}).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := f.db.Create(&[]model.AdminPickup{
|
||||||
|
{PickupNo: "PK-SITE-A", ListingID: listingA.ID, AccountID: account.ID, OwnerID: f.userID, AdminID: f.adminID, Status: "completed", SettlementMode: "owner_wallet", SettleAmountCent: 100},
|
||||||
|
{PickupNo: "PK-SITE-B", ListingID: listingB.ID, AccountID: account.ID, OwnerID: f.userID, AdminID: f.adminID, Status: "completed", SettlementMode: "owner_wallet", SettleAmountCent: 999},
|
||||||
|
}).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
current := model.WithdrawalRequest{WithdrawNo: "WD-SITE-A", UserID: f.userID, DistributionSiteID: siteA.ID, AmountCent: 100, ActualAmountCent: 100, AccountType: "bank", AccountName: "Test User", AccountNo: "****0000", Status: "pending"}
|
||||||
|
if err := f.db.Create(¤t).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
contextDTO, err := f.repo.AdminReviewContext(context.Background(), current.ID, WithdrawalReviewContextQuery{PageSize: 10})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if contextDTO.Summary.OwnerOrderCount != 1 || contextDTO.Summary.OwnerPickupCount != 1 {
|
||||||
|
t.Fatalf("site-scoped business count = %+v", contextDTO.Summary)
|
||||||
|
}
|
||||||
|
if contextDTO.Summary.WalletActualIncomeCent != 200 || contextDTO.Summary.WithdrawalCount != 1 {
|
||||||
|
t.Fatalf("site-scoped income/withdrawal = %+v", contextDTO.Summary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (f withdrawalFixture) create(t *testing.T, amountCent int64) *WithdrawalDTO {
|
func (f withdrawalFixture) create(t *testing.T, amountCent int64) *WithdrawalDTO {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
dto, err := f.repo.Create(context.Background(), f.userID, CreateWithdrawalRequest{
|
dto, err := f.repo.Create(context.Background(), f.userID, CreateWithdrawalRequest{
|
||||||
|
|||||||
@@ -0,0 +1,368 @@
|
|||||||
|
package withdrawal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"hfb_sys/backend/internal/model"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ownerIncomeBizTypes = []string{"owner_income", "deposit_compensation", "arbitration_owner_income"}
|
||||||
|
|
||||||
|
func normalizeReviewContextQuery(query WithdrawalReviewContextQuery) WithdrawalReviewContextQuery {
|
||||||
|
if query.OrderPage < 1 {
|
||||||
|
query.OrderPage = 1
|
||||||
|
}
|
||||||
|
if query.PickupPage < 1 {
|
||||||
|
query.PickupPage = 1
|
||||||
|
}
|
||||||
|
if query.WithdrawalPage < 1 {
|
||||||
|
query.WithdrawalPage = 1
|
||||||
|
}
|
||||||
|
if query.PageSize < 1 || query.PageSize > 50 {
|
||||||
|
query.PageSize = 8
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminReviewContext 返回提现审核弹窗所需的用户财务汇总和最近历史记录。
|
||||||
|
// 该数据只在打开单笔详情时查询,不进入提现分页列表,避免列表产生 N+1。
|
||||||
|
func (r *Repository) AdminReviewContext(ctx context.Context, id uint64, query WithdrawalReviewContextQuery) (*WithdrawalReviewContextDTO, error) {
|
||||||
|
query = normalizeReviewContextQuery(query)
|
||||||
|
|
||||||
|
var current model.WithdrawalRequest
|
||||||
|
if err := r.db.WithContext(ctx).First(¤t, id).Error; err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return nil, ErrWithdrawalNotFound
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
summary, err := r.withdrawalReviewSummary(ctx, current.UserID, current.DistributionSiteID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
orders, err := r.withdrawalReviewOrders(ctx, current.UserID, current.DistributionSiteID, query)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
pickups, err := r.withdrawalReviewPickups(ctx, current.UserID, current.DistributionSiteID, query)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
withdrawals, err := r.withdrawalReviewHistory(ctx, current.UserID, current.DistributionSiteID, query)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &WithdrawalReviewContextDTO{
|
||||||
|
Summary: summary,
|
||||||
|
Orders: orders,
|
||||||
|
OrderPage: query.OrderPage,
|
||||||
|
OrderPageSize: query.PageSize,
|
||||||
|
Pickups: pickups,
|
||||||
|
PickupPage: query.PickupPage,
|
||||||
|
PickupPageSize: query.PageSize,
|
||||||
|
Withdrawals: withdrawals,
|
||||||
|
WithdrawalPage: query.WithdrawalPage,
|
||||||
|
WithdrawalPageSize: query.PageSize,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func scopeWithdrawalSite(db *gorm.DB, column string, siteID uint64) *gorm.DB {
|
||||||
|
if siteID > 0 {
|
||||||
|
return db.Where(column+" = ?", siteID)
|
||||||
|
}
|
||||||
|
return db.Where("(" + column + " IS NULL OR " + column + " = 0)")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Repository) withdrawalReviewSummary(ctx context.Context, userID, siteID uint64) (WithdrawalReviewSummaryDTO, error) {
|
||||||
|
db := r.db.WithContext(ctx)
|
||||||
|
var result WithdrawalReviewSummaryDTO
|
||||||
|
|
||||||
|
var orderSummary struct {
|
||||||
|
OwnerOrderCount int64
|
||||||
|
FinalizedOrderCount int64
|
||||||
|
PlatformManagedIncomeCent int64
|
||||||
|
}
|
||||||
|
orderQuery := scopeWithdrawalSite(db.Table("rental_orders"), "distribution_site_id", siteID)
|
||||||
|
if err := orderQuery.
|
||||||
|
Select(`COUNT(*) AS owner_order_count,
|
||||||
|
COALESCE(SUM(CASE WHEN settlement_status IN ('settled','arbitrated') THEN 1 ELSE 0 END), 0) AS finalized_order_count,
|
||||||
|
COALESCE(SUM(CASE WHEN settlement_mode = 'platform_managed' AND settlement_status IN ('settled','arbitrated')
|
||||||
|
THEN COALESCE(offline_settlement_amount_cent, 0) ELSE 0 END), 0) AS platform_managed_income_cent`).
|
||||||
|
Where("owner_id = ?", userID).
|
||||||
|
Scan(&orderSummary).Error; err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var walletIncome int64
|
||||||
|
walletQuery := scopeWithdrawalSite(db.Table("wallet_ledger AS wl"), "wl.distribution_site_id", siteID)
|
||||||
|
if err := walletQuery.
|
||||||
|
Select("COALESCE(SUM(wl.amount_cent), 0)").
|
||||||
|
Joins("JOIN rental_orders AS o ON o.id = wl.order_id").
|
||||||
|
Where("wl.user_id = ? AND o.owner_id = ? AND o.settlement_mode <> ?", userID, userID, "platform_managed").
|
||||||
|
Where("wl.direction = ? AND wl.biz_type IN ?", "in", ownerIncomeBizTypes).
|
||||||
|
Scan(&walletIncome).Error; err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
type pickupBaseRow struct {
|
||||||
|
SettlementMode string
|
||||||
|
Count int64
|
||||||
|
AmountCent int64
|
||||||
|
}
|
||||||
|
var pickupBases []pickupBaseRow
|
||||||
|
pickupBaseQuery := scopeWithdrawalSite(db.Table("admin_pickups AS p"), "l.distribution_site_id", siteID).
|
||||||
|
Select("p.settlement_mode, COUNT(*) AS count, COALESCE(SUM(p.settle_amount_cent), 0) AS amount_cent").
|
||||||
|
Joins("JOIN rental_listings AS l ON l.id = p.listing_id").
|
||||||
|
Where("p.owner_id = ? AND p.status = ?", userID, "completed").
|
||||||
|
Group("p.settlement_mode")
|
||||||
|
if err := pickupBaseQuery.Scan(&pickupBases).Error; err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
type pickupAdjustmentRow struct {
|
||||||
|
SettlementMode string
|
||||||
|
AmountCent int64
|
||||||
|
}
|
||||||
|
var pickupAdjustments []pickupAdjustmentRow
|
||||||
|
pickupAdjustmentQuery := scopeWithdrawalSite(db.Table("admin_pickup_financial_adjustments AS fa"), "l.distribution_site_id", siteID).
|
||||||
|
Select("p.settlement_mode, COALESCE(SUM(fa.settle_delta_cent), 0) AS amount_cent").
|
||||||
|
Joins("JOIN admin_pickups AS p ON p.id = fa.pickup_id AND p.status = ?", "completed").
|
||||||
|
Joins("JOIN rental_listings AS l ON l.id = p.listing_id").
|
||||||
|
Where("p.owner_id = ?", userID).
|
||||||
|
Group("p.settlement_mode")
|
||||||
|
if err := pickupAdjustmentQuery.Scan(&pickupAdjustments).Error; err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
pickupAmounts := make(map[string]int64, len(pickupBases))
|
||||||
|
for _, row := range pickupBases {
|
||||||
|
pickupAmounts[row.SettlementMode] += row.AmountCent
|
||||||
|
result.OwnerPickupCount += row.Count
|
||||||
|
}
|
||||||
|
for _, row := range pickupAdjustments {
|
||||||
|
pickupAmounts[row.SettlementMode] += row.AmountCent
|
||||||
|
}
|
||||||
|
result.WalletPickupIncomeCent = pickupAmounts["owner_wallet"]
|
||||||
|
result.PlatformManagedPickupIncomeCent = pickupAmounts["platform_managed"]
|
||||||
|
result.PickupIncomeCent = result.WalletPickupIncomeCent + result.PlatformManagedPickupIncomeCent
|
||||||
|
|
||||||
|
var withdrawalSummary struct {
|
||||||
|
WithdrawalCount int64
|
||||||
|
WithdrawnAmountCent int64
|
||||||
|
PendingWithdrawalAmountCent int64
|
||||||
|
RejectedWithdrawalCount int64
|
||||||
|
}
|
||||||
|
withdrawalQuery := scopeWithdrawalSite(db.Table("withdrawal_requests"), "distribution_site_id", siteID)
|
||||||
|
if err := withdrawalQuery.
|
||||||
|
Select(`COUNT(*) AS withdrawal_count,
|
||||||
|
COALESCE(SUM(CASE WHEN status = 'completed' THEN actual_amount_cent ELSE 0 END), 0) AS withdrawn_amount_cent,
|
||||||
|
COALESCE(SUM(CASE WHEN status IN ('pending','processing') THEN actual_amount_cent ELSE 0 END), 0) AS pending_withdrawal_amount_cent,
|
||||||
|
COALESCE(SUM(CASE WHEN status = 'rejected' THEN 1 ELSE 0 END), 0) AS rejected_withdrawal_count`).
|
||||||
|
Where("user_id = ?", userID).
|
||||||
|
Scan(&withdrawalSummary).Error; err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result.OwnerOrderCount = orderSummary.OwnerOrderCount
|
||||||
|
result.FinalizedOrderCount = orderSummary.FinalizedOrderCount
|
||||||
|
result.WalletActualIncomeCent = walletIncome + result.WalletPickupIncomeCent
|
||||||
|
result.PlatformManagedIncomeCent = orderSummary.PlatformManagedIncomeCent + result.PlatformManagedPickupIncomeCent
|
||||||
|
result.WithdrawalCount = withdrawalSummary.WithdrawalCount
|
||||||
|
result.WithdrawnAmountCent = withdrawalSummary.WithdrawnAmountCent
|
||||||
|
result.PendingWithdrawalAmountCent = withdrawalSummary.PendingWithdrawalAmountCent
|
||||||
|
result.RejectedWithdrawalCount = withdrawalSummary.RejectedWithdrawalCount
|
||||||
|
result.ReconcileDifferenceAmountCent = result.WalletActualIncomeCent - withdrawalSummary.WithdrawnAmountCent - withdrawalSummary.PendingWithdrawalAmountCent
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Repository) withdrawalReviewOrders(ctx context.Context, userID, siteID uint64, query WithdrawalReviewContextQuery) ([]WithdrawalReviewOrderDTO, error) {
|
||||||
|
type orderRow struct {
|
||||||
|
ID uint64
|
||||||
|
OrderNo string
|
||||||
|
ListingNo string
|
||||||
|
Title string
|
||||||
|
Status string
|
||||||
|
SettlementStatus string
|
||||||
|
SettlementMode string
|
||||||
|
RentAmountCent int64
|
||||||
|
OfflineSettlementAmountCent int64
|
||||||
|
CreatedAt time.Time
|
||||||
|
SettledAt *time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows []orderRow
|
||||||
|
offset := (query.OrderPage - 1) * query.PageSize
|
||||||
|
orderQuery := scopeWithdrawalSite(r.db.WithContext(ctx), "o.distribution_site_id", siteID)
|
||||||
|
if err := orderQuery.
|
||||||
|
Table("rental_orders AS o").
|
||||||
|
Select(`o.id, o.order_no, l.listing_no, a.title, o.status, o.settlement_status, o.settlement_mode,
|
||||||
|
o.rent_amount_cent, COALESCE(o.offline_settlement_amount_cent, 0) AS offline_settlement_amount_cent,
|
||||||
|
o.created_at, o.settled_at`).
|
||||||
|
Joins("JOIN rental_listings AS l ON l.id = o.listing_id").
|
||||||
|
Joins("JOIN game_accounts AS a ON a.id = o.account_id").
|
||||||
|
Where("o.owner_id = ?", userID).
|
||||||
|
Order("o.id DESC").
|
||||||
|
Offset(offset).Limit(query.PageSize).
|
||||||
|
Scan(&rows).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(rows) == 0 {
|
||||||
|
return []WithdrawalReviewOrderDTO{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
orderIDs := make([]uint64, 0, len(rows))
|
||||||
|
for _, row := range rows {
|
||||||
|
orderIDs = append(orderIDs, row.ID)
|
||||||
|
}
|
||||||
|
var walletRows []struct {
|
||||||
|
OrderID uint64
|
||||||
|
AmountCent int64
|
||||||
|
}
|
||||||
|
if err := r.db.WithContext(ctx).
|
||||||
|
Table("wallet_ledger").
|
||||||
|
Select("order_id, COALESCE(SUM(amount_cent), 0) AS amount_cent").
|
||||||
|
Where("order_id IN ? AND user_id = ? AND direction = ? AND biz_type IN ?", orderIDs, userID, "in", ownerIncomeBizTypes).
|
||||||
|
Group("order_id").
|
||||||
|
Scan(&walletRows).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
walletIncome := make(map[uint64]int64, len(walletRows))
|
||||||
|
for _, row := range walletRows {
|
||||||
|
walletIncome[row.OrderID] = row.AmountCent
|
||||||
|
}
|
||||||
|
|
||||||
|
items := make([]WithdrawalReviewOrderDTO, 0, len(rows))
|
||||||
|
for _, row := range rows {
|
||||||
|
var income *int64
|
||||||
|
if row.SettlementStatus == "settled" || row.SettlementStatus == "arbitrated" {
|
||||||
|
amount := walletIncome[row.ID]
|
||||||
|
if row.SettlementMode == "platform_managed" {
|
||||||
|
amount = row.OfflineSettlementAmountCent
|
||||||
|
}
|
||||||
|
income = &amount
|
||||||
|
}
|
||||||
|
items = append(items, WithdrawalReviewOrderDTO{
|
||||||
|
ID: row.ID,
|
||||||
|
OrderNo: row.OrderNo,
|
||||||
|
ListingNo: row.ListingNo,
|
||||||
|
Title: row.Title,
|
||||||
|
Status: row.Status,
|
||||||
|
SettlementStatus: row.SettlementStatus,
|
||||||
|
SettlementMode: row.SettlementMode,
|
||||||
|
RentAmountCent: row.RentAmountCent,
|
||||||
|
OwnerActualIncomeCent: income,
|
||||||
|
CreatedAt: row.CreatedAt,
|
||||||
|
SettledAt: row.SettledAt,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Repository) withdrawalReviewPickups(ctx context.Context, userID, siteID uint64, query WithdrawalReviewContextQuery) ([]WithdrawalReviewPickupDTO, error) {
|
||||||
|
type pickupRow struct {
|
||||||
|
ID uint64
|
||||||
|
PickupNo string
|
||||||
|
ListingNo string
|
||||||
|
Title string
|
||||||
|
Status string
|
||||||
|
SettlementMode string
|
||||||
|
OfflineSettlementStatus string
|
||||||
|
SettleAmountCent int64
|
||||||
|
CompletedAt *time.Time
|
||||||
|
CreatedAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows []pickupRow
|
||||||
|
offset := (query.PickupPage - 1) * query.PageSize
|
||||||
|
pickupQuery := scopeWithdrawalSite(r.db.WithContext(ctx), "l.distribution_site_id", siteID)
|
||||||
|
if err := pickupQuery.
|
||||||
|
Table("admin_pickups AS p").
|
||||||
|
Select(`p.id, p.pickup_no, l.listing_no, a.title, p.status, p.settlement_mode,
|
||||||
|
p.offline_settlement_status, p.settle_amount_cent, p.completed_at, p.created_at`).
|
||||||
|
Joins("JOIN rental_listings AS l ON l.id = p.listing_id").
|
||||||
|
Joins("JOIN game_accounts AS a ON a.id = p.account_id").
|
||||||
|
Where("p.owner_id = ? AND p.status = ?", userID, "completed").
|
||||||
|
Order("p.id DESC").
|
||||||
|
Offset(offset).Limit(query.PageSize).
|
||||||
|
Scan(&rows).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(rows) == 0 {
|
||||||
|
return []WithdrawalReviewPickupDTO{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
pickupIDs := make([]uint64, 0, len(rows))
|
||||||
|
for _, row := range rows {
|
||||||
|
pickupIDs = append(pickupIDs, row.ID)
|
||||||
|
}
|
||||||
|
var adjustmentRows []struct {
|
||||||
|
PickupID uint64
|
||||||
|
AmountCent int64
|
||||||
|
}
|
||||||
|
if err := r.db.WithContext(ctx).
|
||||||
|
Table("admin_pickup_financial_adjustments").
|
||||||
|
Select("pickup_id, COALESCE(SUM(settle_delta_cent), 0) AS amount_cent").
|
||||||
|
Where("pickup_id IN ?", pickupIDs).
|
||||||
|
Group("pickup_id").
|
||||||
|
Scan(&adjustmentRows).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
adjustments := make(map[uint64]int64, len(adjustmentRows))
|
||||||
|
for _, row := range adjustmentRows {
|
||||||
|
adjustments[row.PickupID] = row.AmountCent
|
||||||
|
}
|
||||||
|
|
||||||
|
items := make([]WithdrawalReviewPickupDTO, 0, len(rows))
|
||||||
|
for _, row := range rows {
|
||||||
|
adjustment := adjustments[row.ID]
|
||||||
|
items = append(items, WithdrawalReviewPickupDTO{
|
||||||
|
ID: row.ID,
|
||||||
|
PickupNo: row.PickupNo,
|
||||||
|
ListingNo: row.ListingNo,
|
||||||
|
Title: row.Title,
|
||||||
|
Status: row.Status,
|
||||||
|
SettlementMode: row.SettlementMode,
|
||||||
|
OfflineSettlementStatus: row.OfflineSettlementStatus,
|
||||||
|
SettleAmountCent: row.SettleAmountCent,
|
||||||
|
SettleAdjustmentCent: adjustment,
|
||||||
|
EffectiveSettleAmountCent: row.SettleAmountCent + adjustment,
|
||||||
|
CompletedAt: row.CompletedAt,
|
||||||
|
CreatedAt: row.CreatedAt,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Repository) withdrawalReviewHistory(ctx context.Context, userID, siteID uint64, query WithdrawalReviewContextQuery) ([]WithdrawalReviewHistoryDTO, error) {
|
||||||
|
var rows []model.WithdrawalRequest
|
||||||
|
offset := (query.WithdrawalPage - 1) * query.PageSize
|
||||||
|
historyQuery := scopeWithdrawalSite(r.db.WithContext(ctx), "distribution_site_id", siteID)
|
||||||
|
if err := historyQuery.
|
||||||
|
Where("user_id = ?", userID).
|
||||||
|
Order("created_at DESC, id DESC").
|
||||||
|
Offset(offset).Limit(query.PageSize).
|
||||||
|
Find(&rows).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items := make([]WithdrawalReviewHistoryDTO, 0, len(rows))
|
||||||
|
for _, row := range rows {
|
||||||
|
items = append(items, WithdrawalReviewHistoryDTO{
|
||||||
|
ID: row.ID,
|
||||||
|
WithdrawNo: row.WithdrawNo,
|
||||||
|
AmountCent: row.AmountCent,
|
||||||
|
FeeCent: row.FeeCent,
|
||||||
|
ActualAmountCent: row.ActualAmountCent,
|
||||||
|
Status: row.Status,
|
||||||
|
CreatedAt: row.CreatedAt,
|
||||||
|
ReviewedAt: row.ReviewedAt,
|
||||||
|
PaidAt: row.PaidAt,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
@@ -96,6 +96,13 @@ func (s *Service) AdminFindByID(ctx context.Context, id uint64) (*WithdrawalDeta
|
|||||||
return s.repo.AdminFindByID(ctx, id)
|
return s.repo.AdminFindByID(ctx, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) AdminReviewContext(ctx context.Context, id uint64, query WithdrawalReviewContextQuery) (*WithdrawalReviewContextDTO, error) {
|
||||||
|
if s.repo == nil {
|
||||||
|
return nil, ErrDependencyUnavailable
|
||||||
|
}
|
||||||
|
return s.repo.AdminReviewContext(ctx, id, query)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Service) Review(ctx context.Context, adminID, id uint64, req ReviewWithdrawalRequest) (*WithdrawalDetailDTO, error) {
|
func (s *Service) Review(ctx context.Context, adminID, id uint64, req ReviewWithdrawalRequest) (*WithdrawalDetailDTO, error) {
|
||||||
if s.repo == nil {
|
if s.repo == nil {
|
||||||
return nil, ErrDependencyUnavailable
|
return nil, ErrDependencyUnavailable
|
||||||
|
|||||||
@@ -846,6 +846,7 @@ func New(cfg config.Config, deps Dependencies, logger *zap.Logger) *gin.Engine {
|
|||||||
// 提现管理
|
// 提现管理
|
||||||
adminRoutes.GET("/withdrawals", requirePerm("withdrawal:list"), withdrawalHandler.AdminList)
|
adminRoutes.GET("/withdrawals", requirePerm("withdrawal:list"), withdrawalHandler.AdminList)
|
||||||
adminRoutes.GET("/withdrawals/:id", requirePerm("withdrawal:detail"), withdrawalHandler.AdminFindByID)
|
adminRoutes.GET("/withdrawals/:id", requirePerm("withdrawal:detail"), withdrawalHandler.AdminFindByID)
|
||||||
|
adminRoutes.GET("/withdrawals/:id/review-context", requirePerm("withdrawal:detail"), withdrawalHandler.AdminReviewContext)
|
||||||
adminRoutes.POST("/withdrawals/:id/review", requirePerm("withdrawal:review"), withdrawalHandler.Review)
|
adminRoutes.POST("/withdrawals/:id/review", requirePerm("withdrawal:review"), withdrawalHandler.Review)
|
||||||
adminRoutes.POST("/withdrawals/:id/confirm-payment", requirePerm("withdrawal:pay"), withdrawalHandler.ConfirmPayment)
|
adminRoutes.POST("/withdrawals/:id/confirm-payment", requirePerm("withdrawal:pay"), withdrawalHandler.ConfirmPayment)
|
||||||
|
|
||||||
|
|||||||
@@ -2,27 +2,32 @@ import { apiClient } from '@/shared/api/client'
|
|||||||
|
|
||||||
import type { ApiResponse, PaginatedResult } from '@/shared/types/types'
|
import type { ApiResponse, PaginatedResult } from '@/shared/types/types'
|
||||||
|
|
||||||
// 管理员端提现详情接口
|
// 管理员端提现列表使用的轻量数据,不包含完整收款凭证和审核详情。
|
||||||
export interface WithdrawalDetail {
|
export interface WithdrawalListItem {
|
||||||
id: number
|
id: number
|
||||||
withdraw_no: string
|
withdraw_no: string
|
||||||
user_id: number
|
user_id: number
|
||||||
distribution_site_id?: number
|
distribution_site_id?: number
|
||||||
distribution_site_name?: string
|
distribution_site_name?: string
|
||||||
distribution_site_code?: string
|
|
||||||
user_nickname: string
|
user_nickname: string
|
||||||
user_phone: string
|
user_phone: string
|
||||||
amount_cent: number
|
amount_cent: number
|
||||||
fee_cent: number
|
fee_cent: number
|
||||||
actual_amount_cent: number
|
actual_amount_cent: number
|
||||||
payment_account_id: number | null
|
|
||||||
account_type: string
|
account_type: string
|
||||||
account_name: string
|
account_name: string
|
||||||
account_no: string // 管理员可见完整账号
|
account_no: string
|
||||||
bank_name: string
|
bank_name: string
|
||||||
|
status: string
|
||||||
|
created_at: string
|
||||||
|
}
|
||||||
|
|
||||||
|
// 管理员端提现完整详情接口
|
||||||
|
export interface WithdrawalDetail extends WithdrawalListItem {
|
||||||
|
distribution_site_code?: string
|
||||||
|
payment_account_id: number | null
|
||||||
bank_branch: string
|
bank_branch: string
|
||||||
certificate_urls: string[] // 收款二维码图片
|
certificate_urls: string[] // 收款二维码图片
|
||||||
status: string
|
|
||||||
reviewed_by: number | null
|
reviewed_by: number | null
|
||||||
reviewed_by_name: string
|
reviewed_by_name: string
|
||||||
reviewed_at: string | null
|
reviewed_at: string | null
|
||||||
@@ -32,10 +37,79 @@ export interface WithdrawalDetail {
|
|||||||
paid_at: string | null
|
paid_at: string | null
|
||||||
payment_proof_url: string
|
payment_proof_url: string
|
||||||
payment_remark: string
|
payment_remark: string
|
||||||
created_at: string
|
|
||||||
updated_at: string
|
updated_at: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface WithdrawalReviewSummary {
|
||||||
|
owner_order_count: number
|
||||||
|
owner_pickup_count?: number
|
||||||
|
finalized_order_count: number
|
||||||
|
wallet_actual_income_cent: number
|
||||||
|
pickup_income_cent?: number
|
||||||
|
wallet_pickup_income_cent?: number
|
||||||
|
platform_managed_pickup_income_cent?: number
|
||||||
|
platform_managed_income_cent: number
|
||||||
|
withdrawal_count: number
|
||||||
|
withdrawn_amount_cent: number
|
||||||
|
pending_withdrawal_amount_cent: number
|
||||||
|
rejected_withdrawal_count: number
|
||||||
|
reconcile_difference_amount_cent: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WithdrawalReviewPickup {
|
||||||
|
id: number
|
||||||
|
pickup_no: string
|
||||||
|
listing_no: string
|
||||||
|
title: string
|
||||||
|
status: string
|
||||||
|
settlement_mode: string
|
||||||
|
offline_settlement_status: string
|
||||||
|
settle_amount_cent: number
|
||||||
|
settle_adjustment_cent: number
|
||||||
|
effective_settle_amount_cent: number
|
||||||
|
completed_at?: string
|
||||||
|
created_at: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WithdrawalReviewOrder {
|
||||||
|
id: number
|
||||||
|
order_no: string
|
||||||
|
listing_no: string
|
||||||
|
title: string
|
||||||
|
status: string
|
||||||
|
settlement_status: string
|
||||||
|
settlement_mode: string
|
||||||
|
rent_amount_cent: number
|
||||||
|
owner_actual_income_cent?: number
|
||||||
|
created_at: string
|
||||||
|
settled_at?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WithdrawalReviewHistory {
|
||||||
|
id: number
|
||||||
|
withdraw_no: string
|
||||||
|
amount_cent: number
|
||||||
|
fee_cent: number
|
||||||
|
actual_amount_cent: number
|
||||||
|
status: string
|
||||||
|
created_at: string
|
||||||
|
reviewed_at?: string
|
||||||
|
paid_at?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WithdrawalReviewContext {
|
||||||
|
summary: WithdrawalReviewSummary
|
||||||
|
orders: WithdrawalReviewOrder[]
|
||||||
|
order_page: number
|
||||||
|
order_page_size: number
|
||||||
|
pickups: WithdrawalReviewPickup[]
|
||||||
|
pickup_page: number
|
||||||
|
pickup_page_size: number
|
||||||
|
withdrawals: WithdrawalReviewHistory[]
|
||||||
|
withdrawal_page: number
|
||||||
|
withdrawal_page_size: number
|
||||||
|
}
|
||||||
|
|
||||||
// 审核请求
|
// 审核请求
|
||||||
export interface ReviewWithdrawalRequest {
|
export interface ReviewWithdrawalRequest {
|
||||||
approved: boolean
|
approved: boolean
|
||||||
@@ -56,7 +130,7 @@ export async function fetchAdminWithdrawals(params: {
|
|||||||
page?: number
|
page?: number
|
||||||
page_size?: number
|
page_size?: number
|
||||||
}) {
|
}) {
|
||||||
const { data } = await apiClient.get<ApiResponse<PaginatedResult<WithdrawalDetail>>>(
|
const { data } = await apiClient.get<ApiResponse<PaginatedResult<WithdrawalListItem>>>(
|
||||||
'/admin/withdrawals',
|
'/admin/withdrawals',
|
||||||
{
|
{
|
||||||
params,
|
params,
|
||||||
@@ -70,6 +144,22 @@ export async function fetchAdminWithdrawal(id: number) {
|
|||||||
return data.data
|
return data.data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchAdminWithdrawalReviewContext(
|
||||||
|
id: number,
|
||||||
|
params: {
|
||||||
|
order_page?: number
|
||||||
|
pickup_page?: number
|
||||||
|
withdrawal_page?: number
|
||||||
|
page_size?: number
|
||||||
|
} = {}
|
||||||
|
) {
|
||||||
|
const { data } = await apiClient.get<ApiResponse<WithdrawalReviewContext>>(
|
||||||
|
`/admin/withdrawals/${id}/review-context`,
|
||||||
|
{ params }
|
||||||
|
)
|
||||||
|
return data.data
|
||||||
|
}
|
||||||
|
|
||||||
export async function reviewWithdrawal(id: number, req: ReviewWithdrawalRequest) {
|
export async function reviewWithdrawal(id: number, req: ReviewWithdrawalRequest) {
|
||||||
const { data } = await apiClient.post<ApiResponse<WithdrawalDetail>>(
|
const { data } = await apiClient.post<ApiResponse<WithdrawalDetail>>(
|
||||||
`/admin/withdrawals/${id}/review`,
|
`/admin/withdrawals/${id}/review`,
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ import {
|
|||||||
} from '@/features/admin/api/adminInvitations'
|
} from '@/features/admin/api/adminInvitations'
|
||||||
import { fetchAdminPayments, type AdminPayment } from '@/features/admin/api/adminPayments'
|
import { fetchAdminPayments, type AdminPayment } from '@/features/admin/api/adminPayments'
|
||||||
import { fetchAdminWalletLedger, type AdminWalletLedger } from '@/features/admin/api/adminWallet'
|
import { fetchAdminWalletLedger, type AdminWalletLedger } from '@/features/admin/api/adminWallet'
|
||||||
import { fetchAdminWithdrawals, type WithdrawalDetail } from '@/features/admin/api/adminWithdrawal'
|
import {
|
||||||
|
fetchAdminWithdrawals,
|
||||||
|
type WithdrawalListItem,
|
||||||
|
} from '@/features/admin/api/adminWithdrawal'
|
||||||
import type { AdminUserItem } from '@/features/admin/api/adminUsers'
|
import type { AdminUserItem } from '@/features/admin/api/adminUsers'
|
||||||
import { fetchAdminOrders, type AdminOrderListItem } from '@/features/orders'
|
import { fetchAdminOrders, type AdminOrderListItem } from '@/features/orders'
|
||||||
import { adminPath } from '@/shared/utils/adminPath'
|
import { adminPath } from '@/shared/utils/adminPath'
|
||||||
@@ -87,7 +90,7 @@ const orderPage = ref(1)
|
|||||||
const orderPageSize = ref(20)
|
const orderPageSize = ref(20)
|
||||||
|
|
||||||
const withdrawalLoading = ref(false)
|
const withdrawalLoading = ref(false)
|
||||||
const withdrawalRows = ref<WithdrawalDetail[]>([])
|
const withdrawalRows = ref<WithdrawalListItem[]>([])
|
||||||
const withdrawalTotal = ref(0)
|
const withdrawalTotal = ref(0)
|
||||||
const withdrawalPage = ref(1)
|
const withdrawalPage = ref(1)
|
||||||
const withdrawalPageSize = ref(20)
|
const withdrawalPageSize = ref(20)
|
||||||
|
|||||||
@@ -1,20 +1,22 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
import { ref } from 'vue'
|
import { computed, ref, watch } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
|
|
||||||
import type { WithdrawalDetail } from '@/features/admin/api/adminWithdrawal'
|
import {
|
||||||
import { reviewWithdrawal, confirmPayment } from '@/features/admin/api/adminWithdrawal'
|
confirmPayment,
|
||||||
import { formatCent } from '@/shared/utils/money'
|
fetchAdminWithdrawalReviewContext,
|
||||||
import { adminPath } from '@/shared/utils/adminPath'
|
reviewWithdrawal,
|
||||||
|
type WithdrawalDetail,
|
||||||
|
type WithdrawalReviewContext,
|
||||||
|
} from '@/features/admin/api/adminWithdrawal'
|
||||||
import AuthImage from '@/shared/components/business/AuthImage.vue'
|
import AuthImage from '@/shared/components/business/AuthImage.vue'
|
||||||
|
import { formatCent, formatCentWithSymbol } from '@/shared/utils/money'
|
||||||
const router = useRouter()
|
import { orderStatusLabel, settlementStatusLabel } from '@/shared/utils/statusLabels'
|
||||||
|
import { formatDateTime } from '@/shared/utils/time'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
modelValue: boolean
|
modelValue: boolean
|
||||||
withdrawal: WithdrawalDetail | null
|
withdrawal: WithdrawalDetail | null
|
||||||
returnQuery?: Record<string, string>
|
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@@ -23,18 +25,80 @@ const emit = defineEmits<{
|
|||||||
}>()
|
}>()
|
||||||
|
|
||||||
const submitting = ref(false)
|
const submitting = ref(false)
|
||||||
|
const contextLoading = ref(false)
|
||||||
|
const reviewContext = ref<WithdrawalReviewContext | null>(null)
|
||||||
|
const historyTab = ref<'orders' | 'pickups' | 'withdrawals'>('orders')
|
||||||
|
const orderPage = ref(1)
|
||||||
|
const pickupPage = ref(1)
|
||||||
|
const withdrawalPage = ref(1)
|
||||||
|
const contextPageSize = 5
|
||||||
|
|
||||||
/** 跳转订单管理页并预填号主搜索,快速查看该号主相关订单 */
|
const pickupCount = computed(() => Number(reviewContext.value?.summary.owner_pickup_count ?? 0))
|
||||||
function goToOwnerOrders() {
|
const historyBusinessCount = computed(
|
||||||
|
() => Number(reviewContext.value?.summary.owner_order_count ?? 0) + pickupCount.value
|
||||||
|
)
|
||||||
|
const platformPickupIncome = computed(() =>
|
||||||
|
Number(reviewContext.value?.summary.platform_managed_pickup_income_cent ?? 0)
|
||||||
|
)
|
||||||
|
|
||||||
|
const reconcileType = computed<'success' | 'error' | 'info'>(() => {
|
||||||
|
const difference = reviewContext.value?.summary.reconcile_difference_amount_cent ?? 0
|
||||||
|
if (difference === 0) return 'success'
|
||||||
|
if (difference < 0) return 'error'
|
||||||
|
return 'info'
|
||||||
|
})
|
||||||
|
|
||||||
|
const reconcileTitle = computed(() => {
|
||||||
|
const difference = reviewContext.value?.summary.reconcile_difference_amount_cent ?? 0
|
||||||
|
if (difference === 0) return '钱包收入与提现记录已对平'
|
||||||
|
if (difference < 0)
|
||||||
|
return `提现金额超过钱包实际收入 ${formatCentWithSymbol(Math.abs(difference))}`
|
||||||
|
return `仍有 ${formatCentWithSymbol(difference)} 钱包收入未提现或待处理`
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => [props.modelValue, props.withdrawal?.id] as const,
|
||||||
|
([visible]) => {
|
||||||
|
if (!visible || !props.withdrawal?.id) return
|
||||||
|
orderPage.value = 1
|
||||||
|
pickupPage.value = 1
|
||||||
|
withdrawalPage.value = 1
|
||||||
|
historyTab.value = 'orders'
|
||||||
|
void loadReviewContext()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
async function loadReviewContext() {
|
||||||
if (!props.withdrawal) return
|
if (!props.withdrawal) return
|
||||||
const keyword = props.withdrawal.user_phone?.trim() || String(props.withdrawal.user_id || '')
|
contextLoading.value = true
|
||||||
void router.push({
|
try {
|
||||||
path: adminPath('orders'),
|
reviewContext.value = await fetchAdminWithdrawalReviewContext(props.withdrawal.id, {
|
||||||
query: {
|
order_page: orderPage.value,
|
||||||
...props.returnQuery,
|
pickup_page: pickupPage.value,
|
||||||
...(keyword ? { keyword } : {}),
|
withdrawal_page: withdrawalPage.value,
|
||||||
},
|
page_size: contextPageSize,
|
||||||
})
|
})
|
||||||
|
} catch (error: any) {
|
||||||
|
reviewContext.value = null
|
||||||
|
ElMessage.error(error.response?.data?.message || '审核汇总加载失败')
|
||||||
|
} finally {
|
||||||
|
contextLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeOrderPage(page: number) {
|
||||||
|
orderPage.value = page
|
||||||
|
void loadReviewContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
function changePickupPage(page: number) {
|
||||||
|
pickupPage.value = page
|
||||||
|
void loadReviewContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeWithdrawalPage(page: number) {
|
||||||
|
withdrawalPage.value = page
|
||||||
|
void loadReviewContext()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleReview(approved: boolean) {
|
async function handleReview(approved: boolean) {
|
||||||
@@ -61,6 +125,7 @@ async function handleReview(approved: boolean) {
|
|||||||
|
|
||||||
ElMessage.success(`审核${action}`)
|
ElMessage.success(`审核${action}`)
|
||||||
emit('saved')
|
emit('saved')
|
||||||
|
await loadReviewContext()
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error !== 'cancel') {
|
if (error !== 'cancel') {
|
||||||
ElMessage.error(error.response?.data?.message || '操作失败')
|
ElMessage.error(error.response?.data?.message || '操作失败')
|
||||||
@@ -96,6 +161,7 @@ async function handleConfirmPayment() {
|
|||||||
|
|
||||||
ElMessage.success('打款完成')
|
ElMessage.success('打款完成')
|
||||||
emit('saved')
|
emit('saved')
|
||||||
|
await loadReviewContext()
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error !== 'cancel') {
|
if (error !== 'cancel') {
|
||||||
ElMessage.error(error.response?.data?.message || '操作失败')
|
ElMessage.error(error.response?.data?.message || '操作失败')
|
||||||
@@ -136,204 +202,407 @@ function accountTypeLabel(type: string) {
|
|||||||
}
|
}
|
||||||
return labels[type] || type
|
return labels[type] || type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function settlementModeLabel(mode: string) {
|
||||||
|
return mode === 'platform_managed' ? '平台代管' : '钱包结算'
|
||||||
|
}
|
||||||
|
|
||||||
|
function pickupSettlementLabel(pickup: {
|
||||||
|
settlement_mode: string
|
||||||
|
offline_settlement_status: string
|
||||||
|
}) {
|
||||||
|
if (pickup.settlement_mode !== 'platform_managed') return '已入钱包'
|
||||||
|
return pickup.offline_settlement_status === 'settled' ? '已线下结算' : '待线下结算'
|
||||||
|
}
|
||||||
|
|
||||||
|
function incomeText(income?: number) {
|
||||||
|
return typeof income === 'number' ? formatCentWithSymbol(income) : '-'
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<el-dialog
|
<el-dialog
|
||||||
:model-value="modelValue"
|
:model-value="modelValue"
|
||||||
title="提现详情"
|
title="提现详情与审核对账"
|
||||||
width="700px"
|
width="min(1320px, 96vw)"
|
||||||
|
top="4vh"
|
||||||
|
class="withdrawal-review-dialog"
|
||||||
@update:model-value="emit('update:modelValue', $event)"
|
@update:model-value="emit('update:modelValue', $event)"
|
||||||
>
|
>
|
||||||
<div v-if="withdrawal" class="withdrawal-detail">
|
<div v-if="withdrawal" class="withdrawal-layout">
|
||||||
<!-- 基本信息 -->
|
<main class="withdrawal-detail">
|
||||||
<el-descriptions :column="2" border>
|
|
||||||
<el-descriptions-item label="提现单号">
|
|
||||||
{{ withdrawal.withdraw_no }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="所属站点">
|
|
||||||
<el-tag v-if="withdrawal.distribution_site_id" type="warning" size="small">
|
|
||||||
{{
|
|
||||||
withdrawal.distribution_site_name || `分销站点 #${withdrawal.distribution_site_id}`
|
|
||||||
}}
|
|
||||||
<template v-if="withdrawal.distribution_site_code">
|
|
||||||
({{ withdrawal.distribution_site_code }})</template
|
|
||||||
>
|
|
||||||
</el-tag>
|
|
||||||
<el-tag v-else type="info" size="small">主站</el-tag>
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="状态">
|
|
||||||
<el-tag :type="statusType(withdrawal.status)">
|
|
||||||
{{ statusLabel(withdrawal.status) }}
|
|
||||||
</el-tag>
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="申请时间">
|
|
||||||
{{ new Date(withdrawal.created_at).toLocaleString('zh-CN') }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
</el-descriptions>
|
|
||||||
|
|
||||||
<!-- 用户信息 -->
|
|
||||||
<h3 style="margin-top: 20px">
|
|
||||||
用户信息
|
|
||||||
<el-button
|
|
||||||
size="small"
|
|
||||||
type="primary"
|
|
||||||
plain
|
|
||||||
style="margin-left: 12px"
|
|
||||||
@click="goToOwnerOrders"
|
|
||||||
>
|
|
||||||
查看该号主订单
|
|
||||||
</el-button>
|
|
||||||
</h3>
|
|
||||||
<el-descriptions :column="2" border>
|
|
||||||
<el-descriptions-item label="用户ID">
|
|
||||||
{{ withdrawal.user_id }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="昵称">
|
|
||||||
{{ withdrawal.user_nickname }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="手机号" :span="2">
|
|
||||||
{{ withdrawal.user_phone }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
</el-descriptions>
|
|
||||||
|
|
||||||
<!-- 金额信息 -->
|
|
||||||
<h3 style="margin-top: 20px">金额信息</h3>
|
|
||||||
<el-descriptions :column="2" border>
|
|
||||||
<el-descriptions-item label="提现金额">
|
|
||||||
<span style="color: #f56c6c; font-weight: 600; font-size: 16px">
|
|
||||||
¥{{ formatCent(withdrawal.amount_cent) }}
|
|
||||||
</span>
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="手续费">
|
|
||||||
¥{{ formatCent(withdrawal.fee_cent) }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="实际到账" :span="2">
|
|
||||||
<span style="color: #67c23a; font-weight: 600; font-size: 16px">
|
|
||||||
¥{{ formatCent(withdrawal.actual_amount_cent) }}
|
|
||||||
</span>
|
|
||||||
</el-descriptions-item>
|
|
||||||
</el-descriptions>
|
|
||||||
|
|
||||||
<!-- 收款账号信息 -->
|
|
||||||
<h3 style="margin-top: 20px">收款账号信息</h3>
|
|
||||||
<el-descriptions :column="2" border>
|
|
||||||
<el-descriptions-item label="账号类型">
|
|
||||||
<el-tag>{{ accountTypeLabel(withdrawal.account_type) }}</el-tag>
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="账户名">
|
|
||||||
{{ withdrawal.account_name }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="账号" :span="2">
|
|
||||||
<span style="font-family: monospace; font-weight: 600">
|
|
||||||
{{ withdrawal.account_no }}
|
|
||||||
</span>
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item v-if="withdrawal.bank_name" label="银行名称">
|
|
||||||
{{ withdrawal.bank_name }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item v-if="withdrawal.bank_branch" label="开户支行">
|
|
||||||
{{ withdrawal.bank_branch }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item
|
|
||||||
v-if="withdrawal.certificate_urls && withdrawal.certificate_urls.length > 0"
|
|
||||||
label="收款二维码"
|
|
||||||
:span="2"
|
|
||||||
>
|
|
||||||
<div style="display: flex; gap: 8px; flex-wrap: wrap">
|
|
||||||
<AuthImage
|
|
||||||
v-for="(url, idx) in withdrawal.certificate_urls"
|
|
||||||
:key="idx"
|
|
||||||
:source="url"
|
|
||||||
:admin="true"
|
|
||||||
:preview-src-list="withdrawal.certificate_urls"
|
|
||||||
fit="cover"
|
|
||||||
:image-style="{
|
|
||||||
width: '100px',
|
|
||||||
height: '100px',
|
|
||||||
borderRadius: '4px',
|
|
||||||
cursor: 'pointer',
|
|
||||||
}"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</el-descriptions-item>
|
|
||||||
</el-descriptions>
|
|
||||||
|
|
||||||
<!-- 审核信息 -->
|
|
||||||
<div v-if="withdrawal.reviewed_at">
|
|
||||||
<h3 style="margin-top: 20px">审核信息</h3>
|
|
||||||
<el-descriptions :column="2" border>
|
<el-descriptions :column="2" border>
|
||||||
<el-descriptions-item label="审核人">
|
<el-descriptions-item label="提现单号">
|
||||||
{{ withdrawal.reviewed_by_name }}
|
{{ withdrawal.withdraw_no }}
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
<el-descriptions-item label="审核时间">
|
<el-descriptions-item label="所属站点">
|
||||||
{{ new Date(withdrawal.reviewed_at).toLocaleString('zh-CN') }}
|
<el-tag v-if="withdrawal.distribution_site_id" type="warning" size="small">
|
||||||
|
{{
|
||||||
|
withdrawal.distribution_site_name || `分销站点 #${withdrawal.distribution_site_id}`
|
||||||
|
}}
|
||||||
|
</el-tag>
|
||||||
|
<el-tag v-else type="info" size="small">主站</el-tag>
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
<el-descriptions-item v-if="withdrawal.review_remark" label="审核备注" :span="2">
|
<el-descriptions-item label="状态">
|
||||||
{{ withdrawal.review_remark }}
|
<el-tag :type="statusType(withdrawal.status)">
|
||||||
|
{{ statusLabel(withdrawal.status) }}
|
||||||
|
</el-tag>
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="申请时间">
|
||||||
|
{{ formatDateTime(withdrawal.created_at) }}
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
</el-descriptions>
|
</el-descriptions>
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 打款信息 -->
|
<h3>用户信息</h3>
|
||||||
<div v-if="withdrawal.paid_at">
|
|
||||||
<h3 style="margin-top: 20px">打款信息</h3>
|
|
||||||
<el-descriptions :column="2" border>
|
<el-descriptions :column="2" border>
|
||||||
<el-descriptions-item label="打款人">
|
<el-descriptions-item label="用户ID">
|
||||||
{{ withdrawal.paid_by_name }}
|
{{ withdrawal.user_id }}
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
<el-descriptions-item label="打款时间">
|
<el-descriptions-item label="昵称">
|
||||||
{{ new Date(withdrawal.paid_at).toLocaleString('zh-CN') }}
|
{{ withdrawal.user_nickname || '-' }}
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
<el-descriptions-item v-if="withdrawal.payment_remark" label="打款备注" :span="2">
|
<el-descriptions-item label="手机号" :span="2">
|
||||||
{{ withdrawal.payment_remark }}
|
{{ withdrawal.user_phone || '-' }}
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item v-if="withdrawal.payment_proof_url" label="打款凭证" :span="2">
|
|
||||||
<AuthImage
|
|
||||||
:source="withdrawal.payment_proof_url"
|
|
||||||
admin
|
|
||||||
alt="打款凭证"
|
|
||||||
class="certificate-image"
|
|
||||||
:preview-src-list="[withdrawal.payment_proof_url]"
|
|
||||||
/>
|
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
</el-descriptions>
|
</el-descriptions>
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 操作提示 -->
|
<h3>金额信息</h3>
|
||||||
<el-alert
|
<el-descriptions :column="2" border>
|
||||||
v-if="withdrawal.status === 'pending'"
|
<el-descriptions-item label="提现金额">
|
||||||
type="warning"
|
<span class="amount-danger">¥{{ formatCent(withdrawal.amount_cent) }}</span>
|
||||||
:closable="false"
|
</el-descriptions-item>
|
||||||
show-icon
|
<el-descriptions-item label="手续费">
|
||||||
style="margin-top: 20px"
|
¥{{ formatCent(withdrawal.fee_cent) }}
|
||||||
>
|
</el-descriptions-item>
|
||||||
<template #title>
|
<el-descriptions-item label="实际到账" :span="2">
|
||||||
<div style="font-size: 13px">
|
<span class="amount-success">¥{{ formatCent(withdrawal.actual_amount_cent) }}</span>
|
||||||
请仔细核对账号信息后进行审核。审核通过后,需要手动转账到用户账号,并确认打款完成。
|
</el-descriptions-item>
|
||||||
</div>
|
</el-descriptions>
|
||||||
</template>
|
|
||||||
</el-alert>
|
|
||||||
|
|
||||||
<el-alert
|
<h3>收款账号信息</h3>
|
||||||
v-if="withdrawal.status === 'processing'"
|
<el-descriptions :column="2" border>
|
||||||
type="info"
|
<el-descriptions-item label="账号类型">
|
||||||
:closable="false"
|
<el-tag>{{ accountTypeLabel(withdrawal.account_type) }}</el-tag>
|
||||||
show-icon
|
</el-descriptions-item>
|
||||||
style="margin-top: 20px"
|
<el-descriptions-item label="账户名">
|
||||||
>
|
{{ withdrawal.account_name || '-' }}
|
||||||
<template #title>
|
</el-descriptions-item>
|
||||||
<div style="font-size: 13px">
|
<el-descriptions-item label="账号" :span="2">
|
||||||
请手动转账
|
<span class="mono-account">{{ withdrawal.account_no || '-' }}</span>
|
||||||
<strong>¥{{ formatCent(withdrawal.actual_amount_cent) }}</strong> 到用户收款账号,
|
</el-descriptions-item>
|
||||||
完成后点击"确认打款"按钮。
|
<el-descriptions-item v-if="withdrawal.bank_name" label="银行名称">
|
||||||
</div>
|
{{ withdrawal.bank_name }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item v-if="withdrawal.bank_branch" label="开户支行">
|
||||||
|
{{ withdrawal.bank_branch }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item
|
||||||
|
v-if="withdrawal.certificate_urls && withdrawal.certificate_urls.length > 0"
|
||||||
|
label="收款二维码"
|
||||||
|
:span="2"
|
||||||
|
>
|
||||||
|
<div class="certificate-list">
|
||||||
|
<AuthImage
|
||||||
|
v-for="(url, idx) in withdrawal.certificate_urls"
|
||||||
|
:key="idx"
|
||||||
|
:source="url"
|
||||||
|
:admin="true"
|
||||||
|
:preview-src-list="withdrawal.certificate_urls"
|
||||||
|
fit="cover"
|
||||||
|
:image-style="{
|
||||||
|
width: '100px',
|
||||||
|
height: '100px',
|
||||||
|
borderRadius: '4px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</el-descriptions-item>
|
||||||
|
</el-descriptions>
|
||||||
|
|
||||||
|
<template v-if="withdrawal.reviewed_at">
|
||||||
|
<h3>审核信息</h3>
|
||||||
|
<el-descriptions :column="2" border>
|
||||||
|
<el-descriptions-item label="审核人">
|
||||||
|
{{ withdrawal.reviewed_by_name || '-' }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="审核时间">
|
||||||
|
{{ formatDateTime(withdrawal.reviewed_at) }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item v-if="withdrawal.review_remark" label="审核备注" :span="2">
|
||||||
|
{{ withdrawal.review_remark }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
</el-descriptions>
|
||||||
</template>
|
</template>
|
||||||
</el-alert>
|
|
||||||
|
<template v-if="withdrawal.paid_at">
|
||||||
|
<h3>打款信息</h3>
|
||||||
|
<el-descriptions :column="2" border>
|
||||||
|
<el-descriptions-item label="打款人">
|
||||||
|
{{ withdrawal.paid_by_name || '-' }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="打款时间">
|
||||||
|
{{ formatDateTime(withdrawal.paid_at) }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item v-if="withdrawal.payment_remark" label="打款备注" :span="2">
|
||||||
|
{{ withdrawal.payment_remark }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item v-if="withdrawal.payment_proof_url" label="打款凭证" :span="2">
|
||||||
|
<AuthImage
|
||||||
|
:source="withdrawal.payment_proof_url"
|
||||||
|
admin
|
||||||
|
alt="打款凭证"
|
||||||
|
class="certificate-image"
|
||||||
|
:preview-src-list="[withdrawal.payment_proof_url]"
|
||||||
|
/>
|
||||||
|
</el-descriptions-item>
|
||||||
|
</el-descriptions>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<el-alert
|
||||||
|
v-if="withdrawal.status === 'pending'"
|
||||||
|
type="warning"
|
||||||
|
:closable="false"
|
||||||
|
show-icon
|
||||||
|
class="review-alert"
|
||||||
|
>
|
||||||
|
请核对右侧历史订单、最终实际收入和历史提现后再审核。审核通过后,需要手动转账并确认打款。
|
||||||
|
</el-alert>
|
||||||
|
|
||||||
|
<el-alert
|
||||||
|
v-if="withdrawal.status === 'processing'"
|
||||||
|
type="info"
|
||||||
|
:closable="false"
|
||||||
|
show-icon
|
||||||
|
class="review-alert"
|
||||||
|
>
|
||||||
|
请手动转账
|
||||||
|
<strong>¥{{ formatCent(withdrawal.actual_amount_cent) }}</strong>
|
||||||
|
到用户收款账号,完成后点击“确认打款”。
|
||||||
|
</el-alert>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<aside v-loading="contextLoading" class="review-panel">
|
||||||
|
<div class="review-panel__header">
|
||||||
|
<div>
|
||||||
|
<strong>用户审核对账</strong>
|
||||||
|
<span>最终结算收入与历史提现</span>
|
||||||
|
</div>
|
||||||
|
<el-tag type="info" effect="plain">UID {{ withdrawal.user_id }}</el-tag>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-if="reviewContext">
|
||||||
|
<div class="review-metrics">
|
||||||
|
<div class="review-metric">
|
||||||
|
<span>历史订单 / 提号</span>
|
||||||
|
<strong>{{ historyBusinessCount }}</strong>
|
||||||
|
<small>
|
||||||
|
订单 {{ reviewContext.summary.owner_order_count }} · 提号
|
||||||
|
{{ pickupCount }}
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
<div class="review-metric">
|
||||||
|
<span>钱包实际收入</span>
|
||||||
|
<strong class="income">{{
|
||||||
|
formatCentWithSymbol(reviewContext.summary.wallet_actual_income_cent)
|
||||||
|
}}</strong>
|
||||||
|
<small>可用于提现核对</small>
|
||||||
|
</div>
|
||||||
|
<div class="review-metric">
|
||||||
|
<span>历史已打款</span>
|
||||||
|
<strong>{{
|
||||||
|
formatCentWithSymbol(reviewContext.summary.withdrawn_amount_cent)
|
||||||
|
}}</strong>
|
||||||
|
<small>共 {{ reviewContext.summary.withdrawal_count }} 笔提现</small>
|
||||||
|
</div>
|
||||||
|
<div class="review-metric">
|
||||||
|
<span>待审核 / 待打款</span>
|
||||||
|
<strong>{{
|
||||||
|
formatCentWithSymbol(reviewContext.summary.pending_withdrawal_amount_cent)
|
||||||
|
}}</strong>
|
||||||
|
<small>拒绝 {{ reviewContext.summary.rejected_withdrawal_count }} 笔</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="offline-income">
|
||||||
|
<div>
|
||||||
|
<span>平台代管线下结算</span>
|
||||||
|
<small>
|
||||||
|
订单
|
||||||
|
{{
|
||||||
|
formatCentWithSymbol(
|
||||||
|
reviewContext.summary.platform_managed_income_cent - platformPickupIncome
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
· 提号
|
||||||
|
{{ formatCentWithSymbol(platformPickupIncome) }}
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
<strong>{{
|
||||||
|
formatCentWithSymbol(reviewContext.summary.platform_managed_income_cent)
|
||||||
|
}}</strong>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<el-alert :type="reconcileType" :closable="false" show-icon class="reconcile-alert">
|
||||||
|
<template #title>
|
||||||
|
<div class="reconcile-title">
|
||||||
|
<span>{{ reconcileTitle }}</span>
|
||||||
|
<strong>
|
||||||
|
{{ formatCentWithSymbol(reviewContext.summary.reconcile_difference_amount_cent) }}
|
||||||
|
</strong>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-alert>
|
||||||
|
|
||||||
|
<el-tabs v-model="historyTab" class="review-tabs">
|
||||||
|
<el-tab-pane label="历史订单" name="orders">
|
||||||
|
<el-table size="small" :data="reviewContext.orders" empty-text="暂无号主订单">
|
||||||
|
<el-table-column label="上架编号 / 订单号" min-width="190">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<div class="listing-cell">
|
||||||
|
<strong class="mono-code">{{ row.listing_no }}</strong>
|
||||||
|
<small>{{ row.order_no }}</small>
|
||||||
|
<span>{{ row.title }} · {{ settlementModeLabel(row.settlement_mode) }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="最终收入" width="92" align="right">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<strong v-if="typeof row.owner_actual_income_cent === 'number'" class="income">
|
||||||
|
{{ incomeText(row.owner_actual_income_cent) }}
|
||||||
|
</strong>
|
||||||
|
<span v-else>-</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="状态" width="92">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<span>{{ orderStatusLabel(row.status) }}</span>
|
||||||
|
<small class="status-sub">{{
|
||||||
|
settlementStatusLabel(row.settlement_status)
|
||||||
|
}}</small>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="结算时间" width="126">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatDateTime(row.settled_at || row.created_at) }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<el-pagination
|
||||||
|
v-if="reviewContext.summary.owner_order_count > contextPageSize"
|
||||||
|
small
|
||||||
|
background
|
||||||
|
layout="prev, pager, next"
|
||||||
|
:page-size="contextPageSize"
|
||||||
|
:current-page="orderPage"
|
||||||
|
:total="reviewContext.summary.owner_order_count"
|
||||||
|
class="review-pagination"
|
||||||
|
@current-change="changeOrderPage"
|
||||||
|
/>
|
||||||
|
</el-tab-pane>
|
||||||
|
|
||||||
|
<el-tab-pane label="线下提号" name="pickups">
|
||||||
|
<el-table size="small" :data="reviewContext.pickups" empty-text="暂无线下提号记录">
|
||||||
|
<el-table-column label="上架编号 / 提号编号" min-width="190">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<div class="listing-cell">
|
||||||
|
<strong class="mono-code">{{ row.listing_no }}</strong>
|
||||||
|
<small>{{ row.pickup_no }}</small>
|
||||||
|
<span>{{ row.title }} · {{ settlementModeLabel(row.settlement_mode) }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="最终结算" width="96" align="right">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<strong class="income">
|
||||||
|
{{ formatCentWithSymbol(row.effective_settle_amount_cent) }}
|
||||||
|
</strong>
|
||||||
|
<small v-if="row.settle_adjustment_cent" class="adjustment-sub">
|
||||||
|
调整 {{ formatCentWithSymbol(row.settle_adjustment_cent) }}
|
||||||
|
</small>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="状态" width="94">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<span>已完成</span>
|
||||||
|
<small class="status-sub">{{ pickupSettlementLabel(row) }}</small>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="完成时间" width="126">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatDateTime(row.completed_at || row.created_at) }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<el-pagination
|
||||||
|
v-if="pickupCount > contextPageSize"
|
||||||
|
small
|
||||||
|
background
|
||||||
|
layout="prev, pager, next"
|
||||||
|
:page-size="contextPageSize"
|
||||||
|
:current-page="pickupPage"
|
||||||
|
:total="pickupCount"
|
||||||
|
class="review-pagination"
|
||||||
|
@current-change="changePickupPage"
|
||||||
|
/>
|
||||||
|
</el-tab-pane>
|
||||||
|
|
||||||
|
<el-tab-pane label="历史提现" name="withdrawals">
|
||||||
|
<el-table size="small" :data="reviewContext.withdrawals" empty-text="暂无提现记录">
|
||||||
|
<el-table-column label="提现单号" min-width="190">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<div class="listing-cell">
|
||||||
|
<strong class="mono-code">{{ row.withdraw_no }}</strong>
|
||||||
|
<small v-if="row.id === withdrawal.id">
|
||||||
|
<el-tag size="small" type="warning" effect="plain">本单</el-tag>
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="申请 / 到账" width="105" align="right">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<div class="amount-stack">
|
||||||
|
<span>{{ formatCentWithSymbol(row.amount_cent) }}</span>
|
||||||
|
<small>到账 {{ formatCentWithSymbol(row.actual_amount_cent) }}</small>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="状态" width="95">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag size="small" :type="statusType(row.status)">
|
||||||
|
{{ statusLabel(row.status) }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="申请 / 打款时间" width="145">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<div class="time-stack">
|
||||||
|
<span>{{ formatDateTime(row.created_at) }}</span>
|
||||||
|
<small v-if="row.paid_at">{{ formatDateTime(row.paid_at) }}</small>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<el-pagination
|
||||||
|
v-if="reviewContext.summary.withdrawal_count > contextPageSize"
|
||||||
|
small
|
||||||
|
background
|
||||||
|
layout="prev, pager, next"
|
||||||
|
:page-size="contextPageSize"
|
||||||
|
:current-page="withdrawalPage"
|
||||||
|
:total="reviewContext.summary.withdrawal_count"
|
||||||
|
class="review-pagination"
|
||||||
|
@current-change="changeWithdrawalPage"
|
||||||
|
/>
|
||||||
|
</el-tab-pane>
|
||||||
|
</el-tabs>
|
||||||
|
</template>
|
||||||
|
<el-empty v-else-if="!contextLoading" description="暂无审核汇总数据" :image-size="80" />
|
||||||
|
</aside>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<div style="display: flex; justify-content: space-between; width: 100%">
|
<div class="dialog-footer">
|
||||||
<div>
|
<div>
|
||||||
<el-button
|
<el-button
|
||||||
v-if="withdrawal?.status === 'pending'"
|
v-if="withdrawal?.status === 'pending'"
|
||||||
@@ -360,13 +629,20 @@ function accountTypeLabel(type: string) {
|
|||||||
确认打款
|
确认打款
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
<el-button @click="emit('update:modelValue', false)"> 关闭 </el-button>
|
<el-button @click="emit('update:modelValue', false)">关闭</el-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
.withdrawal-layout {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) 560px;
|
||||||
|
gap: 20px;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
.withdrawal-detail h3 {
|
.withdrawal-detail h3 {
|
||||||
margin: 20px 0 12px;
|
margin: 20px 0 12px;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
@@ -374,7 +650,223 @@ function accountTypeLabel(type: string) {
|
|||||||
color: #303133;
|
color: #303133;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.amount-danger,
|
||||||
|
.amount-success {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount-danger {
|
||||||
|
color: #f56c6c;
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount-success,
|
||||||
|
.income {
|
||||||
|
color: #16a34a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mono-account,
|
||||||
|
.mono-code {
|
||||||
|
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.certificate-list {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.review-alert {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.review-panel {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
min-height: 420px;
|
||||||
|
padding: 16px;
|
||||||
|
border: 1px solid #e2e8f0;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: linear-gradient(180deg, #f8fafc 0%, #ffffff 45%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.review-panel__header {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
margin-bottom: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.review-panel__header > div {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.review-panel__header strong {
|
||||||
|
font-size: 16px;
|
||||||
|
color: #0f172a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.review-panel__header span {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #64748b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.review-metrics {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.review-metric {
|
||||||
|
display: flex;
|
||||||
|
min-height: 82px;
|
||||||
|
padding: 12px;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
border: 1px solid #e2e8f0;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.review-metric span,
|
||||||
|
.review-metric small,
|
||||||
|
.offline-income span {
|
||||||
|
color: #64748b;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.review-metric strong {
|
||||||
|
margin: 4px 0 2px;
|
||||||
|
color: #0f172a;
|
||||||
|
font-size: 19px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.offline-income {
|
||||||
|
display: flex;
|
||||||
|
margin-top: 10px;
|
||||||
|
padding: 9px 12px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #fffbeb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.offline-income strong {
|
||||||
|
color: #b45309;
|
||||||
|
}
|
||||||
|
|
||||||
|
.offline-income > div {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.offline-income small {
|
||||||
|
color: #b45309;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reconcile-alert {
|
||||||
|
margin: 12px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reconcile-title {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.review-tabs :deep(.el-tabs__header) {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.review-tabs :deep(.el-scrollbar__bar) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.listing-cell {
|
||||||
|
display: flex;
|
||||||
|
min-width: 0;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.listing-cell strong {
|
||||||
|
color: #2563eb;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.listing-cell small,
|
||||||
|
.listing-cell span,
|
||||||
|
.status-sub {
|
||||||
|
overflow: hidden;
|
||||||
|
color: #64748b;
|
||||||
|
font-size: 11px;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-sub {
|
||||||
|
display: block;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time-stack {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount-stack {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time-stack small,
|
||||||
|
.adjustment-sub,
|
||||||
|
.amount-stack small {
|
||||||
|
color: #94a3b8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.adjustment-sub {
|
||||||
|
display: block;
|
||||||
|
margin-top: 2px;
|
||||||
|
font-size: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.review-pagination {
|
||||||
|
margin-top: 10px;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-footer {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
:deep(.el-descriptions__label) {
|
:deep(.el-descriptions__label) {
|
||||||
width: 120px;
|
width: 120px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:global(.withdrawal-review-dialog .el-dialog__body) {
|
||||||
|
max-height: none;
|
||||||
|
overflow: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 980px) {
|
||||||
|
.withdrawal-layout {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.review-panel {
|
||||||
|
position: static;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -12,26 +12,26 @@ import {
|
|||||||
Wallet,
|
Wallet,
|
||||||
} from '@element-plus/icons-vue'
|
} from '@element-plus/icons-vue'
|
||||||
import { computed, onMounted, ref } from 'vue'
|
import { computed, onMounted, ref } from 'vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
fetchAdminWithdrawals,
|
fetchAdminWithdrawals,
|
||||||
|
fetchAdminWithdrawal,
|
||||||
reviewWithdrawal,
|
reviewWithdrawal,
|
||||||
confirmPayment,
|
confirmPayment,
|
||||||
type WithdrawalDetail,
|
type WithdrawalDetail,
|
||||||
|
type WithdrawalListItem,
|
||||||
} from '@/features/admin/api/adminWithdrawal'
|
} from '@/features/admin/api/adminWithdrawal'
|
||||||
import { formatCentWithSymbol } from '@/shared/utils/money'
|
import { formatCentWithSymbol } from '@/shared/utils/money'
|
||||||
import { formatDateTime } from '@/shared/utils/time'
|
import { formatDateTime } from '@/shared/utils/time'
|
||||||
import { adminPath } from '@/shared/utils/adminPath'
|
|
||||||
import AdminTablePagination from '../components/AdminTablePagination.vue'
|
import AdminTablePagination from '../components/AdminTablePagination.vue'
|
||||||
import WithdrawalDetailDialog from '../components/WithdrawalDetailDialog.vue'
|
import WithdrawalDetailDialog from '../components/WithdrawalDetailDialog.vue'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const withdrawals = ref<WithdrawalDetail[]>([])
|
const withdrawals = ref<WithdrawalListItem[]>([])
|
||||||
const total = ref(0)
|
const total = ref(0)
|
||||||
const currentPage = ref(1)
|
const currentPage = ref(1)
|
||||||
const pageSize = ref(20)
|
const pageSize = ref(20)
|
||||||
@@ -43,6 +43,7 @@ const filters = ref({
|
|||||||
|
|
||||||
const showDetailDialog = ref(false)
|
const showDetailDialog = ref(false)
|
||||||
const selectedWithdrawal = ref<WithdrawalDetail | null>(null)
|
const selectedWithdrawal = ref<WithdrawalDetail | null>(null)
|
||||||
|
const detailLoading = ref(false)
|
||||||
|
|
||||||
const statusOptions = [
|
const statusOptions = [
|
||||||
{ label: '全部状态', value: '' },
|
{ label: '全部状态', value: '' },
|
||||||
@@ -53,17 +54,6 @@ const statusOptions = [
|
|||||||
{ label: '已取消', value: 'cancelled' },
|
{ label: '已取消', value: 'cancelled' },
|
||||||
]
|
]
|
||||||
|
|
||||||
const withdrawalReturnQuery = computed<Record<string, string>>(() => {
|
|
||||||
const query: Record<string, string> = {
|
|
||||||
from: 'withdrawals',
|
|
||||||
withdrawal_page: String(currentPage.value),
|
|
||||||
withdrawal_page_size: String(pageSize.value),
|
|
||||||
}
|
|
||||||
if (filters.value.status) query.withdrawal_status = filters.value.status
|
|
||||||
if (filters.value.user_id) query.withdrawal_user_id = String(filters.value.user_id)
|
|
||||||
return query
|
|
||||||
})
|
|
||||||
|
|
||||||
const pendingCount = computed(() => withdrawals.value.filter(w => w.status === 'pending').length)
|
const pendingCount = computed(() => withdrawals.value.filter(w => w.status === 'pending').length)
|
||||||
const processingCount = computed(
|
const processingCount = computed(
|
||||||
() => withdrawals.value.filter(w => w.status === 'processing').length
|
() => withdrawals.value.filter(w => w.status === 'processing').length
|
||||||
@@ -135,23 +125,20 @@ function resetFilters() {
|
|||||||
void loadWithdrawals()
|
void loadWithdrawals()
|
||||||
}
|
}
|
||||||
|
|
||||||
function openDetail(withdrawal: WithdrawalDetail) {
|
async function openDetail(withdrawal: WithdrawalListItem) {
|
||||||
selectedWithdrawal.value = withdrawal
|
if (detailLoading.value) return
|
||||||
showDetailDialog.value = true
|
detailLoading.value = true
|
||||||
|
try {
|
||||||
|
selectedWithdrawal.value = await fetchAdminWithdrawal(withdrawal.id)
|
||||||
|
showDetailDialog.value = true
|
||||||
|
} catch (error: any) {
|
||||||
|
ElMessage.error(error.response?.data?.message || '提现详情加载失败')
|
||||||
|
} finally {
|
||||||
|
detailLoading.value = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function goToOwnerOrders(withdrawal: WithdrawalDetail) {
|
async function handleReview(withdrawal: WithdrawalListItem, approved: boolean) {
|
||||||
const keyword = withdrawal.user_phone?.trim() || String(withdrawal.user_id || '')
|
|
||||||
void router.push({
|
|
||||||
path: adminPath('orders'),
|
|
||||||
query: {
|
|
||||||
...withdrawalReturnQuery.value,
|
|
||||||
...(keyword ? { keyword } : {}),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleReview(withdrawal: WithdrawalDetail, approved: boolean) {
|
|
||||||
const action = approved ? '通过' : '拒绝'
|
const action = approved ? '通过' : '拒绝'
|
||||||
try {
|
try {
|
||||||
const { value: remark } = await ElMessageBox.prompt(
|
const { value: remark } = await ElMessageBox.prompt(
|
||||||
@@ -179,7 +166,7 @@ async function handleReview(withdrawal: WithdrawalDetail, approved: boolean) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleConfirmPayment(withdrawal: WithdrawalDetail) {
|
async function handleConfirmPayment(withdrawal: WithdrawalListItem) {
|
||||||
try {
|
try {
|
||||||
const { value: remark } = await ElMessageBox.prompt(
|
const { value: remark } = await ElMessageBox.prompt(
|
||||||
'请输入打款备注(如:已通过支付宝/微信转账)',
|
'请输入打款备注(如:已通过支付宝/微信转账)',
|
||||||
@@ -438,13 +425,18 @@ function money(cent: number | undefined | null) {
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|
||||||
<el-table-column label="操作" width="240" fixed="right" align="center">
|
<el-table-column label="操作" width="190" fixed="right" align="center">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<div class="action-cell">
|
<div class="action-cell">
|
||||||
<el-button link type="primary" :icon="View" @click="openDetail(row)">
|
<el-button
|
||||||
|
link
|
||||||
|
type="primary"
|
||||||
|
:icon="View"
|
||||||
|
:loading="detailLoading"
|
||||||
|
@click="openDetail(row)"
|
||||||
|
>
|
||||||
详情
|
详情
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button link type="primary" @click="goToOwnerOrders(row)"> 号主订单 </el-button>
|
|
||||||
<el-button
|
<el-button
|
||||||
v-if="row.status === 'pending'"
|
v-if="row.status === 'pending'"
|
||||||
link
|
link
|
||||||
@@ -488,7 +480,6 @@ function money(cent: number | undefined | null) {
|
|||||||
<WithdrawalDetailDialog
|
<WithdrawalDetailDialog
|
||||||
v-model="showDetailDialog"
|
v-model="showDetailDialog"
|
||||||
:withdrawal="selectedWithdrawal"
|
:withdrawal="selectedWithdrawal"
|
||||||
:return-query="withdrawalReturnQuery"
|
|
||||||
@saved="onDetailDialogSaved"
|
@saved="onDetailDialogSaved"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user