feat(admin): 用户管理新增用户明细抽屉,聚合资金与交易全链路数据
- 用户管理操作列新增「明细」入口,抽屉按权限提供 5 个 Tab:钱包流水、订单记录、提现记录、邀请返利、支付记录 - 后端:后台订单列表新增 user_id 精确过滤(owner_id / renter_id),邀请关系与返利流水新增 inviter_id / invitee_id 过滤 - 修复:返利流水的「被邀请人手机号」筛选此前后端未实现,一直无效 - 资金流水页、支付记录页支持 ?user_id= 预填,可从明细直达 - 顺带将 invitation/dto.go、repository.go 中两处既有缩进错位按 gofmt 规整
This commit is contained in:
@@ -12,33 +12,33 @@ type InviteCodeInfoDTO struct {
|
||||
|
||||
// UserInvitationSummaryDTO 个人中心邀请返利概览
|
||||
type UserInvitationSummaryDTO struct {
|
||||
HasInviteCode bool `json:"has_invite_code"`
|
||||
InviteCode string `json:"invite_code"`
|
||||
InviteLink string `json:"invite_link"`
|
||||
IsRealnameVerified bool `json:"is_realname_verified"`
|
||||
TotalInvitedCount int64 `json:"total_invited_count"`
|
||||
ActiveInvitedCount int64 `json:"active_invited_count"`
|
||||
PendingInvitedCount int64 `json:"pending_invited_count"`
|
||||
TotalRebateCent int64 `json:"total_rebate_cent"`
|
||||
CurrentMonthEstCent int64 `json:"current_month_est_cent"`
|
||||
FirstMonthRate float64 `json:"first_month_rate"`
|
||||
SecondMonthRate float64 `json:"second_month_rate"`
|
||||
SubsequentRate float64 `json:"subsequent_rate"`
|
||||
HasInviteCode bool `json:"has_invite_code"`
|
||||
InviteCode string `json:"invite_code"`
|
||||
InviteLink string `json:"invite_link"`
|
||||
IsRealnameVerified bool `json:"is_realname_verified"`
|
||||
TotalInvitedCount int64 `json:"total_invited_count"`
|
||||
ActiveInvitedCount int64 `json:"active_invited_count"`
|
||||
PendingInvitedCount int64 `json:"pending_invited_count"`
|
||||
TotalRebateCent int64 `json:"total_rebate_cent"`
|
||||
CurrentMonthEstCent int64 `json:"current_month_est_cent"`
|
||||
FirstMonthRate float64 `json:"first_month_rate"`
|
||||
SecondMonthRate float64 `json:"second_month_rate"`
|
||||
SubsequentRate float64 `json:"subsequent_rate"`
|
||||
}
|
||||
|
||||
// InvitedUserRecordDTO 邀请好友记录
|
||||
type InvitedUserRecordDTO struct {
|
||||
ID uint64 `json:"id"`
|
||||
InviteeID uint64 `json:"invitee_id"`
|
||||
MaskedPhone string `json:"masked_phone"`
|
||||
Nickname string `json:"nickname"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
Status string `json:"status"` // pending=待实名, active=已实名生效
|
||||
CycleStage string `json:"cycle_stage"` // first_month, second_month, subsequent, unverified
|
||||
DaysSinceVerified int `json:"days_since_verified"`
|
||||
VerifiedAt *time.Time `json:"verified_at,omitempty"`
|
||||
RegisteredAt time.Time `json:"registered_at"`
|
||||
TotalEarnedFromCent int64 `json:"total_earned_from_cent"`
|
||||
ID uint64 `json:"id"`
|
||||
InviteeID uint64 `json:"invitee_id"`
|
||||
MaskedPhone string `json:"masked_phone"`
|
||||
Nickname string `json:"nickname"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
Status string `json:"status"` // pending=待实名, active=已实名生效
|
||||
CycleStage string `json:"cycle_stage"` // first_month, second_month, subsequent, unverified
|
||||
DaysSinceVerified int `json:"days_since_verified"`
|
||||
VerifiedAt *time.Time `json:"verified_at,omitempty"`
|
||||
RegisteredAt time.Time `json:"registered_at"`
|
||||
TotalEarnedFromCent int64 `json:"total_earned_from_cent"`
|
||||
}
|
||||
|
||||
// RebateLedgerDTO 返利明细记录
|
||||
@@ -76,20 +76,27 @@ type UpdateConfigRequest struct {
|
||||
|
||||
// AdminInvitationQuery 后台查询邀请关系
|
||||
type AdminInvitationQuery struct {
|
||||
Page int `form:"page,default=1"`
|
||||
PageSize int `form:"page_size,default=20"`
|
||||
InviterPhone string `form:"inviter_phone"`
|
||||
InviteePhone string `form:"invitee_phone"`
|
||||
Status string `form:"status"`
|
||||
Page int `form:"page,default=1"`
|
||||
PageSize int `form:"page_size,default=20"`
|
||||
InviterPhone string `form:"inviter_phone"`
|
||||
InviteePhone string `form:"invitee_phone"`
|
||||
Status string `form:"status"`
|
||||
DistributionSiteID *uint64 `form:"distribution_site_id"`
|
||||
// InviterID / InviteeID 供用户管理「明细」按用户精确筛选。
|
||||
InviterID uint64 `form:"inviter_id"`
|
||||
InviteeID uint64 `form:"invitee_id"`
|
||||
}
|
||||
|
||||
// AdminRebateLedgerQuery 后台查询返利明细
|
||||
type AdminRebateLedgerQuery struct {
|
||||
Page int `form:"page,default=1"`
|
||||
PageSize int `form:"page_size,default=20"`
|
||||
OrderNo string `form:"order_no"`
|
||||
InviterPhone string `form:"inviter_phone"`
|
||||
TradeRole string `form:"trade_role"`
|
||||
Page int `form:"page,default=1"`
|
||||
PageSize int `form:"page_size,default=20"`
|
||||
OrderNo string `form:"order_no"`
|
||||
InviterPhone string `form:"inviter_phone"`
|
||||
InviteePhone string `form:"invitee_phone"`
|
||||
TradeRole string `form:"trade_role"`
|
||||
DistributionSiteID *uint64 `form:"distribution_site_id"`
|
||||
// InviterID / InviteeID 供用户管理「明细」按用户精确筛选。
|
||||
InviterID uint64 `form:"inviter_id"`
|
||||
InviteeID uint64 `form:"invitee_id"`
|
||||
}
|
||||
|
||||
@@ -572,18 +572,18 @@ func (r *Repository) GetUserSummary(ctx context.Context, userID uint64, siteID u
|
||||
Select("COALESCE(SUM(rebate_amount_cent), 0)").Scan(¤tMonthEstCent).Error
|
||||
|
||||
return &UserInvitationSummaryDTO{
|
||||
HasInviteCode: hasCode,
|
||||
InviteCode: code,
|
||||
InviteLink: fmt.Sprintf("/i/%s", code),
|
||||
IsRealnameVerified: user.RealnameStatus == "verified",
|
||||
TotalInvitedCount: totalCount,
|
||||
ActiveInvitedCount: activeCount,
|
||||
PendingInvitedCount: pendingCount,
|
||||
TotalRebateCent: totalRebateCent,
|
||||
CurrentMonthEstCent: currentMonthEstCent,
|
||||
FirstMonthRate: firstRate,
|
||||
SecondMonthRate: secondRate,
|
||||
SubsequentRate: subsequentRate,
|
||||
HasInviteCode: hasCode,
|
||||
InviteCode: code,
|
||||
InviteLink: fmt.Sprintf("/i/%s", code),
|
||||
IsRealnameVerified: user.RealnameStatus == "verified",
|
||||
TotalInvitedCount: totalCount,
|
||||
ActiveInvitedCount: activeCount,
|
||||
PendingInvitedCount: pendingCount,
|
||||
TotalRebateCent: totalRebateCent,
|
||||
CurrentMonthEstCent: currentMonthEstCent,
|
||||
FirstMonthRate: firstRate,
|
||||
SecondMonthRate: secondRate,
|
||||
SubsequentRate: subsequentRate,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -734,6 +734,12 @@ func (r *Repository) ListAdminInvitations(ctx context.Context, query AdminInvita
|
||||
if query.DistributionSiteID != nil {
|
||||
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
|
||||
if err := db.Count(&total).Error; err != nil {
|
||||
@@ -804,12 +810,21 @@ func (r *Repository) ListAdminRebateLedgers(ctx context.Context, query AdminReba
|
||||
if p := strings.TrimSpace(query.InviterPhone); 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 != "" {
|
||||
db = db.Where("irl.trade_role = ?", t)
|
||||
}
|
||||
if query.DistributionSiteID != nil {
|
||||
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
|
||||
if err := db.Count(&total).Error; err != nil {
|
||||
|
||||
@@ -217,6 +217,8 @@ type AdminOrderQuery struct {
|
||||
HandoffMode string
|
||||
SettlementStatus string
|
||||
OfflineSettlementStatus string
|
||||
// UserID 精确匹配该用户作为号主或租客参与的订单(用户管理「明细」入口使用)。
|
||||
UserID uint64
|
||||
}
|
||||
|
||||
type AuditMeta = auditlog.Meta
|
||||
|
||||
@@ -54,6 +54,7 @@ func parsePagination(c *gin.Context) (int, int) {
|
||||
|
||||
func parseAdminOrderQuery(c *gin.Context) AdminOrderQuery {
|
||||
page, pageSize := parsePagination(c)
|
||||
userID, _ := strconv.ParseUint(strings.TrimSpace(c.Query("user_id")), 10, 64)
|
||||
return AdminOrderQuery{
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
@@ -63,5 +64,6 @@ func parseAdminOrderQuery(c *gin.Context) AdminOrderQuery {
|
||||
HandoffMode: strings.TrimSpace(c.Query("handoff_mode")),
|
||||
SettlementStatus: strings.TrimSpace(c.Query("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 {
|
||||
if query.UserID > 0 {
|
||||
// 精确命中该用户作为号主或租客参与的订单,避免与 keyword 的数字 ID 模糊命中混淆。
|
||||
db = db.Where("(o.owner_id = ? OR o.renter_id = ?)", query.UserID, query.UserID)
|
||||
}
|
||||
if query.Status != "" {
|
||||
db = db.Where("o.status = ?", query.Status)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user