fix: resolve frontend build error and order refund bug, add member price filter

This commit is contained in:
2026-01-07 21:49:04 +08:00
parent 5b45f7d5c4
commit a1de16bc01
18 changed files with 772 additions and 282 deletions

View File

@@ -38,6 +38,37 @@ func (s *content) List(ctx context.Context, filter *content_dto.ContentListFilte
q = q.Where(tbl.IsPinned.Is(*filter.IsPinned))
}
if filter.PriceType != nil && *filter.PriceType != "all" {
if *filter.PriceType == "member" {
q = q.Where(tbl.Visibility.Eq(consts.ContentVisibilityTenantOnly))
} else {
pTbl, pQ := models.ContentPriceQuery.QueryContext(ctx)
var shouldFilter bool
var prices []*models.ContentPrice
if *filter.PriceType == "free" {
shouldFilter = true
prices, _ = pQ.Where(pTbl.PriceAmount.Eq(0)).Select(pTbl.ContentID).Find()
} else if *filter.PriceType == "paid" {
shouldFilter = true
prices, _ = pQ.Where(pTbl.PriceAmount.Gt(0)).Select(pTbl.ContentID).Find()
}
if shouldFilter {
ids := make([]int64, len(prices))
for i, p := range prices {
ids[i] = p.ContentID
}
if len(ids) > 0 {
q = q.Where(tbl.ID.In(ids...))
} else {
q = q.Where(tbl.ID.Eq(-1))
}
}
}
}
// Sort
sort := "latest"
if filter.Sort != nil && *filter.Sort != "" {

View File

@@ -570,7 +570,25 @@ func (s *creator) ListOrders(
if filter.Status != nil && *filter.Status != "" {
q = q.Where(tbl.Status.Eq(consts.OrderStatus(*filter.Status)))
}
// Keyword could match ID or other fields if needed
if filter.Keyword != nil && *filter.Keyword != "" {
k := *filter.Keyword
if id, err := cast.ToInt64E(k); err == nil {
q = q.Where(tbl.ID.Eq(id))
} else {
uTbl, uQ := models.UserQuery.QueryContext(ctx)
users, _ := uQ.Where(uTbl.Nickname.Like("%" + k + "%")).Find()
uids := make([]int64, len(users))
for i, u := range users {
uids[i] = u.ID
}
if len(uids) > 0 {
q = q.Where(tbl.UserID.In(uids...))
} else {
q = q.Where(tbl.ID.Eq(-1)) // Match nothing
}
}
}
list, err := q.Order(tbl.CreatedAt.Desc()).Find()
if err != nil {
@@ -579,11 +597,46 @@ func (s *creator) ListOrders(
var data []creator_dto.Order
for _, o := range list {
// Fetch Buyer Info
u, _ := models.UserQuery.WithContext(ctx).Where(models.UserQuery.ID.Eq(o.UserID)).First()
buyerName := "未知用户"
buyerAvatar := ""
if u != nil {
buyerName = u.Nickname
buyerAvatar = u.Avatar
}
// Fetch Content Info
var title, cover string
item, _ := models.OrderItemQuery.WithContext(ctx).Where(models.OrderItemQuery.OrderID.Eq(o.ID)).First()
if item != nil {
var c models.Content
err := models.ContentQuery.WithContext(ctx).
Where(models.ContentQuery.ID.Eq(item.ContentID)).
UnderlyingDB().
Preload("ContentAssets.Asset").
First(&c).Error
if err == nil {
title = c.Title
for _, ca := range c.ContentAssets {
if ca.Role == consts.ContentAssetRoleCover && ca.Asset != nil {
cover = Common.GetAssetURL(ca.Asset.ObjectKey)
break
}
}
}
}
data = append(data, creator_dto.Order{
ID: cast.ToString(o.ID),
Status: string(o.Status), // Enum conversion
Amount: float64(o.AmountPaid) / 100.0,
CreateTime: o.CreatedAt.Format(time.RFC3339),
ID: cast.ToString(o.ID),
Status: string(o.Status),
Amount: float64(o.AmountPaid) / 100.0,
CreateTime: o.CreatedAt.Format(time.RFC3339),
BuyerName: buyerName,
BuyerAvatar: buyerAvatar,
Title: title,
Cover: cover,
})
}
return data, nil
@@ -803,6 +856,15 @@ func (s *creator) Withdraw(ctx context.Context, userID int64, form *creator_dto.
}
uid := userID
// Validate User Real-name Status
user, err := models.UserQuery.WithContext(ctx).Where(models.UserQuery.ID.Eq(uid)).First()
if err != nil {
return errorx.ErrDatabaseError.WithCause(err)
}
if !user.IsRealNameVerified {
return errorx.ErrPreconditionFailed.WithMsg("请先完成实名认证后再申请提现")
}
amount := int64(form.Amount * 100)
if amount <= 0 {
return errorx.ErrBadRequest.WithMsg("金额无效")

View File

@@ -71,6 +71,16 @@ func (s *notification) MarkRead(ctx context.Context, userID int64, id string) er
return nil
}
func (s *notification) MarkAllRead(ctx context.Context, userID int64) error {
_, err := models.NotificationQuery.WithContext(ctx).
Where(models.NotificationQuery.UserID.Eq(userID), models.NotificationQuery.IsRead.Is(false)).
UpdateSimple(models.NotificationQuery.IsRead.Value(true))
if err != nil {
return errorx.ErrDatabaseError.WithCause(err)
}
return nil
}
func (s *notification) Send(ctx context.Context, userID int64, typ, title, content string) error {
arg := args.NotificationArgs{
UserID: userID,