fix: resolve frontend build error and order refund bug, add member price filter
This commit is contained in:
@@ -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("金额无效")
|
||||
|
||||
Reference in New Issue
Block a user