From 4b32e64d35ca6c644477731fc0dc3ce79fdd63ff Mon Sep 17 00:00:00 2001 From: Rogee Date: Sun, 4 Jan 2026 19:56:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E4=B8=BA=E5=8F=AF=E9=80=89=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E7=8A=B6=E6=80=81=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=8F=8A=E5=AA=92=E4=BD=93=E8=AE=A1=E6=95=B0=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/http/v1/dto/creator.go | 8 +- backend/app/services/creator.go | 88 ++++++++++++++----- .../portal/src/views/creator/ContentsView.vue | 36 ++++++-- 3 files changed, 106 insertions(+), 26 deletions(-) diff --git a/backend/app/http/v1/dto/creator.go b/backend/app/http/v1/dto/creator.go index 226170f..bc474c3 100644 --- a/backend/app/http/v1/dto/creator.go +++ b/backend/app/http/v1/dto/creator.go @@ -38,7 +38,8 @@ type ContentUpdateForm struct { Title string `json:"title"` Genre string `json:"genre"` Key string `json:"key"` - Price float64 `json:"price"` + Price *float64 `json:"price"` + Status string `json:"status"` CoverIDs []string `json:"cover_ids"` MediaIDs []string `json:"media_ids"` } @@ -64,6 +65,11 @@ type CreatorContentItem struct { Price float64 `json:"price"` Views int `json:"views"` Likes int `json:"likes"` + Cover string `json:"cover"` + ImageCount int `json:"image_count"` + VideoCount int `json:"video_count"` + AudioCount int `json:"audio_count"` + Status string `json:"status"` IsPurchased bool `json:"is_purchased"` } diff --git a/backend/app/services/creator.go b/backend/app/services/creator.go index bc494f4..27d0351 100644 --- a/backend/app/services/creator.go +++ b/backend/app/services/creator.go @@ -117,7 +117,12 @@ func (s *creator) ListContents( q = q.Where(tbl.Title.Like("%" + *filter.Keyword + "%")) } - list, err := q.Order(tbl.CreatedAt.Desc()).Find() + var list []*models.Content + err = q.Order(tbl.CreatedAt.Desc()). + UnderlyingDB(). + Preload("ContentAssets"). + Preload("ContentAssets.Asset"). + Find(&list).Error if err != nil { return nil, errorx.ErrDatabaseError.WithCause(err) } @@ -137,6 +142,38 @@ func (s *creator) ListContents( var data []creator_dto.CreatorContentItem for _, item := range list { + var imageCount, videoCount, audioCount int + var cover string + var firstImage string + + for _, ca := range item.ContentAssets { + if ca.Asset == nil { + continue + } + + // Count logic + switch ca.Asset.Type { + case consts.MediaAssetTypeImage: + imageCount++ + if firstImage == "" { + firstImage = Common.GetAssetURL(ca.Asset.ObjectKey) + } + case consts.MediaAssetTypeVideo: + videoCount++ + case consts.MediaAssetTypeAudio: + audioCount++ + } + + // Cover logic + if ca.Role == consts.ContentAssetRoleCover && cover == "" { + cover = Common.GetAssetURL(ca.Asset.ObjectKey) + } + } + + if cover == "" { + cover = firstImage + } + data = append(data, creator_dto.CreatorContentItem{ ID: cast.ToString(item.ID), Title: item.Title, @@ -145,6 +182,11 @@ func (s *creator) ListContents( Price: priceMap[item.ID], Views: int(item.Views), Likes: int(item.Likes), + Cover: cover, + ImageCount: imageCount, + VideoCount: videoCount, + AudioCount: audioCount, + Status: string(item.Status), IsPurchased: false, }) } @@ -239,34 +281,40 @@ func (s *creator) UpdateContent( } // 2. Update Content - _, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).Updates(&models.Content{ + contentUpdates := &models.Content{ Title: form.Title, Genre: form.Genre, Key: form.Key, - }) + } + if form.Status != "" { + contentUpdates.Status = consts.ContentStatus(form.Status) + } + _, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).Updates(contentUpdates) if err != nil { return err } // 3. Update Price // Check if price exists - count, _ := tx.ContentPrice.WithContext(ctx).Where(tx.ContentPrice.ContentID.Eq(cid)).Count() - newPrice := int64(form.Price * 100) - if count > 0 { - _, err = tx.ContentPrice.WithContext(ctx). - Where(tx.ContentPrice.ContentID.Eq(cid)). - UpdateSimple(tx.ContentPrice.PriceAmount.Value(newPrice)) - } else { - err = tx.ContentPrice.WithContext(ctx).Create(&models.ContentPrice{ - TenantID: tid, - UserID: c.UserID, - ContentID: cid, - PriceAmount: newPrice, - Currency: consts.CurrencyCNY, - }) - } - if err != nil { - return err + if form.Price != nil { + count, _ := tx.ContentPrice.WithContext(ctx).Where(tx.ContentPrice.ContentID.Eq(cid)).Count() + newPrice := int64(*form.Price * 100) + if count > 0 { + _, err = tx.ContentPrice.WithContext(ctx). + Where(tx.ContentPrice.ContentID.Eq(cid)). + UpdateSimple(tx.ContentPrice.PriceAmount.Value(newPrice)) + } else { + err = tx.ContentPrice.WithContext(ctx).Create(&models.ContentPrice{ + TenantID: tid, + UserID: c.UserID, + ContentID: cid, + PriceAmount: newPrice, + Currency: consts.CurrencyCNY, + }) + } + if err != nil { + return err + } } // 4. Update Assets (Full replacement strategy) diff --git a/frontend/portal/src/views/creator/ContentsView.vue b/frontend/portal/src/views/creator/ContentsView.vue index 71e03c8..804999d 100644 --- a/frontend/portal/src/views/creator/ContentsView.vue +++ b/frontend/portal/src/views/creator/ContentsView.vue @@ -77,10 +77,21 @@
- ¥ {{ item.price }} + ¥ {{ item.price.toFixed(2) }} 免费 - {{ item.views }} - {{ item.likes }} + + + {{ item.image_count }} + + + {{ item.video_count }} + + + {{ item.audio_count }} + + + {{ item.views }} + {{ item.likes }}
@@ -91,10 +102,12 @@ @click="$router.push(`/creator/contents/${item.id}`)"> 编辑 @@ -108,10 +121,12 @@