diff --git a/backend/app/http/v1/dto/creator.go b/backend/app/http/v1/dto/creator.go index e0a833d..4a34058 100644 --- a/backend/app/http/v1/dto/creator.go +++ b/backend/app/http/v1/dto/creator.go @@ -72,6 +72,7 @@ type CreatorContentItem struct { VideoCount int `json:"video_count"` AudioCount int `json:"audio_count"` Status string `json:"status"` + CreatedAt string `json:"created_at"` IsPinned bool `json:"is_pinned"` IsPurchased bool `json:"is_purchased"` } diff --git a/backend/app/services/content.go b/backend/app/services/content.go index ace4592..b4550b8 100644 --- a/backend/app/services/content.go +++ b/backend/app/services/content.go @@ -71,10 +71,24 @@ func (s *content) List(ctx context.Context, filter *content_dto.ContentListFilte return nil, errorx.ErrDatabaseError.WithCause(err) } + // Fetch Prices + priceMap := make(map[int64]float64) + if len(list) > 0 { + ids := make([]int64, len(list)) + for i, item := range list { + ids[i] = item.ID + } + pTbl, pQ := models.ContentPriceQuery.QueryContext(ctx) + prices, _ := pQ.Where(pTbl.ContentID.In(ids...)).Find() + for _, p := range prices { + priceMap[p.ContentID] = float64(p.PriceAmount) / 100.0 + } + } + // Convert to DTO data := make([]content_dto.ContentItem, len(list)) for i, item := range list { - data[i] = s.toContentItemDTO(item) + data[i] = s.toContentItemDTO(item, priceMap[item.ID]) } return &requests.Pager{ @@ -110,6 +124,13 @@ func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dt return nil, errorx.ErrDatabaseError.WithCause(err) } + // Fetch Price + var price float64 + cp, err := models.ContentPriceQuery.WithContext(ctx).Where(models.ContentPriceQuery.ContentID.Eq(cid)).First() + if err == nil { + price = float64(cp.PriceAmount) / 100.0 + } + // Interaction & Access status isLiked := false isFavorited := false @@ -159,7 +180,7 @@ func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dt } detail := &content_dto.ContentDetail{ - ContentItem: s.toContentItemDTO(&item), + ContentItem: s.toContentItemDTO(&item, price), Description: item.Description, Body: item.Body, MediaUrls: s.toMediaURLs(accessibleAssets), @@ -335,7 +356,7 @@ func (s *content) GetLibrary(ctx context.Context, userID int64) ([]user_dto.Cont var data []user_dto.ContentItem for _, item := range list { - dto := s.toContentItemDTO(item) + dto := s.toContentItemDTO(item, 0) dto.IsPurchased = true data = append(data, dto) } @@ -420,7 +441,7 @@ func (s *content) ListTopics(ctx context.Context) ([]content_dto.Topic, error) { // Helpers -func (s *content) toContentItemDTO(item *models.Content) content_dto.ContentItem { +func (s *content) toContentItemDTO(item *models.Content, price float64) content_dto.ContentItem { dto := content_dto.ContentItem{ ID: cast.ToString(item.ID), Title: item.Title, @@ -428,6 +449,7 @@ func (s *content) toContentItemDTO(item *models.Content) content_dto.ContentItem AuthorID: cast.ToString(item.UserID), Views: int(item.Views), Likes: int(item.Likes), + Price: price, } if item.Author != nil { dto.AuthorName = item.Author.Nickname @@ -600,7 +622,7 @@ func (s *content) getInteractList(ctx context.Context, userID int64, typ string) var data []user_dto.ContentItem for _, item := range list { - data = append(data, s.toContentItemDTO(item)) + data = append(data, s.toContentItemDTO(item, 0)) } return data, nil } diff --git a/backend/app/services/creator.go b/backend/app/services/creator.go index e496ca7..f32c412 100644 --- a/backend/app/services/creator.go +++ b/backend/app/services/creator.go @@ -138,7 +138,7 @@ func (s *creator) ListContents( } var list []*models.Content - err = q.Order(tbl.CreatedAt.Desc()). + err = q.Order(tbl.ID.Desc()). UnderlyingDB(). Preload("ContentAssets"). Preload("ContentAssets.Asset"). @@ -148,13 +148,14 @@ func (s *creator) ListContents( } // Fetch Prices - ids := make([]int64, len(list)) - for i, item := range list { - ids[i] = item.ID - } priceMap := make(map[int64]float64) - if len(ids) > 0 { - prices, _ := models.ContentPriceQuery.WithContext(ctx).Where(models.ContentPriceQuery.ContentID.In(ids...)).Find() + if len(list) > 0 { + ids := make([]int64, len(list)) + for i, item := range list { + ids[i] = item.ID + } + pTbl, pQ := models.ContentPriceQuery.QueryContext(ctx) + prices, _ := pQ.Where(pTbl.ContentID.In(ids...)).Find() for _, p := range prices { priceMap[p.ContentID] = float64(p.PriceAmount) / 100.0 } @@ -207,6 +208,7 @@ func (s *creator) ListContents( VideoCount: videoCount, AudioCount: audioCount, Status: string(item.Status), + CreatedAt: item.CreatedAt.Format("2006-01-02 15:04"), IsPinned: item.IsPinned, IsPurchased: false, }) diff --git a/frontend/portal/src/views/creator/ContentsView.vue b/frontend/portal/src/views/creator/ContentsView.vue index aa273b7..fc8f764 100644 --- a/frontend/portal/src/views/creator/ContentsView.vue +++ b/frontend/portal/src/views/creator/ContentsView.vue @@ -61,73 +61,96 @@
-
-
- 置顶 - [{{ getGenreLabel(item.genre) }}] - [{{ item.key }}] -

- {{ item.title }}

-
- -
- - 封禁 - - - {{ statusStyle(item.status).label }} - -
-
- -
- ¥ {{ item.price.toFixed(2) }} - 免费 - - - {{ item.image_count }} - - - {{ item.video_count }} - - - {{ item.audio_count }} - - - {{ item.views }} - {{ item.likes }} - -
-
- - -
- - - - -
+
+
+ 置顶 + {{ + getGenreLabel(item.genre) }} + {{ + item.key }} +

+ {{ item.title }}

+
+ +
+ + 封禁 + + + {{ statusStyle(item.status).label }} + +
+
+ +
+ + {{ item.created_at }} + + +
+ ¥{{ item.price.toFixed(2) }} + 免费 +
+ +
+ + {{ item.image_count }} + + + {{ item.video_count }} + + + {{ item.audio_count }} + +
+ +
+ {{ item.views }} + {{ item.likes }} +
+
+
+ + +
+ + + + + +