Compare commits
4
Commits
4a9e5f9d66
...
9a52dbdb7b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a52dbdb7b | ||
|
|
0082a60b46 | ||
|
|
ead58417e0 | ||
|
|
0d6a7786a4 |
@@ -19,6 +19,10 @@ RUN --mount=type=cache,target=/go/pkg/mod \
|
|||||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
--mount=type=cache,target=/root/.cache/go-build \
|
--mount=type=cache,target=/root/.cache/go-build \
|
||||||
CGO_ENABLED=0 GOOS=linux go build -o /out/hfb-storage-migrate ./cmd/storage-migrate
|
CGO_ENABLED=0 GOOS=linux go build -o /out/hfb-storage-migrate ./cmd/storage-migrate
|
||||||
|
# 一次性运维脚本:线下提号邀请返利补发(默认预演,-apply 才写库)
|
||||||
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
|
--mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
CGO_ENABLED=0 GOOS=linux go build -o /out/hfb-rebate-backfill ./cmd/rebate-backfill
|
||||||
|
|
||||||
FROM alpine:3.22
|
FROM alpine:3.22
|
||||||
|
|
||||||
@@ -34,6 +38,7 @@ RUN sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.aliyun.com
|
|||||||
&& chown app:app /app/logs
|
&& chown app:app /app/logs
|
||||||
COPY --from=build /out/hfb-api /app/hfb-api
|
COPY --from=build /out/hfb-api /app/hfb-api
|
||||||
COPY --from=build /out/hfb-storage-migrate /app/hfb-storage-migrate
|
COPY --from=build /out/hfb-storage-migrate /app/hfb-storage-migrate
|
||||||
|
COPY --from=build /out/hfb-rebate-backfill /app/hfb-rebate-backfill
|
||||||
COPY --from=build /go/bin/goose /app/goose
|
COPY --from=build /go/bin/goose /app/goose
|
||||||
COPY --from=build /src/migrations /app/migrations
|
COPY --from=build /src/migrations /app/migrations
|
||||||
USER app:app
|
USER app:app
|
||||||
|
|||||||
@@ -0,0 +1,183 @@
|
|||||||
|
// rebate-backfill 为「线下提号」补发邀请返利(一次性运维脚本,可安全重复执行)。
|
||||||
|
//
|
||||||
|
// 背景:线下提号(admin_pickups)不走正常订单结账流程,历史上未接入邀请返利结算,
|
||||||
|
// 导致已完成提号单的号主邀请人拿不到分成。代码侧已在 pickup.Complete 内接入,
|
||||||
|
// 本脚本用于补齐「接入前已完成」的历史提号单;仍在进行中的提号单会在完成时自动发放。
|
||||||
|
//
|
||||||
|
// 幂等:写入 (source='pickup', order_id, trade_role='seller') 唯一键,
|
||||||
|
// 且候选集已排除已有提号返利记录的单据,重复执行不会重复发放。
|
||||||
|
//
|
||||||
|
// 口径:单边基数 = 提号利润对半(profit_amount_cent / 2),与租赁订单卖家侧一致;
|
||||||
|
// 比例阶梯按提号完成时刻距今(被邀请人实名生效)的档位计算。
|
||||||
|
//
|
||||||
|
// 用法(默认预演,不写库):
|
||||||
|
//
|
||||||
|
// go run ./cmd/rebate-backfill # 预演,只列待补发单据
|
||||||
|
// go run ./cmd/rebate-backfill -apply # 实际补发
|
||||||
|
// go run ./cmd/rebate-backfill -apply -pickup-no PK20261011113459355
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"hfb_sys/backend/internal/config"
|
||||||
|
"hfb_sys/backend/internal/database"
|
||||||
|
"hfb_sys/backend/internal/logging"
|
||||||
|
"hfb_sys/backend/internal/model"
|
||||||
|
"hfb_sys/backend/internal/modules/invitation"
|
||||||
|
"hfb_sys/backend/internal/modules/pickup"
|
||||||
|
"hfb_sys/backend/pkg/money"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/clause"
|
||||||
|
)
|
||||||
|
|
||||||
|
type candidate struct {
|
||||||
|
ID uint64
|
||||||
|
PickupNo string
|
||||||
|
OwnerID uint64
|
||||||
|
ProfitAmountCent int64
|
||||||
|
CompletedAt *time.Time
|
||||||
|
ListingSiteID *uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
apply := flag.Bool("apply", false, "实际执行补发(默认仅预演)")
|
||||||
|
pickupNo := flag.String("pickup-no", "", "仅处理指定提号单号")
|
||||||
|
limit := flag.Int("limit", 0, "最多处理条数,0 表示不限制")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
cfg := config.Load()
|
||||||
|
logger, err := logging.New(cfg.Log)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("初始化日志失败: %v", err)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
_ = logger.Sync()
|
||||||
|
}()
|
||||||
|
|
||||||
|
db, err := database.OpenMySQLWithOptions(cfg.MySQLDSN, cfg.Log.Level, logger, database.MySQLOptions{})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("连接数据库失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
rows, err := loadCandidates(db, *pickupNo, *limit)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("查询待补发提号单失败: %v", err)
|
||||||
|
}
|
||||||
|
if len(rows) == 0 {
|
||||||
|
fmt.Println("没有需要补发的提号单:已完成提号单均已覆盖或不存在生效邀请关系。")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mode := "预演"
|
||||||
|
if *apply {
|
||||||
|
mode = "实际补发"
|
||||||
|
}
|
||||||
|
fmt.Printf("模式=%s,候选提号单=%d\n", mode, len(rows))
|
||||||
|
|
||||||
|
var paidCount, skippedCount int
|
||||||
|
var paidCent int64
|
||||||
|
for _, row := range rows {
|
||||||
|
completedAt := time.Now()
|
||||||
|
if row.CompletedAt != nil {
|
||||||
|
completedAt = *row.CompletedAt
|
||||||
|
}
|
||||||
|
siteID := uint64(0)
|
||||||
|
if row.ListingSiteID != nil {
|
||||||
|
siteID = *row.ListingSiteID
|
||||||
|
}
|
||||||
|
|
||||||
|
if !*apply {
|
||||||
|
fmt.Printf("[预演] %s 号主=%d 利润=%s 单边基数=%s 完成于=%s\n",
|
||||||
|
row.PickupNo, row.OwnerID,
|
||||||
|
money.FormatWithSymbol(row.ProfitAmountCent),
|
||||||
|
money.FormatWithSymbol(row.ProfitAmountCent/2),
|
||||||
|
completedAt.Format("2006-01-02 15:04:05"))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
amountCent, err := backfillOne(db, row.ID, siteID, completedAt)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("补发失败 %s: %v", row.PickupNo, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if amountCent <= 0 {
|
||||||
|
skippedCount++
|
||||||
|
fmt.Printf("[跳过] %s 未产生返利(无生效邀请 / 邀请人未实名 / 返利已关闭 / 已存在记录)\n", row.PickupNo)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
paidCount++
|
||||||
|
paidCent += amountCent
|
||||||
|
fmt.Printf("[补发] %s 返利 %s 已入邀请人钱包\n", row.PickupNo, money.FormatWithSymbol(amountCent))
|
||||||
|
}
|
||||||
|
|
||||||
|
if *apply {
|
||||||
|
fmt.Printf("完成:补发 %d 单,合计 %s;跳过 %d 单。\n",
|
||||||
|
paidCount, money.FormatWithSymbol(paidCent), skippedCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadCandidates(db *gorm.DB, pickupNo string, limit int) ([]candidate, error) {
|
||||||
|
query := db.Table("admin_pickups AS p").
|
||||||
|
Select(`p.id, p.pickup_no, p.owner_id, p.profit_amount_cent, p.completed_at,
|
||||||
|
l.distribution_site_id AS listing_site_id`).
|
||||||
|
Joins("JOIN user_invitations i ON i.invitee_id = p.owner_id AND i.status = ? AND i.inviter_id <> p.owner_id", invitation.StatusActive).
|
||||||
|
Joins("LEFT JOIN rental_listings l ON l.id = p.listing_id").
|
||||||
|
Where("p.status = ?", pickup.StatusCompleted).
|
||||||
|
Where("p.profit_amount_cent > 0").
|
||||||
|
Where(`NOT EXISTS (
|
||||||
|
SELECT 1 FROM invitation_rebate_ledgers r
|
||||||
|
WHERE r.source = ? AND r.order_id = p.id AND r.trade_role = 'seller'
|
||||||
|
)`, invitation.RebateSourcePickup).
|
||||||
|
Order("p.completed_at ASC")
|
||||||
|
|
||||||
|
if trimmed := strings.TrimSpace(pickupNo); trimmed != "" {
|
||||||
|
query = query.Where("p.pickup_no = ?", trimmed)
|
||||||
|
}
|
||||||
|
if limit > 0 {
|
||||||
|
query = query.Limit(limit)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows []candidate
|
||||||
|
if err := query.Scan(&rows).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return rows, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// backfillOne 在独立事务内为单张提号单补发返利并返回实际发放金额(分)。
|
||||||
|
func backfillOne(db *gorm.DB, pickupID uint64, siteID uint64, completedAt time.Time) (int64, error) {
|
||||||
|
var amountCent int64
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
var record model.AdminPickup
|
||||||
|
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&record, pickupID).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if record.Status != pickup.StatusCompleted {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
amount, err := invitation.AwardSellerSideRebateTx(tx, invitation.SellerSideRebateInput{
|
||||||
|
Source: invitation.RebateSourcePickup,
|
||||||
|
SourceID: record.ID,
|
||||||
|
SourceNo: record.PickupNo,
|
||||||
|
SellerID: record.OwnerID,
|
||||||
|
GrossBasisCent: record.ProfitAmountCent,
|
||||||
|
BasisCent: record.ProfitAmountCent / 2,
|
||||||
|
SiteID: siteID,
|
||||||
|
RateReferenceAt: completedAt,
|
||||||
|
SettledAt: time.Now(),
|
||||||
|
RemarkPrefix: "邀请卖家提号返利",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
amountCent = amount
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return amountCent, err
|
||||||
|
}
|
||||||
@@ -38,12 +38,13 @@ func (InvitationRebateConfig) TableName() string {
|
|||||||
// InvitationRebateLedger 邀请返利结算记录明细表
|
// InvitationRebateLedger 邀请返利结算记录明细表
|
||||||
type InvitationRebateLedger struct {
|
type InvitationRebateLedger struct {
|
||||||
ID uint64 `gorm:"primaryKey" json:"id"`
|
ID uint64 `gorm:"primaryKey" json:"id"`
|
||||||
OrderID uint64 `gorm:"not null;uniqueIndex:uk_invitation_rebate_order_role,priority:1" json:"order_id"`
|
OrderID uint64 `gorm:"not null;uniqueIndex:uk_invitation_rebate_source_role,priority:2" json:"order_id"`
|
||||||
OrderNo string `gorm:"size:64;not null" json:"order_no"`
|
OrderNo string `gorm:"size:64;not null" json:"order_no"`
|
||||||
|
Source string `gorm:"size:32;not null;default:'rental_order';uniqueIndex:uk_invitation_rebate_source_role,priority:1" json:"source"` // rental_order / pickup
|
||||||
DistributionSiteID uint64 `gorm:"not null;default:0;index:idx_invitation_rebate_site" json:"distribution_site_id"`
|
DistributionSiteID uint64 `gorm:"not null;default:0;index:idx_invitation_rebate_site" json:"distribution_site_id"`
|
||||||
InviterID uint64 `gorm:"not null;index:idx_invitation_rebate_inviter" json:"inviter_id"`
|
InviterID uint64 `gorm:"not null;index:idx_invitation_rebate_inviter" json:"inviter_id"`
|
||||||
InviteeID uint64 `gorm:"not null" json:"invitee_id"`
|
InviteeID uint64 `gorm:"not null" json:"invitee_id"`
|
||||||
TradeRole string `gorm:"size:16;not null;uniqueIndex:uk_invitation_rebate_order_role,priority:2" json:"trade_role"` // buyer / seller
|
TradeRole string `gorm:"size:16;not null;uniqueIndex:uk_invitation_rebate_source_role,priority:3" json:"trade_role"` // buyer / seller
|
||||||
OrderProfitBasisCent int64 `gorm:"not null;default:0" json:"order_profit_basis_cent"`
|
OrderProfitBasisCent int64 `gorm:"not null;default:0" json:"order_profit_basis_cent"`
|
||||||
SingleSideBasisCent int64 `gorm:"not null;default:0" json:"single_side_basis_cent"`
|
SingleSideBasisCent int64 `gorm:"not null;default:0" json:"single_side_basis_cent"`
|
||||||
RateApplied float64 `gorm:"type:decimal(6,4);not null;default:0" json:"rate_applied"`
|
RateApplied float64 `gorm:"type:decimal(6,4);not null;default:0" json:"rate_applied"`
|
||||||
|
|||||||
@@ -12,33 +12,33 @@ type InviteCodeInfoDTO struct {
|
|||||||
|
|
||||||
// UserInvitationSummaryDTO 个人中心邀请返利概览
|
// UserInvitationSummaryDTO 个人中心邀请返利概览
|
||||||
type UserInvitationSummaryDTO struct {
|
type UserInvitationSummaryDTO struct {
|
||||||
HasInviteCode bool `json:"has_invite_code"`
|
HasInviteCode bool `json:"has_invite_code"`
|
||||||
InviteCode string `json:"invite_code"`
|
InviteCode string `json:"invite_code"`
|
||||||
InviteLink string `json:"invite_link"`
|
InviteLink string `json:"invite_link"`
|
||||||
IsRealnameVerified bool `json:"is_realname_verified"`
|
IsRealnameVerified bool `json:"is_realname_verified"`
|
||||||
TotalInvitedCount int64 `json:"total_invited_count"`
|
TotalInvitedCount int64 `json:"total_invited_count"`
|
||||||
ActiveInvitedCount int64 `json:"active_invited_count"`
|
ActiveInvitedCount int64 `json:"active_invited_count"`
|
||||||
PendingInvitedCount int64 `json:"pending_invited_count"`
|
PendingInvitedCount int64 `json:"pending_invited_count"`
|
||||||
TotalRebateCent int64 `json:"total_rebate_cent"`
|
TotalRebateCent int64 `json:"total_rebate_cent"`
|
||||||
CurrentMonthEstCent int64 `json:"current_month_est_cent"`
|
CurrentMonthEstCent int64 `json:"current_month_est_cent"`
|
||||||
FirstMonthRate float64 `json:"first_month_rate"`
|
FirstMonthRate float64 `json:"first_month_rate"`
|
||||||
SecondMonthRate float64 `json:"second_month_rate"`
|
SecondMonthRate float64 `json:"second_month_rate"`
|
||||||
SubsequentRate float64 `json:"subsequent_rate"`
|
SubsequentRate float64 `json:"subsequent_rate"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InvitedUserRecordDTO 邀请好友记录
|
// InvitedUserRecordDTO 邀请好友记录
|
||||||
type InvitedUserRecordDTO struct {
|
type InvitedUserRecordDTO struct {
|
||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
InviteeID uint64 `json:"invitee_id"`
|
InviteeID uint64 `json:"invitee_id"`
|
||||||
MaskedPhone string `json:"masked_phone"`
|
MaskedPhone string `json:"masked_phone"`
|
||||||
Nickname string `json:"nickname"`
|
Nickname string `json:"nickname"`
|
||||||
AvatarURL string `json:"avatar_url"`
|
AvatarURL string `json:"avatar_url"`
|
||||||
Status string `json:"status"` // pending=待实名, active=已实名生效
|
Status string `json:"status"` // pending=待实名, active=已实名生效
|
||||||
CycleStage string `json:"cycle_stage"` // first_month, second_month, subsequent, unverified
|
CycleStage string `json:"cycle_stage"` // first_month, second_month, subsequent, unverified
|
||||||
DaysSinceVerified int `json:"days_since_verified"`
|
DaysSinceVerified int `json:"days_since_verified"`
|
||||||
VerifiedAt *time.Time `json:"verified_at,omitempty"`
|
VerifiedAt *time.Time `json:"verified_at,omitempty"`
|
||||||
RegisteredAt time.Time `json:"registered_at"`
|
RegisteredAt time.Time `json:"registered_at"`
|
||||||
TotalEarnedFromCent int64 `json:"total_earned_from_cent"`
|
TotalEarnedFromCent int64 `json:"total_earned_from_cent"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RebateLedgerDTO 返利明细记录
|
// RebateLedgerDTO 返利明细记录
|
||||||
@@ -76,20 +76,27 @@ type UpdateConfigRequest struct {
|
|||||||
|
|
||||||
// AdminInvitationQuery 后台查询邀请关系
|
// AdminInvitationQuery 后台查询邀请关系
|
||||||
type AdminInvitationQuery struct {
|
type AdminInvitationQuery struct {
|
||||||
Page int `form:"page,default=1"`
|
Page int `form:"page,default=1"`
|
||||||
PageSize int `form:"page_size,default=20"`
|
PageSize int `form:"page_size,default=20"`
|
||||||
InviterPhone string `form:"inviter_phone"`
|
InviterPhone string `form:"inviter_phone"`
|
||||||
InviteePhone string `form:"invitee_phone"`
|
InviteePhone string `form:"invitee_phone"`
|
||||||
Status string `form:"status"`
|
Status string `form:"status"`
|
||||||
DistributionSiteID *uint64 `form:"distribution_site_id"`
|
DistributionSiteID *uint64 `form:"distribution_site_id"`
|
||||||
|
// InviterID / InviteeID 供用户管理「明细」按用户精确筛选。
|
||||||
|
InviterID uint64 `form:"inviter_id"`
|
||||||
|
InviteeID uint64 `form:"invitee_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AdminRebateLedgerQuery 后台查询返利明细
|
// AdminRebateLedgerQuery 后台查询返利明细
|
||||||
type AdminRebateLedgerQuery struct {
|
type AdminRebateLedgerQuery struct {
|
||||||
Page int `form:"page,default=1"`
|
Page int `form:"page,default=1"`
|
||||||
PageSize int `form:"page_size,default=20"`
|
PageSize int `form:"page_size,default=20"`
|
||||||
OrderNo string `form:"order_no"`
|
OrderNo string `form:"order_no"`
|
||||||
InviterPhone string `form:"inviter_phone"`
|
InviterPhone string `form:"inviter_phone"`
|
||||||
TradeRole string `form:"trade_role"`
|
InviteePhone string `form:"invitee_phone"`
|
||||||
|
TradeRole string `form:"trade_role"`
|
||||||
DistributionSiteID *uint64 `form:"distribution_site_id"`
|
DistributionSiteID *uint64 `form:"distribution_site_id"`
|
||||||
|
// InviterID / InviteeID 供用户管理「明细」按用户精确筛选。
|
||||||
|
InviterID uint64 `form:"inviter_id"`
|
||||||
|
InviteeID uint64 `form:"invitee_id"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -38,6 +39,10 @@ const (
|
|||||||
DefaultFirstMonthRate = 0.6000
|
DefaultFirstMonthRate = 0.6000
|
||||||
DefaultSecondMonthRate = 0.3000
|
DefaultSecondMonthRate = 0.3000
|
||||||
DefaultSubsequentRate = 0.1500
|
DefaultSubsequentRate = 0.1500
|
||||||
|
|
||||||
|
// 返利来源单据类型:source=biz_type 用于区分返利由哪类单据产生。
|
||||||
|
RebateSourceRentalOrder = "rental_order"
|
||||||
|
RebateSourcePickup = "pickup"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
@@ -433,7 +438,7 @@ func (r *Repository) ProcessOrderInvitationRebate(ctx context.Context, tx *gorm.
|
|||||||
BalanceType: "available",
|
BalanceType: "available",
|
||||||
BizType: "invite_rebate",
|
BizType: "invite_rebate",
|
||||||
BizNo: order.OrderNo,
|
BizNo: order.OrderNo,
|
||||||
Remark: fmt.Sprintf("邀请买家成交返利(订单 %s,%s)", order.OrderNo, cycleLabel(cycle)),
|
Remark: fmt.Sprintf("邀请买家成交返利(订单 %s,%s)", order.OrderNo, cycleLabel(cycle, rate)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -495,7 +500,7 @@ func (r *Repository) ProcessOrderInvitationRebate(ctx context.Context, tx *gorm.
|
|||||||
BalanceType: "available",
|
BalanceType: "available",
|
||||||
BizType: "invite_rebate",
|
BizType: "invite_rebate",
|
||||||
BizNo: order.OrderNo,
|
BizNo: order.OrderNo,
|
||||||
Remark: fmt.Sprintf("邀请卖家成交返利(订单 %s,%s)", order.OrderNo, cycleLabel(cycle)),
|
Remark: fmt.Sprintf("邀请卖家成交返利(订单 %s,%s)", order.OrderNo, cycleLabel(cycle, rate)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -508,17 +513,137 @@ func (r *Repository) ProcessOrderInvitationRebate(ctx context.Context, tx *gorm.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cycleLabel(cycle string) string {
|
// cycleLabel 生成返利周期的展示文案。
|
||||||
|
// 比例必须取本次实际生效的 rate(后台/分销站可改配置),
|
||||||
|
// 不能写死 60%/30%/15%,否则钱包流水备注会和实际比例不一致。
|
||||||
|
func cycleLabel(cycle string, rate float64) string {
|
||||||
|
percent := formatRebateRate(rate)
|
||||||
switch cycle {
|
switch cycle {
|
||||||
case CycleFirstMonth:
|
case CycleFirstMonth:
|
||||||
return "首月高额奖励 60%"
|
return "首月奖励 " + percent
|
||||||
case CycleSecondMonth:
|
case CycleSecondMonth:
|
||||||
return "次月奖励 30%"
|
return "次月奖励 " + percent
|
||||||
|
case CycleSubsequent:
|
||||||
|
return "长期奖励 " + percent
|
||||||
default:
|
default:
|
||||||
return "长期奖励 15%"
|
return "返利 " + percent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// formatRebateRate 把比例(0.6)格式化为展示文案(60%)。
|
||||||
|
// 先按配置列精度 decimal(6,4) 规整,避免浮点尾差显示成 59.999999%。
|
||||||
|
func formatRebateRate(rate float64) string {
|
||||||
|
percent := math.Round(rate*10000) / 100
|
||||||
|
return strconv.FormatFloat(percent, 'f', -1, 64) + "%"
|
||||||
|
}
|
||||||
|
|
||||||
|
// SellerSideRebateInput 单边(卖家/服务提供方)返利结算入参。
|
||||||
|
//
|
||||||
|
// 租赁订单与线下提号共用同一套规则:按被邀请人实名生效时刻计算比例阶梯、
|
||||||
|
// 用 (source, order_id, trade_role) 唯一键保证幂等、入账到邀请人钱包可用余额。
|
||||||
|
// 差异只在来源标识与收益基数,因此统一走这里,避免两处各写一遍算钱逻辑。
|
||||||
|
type SellerSideRebateInput struct {
|
||||||
|
Source string // 来源单据类型:RebateSourceRentalOrder / RebateSourcePickup
|
||||||
|
SourceID uint64 // 来源单据 ID
|
||||||
|
SourceNo string // 来源单据编号(写入返利流水与钱包流水备注)
|
||||||
|
SellerID uint64 // 交易人(被邀请人本人)
|
||||||
|
GrossBasisCent int64 // 来源单据整体收益基数(分)
|
||||||
|
BasisCent int64 // 单边收益基数(分),通常为 GrossBasisCent 对半
|
||||||
|
SiteID uint64 // 成本分担站点(0=主站)
|
||||||
|
RateReferenceAt time.Time // 比例阶梯的基准时刻(单据完成时刻);零值取当前时间
|
||||||
|
SettledAt time.Time // 实际入账时刻;零值取当前时间
|
||||||
|
RemarkPrefix string // 钱包流水备注前缀
|
||||||
|
}
|
||||||
|
|
||||||
|
// AwardSellerSideRebateTx 在事务内为「交易人的邀请人」发放单边返利(幂等)。
|
||||||
|
// 未命中生效邀请关系、邀请人未实名、返利配置关闭或金额为 0 时不写任何记录并返回 0。
|
||||||
|
func AwardSellerSideRebateTx(tx *gorm.DB, in SellerSideRebateInput) (int64, error) {
|
||||||
|
if tx == nil || in.SellerID == 0 || in.SourceID == 0 || in.BasisCent <= 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
var invitation model.UserInvitation
|
||||||
|
if err := tx.WithContext(ctx).
|
||||||
|
Where("invitee_id = ? AND status = ?", in.SellerID, StatusActive).
|
||||||
|
First(&invitation).Error; err != nil {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
if invitation.VerifiedAt == nil {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
var inviter model.User
|
||||||
|
if err := tx.WithContext(ctx).First(&inviter, invitation.InviterID).Error; err != nil {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
if inviter.RealnameStatus != "verified" || inviter.ID == in.SellerID {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
repo := NewRepository(tx)
|
||||||
|
cfg, _ := repo.GetRebateConfig(ctx, in.SiteID)
|
||||||
|
if cfg != nil && !cfg.Enabled {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
referenceAt := in.RateReferenceAt
|
||||||
|
if referenceAt.IsZero() {
|
||||||
|
referenceAt = time.Now()
|
||||||
|
}
|
||||||
|
settledAt := in.SettledAt
|
||||||
|
if settledAt.IsZero() {
|
||||||
|
settledAt = time.Now()
|
||||||
|
}
|
||||||
|
rate, cycle, days := CalculateRebateRate(*invitation.VerifiedAt, referenceAt, cfg)
|
||||||
|
rebateCent := int64(math.Round(float64(in.BasisCent) * rate))
|
||||||
|
if rebateCent <= 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
grossBasis := in.GrossBasisCent
|
||||||
|
if grossBasis <= 0 {
|
||||||
|
grossBasis = in.BasisCent
|
||||||
|
}
|
||||||
|
ledger := model.InvitationRebateLedger{
|
||||||
|
OrderID: in.SourceID,
|
||||||
|
OrderNo: in.SourceNo,
|
||||||
|
Source: in.Source,
|
||||||
|
DistributionSiteID: in.SiteID,
|
||||||
|
InviterID: invitation.InviterID,
|
||||||
|
InviteeID: in.SellerID,
|
||||||
|
TradeRole: "seller",
|
||||||
|
OrderProfitBasisCent: grossBasis,
|
||||||
|
SingleSideBasisCent: in.BasisCent,
|
||||||
|
RateApplied: rate,
|
||||||
|
DaysSinceVerified: days,
|
||||||
|
CycleStage: cycle,
|
||||||
|
RebateAmountCent: rebateCent,
|
||||||
|
WalletLedgerNo: fmt.Sprintf("REB-S-%s-%d", in.SourceNo, invitation.InviterID),
|
||||||
|
Status: "settled",
|
||||||
|
SettledAt: settledAt,
|
||||||
|
}
|
||||||
|
if err := tx.WithContext(ctx).Clauses(clause.OnConflict{DoNothing: true}).Create(&ledger).Error; err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if ledger.ID == 0 {
|
||||||
|
// 同来源同角色已有返利记录:幂等跳过(重复调用、补发脚本重跑均安全)。
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
if err := wallet.AppendEntries(tx, wallet.Entry{
|
||||||
|
UserID: invitation.InviterID,
|
||||||
|
DistributionSiteID: in.SiteID,
|
||||||
|
Direction: "in",
|
||||||
|
AmountCent: rebateCent,
|
||||||
|
BalanceType: "available",
|
||||||
|
BizType: "invite_rebate",
|
||||||
|
BizNo: in.SourceNo,
|
||||||
|
Remark: fmt.Sprintf("%s(%s,%s)", in.RemarkPrefix, in.SourceNo, cycleLabel(cycle, rate)),
|
||||||
|
}); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return rebateCent, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetUserSummary 获取用户个人中心的邀请返利数据看板
|
// GetUserSummary 获取用户个人中心的邀请返利数据看板
|
||||||
func (r *Repository) GetUserSummary(ctx context.Context, userID uint64, siteID uint64) (*UserInvitationSummaryDTO, error) {
|
func (r *Repository) GetUserSummary(ctx context.Context, userID uint64, siteID uint64) (*UserInvitationSummaryDTO, error) {
|
||||||
if r == nil || r.db == nil {
|
if r == nil || r.db == nil {
|
||||||
@@ -572,18 +697,18 @@ func (r *Repository) GetUserSummary(ctx context.Context, userID uint64, siteID u
|
|||||||
Select("COALESCE(SUM(rebate_amount_cent), 0)").Scan(¤tMonthEstCent).Error
|
Select("COALESCE(SUM(rebate_amount_cent), 0)").Scan(¤tMonthEstCent).Error
|
||||||
|
|
||||||
return &UserInvitationSummaryDTO{
|
return &UserInvitationSummaryDTO{
|
||||||
HasInviteCode: hasCode,
|
HasInviteCode: hasCode,
|
||||||
InviteCode: code,
|
InviteCode: code,
|
||||||
InviteLink: fmt.Sprintf("/i/%s", code),
|
InviteLink: fmt.Sprintf("/i/%s", code),
|
||||||
IsRealnameVerified: user.RealnameStatus == "verified",
|
IsRealnameVerified: user.RealnameStatus == "verified",
|
||||||
TotalInvitedCount: totalCount,
|
TotalInvitedCount: totalCount,
|
||||||
ActiveInvitedCount: activeCount,
|
ActiveInvitedCount: activeCount,
|
||||||
PendingInvitedCount: pendingCount,
|
PendingInvitedCount: pendingCount,
|
||||||
TotalRebateCent: totalRebateCent,
|
TotalRebateCent: totalRebateCent,
|
||||||
CurrentMonthEstCent: currentMonthEstCent,
|
CurrentMonthEstCent: currentMonthEstCent,
|
||||||
FirstMonthRate: firstRate,
|
FirstMonthRate: firstRate,
|
||||||
SecondMonthRate: secondRate,
|
SecondMonthRate: secondRate,
|
||||||
SubsequentRate: subsequentRate,
|
SubsequentRate: subsequentRate,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -734,6 +859,12 @@ func (r *Repository) ListAdminInvitations(ctx context.Context, query AdminInvita
|
|||||||
if query.DistributionSiteID != nil {
|
if query.DistributionSiteID != nil {
|
||||||
db = db.Where("ui.distribution_site_id = ?", *query.DistributionSiteID)
|
db = db.Where("ui.distribution_site_id = ?", *query.DistributionSiteID)
|
||||||
}
|
}
|
||||||
|
if query.InviterID > 0 {
|
||||||
|
db = db.Where("ui.inviter_id = ?", query.InviterID)
|
||||||
|
}
|
||||||
|
if query.InviteeID > 0 {
|
||||||
|
db = db.Where("ui.invitee_id = ?", query.InviteeID)
|
||||||
|
}
|
||||||
|
|
||||||
var total int64
|
var total int64
|
||||||
if err := db.Count(&total).Error; err != nil {
|
if err := db.Count(&total).Error; err != nil {
|
||||||
@@ -804,12 +935,21 @@ func (r *Repository) ListAdminRebateLedgers(ctx context.Context, query AdminReba
|
|||||||
if p := strings.TrimSpace(query.InviterPhone); p != "" {
|
if p := strings.TrimSpace(query.InviterPhone); p != "" {
|
||||||
db = db.Where("inviter.phone = ?", p)
|
db = db.Where("inviter.phone = ?", p)
|
||||||
}
|
}
|
||||||
|
if p := strings.TrimSpace(query.InviteePhone); p != "" {
|
||||||
|
db = db.Where("invitee.phone = ?", p)
|
||||||
|
}
|
||||||
if t := strings.TrimSpace(query.TradeRole); t != "" {
|
if t := strings.TrimSpace(query.TradeRole); t != "" {
|
||||||
db = db.Where("irl.trade_role = ?", t)
|
db = db.Where("irl.trade_role = ?", t)
|
||||||
}
|
}
|
||||||
if query.DistributionSiteID != nil {
|
if query.DistributionSiteID != nil {
|
||||||
db = db.Where("irl.distribution_site_id = ?", *query.DistributionSiteID)
|
db = db.Where("irl.distribution_site_id = ?", *query.DistributionSiteID)
|
||||||
}
|
}
|
||||||
|
if query.InviterID > 0 {
|
||||||
|
db = db.Where("irl.inviter_id = ?", query.InviterID)
|
||||||
|
}
|
||||||
|
if query.InviteeID > 0 {
|
||||||
|
db = db.Where("irl.invitee_id = ?", query.InviteeID)
|
||||||
|
}
|
||||||
|
|
||||||
var total int64
|
var total int64
|
||||||
if err := db.Count(&total).Error; err != nil {
|
if err := db.Count(&total).Error; err != nil {
|
||||||
@@ -820,6 +960,7 @@ func (r *Repository) ListAdminRebateLedgers(ctx context.Context, query AdminReba
|
|||||||
ID uint64 `gorm:"column:id"`
|
ID uint64 `gorm:"column:id"`
|
||||||
OrderID uint64 `gorm:"column:order_id"`
|
OrderID uint64 `gorm:"column:order_id"`
|
||||||
OrderNo string `gorm:"column:order_no"`
|
OrderNo string `gorm:"column:order_no"`
|
||||||
|
Source string `gorm:"column:source"`
|
||||||
DistributionSiteID uint64 `gorm:"column:distribution_site_id"`
|
DistributionSiteID uint64 `gorm:"column:distribution_site_id"`
|
||||||
InviterID uint64 `gorm:"column:inviter_id"`
|
InviterID uint64 `gorm:"column:inviter_id"`
|
||||||
InviterPhone string `gorm:"column:inviter_phone"`
|
InviterPhone string `gorm:"column:inviter_phone"`
|
||||||
@@ -838,7 +979,7 @@ func (r *Repository) ListAdminRebateLedgers(ctx context.Context, query AdminReba
|
|||||||
|
|
||||||
var rows []rawLedger
|
var rows []rawLedger
|
||||||
offset := (query.Page - 1) * query.PageSize
|
offset := (query.Page - 1) * query.PageSize
|
||||||
err := db.Select("irl.id, irl.order_id, irl.order_no, irl.distribution_site_id, irl.inviter_id, inviter.phone as inviter_phone, irl.invitee_id, invitee.phone as invitee_phone, irl.trade_role, irl.order_profit_basis_cent, irl.single_side_basis_cent, irl.rate_applied, irl.days_since_verified, irl.cycle_stage, irl.rebate_amount_cent, irl.status, irl.settled_at").
|
err := db.Select("irl.id, irl.order_id, irl.order_no, irl.source, irl.distribution_site_id, irl.inviter_id, inviter.phone as inviter_phone, irl.invitee_id, invitee.phone as invitee_phone, irl.trade_role, irl.order_profit_basis_cent, irl.single_side_basis_cent, irl.rate_applied, irl.days_since_verified, irl.cycle_stage, irl.rebate_amount_cent, irl.status, irl.settled_at").
|
||||||
Order("irl.id DESC").Offset(offset).Limit(query.PageSize).Scan(&rows).Error
|
Order("irl.id DESC").Offset(offset).Limit(query.PageSize).Scan(&rows).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
@@ -850,6 +991,7 @@ func (r *Repository) ListAdminRebateLedgers(ctx context.Context, query AdminReba
|
|||||||
"id": row.ID,
|
"id": row.ID,
|
||||||
"order_id": row.OrderID,
|
"order_id": row.OrderID,
|
||||||
"order_no": row.OrderNo,
|
"order_no": row.OrderNo,
|
||||||
|
"source": row.Source,
|
||||||
"distribution_site_id": row.DistributionSiteID,
|
"distribution_site_id": row.DistributionSiteID,
|
||||||
"inviter_id": row.InviterID,
|
"inviter_id": row.InviterID,
|
||||||
"inviter_phone": row.InviterPhone,
|
"inviter_phone": row.InviterPhone,
|
||||||
|
|||||||
@@ -289,3 +289,143 @@ func TestCrossSiteDistributionRebate(t *testing.T) {
|
|||||||
t.Fatalf("卖家端跨站返利错误: siteID=%d, amount=%d", sellerLedger.DistributionSiteID, sellerLedger.RebateAmountCent)
|
t.Fatalf("卖家端跨站返利错误: siteID=%d, amount=%d", sellerLedger.DistributionSiteID, sellerLedger.RebateAmountCent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cycleLabel 的比例必须来自实际生效配置,改配置后文案要跟着变,
|
||||||
|
// 否则钱包流水备注会与后台比例不一致(历史缺陷)。
|
||||||
|
func TestCycleLabelFollowsConfiguredRate(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
cycle string
|
||||||
|
rate float64
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{CycleFirstMonth, 0.60, "首月奖励 60%"},
|
||||||
|
{CycleFirstMonth, 0.50, "首月奖励 50%"},
|
||||||
|
{CycleFirstMonth, 0.80, "首月奖励 80%"},
|
||||||
|
{CycleSecondMonth, 0.30, "次月奖励 30%"},
|
||||||
|
{CycleSecondMonth, 0.25, "次月奖励 25%"},
|
||||||
|
{CycleSubsequent, 0.15, "长期奖励 15%"},
|
||||||
|
{CycleSubsequent, 0.125, "长期奖励 12.5%"},
|
||||||
|
{CycleSubsequent, 0, "长期奖励 0%"},
|
||||||
|
}
|
||||||
|
for _, c := range cases {
|
||||||
|
if got := cycleLabel(c.cycle, c.rate); got != c.want {
|
||||||
|
t.Fatalf("cycleLabel(%s, %v) = %q, want %q", c.cycle, c.rate, got, c.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 线下提号返利与租赁订单卖家侧共用同一个入口 AwardSellerSideRebateTx:
|
||||||
|
// 这里验证金额计算正确,且同一来源单据重复调用不会重复入账
|
||||||
|
// (唯一键 source+order_id+trade_role 保证幂等,补发脚本重跑安全)。
|
||||||
|
func TestAwardSellerSideRebateTxAwardsOncePerSource(t *testing.T) {
|
||||||
|
db := setupTestDB(t)
|
||||||
|
|
||||||
|
inviterCode := "inv9001"
|
||||||
|
inviter := model.User{
|
||||||
|
Phone: "13800009001",
|
||||||
|
Nickname: "提号邀请人",
|
||||||
|
RealnameStatus: "verified",
|
||||||
|
Status: "active",
|
||||||
|
InviteCode: &inviterCode,
|
||||||
|
}
|
||||||
|
if err := db.Create(&inviter).Error; err != nil {
|
||||||
|
t.Fatalf("创建邀请人失败: %v", err)
|
||||||
|
}
|
||||||
|
seller := model.User{
|
||||||
|
Phone: "13800009002",
|
||||||
|
Nickname: "提号号主",
|
||||||
|
RealnameStatus: "verified",
|
||||||
|
Status: "active",
|
||||||
|
}
|
||||||
|
if err := db.Create(&seller).Error; err != nil {
|
||||||
|
t.Fatalf("创建号主失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 距结算 2 天 => 首月 60%。
|
||||||
|
// Truncate 到整秒:DATETIME(0) 会把小数秒四舍五入,带小数时可能进位成不足 48 小时而算作 1 天。
|
||||||
|
verifiedAt := time.Now().AddDate(0, 0, -2).Truncate(time.Second)
|
||||||
|
if err := db.Create(&model.UserInvitation{
|
||||||
|
InviterID: inviter.ID,
|
||||||
|
InviteeID: seller.ID,
|
||||||
|
InviteCode: inviterCode,
|
||||||
|
Status: StatusActive,
|
||||||
|
VerifiedAt: &verifiedAt,
|
||||||
|
}).Error; err != nil {
|
||||||
|
t.Fatalf("创建邀请关系失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
input := SellerSideRebateInput{
|
||||||
|
Source: RebateSourcePickup,
|
||||||
|
SourceID: 900001,
|
||||||
|
SourceNo: "PK-REBATE-TEST-1",
|
||||||
|
SellerID: seller.ID,
|
||||||
|
GrossBasisCent: 10000,
|
||||||
|
BasisCent: 5000,
|
||||||
|
SiteID: 0,
|
||||||
|
SettledAt: time.Now(),
|
||||||
|
RemarkPrefix: "邀请卖家提号返利",
|
||||||
|
}
|
||||||
|
|
||||||
|
apply := func() int64 {
|
||||||
|
t.Helper()
|
||||||
|
var amount int64
|
||||||
|
if err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
got, err := AwardSellerSideRebateTx(tx, input)
|
||||||
|
amount = got
|
||||||
|
return err
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatalf("发放提号返利失败: %v", err)
|
||||||
|
}
|
||||||
|
return amount
|
||||||
|
}
|
||||||
|
|
||||||
|
// 单边基数 5000,首月 60% => 3000 分
|
||||||
|
if got := apply(); got != 3000 {
|
||||||
|
t.Fatalf("首次发放金额 = %d, want 3000", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rebate model.InvitationRebateLedger
|
||||||
|
if err := db.Where("source = ? AND order_id = ? AND trade_role = 'seller'", RebateSourcePickup, input.SourceID).
|
||||||
|
First(&rebate).Error; err != nil {
|
||||||
|
t.Fatalf("未找到提号返利流水: %v", err)
|
||||||
|
}
|
||||||
|
if rebate.InviterID != inviter.ID || rebate.InviteeID != seller.ID || rebate.OrderNo != input.SourceNo {
|
||||||
|
t.Fatalf("返利流水字段错误: %+v", rebate)
|
||||||
|
}
|
||||||
|
if rebate.CycleStage != CycleFirstMonth || rebate.DaysSinceVerified != 2 {
|
||||||
|
t.Fatalf("返利档位错误: cycle=%s, days=%d", rebate.CycleStage, rebate.DaysSinceVerified)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 同来源同角色重复调用必须跳过,不重复写流水、不重复入账
|
||||||
|
if got := apply(); got != 0 {
|
||||||
|
t.Fatalf("重复调用应幂等跳过, got %d", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
var ledgerCount int64
|
||||||
|
if err := db.Model(&model.InvitationRebateLedger{}).
|
||||||
|
Where("source = ? AND order_id = ?", RebateSourcePickup, input.SourceID).
|
||||||
|
Count(&ledgerCount).Error; err != nil {
|
||||||
|
t.Fatalf("统计返利流水失败: %v", err)
|
||||||
|
}
|
||||||
|
if ledgerCount != 1 {
|
||||||
|
t.Fatalf("返利流水条数 = %d, want 1", ledgerCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
var walletCount int64
|
||||||
|
if err := db.Model(&model.WalletLedger{}).
|
||||||
|
Where("biz_type = ? AND biz_no = ?", "invite_rebate", input.SourceNo).
|
||||||
|
Count(&walletCount).Error; err != nil {
|
||||||
|
t.Fatalf("统计钱包流水失败: %v", err)
|
||||||
|
}
|
||||||
|
if walletCount != 1 {
|
||||||
|
t.Fatalf("钱包流水条数 = %d, want 1", walletCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
var account model.WalletAccount
|
||||||
|
if err := db.Where("user_id = ? AND distribution_site_id = 0", inviter.ID).First(&account).Error; err != nil {
|
||||||
|
t.Fatalf("未找到邀请人钱包账户: %v", err)
|
||||||
|
}
|
||||||
|
if account.AvailableBalanceCent != 3000 {
|
||||||
|
t.Fatalf("邀请人可用余额 = %d, want 3000", account.AvailableBalanceCent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -217,6 +217,8 @@ type AdminOrderQuery struct {
|
|||||||
HandoffMode string
|
HandoffMode string
|
||||||
SettlementStatus string
|
SettlementStatus string
|
||||||
OfflineSettlementStatus string
|
OfflineSettlementStatus string
|
||||||
|
// UserID 精确匹配该用户作为号主或租客参与的订单(用户管理「明细」入口使用)。
|
||||||
|
UserID uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuditMeta = auditlog.Meta
|
type AuditMeta = auditlog.Meta
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ func parsePagination(c *gin.Context) (int, int) {
|
|||||||
|
|
||||||
func parseAdminOrderQuery(c *gin.Context) AdminOrderQuery {
|
func parseAdminOrderQuery(c *gin.Context) AdminOrderQuery {
|
||||||
page, pageSize := parsePagination(c)
|
page, pageSize := parsePagination(c)
|
||||||
|
userID, _ := strconv.ParseUint(strings.TrimSpace(c.Query("user_id")), 10, 64)
|
||||||
return AdminOrderQuery{
|
return AdminOrderQuery{
|
||||||
Page: page,
|
Page: page,
|
||||||
PageSize: pageSize,
|
PageSize: pageSize,
|
||||||
@@ -63,5 +64,6 @@ func parseAdminOrderQuery(c *gin.Context) AdminOrderQuery {
|
|||||||
HandoffMode: strings.TrimSpace(c.Query("handoff_mode")),
|
HandoffMode: strings.TrimSpace(c.Query("handoff_mode")),
|
||||||
SettlementStatus: strings.TrimSpace(c.Query("settlement_status")),
|
SettlementStatus: strings.TrimSpace(c.Query("settlement_status")),
|
||||||
OfflineSettlementStatus: strings.TrimSpace(c.Query("offline_settlement_status")),
|
OfflineSettlementStatus: strings.TrimSpace(c.Query("offline_settlement_status")),
|
||||||
|
UserID: userID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -310,6 +310,10 @@ func adminListItemNeedsOwnerIncome(row orderRow) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func applyAdminOrderFilters(db *gorm.DB, query AdminOrderQuery) *gorm.DB {
|
func applyAdminOrderFilters(db *gorm.DB, query AdminOrderQuery) *gorm.DB {
|
||||||
|
if query.UserID > 0 {
|
||||||
|
// 精确命中该用户作为号主或租客参与的订单,避免与 keyword 的数字 ID 模糊命中混淆。
|
||||||
|
db = db.Where("(o.owner_id = ? OR o.renter_id = ?)", query.UserID, query.UserID)
|
||||||
|
}
|
||||||
if query.Status != "" {
|
if query.Status != "" {
|
||||||
db = db.Where("o.status = ?", query.Status)
|
db = db.Where("o.status = ?", query.Status)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"hfb_sys/backend/internal/auditlog"
|
"hfb_sys/backend/internal/auditlog"
|
||||||
"hfb_sys/backend/internal/listingstatus"
|
"hfb_sys/backend/internal/listingstatus"
|
||||||
"hfb_sys/backend/internal/model"
|
"hfb_sys/backend/internal/model"
|
||||||
|
"hfb_sys/backend/internal/modules/invitation"
|
||||||
"hfb_sys/backend/internal/modules/notification"
|
"hfb_sys/backend/internal/modules/notification"
|
||||||
"hfb_sys/backend/internal/modules/wallet"
|
"hfb_sys/backend/internal/modules/wallet"
|
||||||
"hfb_sys/backend/internal/timeutil"
|
"hfb_sys/backend/internal/timeutil"
|
||||||
@@ -305,6 +306,30 @@ func (r *Repository) Complete(ctx context.Context, pickupID uint64, req Complete
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 邀请返利:线下提号不走正常订单结账流程,必须在这里补发号主(卖家)侧返利,
|
||||||
|
// 否则号主邀请人永远拿不到提号产生的分成。基数按提号利润对半(与租赁订单卖家侧口径一致)。
|
||||||
|
if grossBasisCent := pickup.ProfitAmountCent; grossBasisCent > 0 {
|
||||||
|
sellerSiteID := uint64(0)
|
||||||
|
if listing.DistributionSiteID != nil {
|
||||||
|
sellerSiteID = *listing.DistributionSiteID
|
||||||
|
}
|
||||||
|
if _, err := invitation.AwardSellerSideRebateTx(tx, invitation.SellerSideRebateInput{
|
||||||
|
Source: invitation.RebateSourcePickup,
|
||||||
|
SourceID: pickup.ID,
|
||||||
|
SourceNo: pickup.PickupNo,
|
||||||
|
SellerID: pickup.OwnerID,
|
||||||
|
GrossBasisCent: grossBasisCent,
|
||||||
|
BasisCent: grossBasisCent / 2,
|
||||||
|
SiteID: sellerSiteID,
|
||||||
|
RateReferenceAt: now,
|
||||||
|
SettledAt: now,
|
||||||
|
RemarkPrefix: "邀请卖家提号返利",
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := appendPickupEvent(tx, pickup, "pickup_completed", adminID, "管理员完成提号。", pickup.CompleteRemark, map[string]any{
|
if err := appendPickupEvent(tx, pickup, "pickup_completed", adminID, "管理员完成提号。", pickup.CompleteRemark, map[string]any{
|
||||||
"settle_amount_cent": pickup.SettleAmountCent, "profit_amount_cent": pickup.ProfitAmountCent,
|
"settle_amount_cent": pickup.SettleAmountCent, "profit_amount_cent": pickup.ProfitAmountCent,
|
||||||
"settlement_mode": pickup.SettlementMode, "offline_settlement_status": pickup.OfflineSettlementStatus,
|
"settlement_mode": pickup.SettlementMode, "offline_settlement_status": pickup.OfflineSettlementStatus,
|
||||||
|
|||||||
@@ -365,6 +365,75 @@ func TestRepositoryCompleteInternalPickupCreditsWallet(t *testing.T) {
|
|||||||
assertInt64(t, "站内提号钱包入账", ledger.AmountCent, 12000)
|
assertInt64(t, "站内提号钱包入账", ledger.AmountCent, 12000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 线下提号不走正常订单结账流程,完成时必须同步给号主邀请人发放返利,
|
||||||
|
// 否则邀请人永远拿不到提号产生的分成(历史漏发缺口)。
|
||||||
|
func TestRepositoryCompletePickupAwardsSellerInvitationRebate(t *testing.T) {
|
||||||
|
repo, db := newPickupTestRepo(t)
|
||||||
|
|
||||||
|
inviter := model.User{Phone: "19900000001", Nickname: "提号邀请人", RealnameStatus: "verified", Status: "active"}
|
||||||
|
if err := db.Create(&inviter).Error; err != nil {
|
||||||
|
t.Fatalf("创建邀请人失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
listing := seedAvailableListing(t, db, "LST-REBATE-001", "返利提号账号", false)
|
||||||
|
// 距提号完成 2 天 => 首月 60% 档;Truncate 到整秒避免 DATETIME(0) 四舍五入影响天数计算。
|
||||||
|
verifiedAt := time.Now().AddDate(0, 0, -2).Truncate(time.Second)
|
||||||
|
if err := db.Create(&model.UserInvitation{
|
||||||
|
InviterID: inviter.ID,
|
||||||
|
InviteeID: listing.OwnerID,
|
||||||
|
InviteCode: "rebate01",
|
||||||
|
Status: "active",
|
||||||
|
VerifiedAt: &verifiedAt,
|
||||||
|
}).Error; err != nil {
|
||||||
|
t.Fatalf("绑定号主邀请关系失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
pickup, err := repo.Create(t.Context(), CreateRequest{
|
||||||
|
ListingID: listing.ID,
|
||||||
|
OrderAmountCent: 20000,
|
||||||
|
ProfitAmountCent: 10000,
|
||||||
|
}, 99, auditlog.Meta{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Create() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var stored model.AdminPickup
|
||||||
|
if err := db.First(&stored, pickup.ID).Error; err != nil {
|
||||||
|
t.Fatalf("读取提号记录失败: %v", err)
|
||||||
|
}
|
||||||
|
if stored.ProfitAmountCent != 10000 {
|
||||||
|
t.Fatalf("提号利润被改写为 %d,期望 10000(用例前提失效,请同步调整断言)", stored.ProfitAmountCent)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := repo.Complete(t.Context(), pickup.ID, CompleteRequest{SettleAmountCent: 10000}, 99, auditlog.Meta{}); err != nil {
|
||||||
|
t.Fatalf("Complete() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rebate model.InvitationRebateLedger
|
||||||
|
if err := db.Where("source = ? AND order_id = ? AND trade_role = ?", "pickup", pickup.ID, "seller").
|
||||||
|
First(&rebate).Error; err != nil {
|
||||||
|
t.Fatalf("提号完成应发放号主邀请人返利: %v", err)
|
||||||
|
}
|
||||||
|
if rebate.InviterID != inviter.ID || rebate.InviteeID != listing.OwnerID {
|
||||||
|
t.Fatalf("返利双方 = %d/%d, want %d/%d", rebate.InviterID, rebate.InviteeID, inviter.ID, listing.OwnerID)
|
||||||
|
}
|
||||||
|
if rebate.OrderNo != pickup.PickupNo {
|
||||||
|
t.Fatalf("返利单据号 = %q, want %q", rebate.OrderNo, pickup.PickupNo)
|
||||||
|
}
|
||||||
|
// 基数 = 提号利润 10000 对半 = 5000,首月 60% = 3000
|
||||||
|
assertInt64(t, "提号返利单边基数", rebate.SingleSideBasisCent, 5000)
|
||||||
|
assertInt64(t, "提号返利金额", rebate.RebateAmountCent, 3000)
|
||||||
|
|
||||||
|
var wallet model.WalletLedger
|
||||||
|
if err := db.Where("biz_type = ? AND biz_no = ?", "invite_rebate", pickup.PickupNo).First(&wallet).Error; err != nil {
|
||||||
|
t.Fatalf("提号返利应写钱包流水: %v", err)
|
||||||
|
}
|
||||||
|
if wallet.UserID != inviter.ID {
|
||||||
|
t.Fatalf("返利入账用户 = %d, want %d", wallet.UserID, inviter.ID)
|
||||||
|
}
|
||||||
|
assertInt64(t, "提号返利入账金额", wallet.AmountCent, 3000)
|
||||||
|
}
|
||||||
|
|
||||||
func TestRepositoryCompletePlatformManagedPickupUsesOfflineSettlement(t *testing.T) {
|
func TestRepositoryCompletePlatformManagedPickupUsesOfflineSettlement(t *testing.T) {
|
||||||
repo, db := newPickupTestRepo(t)
|
repo, db := newPickupTestRepo(t)
|
||||||
listing := seedAvailableListing(t, db, "LST-CMPL-EXTERNAL", "代管结算账号", true)
|
listing := seedAvailableListing(t, db, "LST-CMPL-EXTERNAL", "代管结算账号", true)
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
-- +goose Up
|
||||||
|
|
||||||
|
-- 邀请返利来源扩展:线下提号(admin_pickups)此前不经过正常订单结账流程,
|
||||||
|
-- 因此提号产生的平台毛利从未参与返利计算(已确认漏发)。
|
||||||
|
-- source 标识来源单据类型:rental_order=租赁订单,pickup=线下提号;
|
||||||
|
-- order_id 统一存「来源单据 ID」(rental_orders.id 或 admin_pickups.id);
|
||||||
|
-- 唯一键加入 source 后,两类来源的幂等键互不干扰,历史租赁订单行默认 rental_order。
|
||||||
|
ALTER TABLE invitation_rebate_ledgers
|
||||||
|
ADD COLUMN source VARCHAR(32) NOT NULL DEFAULT 'rental_order' COMMENT '来源单据类型: rental_order=租赁订单, pickup=线下提号' AFTER order_no,
|
||||||
|
MODIFY COLUMN order_id BIGINT UNSIGNED NOT NULL COMMENT '来源单据ID(rental_order=>rental_orders.id;pickup=>admin_pickups.id)',
|
||||||
|
DROP INDEX uk_invitation_rebate_order_role,
|
||||||
|
ADD UNIQUE KEY uk_invitation_rebate_source_role (source, order_id, trade_role);
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
|
||||||
|
ALTER TABLE invitation_rebate_ledgers
|
||||||
|
DROP INDEX uk_invitation_rebate_source_role,
|
||||||
|
ADD UNIQUE KEY uk_invitation_rebate_order_role (order_id, trade_role),
|
||||||
|
MODIFY COLUMN order_id BIGINT UNSIGNED NOT NULL COMMENT '关联订单ID',
|
||||||
|
DROP COLUMN source;
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import { apiClient } from '@/shared/api/client'
|
||||||
|
|
||||||
|
import type { ApiResponse, PaginatedResult } from '@/shared/types/types'
|
||||||
|
|
||||||
|
/** 后台邀请关系行(/admin/invitations) */
|
||||||
|
export interface AdminInvitationRow {
|
||||||
|
id: number
|
||||||
|
inviter_id: number
|
||||||
|
inviter_phone: string
|
||||||
|
inviter_nickname: string
|
||||||
|
invitee_id: number
|
||||||
|
invitee_phone: string
|
||||||
|
invitee_nickname: string
|
||||||
|
distribution_site_id: number
|
||||||
|
invite_code: string
|
||||||
|
status: string
|
||||||
|
verified_at?: string
|
||||||
|
created_at: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 后台返利结算流水行(/admin/invitations/rebates) */
|
||||||
|
export interface AdminRebateRow {
|
||||||
|
id: number
|
||||||
|
order_id: number
|
||||||
|
order_no: string
|
||||||
|
/** 来源单据类型:rental_order=租赁订单,pickup=线下提号 */
|
||||||
|
source?: string
|
||||||
|
distribution_site_id: number
|
||||||
|
inviter_id: number
|
||||||
|
inviter_phone: string
|
||||||
|
invitee_id: number
|
||||||
|
invitee_phone: string
|
||||||
|
trade_role: string
|
||||||
|
order_profit_basis_cent: number
|
||||||
|
single_side_basis_cent: number
|
||||||
|
rate_applied: number
|
||||||
|
days_since_verified: number
|
||||||
|
cycle_stage: string
|
||||||
|
rebate_amount_cent: number
|
||||||
|
status: string
|
||||||
|
settled_at: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AdminInvitationQuery {
|
||||||
|
inviter_id?: number
|
||||||
|
invitee_id?: number
|
||||||
|
page?: number
|
||||||
|
page_size?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchAdminInvitations(query: AdminInvitationQuery = {}) {
|
||||||
|
const { data } = await apiClient.get<ApiResponse<PaginatedResult<AdminInvitationRow>>>(
|
||||||
|
'/admin/invitations',
|
||||||
|
{ params: query }
|
||||||
|
)
|
||||||
|
const result = data.data
|
||||||
|
return {
|
||||||
|
items: Array.isArray(result?.items) ? result.items : [],
|
||||||
|
total: Number(result?.total ?? 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchAdminRebates(query: AdminInvitationQuery = {}) {
|
||||||
|
const { data } = await apiClient.get<ApiResponse<PaginatedResult<AdminRebateRow>>>(
|
||||||
|
'/admin/invitations/rebates',
|
||||||
|
{ params: query }
|
||||||
|
)
|
||||||
|
const result = data.data
|
||||||
|
return {
|
||||||
|
items: Array.isArray(result?.items) ? result.items : [],
|
||||||
|
total: Number(result?.total ?? 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
.user-detail {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-detail__head {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 16px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 16px;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #f8fafc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-detail__identity {
|
||||||
|
display: grid;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-detail__identity strong {
|
||||||
|
color: #0f172a;
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-detail__identity span {
|
||||||
|
color: #475569;
|
||||||
|
font-size: 14px;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-detail__identity small {
|
||||||
|
color: #94a3b8;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-detail__metrics {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(4, minmax(96px, 1fr));
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-detail__metrics > div {
|
||||||
|
display: grid;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-detail__metrics span {
|
||||||
|
color: #64748b;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-detail__metrics strong {
|
||||||
|
color: #0f172a;
|
||||||
|
font-size: 15px;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-toolbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
color: #64748b;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount-in {
|
||||||
|
color: #16a34a;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount-out {
|
||||||
|
color: #dc2626;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.role-tag {
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cell-sub {
|
||||||
|
color: #64748b;
|
||||||
|
font-size: 12px;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-toolbar :deep(.el-radio-group) {
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
}
|
||||||
@@ -0,0 +1,828 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import { computed, ref, watch } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
|
||||||
|
import {
|
||||||
|
fetchAdminInvitations,
|
||||||
|
fetchAdminRebates,
|
||||||
|
type AdminInvitationRow,
|
||||||
|
type AdminRebateRow,
|
||||||
|
} from '@/features/admin/api/adminInvitations'
|
||||||
|
import { fetchAdminPayments, type AdminPayment } from '@/features/admin/api/adminPayments'
|
||||||
|
import { fetchAdminWalletLedger, type AdminWalletLedger } from '@/features/admin/api/adminWallet'
|
||||||
|
import { fetchAdminWithdrawals, type WithdrawalDetail } from '@/features/admin/api/adminWithdrawal'
|
||||||
|
import type { AdminUserItem } from '@/features/admin/api/adminUsers'
|
||||||
|
import { fetchAdminOrders, type AdminOrderListItem } from '@/features/orders'
|
||||||
|
import { adminPath } from '@/shared/utils/adminPath'
|
||||||
|
import { readError } from '@/shared/utils/error'
|
||||||
|
import { formatCentWithSymbol } from '@/shared/utils/money'
|
||||||
|
import {
|
||||||
|
balanceTypeLabel,
|
||||||
|
ledgerDirectionLabel,
|
||||||
|
orderStatusLabel,
|
||||||
|
walletBizTypeLabel,
|
||||||
|
} from '@/shared/utils/statusLabels'
|
||||||
|
import { formatDateTime } from '@/shared/utils/time'
|
||||||
|
import { useAdminSessionStore } from '@/stores/adminSession'
|
||||||
|
import AdminTablePagination from './AdminTablePagination.vue'
|
||||||
|
|
||||||
|
type TabKey = 'wallet' | 'orders' | 'withdrawals' | 'invite' | 'payments'
|
||||||
|
type InviteMode = 'rebates' | 'invited' | 'invitedBy'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
modelValue: boolean
|
||||||
|
user?: AdminUserItem | null
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'update:modelValue', val: boolean): void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
const adminSession = useAdminSessionStore()
|
||||||
|
|
||||||
|
const canViewWallet = computed(() => adminSession.hasPermission('wallet:view'))
|
||||||
|
const canViewOrders = computed(() => adminSession.hasPermission('order:list'))
|
||||||
|
const canViewWithdrawals = computed(() => adminSession.hasPermission('withdrawal:list'))
|
||||||
|
const canViewInviteRelations = computed(() => adminSession.hasPermission('distribution:site_view'))
|
||||||
|
const canViewRebates = computed(() => adminSession.hasPermission('distribution:settlement_view'))
|
||||||
|
const canViewInvite = computed(() => canViewInviteRelations.value || canViewRebates.value)
|
||||||
|
const canViewPayments = computed(() => adminSession.hasPermission('wallet:view'))
|
||||||
|
|
||||||
|
const tabs = computed<{ key: TabKey; label: string }[]>(() => {
|
||||||
|
const list: { key: TabKey; label: string }[] = []
|
||||||
|
if (canViewWallet.value) list.push({ key: 'wallet', label: '钱包流水' })
|
||||||
|
if (canViewOrders.value) list.push({ key: 'orders', label: '订单记录' })
|
||||||
|
if (canViewWithdrawals.value) list.push({ key: 'withdrawals', label: '提现记录' })
|
||||||
|
if (canViewInvite.value) list.push({ key: 'invite', label: '邀请返利' })
|
||||||
|
if (canViewPayments.value) list.push({ key: 'payments', label: '支付记录' })
|
||||||
|
return list
|
||||||
|
})
|
||||||
|
|
||||||
|
// 邀请返利页内视图,按接口权限收敛(关系查 distribution:site_view,流水查 distribution:settlement_view)。
|
||||||
|
const inviteModes = computed<{ key: InviteMode; label: string }[]>(() => {
|
||||||
|
const list: { key: InviteMode; label: string }[] = []
|
||||||
|
if (canViewRebates.value) list.push({ key: 'rebates', label: '我获得的返利' })
|
||||||
|
if (canViewInviteRelations.value) {
|
||||||
|
list.push({ key: 'invited', label: '我邀请的好友' })
|
||||||
|
list.push({ key: 'invitedBy', label: '我作为被邀请人' })
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
})
|
||||||
|
|
||||||
|
const activeTab = ref<TabKey>('wallet')
|
||||||
|
const inviteMode = ref<InviteMode>('rebates')
|
||||||
|
|
||||||
|
const walletLoading = ref(false)
|
||||||
|
const walletRows = ref<AdminWalletLedger[]>([])
|
||||||
|
const walletTotal = ref(0)
|
||||||
|
const walletPage = ref(1)
|
||||||
|
const walletPageSize = ref(20)
|
||||||
|
|
||||||
|
const orderLoading = ref(false)
|
||||||
|
const orderRows = ref<AdminOrderListItem[]>([])
|
||||||
|
const orderTotal = ref(0)
|
||||||
|
const orderPage = ref(1)
|
||||||
|
const orderPageSize = ref(20)
|
||||||
|
|
||||||
|
const withdrawalLoading = ref(false)
|
||||||
|
const withdrawalRows = ref<WithdrawalDetail[]>([])
|
||||||
|
const withdrawalTotal = ref(0)
|
||||||
|
const withdrawalPage = ref(1)
|
||||||
|
const withdrawalPageSize = ref(20)
|
||||||
|
|
||||||
|
const rebateLoading = ref(false)
|
||||||
|
const rebateRows = ref<AdminRebateRow[]>([])
|
||||||
|
const rebateTotal = ref(0)
|
||||||
|
const rebatePage = ref(1)
|
||||||
|
const rebatePageSize = ref(20)
|
||||||
|
|
||||||
|
const inviteLoading = ref(false)
|
||||||
|
const inviteRows = ref<AdminInvitationRow[]>([])
|
||||||
|
const inviteTotal = ref(0)
|
||||||
|
const invitePage = ref(1)
|
||||||
|
const invitePageSize = ref(20)
|
||||||
|
|
||||||
|
const paymentLoading = ref(false)
|
||||||
|
const paymentRows = ref<AdminPayment[]>([])
|
||||||
|
const paymentTotal = ref(0)
|
||||||
|
const paymentPage = ref(1)
|
||||||
|
const paymentPageSize = ref(20)
|
||||||
|
|
||||||
|
const userId = computed(() => props.user?.id || 0)
|
||||||
|
const userPhone = computed(() => props.user?.phone || '')
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.modelValue,
|
||||||
|
visible => {
|
||||||
|
if (!visible) return
|
||||||
|
resetState()
|
||||||
|
const first = tabs.value[0]?.key || 'wallet'
|
||||||
|
// 切换标签本身会触发 watch(activeTab) 加载;同标签则显式加载,避免重复请求。
|
||||||
|
if (activeTab.value === first) {
|
||||||
|
void loadActive()
|
||||||
|
} else {
|
||||||
|
activeTab.value = first
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(activeTab, () => {
|
||||||
|
if (props.modelValue) void loadActive()
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(inviteMode, () => {
|
||||||
|
if (!props.modelValue || activeTab.value !== 'invite') return
|
||||||
|
// 切换数据视图时回到第一页,避免沿用上一个视图的页码导致空列表。
|
||||||
|
rebatePage.value = 1
|
||||||
|
invitePage.value = 1
|
||||||
|
void loadInvite()
|
||||||
|
})
|
||||||
|
|
||||||
|
function resetState() {
|
||||||
|
walletPage.value = 1
|
||||||
|
orderPage.value = 1
|
||||||
|
withdrawalPage.value = 1
|
||||||
|
rebatePage.value = 1
|
||||||
|
invitePage.value = 1
|
||||||
|
paymentPage.value = 1
|
||||||
|
walletRows.value = []
|
||||||
|
orderRows.value = []
|
||||||
|
withdrawalRows.value = []
|
||||||
|
rebateRows.value = []
|
||||||
|
inviteRows.value = []
|
||||||
|
paymentRows.value = []
|
||||||
|
walletTotal.value = 0
|
||||||
|
orderTotal.value = 0
|
||||||
|
withdrawalTotal.value = 0
|
||||||
|
rebateTotal.value = 0
|
||||||
|
inviteTotal.value = 0
|
||||||
|
paymentTotal.value = 0
|
||||||
|
// 权限变化时回落到当前可用的第一个视图,否则保留上次选择。
|
||||||
|
if (!inviteModes.value.some(mode => mode.key === inviteMode.value)) {
|
||||||
|
inviteMode.value = inviteModes.value[0]?.key || 'rebates'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
emit('update:modelValue', false)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadActive() {
|
||||||
|
if (!props.modelValue || userId.value <= 0) return
|
||||||
|
if (activeTab.value === 'wallet') return loadWallet()
|
||||||
|
if (activeTab.value === 'orders') return loadOrders()
|
||||||
|
if (activeTab.value === 'withdrawals') return loadWithdrawals()
|
||||||
|
if (activeTab.value === 'invite') return loadInvite()
|
||||||
|
return loadPayments()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadWallet() {
|
||||||
|
walletLoading.value = true
|
||||||
|
try {
|
||||||
|
const result = await fetchAdminWalletLedger({
|
||||||
|
user_id: String(userId.value),
|
||||||
|
page: walletPage.value,
|
||||||
|
page_size: walletPageSize.value,
|
||||||
|
})
|
||||||
|
walletRows.value = Array.isArray(result.items) ? result.items : []
|
||||||
|
walletTotal.value = Number(result.total ?? 0)
|
||||||
|
} catch (error) {
|
||||||
|
walletRows.value = []
|
||||||
|
walletTotal.value = 0
|
||||||
|
ElMessage.error(readError(error, '获取钱包流水失败'))
|
||||||
|
} finally {
|
||||||
|
walletLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadOrders() {
|
||||||
|
orderLoading.value = true
|
||||||
|
try {
|
||||||
|
const result = await fetchAdminOrders(orderPage.value, orderPageSize.value, {
|
||||||
|
user_id: userId.value,
|
||||||
|
})
|
||||||
|
orderRows.value = Array.isArray(result.items) ? result.items : []
|
||||||
|
orderTotal.value = Number(result.total ?? 0)
|
||||||
|
} catch (error) {
|
||||||
|
orderRows.value = []
|
||||||
|
orderTotal.value = 0
|
||||||
|
ElMessage.error(readError(error, '获取订单记录失败'))
|
||||||
|
} finally {
|
||||||
|
orderLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadWithdrawals() {
|
||||||
|
withdrawalLoading.value = true
|
||||||
|
try {
|
||||||
|
const result = await fetchAdminWithdrawals({
|
||||||
|
user_id: userId.value,
|
||||||
|
page: withdrawalPage.value,
|
||||||
|
page_size: withdrawalPageSize.value,
|
||||||
|
})
|
||||||
|
withdrawalRows.value = Array.isArray(result.items) ? result.items : []
|
||||||
|
withdrawalTotal.value = Number(result.total ?? 0)
|
||||||
|
} catch (error) {
|
||||||
|
withdrawalRows.value = []
|
||||||
|
withdrawalTotal.value = 0
|
||||||
|
ElMessage.error(readError(error, '获取提现记录失败'))
|
||||||
|
} finally {
|
||||||
|
withdrawalLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadInvite() {
|
||||||
|
if (inviteMode.value === 'rebates') return loadRebates()
|
||||||
|
return loadInvitations()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadRebates() {
|
||||||
|
rebateLoading.value = true
|
||||||
|
try {
|
||||||
|
const result = await fetchAdminRebates({
|
||||||
|
inviter_id: userId.value,
|
||||||
|
page: rebatePage.value,
|
||||||
|
page_size: rebatePageSize.value,
|
||||||
|
})
|
||||||
|
rebateRows.value = result.items
|
||||||
|
rebateTotal.value = result.total
|
||||||
|
} catch (error) {
|
||||||
|
rebateRows.value = []
|
||||||
|
rebateTotal.value = 0
|
||||||
|
ElMessage.error(readError(error, '获取返利流水失败'))
|
||||||
|
} finally {
|
||||||
|
rebateLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadInvitations() {
|
||||||
|
inviteLoading.value = true
|
||||||
|
try {
|
||||||
|
const result = await fetchAdminInvitations({
|
||||||
|
...(inviteMode.value === 'invitedBy'
|
||||||
|
? { invitee_id: userId.value }
|
||||||
|
: { inviter_id: userId.value }),
|
||||||
|
page: invitePage.value,
|
||||||
|
page_size: invitePageSize.value,
|
||||||
|
})
|
||||||
|
inviteRows.value = result.items
|
||||||
|
inviteTotal.value = result.total
|
||||||
|
} catch (error) {
|
||||||
|
inviteRows.value = []
|
||||||
|
inviteTotal.value = 0
|
||||||
|
ElMessage.error(readError(error, '获取邀请关系失败'))
|
||||||
|
} finally {
|
||||||
|
inviteLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadPayments() {
|
||||||
|
paymentLoading.value = true
|
||||||
|
try {
|
||||||
|
const result = await fetchAdminPayments({
|
||||||
|
user_id: String(userId.value),
|
||||||
|
page: paymentPage.value,
|
||||||
|
page_size: paymentPageSize.value,
|
||||||
|
})
|
||||||
|
paymentRows.value = Array.isArray(result.items) ? result.items : []
|
||||||
|
paymentTotal.value = Number(result.total ?? 0)
|
||||||
|
} catch (error) {
|
||||||
|
paymentRows.value = []
|
||||||
|
paymentTotal.value = 0
|
||||||
|
ElMessage.error(readError(error, '获取支付记录失败'))
|
||||||
|
} finally {
|
||||||
|
paymentLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 依据手机号判定该用户在本单中的角色(列表接口只回传手机号)。 */
|
||||||
|
function orderRoles(row: AdminOrderListItem): string[] {
|
||||||
|
const phone = userPhone.value
|
||||||
|
if (!phone) return []
|
||||||
|
const roles: string[] = []
|
||||||
|
if (row.renter_phone === phone) roles.push('租客')
|
||||||
|
if (row.owner_phone === phone) roles.push('号主')
|
||||||
|
return roles
|
||||||
|
}
|
||||||
|
|
||||||
|
function walletDirectionType(direction: string): 'success' | 'danger' | 'warning' {
|
||||||
|
if (direction === 'in') return 'success'
|
||||||
|
if (direction === 'out') return 'danger'
|
||||||
|
return 'warning'
|
||||||
|
}
|
||||||
|
|
||||||
|
function withdrawalStatusLabel(status: string) {
|
||||||
|
const labels: Record<string, string> = {
|
||||||
|
pending: '待审核',
|
||||||
|
processing: '待打款',
|
||||||
|
completed: '已打款',
|
||||||
|
rejected: '已拒绝',
|
||||||
|
cancelled: '已取消',
|
||||||
|
}
|
||||||
|
return labels[status] || status || '-'
|
||||||
|
}
|
||||||
|
|
||||||
|
function withdrawalStatusType(
|
||||||
|
status: string
|
||||||
|
): 'success' | 'warning' | 'danger' | 'info' | 'primary' {
|
||||||
|
const types: Record<string, 'success' | 'warning' | 'danger' | 'info' | 'primary'> = {
|
||||||
|
pending: 'warning',
|
||||||
|
processing: 'primary',
|
||||||
|
completed: 'success',
|
||||||
|
rejected: 'danger',
|
||||||
|
cancelled: 'info',
|
||||||
|
}
|
||||||
|
return types[status] || 'info'
|
||||||
|
}
|
||||||
|
|
||||||
|
function invitationStatusLabel(status: string) {
|
||||||
|
const labels: Record<string, string> = {
|
||||||
|
active: '已实名(生效中)',
|
||||||
|
pending: '待实名(未生效)',
|
||||||
|
invalid: '已失效',
|
||||||
|
}
|
||||||
|
return labels[status] || status || '-'
|
||||||
|
}
|
||||||
|
|
||||||
|
function invitationStatusType(status: string): 'success' | 'warning' | 'info' {
|
||||||
|
if (status === 'active') return 'success'
|
||||||
|
if (status === 'pending') return 'warning'
|
||||||
|
return 'info'
|
||||||
|
}
|
||||||
|
|
||||||
|
function tradeRoleLabel(role: string) {
|
||||||
|
if (role === 'buyer') return '买家端'
|
||||||
|
if (role === 'seller') return '卖家端'
|
||||||
|
return role || '-'
|
||||||
|
}
|
||||||
|
|
||||||
|
function cycleStageLabel(stage: string) {
|
||||||
|
const labels: Record<string, string> = {
|
||||||
|
first_month: '首月',
|
||||||
|
second_month: '次月',
|
||||||
|
subsequent: '长期',
|
||||||
|
}
|
||||||
|
return labels[stage] || stage || '-'
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 返利来源单据类型文案(提号单不走正常订单流程,需要单独标识)。 */
|
||||||
|
function rebateSourceLabel(source?: string) {
|
||||||
|
if (source === 'pickup') return '提号'
|
||||||
|
if (source === 'rental_order') return '订单'
|
||||||
|
return source || '订单'
|
||||||
|
}
|
||||||
|
|
||||||
|
function paymentStatusLabel(status: string) {
|
||||||
|
const labels: Record<string, string> = {
|
||||||
|
created: '已创建',
|
||||||
|
paying: '支付中',
|
||||||
|
paid: '已支付',
|
||||||
|
refunding: '退款中',
|
||||||
|
refunded: '已退款',
|
||||||
|
failed: '失败',
|
||||||
|
closed: '已关闭',
|
||||||
|
}
|
||||||
|
return labels[status] || status || '-'
|
||||||
|
}
|
||||||
|
|
||||||
|
function paymentStatusType(status: string): 'success' | 'warning' | 'danger' | 'info' | 'primary' {
|
||||||
|
if (['paid', 'refunded'].includes(status)) return 'success'
|
||||||
|
if (status === 'failed') return 'danger'
|
||||||
|
if (['paying', 'refunding'].includes(status)) return 'warning'
|
||||||
|
return 'info'
|
||||||
|
}
|
||||||
|
|
||||||
|
function paymentBizTypeLabel(type: string) {
|
||||||
|
const labels: Record<string, string> = {
|
||||||
|
order_pay: '订单支付',
|
||||||
|
cancel_refund: '取消退款',
|
||||||
|
admin_close_refund: '客服关闭退款',
|
||||||
|
admin_refund: '人工退款',
|
||||||
|
checkout_refund: '结账退款',
|
||||||
|
deposit_refund: '押金退款',
|
||||||
|
rent_refund: '租金退款',
|
||||||
|
arbitration_refund: '仲裁退款',
|
||||||
|
mohong_pay: '撞车支付',
|
||||||
|
mohong_refund: '撞车退款',
|
||||||
|
}
|
||||||
|
return labels[type] || type || '-'
|
||||||
|
}
|
||||||
|
|
||||||
|
function goOrderDetail(row: AdminOrderListItem) {
|
||||||
|
close()
|
||||||
|
void router.push(adminPath(`orders/${row.id}`))
|
||||||
|
}
|
||||||
|
|
||||||
|
function goWithdrawals() {
|
||||||
|
close()
|
||||||
|
void router.push({
|
||||||
|
path: adminPath('withdrawals'),
|
||||||
|
query: { withdrawal_user_id: String(userId.value) },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function goWalletLedger() {
|
||||||
|
close()
|
||||||
|
void router.push({ path: adminPath('wallet-ledger'), query: { user_id: String(userId.value) } })
|
||||||
|
}
|
||||||
|
|
||||||
|
function goPayments() {
|
||||||
|
close()
|
||||||
|
void router.push({ path: adminPath('payments'), query: { user_id: String(userId.value) } })
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<el-drawer
|
||||||
|
:model-value="modelValue"
|
||||||
|
size="78%"
|
||||||
|
destroy-on-close
|
||||||
|
:title="`用户明细 · ${user?.nickname || user?.phone || userId}`"
|
||||||
|
@update:model-value="(val: boolean) => emit('update:modelValue', val)"
|
||||||
|
>
|
||||||
|
<div v-if="user" class="user-detail">
|
||||||
|
<header class="user-detail__head">
|
||||||
|
<div class="user-detail__identity">
|
||||||
|
<strong>{{ user.nickname || '-' }}</strong>
|
||||||
|
<span>{{ user.phone }}</span>
|
||||||
|
<small>UID: {{ user.id }}</small>
|
||||||
|
</div>
|
||||||
|
<div class="user-detail__metrics">
|
||||||
|
<div>
|
||||||
|
<span>可用余额</span>
|
||||||
|
<strong>{{ formatCentWithSymbol(user.available_balance_cent) }}</strong>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span>冻结余额</span>
|
||||||
|
<strong>{{ formatCentWithSymbol(user.frozen_balance_cent) }}</strong>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span>成长等级</span>
|
||||||
|
<strong>{{ user.renter_growth_level_name || '普通' }}</strong>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span>注册时间</span>
|
||||||
|
<strong>{{ formatDateTime(user.created_at) }}</strong>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<el-empty v-if="!tabs.length" description="当前账号没有查看资金与订单的权限" />
|
||||||
|
|
||||||
|
<el-tabs v-else v-model="activeTab">
|
||||||
|
<el-tab-pane v-if="canViewWallet" label="钱包流水" name="wallet">
|
||||||
|
<div class="tab-toolbar">
|
||||||
|
<span>共 {{ walletTotal }} 条流水</span>
|
||||||
|
<el-button text type="primary" size="small" @click="goWalletLedger">
|
||||||
|
前往资金流水页
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
<el-table
|
||||||
|
v-loading="walletLoading"
|
||||||
|
size="small"
|
||||||
|
border
|
||||||
|
:data="walletRows"
|
||||||
|
empty-text="暂无钱包流水"
|
||||||
|
>
|
||||||
|
<el-table-column label="时间" width="160">
|
||||||
|
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="方向" width="80">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag size="small" :type="walletDirectionType(row.direction)">
|
||||||
|
{{ ledgerDirectionLabel(row.direction) }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="金额" width="120" align="right">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<span :class="row.direction === 'in' ? 'amount-in' : 'amount-out'">
|
||||||
|
{{ row.direction === 'in' ? '+' : '-'
|
||||||
|
}}{{ formatCentWithSymbol(row.amount_cent) }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="业务类型" width="130">
|
||||||
|
<template #default="{ row }">{{ walletBizTypeLabel(row.biz_type) }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="余额口径" width="100">
|
||||||
|
<template #default="{ row }">{{ balanceTypeLabel(row.balance_type) }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="余额快照" width="120" align="right">
|
||||||
|
<template #default="{ row }">{{
|
||||||
|
formatCentWithSymbol(row.balance_after_cent)
|
||||||
|
}}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column prop="order_no" label="关联订单" width="180" show-overflow-tooltip />
|
||||||
|
<el-table-column prop="remark" label="备注" min-width="200" show-overflow-tooltip />
|
||||||
|
</el-table>
|
||||||
|
<AdminTablePagination
|
||||||
|
v-if="walletTotal > 0"
|
||||||
|
v-model:current-page="walletPage"
|
||||||
|
v-model:page-size="walletPageSize"
|
||||||
|
:total="walletTotal"
|
||||||
|
:loading="walletLoading"
|
||||||
|
@page-change="loadWallet"
|
||||||
|
/>
|
||||||
|
</el-tab-pane>
|
||||||
|
|
||||||
|
<el-tab-pane v-if="canViewOrders" label="订单记录" name="orders">
|
||||||
|
<div class="tab-toolbar">
|
||||||
|
<span>共 {{ orderTotal }} 笔订单(作为租客或号主)</span>
|
||||||
|
</div>
|
||||||
|
<el-table
|
||||||
|
v-loading="orderLoading"
|
||||||
|
size="small"
|
||||||
|
border
|
||||||
|
:data="orderRows"
|
||||||
|
empty-text="暂无订单记录"
|
||||||
|
>
|
||||||
|
<el-table-column prop="order_no" label="订单号" width="180" show-overflow-tooltip />
|
||||||
|
<el-table-column label="角色" width="110">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag
|
||||||
|
v-for="role in orderRoles(row)"
|
||||||
|
:key="role"
|
||||||
|
size="small"
|
||||||
|
effect="plain"
|
||||||
|
class="role-tag"
|
||||||
|
>
|
||||||
|
{{ role }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column prop="title" label="商品" min-width="180" show-overflow-tooltip />
|
||||||
|
<el-table-column label="状态" width="130">
|
||||||
|
<template #default="{ row }">{{ orderStatusLabel(row.status) }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="租金" width="110" align="right">
|
||||||
|
<template #default="{ row }">{{
|
||||||
|
formatCentWithSymbol(row.rent_amount_cent)
|
||||||
|
}}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="创建时间" width="160">
|
||||||
|
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" width="90" fixed="right">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-button text type="primary" size="small" @click="goOrderDetail(row)">
|
||||||
|
详情
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<AdminTablePagination
|
||||||
|
v-if="orderTotal > 0"
|
||||||
|
v-model:current-page="orderPage"
|
||||||
|
v-model:page-size="orderPageSize"
|
||||||
|
:total="orderTotal"
|
||||||
|
:loading="orderLoading"
|
||||||
|
@page-change="loadOrders"
|
||||||
|
/>
|
||||||
|
</el-tab-pane>
|
||||||
|
|
||||||
|
<el-tab-pane v-if="canViewWithdrawals" label="提现记录" name="withdrawals">
|
||||||
|
<div class="tab-toolbar">
|
||||||
|
<span>共 {{ withdrawalTotal }} 条提现申请</span>
|
||||||
|
<el-button text type="primary" size="small" @click="goWithdrawals">
|
||||||
|
前往提现管理
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
<el-table
|
||||||
|
v-loading="withdrawalLoading"
|
||||||
|
size="small"
|
||||||
|
border
|
||||||
|
:data="withdrawalRows"
|
||||||
|
empty-text="暂无提现记录"
|
||||||
|
>
|
||||||
|
<el-table-column
|
||||||
|
prop="withdraw_no"
|
||||||
|
label="提现单号"
|
||||||
|
width="190"
|
||||||
|
show-overflow-tooltip
|
||||||
|
/>
|
||||||
|
<el-table-column label="申请金额" width="120" align="right">
|
||||||
|
<template #default="{ row }">{{ formatCentWithSymbol(row.amount_cent) }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="实际到账" width="120" align="right">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatCentWithSymbol(row.actual_amount_cent ?? row.amount_cent) }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="收款账户" min-width="180">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ row.account_name || '-' }} · {{ row.account_no || '-' }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="状态" width="100">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag size="small" :type="withdrawalStatusType(row.status)">
|
||||||
|
{{ withdrawalStatusLabel(row.status) }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="申请时间" width="160">
|
||||||
|
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<AdminTablePagination
|
||||||
|
v-if="withdrawalTotal > 0"
|
||||||
|
v-model:current-page="withdrawalPage"
|
||||||
|
v-model:page-size="withdrawalPageSize"
|
||||||
|
:total="withdrawalTotal"
|
||||||
|
:loading="withdrawalLoading"
|
||||||
|
@page-change="loadWithdrawals"
|
||||||
|
/>
|
||||||
|
</el-tab-pane>
|
||||||
|
|
||||||
|
<el-tab-pane v-if="canViewInvite" label="邀请返利" name="invite">
|
||||||
|
<div class="tab-toolbar">
|
||||||
|
<el-radio-group v-model="inviteMode" size="small">
|
||||||
|
<el-radio-button v-for="mode in inviteModes" :key="mode.key" :value="mode.key">
|
||||||
|
{{ mode.label }}
|
||||||
|
</el-radio-button>
|
||||||
|
</el-radio-group>
|
||||||
|
<span v-if="inviteMode === 'rebates'">共 {{ rebateTotal }} 笔返利</span>
|
||||||
|
<span v-else>共 {{ inviteTotal }} 条邀请关系</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-if="inviteMode === 'rebates'">
|
||||||
|
<el-table
|
||||||
|
v-loading="rebateLoading"
|
||||||
|
size="small"
|
||||||
|
border
|
||||||
|
:data="rebateRows"
|
||||||
|
empty-text="暂无返利流水"
|
||||||
|
>
|
||||||
|
<el-table-column label="入账时间" width="160">
|
||||||
|
<template #default="{ row }">{{ formatDateTime(row.settled_at) }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="来源" width="80">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag
|
||||||
|
size="small"
|
||||||
|
effect="plain"
|
||||||
|
:type="row.source === 'pickup' ? 'warning' : 'info'"
|
||||||
|
>
|
||||||
|
{{ rebateSourceLabel(row.source) }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column prop="order_no" label="关联单据" width="180" show-overflow-tooltip />
|
||||||
|
<el-table-column label="交易人(被邀请人)" min-width="140">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<code class="cell-sub">{{ row.invitee_phone || '-' }}</code>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="交易端" width="90">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag
|
||||||
|
size="small"
|
||||||
|
:type="row.trade_role === 'buyer' ? 'primary' : 'danger'"
|
||||||
|
effect="plain"
|
||||||
|
>
|
||||||
|
{{ tradeRoleLabel(row.trade_role) }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="收益基数" width="110" align="right">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatCentWithSymbol(row.single_side_basis_cent) }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="提成比例" width="90" align="right">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ Math.round((row.rate_applied || 0) * 100) }}%
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="周期" width="80">
|
||||||
|
<template #default="{ row }">{{ cycleStageLabel(row.cycle_stage) }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="返利金额" width="110" align="right">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<span class="amount-in">+{{ formatCentWithSymbol(row.rebate_amount_cent) }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<AdminTablePagination
|
||||||
|
v-if="rebateTotal > 0"
|
||||||
|
v-model:current-page="rebatePage"
|
||||||
|
v-model:page-size="rebatePageSize"
|
||||||
|
:total="rebateTotal"
|
||||||
|
:loading="rebateLoading"
|
||||||
|
@page-change="loadRebates"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<el-table
|
||||||
|
v-loading="inviteLoading"
|
||||||
|
size="small"
|
||||||
|
border
|
||||||
|
:data="inviteRows"
|
||||||
|
empty-text="暂无邀请关系"
|
||||||
|
>
|
||||||
|
<el-table-column label="邀请人" min-width="150">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<div>{{ row.inviter_nickname || '-' }}</div>
|
||||||
|
<code class="cell-sub">{{ row.inviter_phone || '-' }}</code>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="被邀请人" min-width="150">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<div>{{ row.invitee_nickname || '-' }}</div>
|
||||||
|
<code class="cell-sub">{{ row.invitee_phone || '-' }}</code>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="使用邀请码" width="110">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag size="small">{{ row.invite_code || '-' }}</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="生效状态" width="140">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag size="small" :type="invitationStatusType(row.status)">
|
||||||
|
{{ invitationStatusLabel(row.status) }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="实名生效时间" width="160">
|
||||||
|
<template #default="{ row }">{{ formatDateTime(row.verified_at) }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="绑定时间" width="160">
|
||||||
|
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<AdminTablePagination
|
||||||
|
v-if="inviteTotal > 0"
|
||||||
|
v-model:current-page="invitePage"
|
||||||
|
v-model:page-size="invitePageSize"
|
||||||
|
:total="inviteTotal"
|
||||||
|
:loading="inviteLoading"
|
||||||
|
@page-change="loadInvitations"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</el-tab-pane>
|
||||||
|
|
||||||
|
<el-tab-pane v-if="canViewPayments" label="支付记录" name="payments">
|
||||||
|
<div class="tab-toolbar">
|
||||||
|
<span>共 {{ paymentTotal }} 笔支付/退款单</span>
|
||||||
|
<el-button text type="primary" size="small" @click="goPayments">
|
||||||
|
前往支付记录页
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
<el-table
|
||||||
|
v-loading="paymentLoading"
|
||||||
|
size="small"
|
||||||
|
border
|
||||||
|
:data="paymentRows"
|
||||||
|
empty-text="暂无支付记录"
|
||||||
|
>
|
||||||
|
<el-table-column label="创建时间" width="160">
|
||||||
|
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column prop="payment_no" label="支付单号" width="190" show-overflow-tooltip />
|
||||||
|
<el-table-column prop="order_no" label="关联订单" width="180" show-overflow-tooltip />
|
||||||
|
<el-table-column label="业务类型" width="120">
|
||||||
|
<template #default="{ row }">{{ paymentBizTypeLabel(row.biz_type) }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="渠道/方式" width="120">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ row.provider || '-' }} · {{ row.pay_way || '-' }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="金额" width="110" align="right">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<span :class="row.biz_type.includes('refund') ? 'amount-out' : 'amount-in'">
|
||||||
|
{{ formatCentWithSymbol(row.amount_cent) }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="状态" width="100">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag size="small" :type="paymentStatusType(row.status)">
|
||||||
|
{{ paymentStatusLabel(row.status) }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="支付时间" width="160">
|
||||||
|
<template #default="{ row }">{{ formatDateTime(row.paid_at) }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<AdminTablePagination
|
||||||
|
v-if="paymentTotal > 0"
|
||||||
|
v-model:current-page="paymentPage"
|
||||||
|
v-model:page-size="paymentPageSize"
|
||||||
|
:total="paymentTotal"
|
||||||
|
:loading="paymentLoading"
|
||||||
|
@page-change="loadPayments"
|
||||||
|
/>
|
||||||
|
</el-tab-pane>
|
||||||
|
</el-tabs>
|
||||||
|
</div>
|
||||||
|
</el-drawer>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped src="./AdminUserDetailDrawer.css"></style>
|
||||||
@@ -401,7 +401,18 @@ function cycleLabel(cycle: string) {
|
|||||||
style="width: 100%; margin-top: 16px"
|
style="width: 100%; margin-top: 16px"
|
||||||
>
|
>
|
||||||
<el-table-column prop="id" label="ID" width="70" />
|
<el-table-column prop="id" label="ID" width="70" />
|
||||||
<el-table-column prop="order_no" label="关联订单号" min-width="160">
|
<el-table-column label="来源" width="80">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag
|
||||||
|
size="small"
|
||||||
|
effect="plain"
|
||||||
|
:type="row.source === 'pickup' ? 'warning' : 'info'"
|
||||||
|
>
|
||||||
|
{{ row.source === 'pickup' ? '提号' : '订单' }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column prop="order_no" label="关联单据号" min-width="160">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<code>{{ row.order_no }}</code>
|
<code>{{ row.order_no }}</code>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
Wallet,
|
Wallet,
|
||||||
} from '@element-plus/icons-vue'
|
} from '@element-plus/icons-vue'
|
||||||
import { computed, onMounted, reactive, ref } from 'vue'
|
import { computed, onMounted, reactive, ref } from 'vue'
|
||||||
|
import { useRoute } from 'vue-router'
|
||||||
|
|
||||||
import { fetchAdminPayments, type AdminPayment } from '@/features/admin/api/adminPayments'
|
import { fetchAdminPayments, type AdminPayment } from '@/features/admin/api/adminPayments'
|
||||||
import { adminPath } from '@/shared/utils/adminPath'
|
import { adminPath } from '@/shared/utils/adminPath'
|
||||||
@@ -45,7 +46,14 @@ const refundAmount = computed(() =>
|
|||||||
.reduce((sum, item) => sum + Number(item.amount_cent || 0), 0)
|
.reduce((sum, item) => sum + Number(item.amount_cent || 0), 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
onMounted(loadPayments)
|
onMounted(() => {
|
||||||
|
// 支持从用户管理「明细」跳转预填用户,直接查看该用户的支付记录。
|
||||||
|
const routeUserID = useRoute().query.user_id
|
||||||
|
if (typeof routeUserID === 'string' && routeUserID.trim()) {
|
||||||
|
filters.user_id = routeUserID.trim()
|
||||||
|
}
|
||||||
|
void loadPayments()
|
||||||
|
})
|
||||||
|
|
||||||
async function loadPayments() {
|
async function loadPayments() {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|||||||
@@ -22,13 +22,21 @@ import { realnameStatusLabel, userStatusLabel } from '@/shared/utils/statusLabel
|
|||||||
import { formatDateTime } from '@/shared/utils/time'
|
import { formatDateTime } from '@/shared/utils/time'
|
||||||
import { useAdminSessionStore } from '@/stores/adminSession'
|
import { useAdminSessionStore } from '@/stores/adminSession'
|
||||||
import AdminTablePagination from '../components/AdminTablePagination.vue'
|
import AdminTablePagination from '../components/AdminTablePagination.vue'
|
||||||
|
import AdminUserDetailDrawer from '../components/AdminUserDetailDrawer.vue'
|
||||||
|
|
||||||
const adminSession = useAdminSessionStore()
|
const adminSession = useAdminSessionStore()
|
||||||
const canAdjustWallet = computed(() => adminSession.hasPermission('user:wallet_adjust'))
|
const canAdjustWallet = computed(() => adminSession.hasPermission('user:wallet_adjust'))
|
||||||
const canAdjustGrowthPoints = computed(() => adminSession.hasPermission('user:growth_points'))
|
const canAdjustGrowthPoints = computed(() => adminSession.hasPermission('user:growth_points'))
|
||||||
|
const canViewUserDetail = computed(
|
||||||
|
() =>
|
||||||
|
adminSession.hasPermission('wallet:view') ||
|
||||||
|
adminSession.hasPermission('order:list') ||
|
||||||
|
adminSession.hasPermission('withdrawal:list')
|
||||||
|
)
|
||||||
|
|
||||||
const submitting = ref(false)
|
const submitting = ref(false)
|
||||||
const activeUser = ref<AdminUserItem | null>(null)
|
const activeUser = ref<AdminUserItem | null>(null)
|
||||||
|
const detailUser = ref<AdminUserItem | null>(null)
|
||||||
const quotaUser = ref<AdminUserItem | null>(null)
|
const quotaUser = ref<AdminUserItem | null>(null)
|
||||||
const realnameUser = ref<AdminUserItem | null>(null)
|
const realnameUser = ref<AdminUserItem | null>(null)
|
||||||
const manualRealnameUser = ref<AdminUserItem | null>(null)
|
const manualRealnameUser = ref<AdminUserItem | null>(null)
|
||||||
@@ -82,6 +90,10 @@ function resetFilters() {
|
|||||||
queryUsers()
|
queryUsers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openUserDetail(row: AdminUserItem) {
|
||||||
|
detailUser.value = row
|
||||||
|
}
|
||||||
|
|
||||||
function openFreeze(row: AdminUserItem) {
|
function openFreeze(row: AdminUserItem) {
|
||||||
activeUser.value = row
|
activeUser.value = row
|
||||||
freezeReason.value = ''
|
freezeReason.value = ''
|
||||||
@@ -412,9 +424,18 @@ function moneyCent(value: number | string | undefined) {
|
|||||||
<el-table-column label="注册时间" min-width="160">
|
<el-table-column label="注册时间" min-width="160">
|
||||||
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
|
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作" width="360" fixed="right" align="right">
|
<el-table-column label="操作" width="400" fixed="right" align="right">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<div class="table-actions">
|
<div class="table-actions">
|
||||||
|
<el-button
|
||||||
|
v-if="canViewUserDetail"
|
||||||
|
text
|
||||||
|
type="primary"
|
||||||
|
size="small"
|
||||||
|
@click="openUserDetail(row)"
|
||||||
|
>
|
||||||
|
明细
|
||||||
|
</el-button>
|
||||||
<el-button
|
<el-button
|
||||||
v-if="canAdjustWallet"
|
v-if="canAdjustWallet"
|
||||||
text
|
text
|
||||||
@@ -752,6 +773,12 @@ function moneyCent(value: number | string | undefined) {
|
|||||||
</el-button>
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
|
<AdminUserDetailDrawer
|
||||||
|
:model-value="!!detailUser"
|
||||||
|
:user="detailUser"
|
||||||
|
@update:model-value="(val: boolean) => !val && (detailUser = null)"
|
||||||
|
/>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
Wallet,
|
Wallet,
|
||||||
} from '@element-plus/icons-vue'
|
} from '@element-plus/icons-vue'
|
||||||
import { computed, onMounted, reactive, ref } from 'vue'
|
import { computed, onMounted, reactive, ref } from 'vue'
|
||||||
|
import { useRoute } from 'vue-router'
|
||||||
|
|
||||||
import { fetchAdminWalletLedger, type AdminWalletLedger } from '@/features/admin/api/adminWallet'
|
import { fetchAdminWalletLedger, type AdminWalletLedger } from '@/features/admin/api/adminWallet'
|
||||||
import { adminPath } from '@/shared/utils/adminPath'
|
import { adminPath } from '@/shared/utils/adminPath'
|
||||||
@@ -32,6 +33,7 @@ const filters = reactive({
|
|||||||
order_id: '',
|
order_id: '',
|
||||||
biz_type: '',
|
biz_type: '',
|
||||||
})
|
})
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
const inAmount = computed(() =>
|
const inAmount = computed(() =>
|
||||||
ledger.value
|
ledger.value
|
||||||
@@ -44,7 +46,14 @@ const outAmount = computed(() =>
|
|||||||
.reduce((sum, item) => sum + Number(item.amount_cent || 0), 0)
|
.reduce((sum, item) => sum + Number(item.amount_cent || 0), 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
onMounted(loadLedger)
|
onMounted(() => {
|
||||||
|
// 支持从用户管理「明细」跳转预填用户,直接查看该用户的资金流水。
|
||||||
|
const routeUserID = route.query.user_id
|
||||||
|
if (typeof routeUserID === 'string' && routeUserID.trim()) {
|
||||||
|
filters.user_id = routeUserID.trim()
|
||||||
|
}
|
||||||
|
void loadLedger()
|
||||||
|
})
|
||||||
|
|
||||||
async function loadLedger() {
|
async function loadLedger() {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import { formatDateMinute } from '@/shared/utils/time'
|
|||||||
import { uploadFile } from '@/shared/api/files'
|
import { uploadFile } from '@/shared/api/files'
|
||||||
import { formatCent } from '@/shared/utils/money'
|
import { formatCent } from '@/shared/utils/money'
|
||||||
import { setPassword } from '@/features/auth/api/auth'
|
import { setPassword } from '@/features/auth/api/auth'
|
||||||
|
import { fetchUserInvitationSummary } from '@/features/invitation/api/invitation'
|
||||||
|
|
||||||
import { useDistributionSiteStore } from '@/stores/distributionSite'
|
import { useDistributionSiteStore } from '@/stores/distributionSite'
|
||||||
|
|
||||||
@@ -24,6 +25,9 @@ const session = useSessionStore()
|
|||||||
const siteStore = useDistributionSiteStore()
|
const siteStore = useDistributionSiteStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
|
/** 邀请返利入口右侧比例文案,取自后台返利配置。 */
|
||||||
|
const inviteRateText = ref('')
|
||||||
const { unreadCount: notificationUnreadCount, unreadLabel: notificationUnreadLabel } =
|
const { unreadCount: notificationUnreadCount, unreadLabel: notificationUnreadLabel } =
|
||||||
useNotificationUnreadCount(route)
|
useNotificationUnreadCount(route)
|
||||||
|
|
||||||
@@ -117,6 +121,7 @@ onMounted(async () => {
|
|||||||
// 保留本地会话展示,避免个人中心因网络短暂异常整页不可用。
|
// 保留本地会话展示,避免个人中心因网络短暂异常整页不可用。
|
||||||
}
|
}
|
||||||
void loadBalance()
|
void loadBalance()
|
||||||
|
void loadInviteRate()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -129,6 +134,17 @@ async function loadBalance() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 邀请返利入口右侧文案取后台实时配置的首月比例,不能写死。
|
||||||
|
async function loadInviteRate() {
|
||||||
|
try {
|
||||||
|
const summary = await fetchUserInvitationSummary()
|
||||||
|
inviteRateText.value = `首月 ${Math.round(summary.first_month_rate * 100)}% 收益`
|
||||||
|
} catch {
|
||||||
|
// 取不到配置时不展示数字,避免与后台实际比例不一致。
|
||||||
|
inviteRateText.value = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function openLedgers() {
|
async function openLedgers() {
|
||||||
showLedgers.value = true
|
showLedgers.value = true
|
||||||
loadingLedgers.value = true
|
loadingLedgers.value = true
|
||||||
@@ -472,7 +488,7 @@ function resolveAvatarURL(url: string | undefined | null) {
|
|||||||
icon="gold-coin-o"
|
icon="gold-coin-o"
|
||||||
is-link
|
is-link
|
||||||
to="/m/invitations"
|
to="/m/invitations"
|
||||||
value="首月60%收益"
|
:value="inviteRateText || '阶梯返利'"
|
||||||
/>
|
/>
|
||||||
<van-cell title="租后须知" icon="info-o" is-link @click="openPostRentalNotice" />
|
<van-cell title="租后须知" icon="info-o" is-link @click="openPostRentalNotice" />
|
||||||
<van-cell title="系统设置" icon="setting-o" is-link @click="showSettings = true" />
|
<van-cell title="系统设置" icon="setting-o" is-link @click="showSettings = true" />
|
||||||
|
|||||||
@@ -143,16 +143,43 @@ function formatRate(rate: number) {
|
|||||||
return `${Math.round(rate * 100)}%`
|
return `${Math.round(rate * 100)}%`
|
||||||
}
|
}
|
||||||
|
|
||||||
function cycleLabel(cycle: string) {
|
/** 配置未加载时用占位符,避免展示与后台配置不符的假比例。 */
|
||||||
|
function formatRateOrPlaceholder(rate: number | undefined | null) {
|
||||||
|
return rate === undefined || rate === null ? '-' : formatRate(rate)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 返利阶段文案:比例取该笔流水实际生效的 rate_applied,不能写死 60/30/15。 */
|
||||||
|
function cycleLabel(cycle: string, rate: number) {
|
||||||
|
const percent = formatRate(rate)
|
||||||
switch (cycle) {
|
switch (cycle) {
|
||||||
case 'first_month':
|
case 'first_month':
|
||||||
return '首月高额 (60%)'
|
return `首月奖励 ${percent}`
|
||||||
case 'second_month':
|
case 'second_month':
|
||||||
return '次月奖励 (30%)'
|
return `次月奖励 ${percent}`
|
||||||
|
case 'subsequent':
|
||||||
|
return `长期奖励 ${percent}`
|
||||||
default:
|
default:
|
||||||
return '长期分成 (15%)'
|
return `返利 ${percent}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 顶部横幅文案按后台实时配置比例生成。 */
|
||||||
|
const heroSubtitle = computed(() => {
|
||||||
|
const current = summary.value
|
||||||
|
if (!current) return '买卖双边分成按实名生效周期阶梯计算 · 多劳多得零门槛'
|
||||||
|
return `买卖双边分成:首月单边 ${formatRate(current.first_month_rate)},次月 ${formatRate(
|
||||||
|
current.second_month_rate
|
||||||
|
)},长期 ${formatRate(current.subsequent_rate)} · 多劳多得零门槛`
|
||||||
|
})
|
||||||
|
|
||||||
|
/** 好友空态文案按首月配置比例生成。 */
|
||||||
|
const emptyFriendsTip = computed(() => {
|
||||||
|
const rate = summary.value?.first_month_rate
|
||||||
|
if (rate === undefined || rate === null) {
|
||||||
|
return '您尚未邀请好友,快去分享专属链接赚取返利吧!'
|
||||||
|
}
|
||||||
|
return `您尚未邀请好友,快去分享专属链接赚取首月 ${formatRate(rate)} 返利吧!`
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -166,7 +193,7 @@ function cycleLabel(cycle: string) {
|
|||||||
</div>
|
</div>
|
||||||
<h1 class="hero-title">邀请好友赚丰厚返利</h1>
|
<h1 class="hero-title">邀请好友赚丰厚返利</h1>
|
||||||
<p class="hero-subtitle">
|
<p class="hero-subtitle">
|
||||||
买卖双边分成:首月单边高达 60%,次月 30%,永久 15% · 多劳多得零门槛
|
{{ heroSubtitle }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -279,21 +306,21 @@ function cycleLabel(cycle: string) {
|
|||||||
<div class="ladder-grid">
|
<div class="ladder-grid">
|
||||||
<div class="ladder-item ladder-first">
|
<div class="ladder-item ladder-first">
|
||||||
<div class="ladder-tag">阶梯一 · 首月</div>
|
<div class="ladder-tag">阶梯一 · 首月</div>
|
||||||
<div class="ladder-rate">{{ formatRate(summary?.first_month_rate || 0.6) }}</div>
|
<div class="ladder-rate">{{ formatRateOrPlaceholder(summary?.first_month_rate) }}</div>
|
||||||
<div class="ladder-time">实名生效 1 ~ 30 天</div>
|
<div class="ladder-time">实名生效 1 ~ 30 天</div>
|
||||||
<div class="ladder-desc">每笔订单单边收益高比例奖励</div>
|
<div class="ladder-desc">每笔订单单边收益高比例奖励</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="ladder-item ladder-second">
|
<div class="ladder-item ladder-second">
|
||||||
<div class="ladder-tag">阶梯二 · 次月</div>
|
<div class="ladder-tag">阶梯二 · 次月</div>
|
||||||
<div class="ladder-rate">{{ formatRate(summary?.second_month_rate || 0.3) }}</div>
|
<div class="ladder-rate">{{ formatRateOrPlaceholder(summary?.second_month_rate) }}</div>
|
||||||
<div class="ladder-time">实名生效 31 ~ 60 天</div>
|
<div class="ladder-time">实名生效 31 ~ 60 天</div>
|
||||||
<div class="ladder-desc">持续稳定鼓励买卖活跃交易</div>
|
<div class="ladder-desc">持续稳定鼓励买卖活跃交易</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="ladder-item ladder-subsequent">
|
<div class="ladder-item ladder-subsequent">
|
||||||
<div class="ladder-tag">阶梯三 · 长期永久</div>
|
<div class="ladder-tag">阶梯三 · 长期永久</div>
|
||||||
<div class="ladder-rate">{{ formatRate(summary?.subsequent_rate || 0.15) }}</div>
|
<div class="ladder-rate">{{ formatRateOrPlaceholder(summary?.subsequent_rate) }}</div>
|
||||||
<div class="ladder-time">实名生效 60 天后永久</div>
|
<div class="ladder-time">实名生效 60 天后永久</div>
|
||||||
<div class="ladder-desc">终身绑定,笔笔成交享分成收益</div>
|
<div class="ladder-desc">终身绑定,笔笔成交享分成收益</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -339,7 +366,7 @@ function cycleLabel(cycle: string) {
|
|||||||
<div v-if="loadingFriends" class="loading-state">加载好友列表中...</div>
|
<div v-if="loadingFriends" class="loading-state">加载好友列表中...</div>
|
||||||
<div v-else-if="friends.length === 0" class="empty-state">
|
<div v-else-if="friends.length === 0" class="empty-state">
|
||||||
<el-icon :size="40" color="#cbd5e1"><User /></el-icon>
|
<el-icon :size="40" color="#cbd5e1"><User /></el-icon>
|
||||||
<p>您尚未邀请好友,快去分享专属链接赚取首月60%返利吧!</p>
|
<p>{{ emptyFriendsTip }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="table-responsive">
|
<div v-else class="table-responsive">
|
||||||
<table class="data-table">
|
<table class="data-table">
|
||||||
@@ -414,7 +441,7 @@ function cycleLabel(cycle: string) {
|
|||||||
</td>
|
</td>
|
||||||
<td>¥{{ formatCent(r.single_side_basis_cent) }}</td>
|
<td>¥{{ formatCent(r.single_side_basis_cent) }}</td>
|
||||||
<td>
|
<td>
|
||||||
<span class="cycle-pill">{{ cycleLabel(r.cycle_stage) }}</span>
|
<span class="cycle-pill">{{ cycleLabel(r.cycle_stage, r.rate_applied) }}</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="rebate-amount">+¥{{ formatCent(r.rebate_amount_cent) }}</td>
|
<td class="rebate-amount">+¥{{ formatCent(r.rebate_amount_cent) }}</td>
|
||||||
<td>{{ r.settled_at ? r.settled_at.slice(0, 16) : '-' }}</td>
|
<td>{{ r.settled_at ? r.settled_at.slice(0, 16) : '-' }}</td>
|
||||||
|
|||||||
@@ -277,6 +277,8 @@ export interface AdminOrderQuery {
|
|||||||
handoff_mode?: string
|
handoff_mode?: string
|
||||||
settlement_status?: string
|
settlement_status?: string
|
||||||
offline_settlement_status?: 'pending' | 'settled' | ''
|
offline_settlement_status?: 'pending' | 'settled' | ''
|
||||||
|
// 精确按用户过滤:命中该用户作为号主或租客参与的订单。
|
||||||
|
user_id?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SubmitCheckoutRequest {
|
interface SubmitCheckoutRequest {
|
||||||
|
|||||||
Reference in New Issue
Block a user