Initial commit

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 13:57:10 +08:00
co-authored by Claude Opus 5
commit 8679200f41
1897 changed files with 257900 additions and 0 deletions
+213
View File
@@ -0,0 +1,213 @@
package mediamod
import (
"91porn-server/models/commod"
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type ObjectID = primitive.ObjectID
type AppMediaBase struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` // 文档id
SortCode int `json:"sortCode" bson:"sortCode"` // 排序
Status int `json:"status" bson:"status"` // 状态
Title string `json:"title" bson:"title"` // 标题
HorizontalCover string `json:"horizontalCover" bson:"horizontalCover"` // 横版封面
VerticalCover string `json:"verticalCover" bson:"verticalCover"` // 竖版封面
Tags []primitive.ObjectID `json:"tags" bson:"tags"` // 标签
TagDetails []TagDetail `json:"tagDetails" bson:"tagDetails"` // 标签对象
Summary string `json:"summary" bson:"summary"` // 简介
TotalEpisode int `json:"totalEpisode" bson:"totalEpisode"` // 总集数
CurrentEpisode int `json:"currentEpisode" bson:"currentEpisode"` // 当前更新的集数
FreeEpisode int `json:"freeEpisode" bson:"freeEpisode"` // 免费集数
UpdateStatus int `json:"updateStatus" bson:"updateStatus"` // 更新状态
MediaType string `json:"mediaType" bson:"mediaType"` // 媒体类型 "video":动漫,"image":漫画 "text":小说
MediaSubType MediaSubType `json:"mediaSubType" bson:"mediaSubType"` // 子类型 ,暂时只有小说使用 0-默认文本小说 1-有声小说
DefaultContent DefaultContent `json:"defaultContent" bson:"defaultContent"` // 默认展示内容,暂时只有漫画需要
Kind int `json:"kind" bson:"kind"` // 种类(1、哩番,2、3D,3、同人动画,4、单行本,5、连载漫画,6、韩漫 )
Style int `json:"style" bson:"style"` // 展示背景颜色 0-随机 1~5对应ui五种颜色
PermissionIconHide bool `json:"permissionIconHide" bson:"permissionIconHide"` // 售卖类型标识隐藏
Permission int `json:"permission" bson:"permission"` // 收听权限 0:会员 1:金币购买 2:免费
Price int64 `json:"price" bson:"price"` // 价格(整部购买的类型 小说 cos 写真)
ContentsPrice int64 `json:"contentsPrice" bson:"contentsPrice"` // 所有子集加起来的价格
Direction int64 `json:"direction" bson:"direction"` // 排版方向 0横 1竖(冗余字段)
//SellType int `json:"sellType" bson:"sellType"` // 商品售卖类型(0单集售卖 1整部售卖)
FreeTime int `json:"freeTime" bson:"freeTime"` // 免费试看时长 单位 s
MID string `json:"mId" bson:"mId"` // 模块ID
ModuleName string `json:"moduleName" bson:"moduleName"` // 模块名称
SectionName string `json:"sectionName" bson:"sectionName"` // 专题名称
SID primitive.ObjectID `json:"sId" bson:"sId"` // 专题ID
SectionSort int `json:"sectionSort" bson:"sectionSort"` // 专题排序
CountComment int64 `json:"countComment" bson:"countComment"` // 评论数
CountPurchases int64 `json:"countPurchases" bson:"countPurchases"` // 购买数
HasFollow bool `json:"hasFollow" bson:"hasFollow"` // 是否关注
CountBrowse int64 `json:"countBrowse" bson:"countBrowse"` // 浏览数
CountCollect int64 `json:"countCollect" bson:"countCollect"` // 收藏数
CountLike int64 `json:"countLike" bson:"countLike"` // 喜欢数
CountDisLike int64 `json:"countDisLike" bson:"countDisLike"` // 不喜欢数
CountView int64 `json:"countView" bson:"countView"` // 展现数
CountShare int64 `json:"countShare" bson:"countShare"` // 分享数
MediaStatus MediaStatus `json:"mediaStatus" bson:"mediaStatus"` // 媒体状态
Number int64 `json:"number" bson:"number"` // 编号
Author string `json:"author"` // 作者
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 文档创建时间
UpdateTime time.Time `json:"updateTime" bson:"updateTime"` // 文档更新时间
LatestPublishedAt time.Time `json:"latestPublishedAt" bson:"latestPublishedAt"` // 最新上架或子集更新时间
LsjId string `json:"lsjId" bson:"lsjId"` // 老司机ID
HasDramaCard bool `json:"hasDramaCard" bson:"hasDramaCard"` // 是否持有有效短剧权益卡
}
// MediaStatus 媒体状态
type MediaStatus struct {
HasPaid bool `json:"hasPaid" bson:"hasPaid"` // 已支付(如果是父集,表示整本购买)
HasCollected bool `json:"hasCollected" bson:"hasCollected"` // 已收藏
HasLiked bool `json:"hasLiked" bson:"hasLiked"` // 已点赞
}
type MediaContent struct {
ID primitive.ObjectID `json:"id"` // 文档id
MediaID primitive.ObjectID `json:"mediaId"` // 媒体资源ID
EpisodeNumber int `json:"episodeNumber"` // 第几集
ListenPermission int `json:"listenPermission"` // 收听权限 0:会员 1:金币购买 2:免费
Price int64 `json:"price"` // 购买价格
Name string `json:"name"` // 章节名
Text string `json:"text"` // 内容(小说专用)
Md5 string `json:"md5"` // 媒体md5
VideoUrl string `json:"videoUrl"` // 视频地址
AudioUrl string `json:"audioUrl" bson:"audioUrl"` // 有声小说地址
UrlSet []string `json:"urlSet"` // 地址集(多个资源地址用 例如漫画)
Height int `json:"height"` // 高
Weight int `json:"weight"` // 宽
CountComment int64 `json:"countComment" bson:"countComment"` // 评论数
CountPurchases int64 `json:"countPurchases" bson:"countPurchases"` // 购买数
CountBrowse int64 `json:"countBrowse" bson:"countBrowse"` // 浏览数
CountCollect int64 `json:"countCollect" bson:"countCollect"` // 收藏数
CountLike int64 `json:"countLike" bson:"countLike"` // 喜欢数
CountDisLike int64 `json:"countDisLike" bson:"countDisLike"` // 不喜欢数
MediaSize int64 `json:"mediaSize"` // 资源大小
PlayTime uint `json:"playTime"` // 影片长度
Ratio float64 `json:"ratio"` // 宽高比
MediaStatus MediaStatus `json:"mediaStatus" bson:"mediaStatus"` // 媒体状态
CreatedAt time.Time `json:"createdAt"` // 文档创建时间
UpdateTime time.Time `json:"updateTime"` // 文档更新时间
}
type AppLibrary struct {
Key string `json:"key" bson:"key"` // 健值
Name string `json:"name" bson:"name"` // 健名称
Kind []KindInfo `json:"kind" bson:"kind"` // 种类 (1、哩番,2、3D,3、同人动画,4、单行本,5、连载漫画,6、韩漫 )
}
type KindInfo struct {
Key string `json:"key" bson:"key"` // 健值
Name string `json:"name" bson:"name"` // 健名称
Cover string `json:"cover" bson:"cover"` // 封面
Dimension []DimensionInfo `json:"dimension" bson:"dimension"` // 纬度
}
type DimensionInfo struct {
Key string `json:"key" bson:"key"` // 健值
Name string `json:"name" bson:"name"` // 健名称
Tag []TagInfo `json:"tag" bson:"tag"` // 标签
}
type TagInfo struct {
ID string `json:"id" bson:"id"` // 标签ID
Name string `json:"name" bson:"name"` // 标签名称
}
type AppLibraryReq struct {
MediaType string `json:"mediaType" bson:"mediaType"` // 媒体类型
TagIds []string `json:"tagIds" bson:"tagIds"` // 标签ID
SortType int `json:"sortType" bson:"sortType"` // 排序 1、精选,2、最新,3、最热,4、最多收藏
commod.Page
}
type AppElasticSearchLibraryResponse struct {
List []*AppMediaBase `json:"list"` // list
HasNext bool `json:"hasNext"` // hasNext
}
func (p AppLibraryReq) Filter(ids []primitive.ObjectID) bson.M {
filter := bson.M{}
filter["_id"] = bson.M{"$in": ids}
return filter
}
func AppLibrarySortField(sortType int) string {
switch sortType {
case 1:
return "choiceSort"
case 3:
return "countLike"
case 4:
return "countCollect"
default:
return "updateTime"
}
}
func (p AppLibraryReq) Options() bson.D {
if p.MediaType == MediaTypeDrama && p.SortType == 1 {
return bson.D{
{Key: "sortCode", Value: -1},
{Key: "createdAt", Value: -1},
{Key: "_id", Value: -1},
}
}
return bson.D{{Key: AppLibrarySortField(p.SortType), Value: -1}}
}
type AppSearchReq struct {
KeyWord string `form:"keyword" json:"keyword"` // 搜索关键词
TagName string `form:"tagName" json:"tagName"` // 搜索标签名
Kind int `form:"kind" json:"kind"` // 种类 1、动漫 2、漫画 3、小说 4、短剧
commod.Page
SortType int `json:"sortType" form:"sortType"` // 1-最新上架 2-最多观看
}
type AppElasticSearchResponse struct {
List []*AppMediaBase `json:"list"` // list
TagID string `json:"tagID"` // 帖子搜索时附带的tagID
TagMediaList []*AppMediaBase `json:"tagMediaList"` // 搜索时tag相关的帖子
HasNext bool `json:"hasNext"` // hasNext
}
func (p AppSearchReq) Options() bson.D {
if p.Kind == 4 {
if p.SortType == 2 {
return bson.D{{Key: "countBrowse", Value: -1}, {Key: "latestPublishedAt", Value: -1}, {Key: "_id", Value: -1}}
}
return bson.D{{Key: "latestPublishedAt", Value: -1}, {Key: "createdAt", Value: -1}, {Key: "_id", Value: -1}}
}
return bson.D{{Key: "createdAt", Value: -1}}
}
type AppLibraryV2Req struct {
MediaType string `json:"mediaType" form:"mediaType"` // 动漫类型 video-动漫 image-漫画 text-小说
}
type AppLibraryV2Resp struct {
MediaType []AppLibraryItem `json:"mediaType"`
SortType []AppLibraryItem `json:"sortType"` // 1-最多播放 2-收藏最多 3-最新上架
TagName []AppLibraryItem `json:"tagName"` // 标签名
PayType []AppLibraryItem `json:"payType"` // 付费类型
}
type AppLibraryItem struct {
Name string `json:"name"`
Value string `json:"value"`
}
type AppLibrarySearchV2Req struct {
MediaType string `json:"mediaType" form:"mediaType"` // 媒体类型
SortType string `json:"sortType" form:"sortType"` // 排序类型
TagName string `json:"tagName" form:"tagName"` // 标签名
PayType string `json:"payType" form:"payType"` // 付费类型
commod.Page
}
+154
View File
@@ -0,0 +1,154 @@
package mediamod
import (
"fmt"
"91porn-server/common/elastic"
"91porn-server/common/log"
"91porn-server/models"
)
var es *elastic.Client
const ESTable = models.ESMediaTable
func InitESIndex() {
es = elastic.Init()
var setting = elastic.M{
"settings": elastic.M{
"number_of_shards": elastic.NumberOfShards,
"number_of_replicas": elastic.NumberOfReplicas,
"analysis": elastic.M{
"analyzer": elastic.M{
"ik": elastic.M{
"tokenizer": elastic.AnalyzerIkSmart,
},
},
},
},
"mappings": elastic.M{
"properties": elastic.M{
"title": elastic.M{
"type": "text",
"analyzer": elastic.AnalyzerIkSmart,
"search_analyzer": elastic.AnalyzerIkSmart,
},
"tagsName": elastic.M{
"type": "text",
"analyzer": elastic.AnalyzerIkSmart,
"search_analyzer": elastic.AnalyzerIkSmart,
},
},
},
}
if err := es.CreateIndices(ESTable, setting); err != nil {
panic(fmt.Sprintf("%s index indeices err ==>[%+v]", ESTable, err))
}
}
// Search 根据关键字搜索
func Search(keywords string, from int64, size int64) (data []ESMediaSource, err error) {
es = elastic.Init()
query := elastic.M{
"query": elastic.M{
"bool": elastic.M{
"must": elastic.A{
{"multi_match": elastic.M{
"query": keywords,
"fields": []string{"title"}},
},
{"terms": elastic.M{"status": []int{1}}},
{"range": elastic.M{"playTime": elastic.M{"lt": 300}}},
},
},
},
"sort": elastic.A{{"hot": elastic.M{"order": "desc"}}},
"from": from,
"size": size,
}
if err = es.Search(ESTable, &data, query); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Search", table, "CommonSearch", err),
log.Any("keywords", keywords),
log.Any("from", from),
log.Any("size", size))
return
}
return
}
func SearchWithTotal(keywords string, from int64, size int64) (data ESVideoSourceWithTotal, err error) {
es = elastic.Init()
query := elastic.M{
"query": elastic.M{
"bool": elastic.M{
"must": elastic.A{
{"multi_match": elastic.M{
"query": keywords,
"fields": []string{"title"}},
},
{"terms": elastic.M{"status": []int{1, 3}}},
},
},
},
"sort": elastic.A{{"hot": elastic.M{"order": "desc"}}},
"from": from,
"size": size,
}
if err = es.SearchWithTotal(ESTable, &data, query); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Search", table, "CommonSearch", err),
log.Any("keywords", keywords),
log.Any("from", from),
log.Any("size", size))
return
}
return
}
// DirectSearch 用户根据关键字搜索
func DirectSearch(keywords string, vidType string, from int64, size int64) (data []ESMediaSource, err error) {
es = elastic.Init()
query := elastic.M{
"query": elastic.M{
"bool": elastic.M{
"must": elastic.A{
{"multi_match": elastic.M{
"query": keywords,
"fields": []string{"title"}},
},
{"term": elastic.M{"mediaType.keyword": vidType}},
{"term": elastic.M{"isDelete": false}},
{"term": elastic.M{"status": 1}},
},
},
},
// "sort": elastic.A{{"hot": elastic.M{"order": "desc"}}},
"from": from,
"size": size,
}
if err = es.Search(ESTable, &data, query); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Search", table, "CommonSearch", err),
log.Any("keywords", keywords),
log.Any("from", from),
log.Any("size", size))
return
}
return
}
func DeleteByCond(filter elastic.M) (err error) {
es = elastic.Init()
if err = es.BulkDelete(ESTable, filter); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Search", table, "CommonSearch", err), log.Any("filter", filter))
return
}
return
}
func SearchByCondWithTotal(filter elastic.M) (data ESVideoSourceWithTotal, err error) {
es = elastic.Init()
if err = es.SearchWithTotal(ESTable, &data, filter); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Search", table, "CommonSearch", err), log.Any("filter", filter))
return
}
return
}
+608
View File
@@ -0,0 +1,608 @@
package mediamod
import (
"91porn-server/models"
"encoding/json"
"errors"
"fmt"
"time"
"91porn-server/common/db"
"91porn-server/common/log"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
const table = models.Media
func coll(t *db.MongoTool) *db.MongoTool {
if t == nil {
return mdb.Coll(table)
}
return t.Coll(table)
}
func initIndex() {
many := []mongo.IndexModel{
{
Keys: bson.D{{Key: "lsjId", Value: 1}},
},
{
Keys: bson.D{{Key: "sId", Value: 1}, {Key: "sortCode", Value: -1}, {Key: "createdAt", Value: -1}},
},
{
Keys: bson.D{{Key: "sId", Value: 1}, {Key: "sectionSort", Value: -1}, {Key: "createdAt", Value: -1}},
},
{
Keys: bson.D{{Key: "tags", Value: 1}},
}, {
Keys: bson.D{{Key: "tags", Value: 1}, {"isDelete", 1}, {"status", 1}, {"hot", -1}, {"createdAt", -1}},
}, {
Keys: bson.D{{Key: "tags", Value: 1}, {"isDelete", 1}, {"status", 1}, {"countCollect", -1}, {"createdAt", -1}},
}, {
Keys: bson.D{{Key: "tags", Value: 1}, {"isDelete", 1}, {"status", 1}, {"countBrowse", -1}, {"createdAt", -1}},
}, {
Keys: bson.D{{Key: "tags", Value: 1}, {"isDelete", 1}, {"status", 1}, {"createdAt", -1}},
},
{
Keys: bson.D{{Key: "kind", Value: 1}},
},
{
Keys: bson.D{{Key: "isActive", Value: 1}},
},
{
Keys: bson.D{{Key: "specialSubjectID", Value: 1}},
},
{
Keys: bson.D{{Key: "updatedAt", Value: -1}},
},
{
Keys: bson.D{{Key: "createdAt", Value: -1}},
},
{
Keys: bson.D{{Key: "mediaContentId", Value: 1}},
},
{
Keys: bson.D{{Key: "title", Value: 1}},
}, { // 年度排行需要
Keys: bson.D{{Key: "mediaType", Value: 1}, {Key: "status", Value: 1}, {"isDelete", 1}, {"countBrowse", -1}, {Key: "createdAt", Value: -1}},
}, {
Keys: bson.D{{Key: "sId", Value: 1}, {Key: "status", Value: 1}, {"isDelete", 1}, {Key: "createdAt", Value: -1}},
}, {
Keys: bson.D{{Key: "sId", Value: 1}, {Key: "status", Value: 1}, {"isDelete", 1}, {Key: "countLike", Value: -1}, {Key: "createdAt", Value: -1}},
}, {
Keys: bson.D{{Key: "sId", Value: 1}, {Key: "status", Value: 1}, {"isDelete", 1}, {Key: "countCollect", Value: -1}, {Key: "createdAt", Value: -1}},
}, {
Keys: bson.D{{Key: "sId", Value: 1}, {Key: "status", Value: 1}, {"isDelete", 1}, {Key: "countBrowse", Value: -1}, {Key: "createdAt", Value: -1}},
}, {
Keys: bson.D{{Key: "sId", Value: 1}, {Key: "status", Value: 1}, {"isDelete", 1}, {Key: "hot", Value: -1}, {Key: "createdAt", Value: -1}},
},
// 首页优化
{
Keys: bson.D{{Key: "mId", Value: 1}, {Key: "status", Value: 1}, {"isDelete", 1}, {Key: "createdAt", Value: -1}},
}, {
Keys: bson.D{{Key: "mId", Value: 1}, {Key: "status", Value: 1}, {"isDelete", 1}, {Key: "countLike", Value: -1}, {Key: "createdAt", Value: -1}},
}, {
Keys: bson.D{{Key: "mId", Value: 1}, {Key: "status", Value: 1}, {"isDelete", 1}, {Key: "countBrowse", Value: -1}, {Key: "createdAt", Value: -1}},
}, {
Keys: bson.D{{Key: "mId", Value: 1}, {Key: "status", Value: 1}, {"isDelete", 1}, {Key: "countCollect", Value: -1}, {Key: "createdAt", Value: -1}},
}, {
Keys: bson.D{{Key: "mId", Value: 1}, {Key: "status", Value: 1}, {"isDelete", 1}, {Key: "hot", Value: -1}, {Key: "createdAt", Value: -1}},
},
{
Keys: bson.D{{Key: "mId", Value: 1}, {Key: "sortCode", Value: -1}, {Key: "createdAt", Value: -1}},
},
{
Keys: bson.D{
{Key: "mId", Value: 1},
{Key: "status", Value: 1},
{Key: "isDelete", Value: 1},
{Key: "latestPublishedAt", Value: -1},
{Key: "contentUpdateTime", Value: -1},
{Key: "createdAt", Value: -1},
{Key: "_id", Value: -1},
},
},
}
if _, err := coll(nil).CreateIndex(many); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", table, err))
}
}
// Init 初始化索引
func Init() {
mdb = db.Init(table)
initIndex()
}
// GetList 获取列表
func GetList(cond bson.M, skip, limit int64, sort bson.D) (res []*Media, hasNext bool, err error) {
opts := options.Find()
if len(sort) > 0 {
opts.SetSort(sort)
}
opts = opts.SetSort(sort).SetSkip(skip).SetLimit(limit + 1)
if err = coll(nil).Find(&res, cond, opts); err != nil {
return
}
// 判断下一页
if len(res) > int(limit) {
hasNext = true
res = res[:limit]
}
return
}
// QueryAllList 分页查询文档
func QueryAllList(filter primitive.M, opts ...*options.FindOptions) (out []*Media, err error) {
if err = coll(nil).Find(&out, filter, opts...); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "QueryAllList", table, "Find", err),
log.Any("filter", filter),
log.Any("opts", opts),
)
return nil, err
}
return
}
// QueryAllCount 查询文档条目数
func QueryAllCount(filter primitive.M) (int64, error) {
if count, err := coll(nil).Count(filter); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "QueryAllCount", table, "Count", err),
log.Any("filter", filter),
)
return 0, err
} else {
return count, nil
}
}
// GetLatestIDForESSync 固定本轮同步的 ID 上界,仅读取已有主键索引。
func GetLatestIDForESSync() (primitive.ObjectID, error) {
var data []*Media
opts := options.Find().SetSort(bson.D{{Key: "_id", Value: -1}}).
SetProjection(bson.M{"_id": 1}).SetHint("_id_").SetLimit(1).SetMaxTime(30 * time.Second)
if err := coll(nil).Find(&data, bson.M{}, opts); err != nil {
return primitive.NilObjectID, err
}
if len(data) == 0 {
return primitive.NilObjectID, nil
}
return data[0].ID, nil
}
// GetListForESSync 不限制更新时间上界,防止浏览等持续更新使记录逃出同步窗口。
// 使用稳定的 ID 游标,避免修改 updateTime 导致 skip 分页漏数据。
func GetListForESSync(since time.Time, after, maxID primitive.ObjectID, size int) (data []*Media, err error) {
query := bson.M{
"updateTime": bson.M{"$gte": since},
"_id": bson.M{"$gt": after, "$lte": maxID},
}
opts := options.Find().SetSort(bson.D{{Key: "_id", Value: 1}}).
SetHint("_id_").SetLimit(int64(size)).SetMaxTime(30 * time.Second)
err = coll(nil).Find(&data, query, opts)
return
}
var MediaNotFound = errors.New("media not found")
// GetInfoByMediaCenterId 通过mediaCenterId获取详细信息
func GetInfoByMediaCenterId(mediaCenterId uint) (Media, error) {
v := Media{}
if err := coll(nil).FindOne(&v, bson.M{"mediaCenterId": mediaCenterId, "isDelete": false}); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetInfoByMediaCenterId", table, "FindOne", err),
log.Any("mediaCenterId", mediaCenterId),
)
return v, err
}
if v.ID.IsZero() {
return v, MediaNotFound
}
return v, nil
}
// GetInfoByTitle 通过标题获取详细信息
func GetInfoByTitle(title string) (Media, error) {
v := Media{}
if err := coll(nil).FindOne(&v, bson.M{"title": title, "isDelete": false}); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetInfoByTitle", table, "FindOne", err),
log.Any("title", title),
)
return v, err
}
if v.ID.IsZero() {
return v, MediaNotFound
}
return v, nil
}
// GetInfo 通过id获取详细信息
func GetInfo(id primitive.ObjectID) (Media, error) {
v := Media{}
if err := coll(nil).FindOne(&v, bson.M{"_id": id}); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetInfo", table, "FindOne", err),
log.Any("id", id),
)
return v, err
}
if v.ID.IsZero() {
return v, errors.New("record not found")
}
return v, nil
}
func GetListByIds(ids []primitive.ObjectID) (list []Media, res map[primitive.ObjectID]Media, err error) {
if err := coll(nil).Find(&list, bson.M{"_id": bson.M{"$in": ids}}); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetListByIds", table, "Find", err),
log.Any("ids", ids),
)
return nil, nil, err
}
res = make(map[primitive.ObjectID]Media)
for _, v := range list {
res[v.ID] = v
}
return list, res, nil
}
// IncreaseCountLikeByIDs 更新媒体点赞数
func IncreaseCountLikeByIDs(value int, ids ...primitive.ObjectID) (err error) {
var query = bson.M{}
if len(ids) == 1 {
query["_id"] = ids[0]
} else {
query["_id"] = bson.M{"$in": ids}
}
if _, err = coll(nil).UpdateOne(query, bson.M{"$inc": bson.M{"countLike": value}}); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "IncreaseLikeCountByID", table, "UpdateOne", err),
log.Any("id", ids),
log.Any("value", value),
)
return
}
return
}
// IncreaseCountShareByID 累计短剧真实分享次数,供推荐互动分计算。
func IncreaseCountShareByID(id primitive.ObjectID, value int) error {
_, err := coll(nil).UpdateOne(bson.M{"_id": id, "mediaType": MediaTypeDrama}, bson.M{"$inc": bson.M{"countShare": value}})
return err
}
// IncrCommentCountByID 更新媒体评论数
func IncrCommentCountByID(id primitive.ObjectID, value int) (err error) {
if _, err = coll(nil).UpdateOne(bson.M{"_id": id}, bson.M{"$inc": bson.M{"countComment": value}}); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "IncrCommentCountByID", table, "UpdateOne", err),
log.Any("id", id),
log.Any("value", value),
)
return
}
return
}
// QueryMediaByID 查询文档
func QueryMediaByID(filter primitive.M) (out *Media, err error) {
if err = coll(nil).FindOne(&out, filter); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "QueryAllList", table, "Find", err),
log.Any("filter", filter),
)
return nil, err
}
return
}
// QueryMediaByCond 查询文档
func QueryMediaByCond(filter primitive.M, opts *options.FindOptions) (out []*Media, err error) {
if err = coll(nil).Find(&out, filter, opts); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "QueryAllList", table, "Find", err),
log.Any("filter", filter),
)
return nil, err
}
return
}
// Insert 插入记录
func Insert(t *db.MongoTool, d Media) (data primitive.ObjectID, err error) {
normalizeLatestPublishedAt(&d)
result, err := coll(t).InsertOne(&d)
if err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Insert", table, "InsertOne", err))
return
}
byteID, err := json.Marshal(result.InsertedID)
if err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Insert", table, "Marshal", err))
return
}
if err = data.UnmarshalJSON(byteID); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Insert", table, "UnmarshalJSON", err))
return
}
return
}
func InsertMany(c []Media) error {
for i := range c {
normalizeLatestPublishedAt(&c[i])
}
if _, err := coll(nil).InsertMany(c); err != nil {
log.Warn(fmt.Sprintf("METHOD-%s==> Model %s %s fail error:%+v:", "InsertMany", table, "InsertMany", err))
return err
}
return nil
}
func normalizeLatestPublishedAt(media *Media) {
if media == nil || media.Status != 1 || !media.LatestPublishedAt.IsZero() {
return
}
switch {
case !media.ContentUpdateTime.IsZero():
media.LatestPublishedAt = media.ContentUpdateTime
case !media.UpdateTime.IsZero():
media.LatestPublishedAt = media.UpdateTime
case !media.CreatedAt.IsZero():
media.LatestPublishedAt = media.CreatedAt
default:
media.LatestPublishedAt = time.Now()
}
}
// UpdateByID 根据id更新数据
func UpdateByID(t *db.MongoTool, id primitive.ObjectID, data map[string]interface{}) (int64, error) {
cond := bson.M{"_id": id}
return update(t, cond, data)
}
// UpdateByIDS 根据ids更新数据
func UpdateByIDS(t *db.MongoTool, ids []primitive.ObjectID, data map[string]interface{}) (int64, error) {
cond := bson.M{"_id": bson.M{"$in": ids}}
return update(t, cond, data)
}
// SectionVideosBySectionID 根据专题获取视频列表
func SectionVideosBySectionID(sectionID primitive.ObjectID, opts *options.FindOptions) ([]*Media, error) {
var out []*Media
return out, coll(nil).Find(&out, bson.M{"sId": sectionID, "isDelete": false, "status": 1}, opts)
}
type SectionWorkCount struct {
SectionID primitive.ObjectID `bson:"_id"`
Count int64 `bson:"count"`
}
// CountActiveDramaBySectionIDs groups all visible short dramas for one bounded topic page.
func CountActiveDramaBySectionIDs(sectionIDs []primitive.ObjectID) (map[primitive.ObjectID]int64, error) {
counts := make(map[primitive.ObjectID]int64, len(sectionIDs))
if len(sectionIDs) == 0 {
return counts, nil
}
var rows []SectionWorkCount
err := coll(nil).Aggregate(&rows, []bson.M{
{"$match": bson.M{"sId": bson.M{"$in": sectionIDs}, "mediaType": MediaTypeDrama, "status": 1, "isDelete": false}},
{"$group": bson.M{"_id": "$sId", "count": bson.M{"$sum": 1}}},
})
if err != nil {
return nil, err
}
for _, row := range rows {
counts[row.SectionID] = row.Count
}
return counts, nil
}
// ListActiveDramaByInteractionScore computes the full-history ranking in MongoDB
// and only returns the requested page. The formula is:
// likes + collections*2 + comments*3 + shares*5.
func ListActiveDramaByInteractionScore(skip, limit int64) ([]*Media, error) {
if skip < 0 {
skip = 0
}
if limit <= 0 || limit > 101 {
limit = 21
}
var list []*Media
pipeline := []bson.M{
{"$match": bson.M{"mediaType": MediaTypeDrama, "status": 1, "isDelete": false}},
{"$addFields": bson.M{"_dramaInteractionScore": bson.M{"$add": []any{
bson.M{"$ifNull": []any{"$countLike", 0}},
bson.M{"$multiply": []any{bson.M{"$ifNull": []any{"$countCollect", 0}}, 2}},
bson.M{"$multiply": []any{bson.M{"$ifNull": []any{"$countComment", 0}}, 3}},
bson.M{"$multiply": []any{bson.M{"$ifNull": []any{"$countShare", 0}}, 5}},
}}}},
{"$sort": bson.D{{Key: "_dramaInteractionScore", Value: -1}, {Key: "latestPublishedAt", Value: -1}, {Key: "_id", Value: -1}}},
{"$skip": skip},
{"$limit": limit},
{"$project": bson.M{"_dramaInteractionScore": 0}},
}
err := coll(nil).Aggregate(&list, pipeline, options.Aggregate().SetAllowDiskUse(true))
return list, err
}
// update 更新数据
func update(t *db.MongoTool, cond primitive.M, data map[string]interface{}) (int64, error) {
result, err := coll(t).UpdateMany(cond, bson.M{"$set": bson.M(data)})
if err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Update", table, "UpdateMany", err),
log.Any("cond", cond),
log.Any("update", data),
)
return 0, err
}
return result.ModifiedCount, nil
}
// DeleteByID 删除数据
func DeleteByID(t *db.MongoTool, id primitive.ObjectID) error {
_, err := coll(t).UpdateOne(bson.M{"_id": id}, bson.M{"$set": bson.M{"isDelete": true}})
if err != nil {
if err == mongo.ErrNoDocuments {
return nil
} else {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "DeleteByID", table, "DeleteMany", err), log.Any("id", id))
}
}
return err
}
// IncCollectCount 收藏次数增加
func IncCollectCount(id ObjectID, inc int) error {
query := bson.M{"_id": id}
update := bson.M{"$set": bson.M{"updateTime": time.Now()}, "$inc": bson.M{"countCollect": inc}}
_, err := coll(nil).UpdateOne(query, update)
if err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "IncCollectCount", table, "UpdateOne", err),
log.Any("id", id),
)
return err
}
return nil
}
// IncContentPurchasesCount 子集购买次数增加
func IncContentPurchasesCount(id ObjectID, inc int) error {
query := bson.M{"_id": id}
update := bson.M{"$set": bson.M{"updateTime": time.Now()}, "$inc": bson.M{"countContentPurchases": inc}}
_, err := coll(nil).UpdateOne(query, update)
if err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "IncPurchasesCount", table, "UpdateOne", err),
log.Any("id", id),
)
return err
}
return nil
}
// IncPurchasesCount 购买次数增加
func IncPurchasesCount(id ObjectID, inc int) error {
return IncPurchasesCountWithTool(nil, id, inc)
}
func IncPurchasesCountWithTool(t *db.MongoTool, id ObjectID, inc int) error {
query := bson.M{"_id": id}
update := bson.M{"$set": bson.M{"updateTime": time.Now()}, "$inc": bson.M{"countPurchases": inc}}
_, err := coll(t).UpdateOne(query, update)
if err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "IncPurchasesCount", table, "UpdateOne", err),
log.Any("id", id),
)
return err
}
return nil
}
// IncBrowseCount 浏览次数增加
func IncBrowseCount(id ObjectID, inc int) error {
query := bson.M{"_id": id}
update := bson.M{"$set": bson.M{"updateTime": time.Now()}, "$inc": bson.M{"countBrowse": inc}}
_, err := coll(nil).UpdateOne(query, update)
if err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "IncBrowseCount", table, "UpdateOne", err),
log.Any("id", id),
)
return err
}
return nil
}
func Bulk(models []mongo.WriteModel) error {
_, err := coll(nil).Bulk(models, options.BulkWrite().SetOrdered(false))
return err
}
func GetListByLsjIds(lsjIds []string) ([]Media, error) {
filter := bson.M{
"lsjId": bson.M{"$in": lsjIds},
}
var ms []Media
return ms, coll(nil).Find(&ms, filter)
}
func GetListByLsjId(lsjId string) (Media, error) {
filter := bson.M{
"lsjId": lsjId,
}
var ms Media
return ms, coll(nil).FindOne(&ms, filter)
}
// UpdateMany 根据ids更新数据
func UpdateMany(t *db.MongoTool, filter bson.M, data bson.M) (int64, error) {
result, err := coll(t).UpdateMany(filter, data)
if err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Update", table, "UpdateMany", err),
log.Any("cond", filter),
log.Any("update", data),
)
return 0, err
}
return result.ModifiedCount, nil
}
// FindForReviewBatch 按 _id 游标分页扫描上架 Media,用于内容审查任务
// 仅扫描 status=1(上架)
func FindForReviewBatch(lastID primitive.ObjectID, limit int64) ([]*Media, error) {
cond := bson.M{"status": 1}
if !lastID.IsZero() {
cond["_id"] = bson.M{"$gt": lastID}
}
opts := options.Find().
SetSort(bson.D{{Key: "_id", Value: 1}}).
SetLimit(limit)
var list []*Media
if err := coll(nil).Find(&list, cond, opts); err != nil {
return nil, err
}
return list, nil
}
// CountForReview 上架 Media 总数;条件与 FindForReviewBatch 保持一致
func CountForReview() (int64, error) {
return coll(nil).Count(bson.M{"status": 1})
}
// UpdateForReview 内容审查通过后回写文本字段
// title 对应 Media.Titlecontent 对应 Media.Summary
func UpdateForReview(id primitive.ObjectID, title, content string) error {
set := bson.M{}
if title != "" {
set["title"] = title
}
if content != "" {
set["summary"] = content
}
if len(set) == 0 {
return nil
}
set["updateTime"] = time.Now()
_, err := coll(nil).UpdateOne(bson.M{"_id": id}, bson.M{"$set": set})
return err
}
// OffShelfManyForReview 内容审查命中后批量下架 Mediastatus -> 0
// 仅当前 status=1 的会被改动
func OffShelfManyForReview(ids []primitive.ObjectID) error {
if len(ids) == 0 {
return nil
}
_, err := coll(nil).UpdateMany(
bson.M{"_id": bson.M{"$in": ids}, "status": 1},
bson.M{"$set": bson.M{"status": 0, "updateTime": time.Now()}},
)
return err
}
@@ -0,0 +1,25 @@
package mediamod
import (
"testing"
"time"
)
func TestNormalizeLatestPublishedAt(t *testing.T) {
createdAt := time.Date(2026, 7, 20, 1, 0, 0, 0, time.UTC)
updateTime := createdAt.Add(time.Hour)
contentUpdateTime := updateTime.Add(time.Hour)
media := &Media{Status: 1, CreatedAt: createdAt, UpdateTime: updateTime, ContentUpdateTime: contentUpdateTime}
normalizeLatestPublishedAt(media)
if !media.LatestPublishedAt.Equal(contentUpdateTime) {
t.Fatalf("latestPublishedAt = %v, want %v", media.LatestPublishedAt, contentUpdateTime)
}
}
func TestNormalizeLatestPublishedAtDoesNotPublishOffShelfMedia(t *testing.T) {
media := &Media{Status: 0, CreatedAt: time.Now()}
normalizeLatestPublishedAt(media)
if !media.LatestPublishedAt.IsZero() {
t.Fatalf("off-shelf media latestPublishedAt = %v, want zero", media.LatestPublishedAt)
}
}
+130
View File
@@ -0,0 +1,130 @@
package mediamod
import (
"time"
"91porn-server/common/db"
"go.mongodb.org/mongo-driver/bson/primitive"
)
var mdb *db.MongoDB
type MediaSubType int
type Media struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` // 文档id
LsjId string `json:"lsjId" bson:"lsjId"` // 老司机ID
SortCode int `json:"sortCode" bson:"sortCode"` // 排序
Status int `json:"status" bson:"status"` // 状态 0 下架 1 上架
Title string `json:"title" bson:"title"` // 标题
HorizontalCover string `json:"horizontalCover" bson:"horizontalCover"` // 横版封面
VerticalCover string `json:"verticalCover" bson:"verticalCover"` // 竖版封面
Tags []primitive.ObjectID `json:"tags" bson:"tags"` // 标签
TagDetails []TagDetail `json:"tagDetails" bson:"tagDetails"` // 标签对象
Summary string `json:"summary" bson:"summary"` // 简介
TotalEpisode int `json:"totalEpisode" bson:"totalEpisode"` // 总集数
CurrentEpisode int `json:"currentEpisode" bson:"currentEpisode"` // 当前更新的集数
FreeEpisode int `json:"freeEpisode" bson:"freeEpisode"` // 免费集数
UpdateStatus int `json:"updateStatus" bson:"updateStatus"` // 更新状态 1-连载中 2-已完结
MediaType string `json:"mediaType" bson:"mediaType"` // 媒体类型 "video":视频,"image":图片,"text":小说
MediaSubType MediaSubType `json:"mediaSubType" bson:"mediaSubType"` // 子类型 ,暂时只有小说使用 0-默认文本小说 1-有声小说
Kind int `json:"kind" bson:"kind"` // 种类(1、哩番,2、3D,3、同人动画,4、单行本,5、连载漫画,6、韩漫 7、小说 )
PermissionIconHide bool `json:"permissionIconHide" bson:"permissionIconHide"` // 售卖类型标识隐藏
Permission int `json:"permission" bson:"permission"` // 收听权限 0:会员 1:金币购买 2:免费
Style int `json:"style" bson:"style"` // 对应五种风格背景颜色,0默认前端随机
Price int64 `json:"price" bson:"price"` // 价格(整部购买的类型 小说 cos 写真)
ContentsPrice int64 `json:"contentsPrice" bson:"contentsPrice"` // 所有子集加起来的价格
Direction int64 `json:"direction" bson:"direction"` // 排版方向 0横 1竖(冗余字段)
FreeTime int `json:"freeTime" bson:"freeTime"` // 免费试看时长 单位 s
DefaultContent DefaultContent `json:"defaultContent" bson:"defaultContent"` // 默认展示内容,暂时只有漫画需要,展示第一章前五张图片
MID primitive.ObjectID `json:"mId" bson:"mId"` // 模块ID
ModuleName string `json:"moduleName" bson:"moduleName"` // 模块名称
SectionName string `json:"sectionName" bson:"sectionName"` // 专题名称
SID primitive.ObjectID `json:"sId" bson:"sId"` // 专题ID
SectionSort int `json:"sectionSort" bson:"sectionSort"` // 专题排序
Choice primitive.ObjectID `json:"choice" bson:"choice"` // 精选
ChoiceSort int `json:"choiceSort" bson:"choiceSort"` // 精选专题排序
CountComment int64 `json:"countComment" bson:"countComment"` // 评论数
CountPurchases int64 `json:"countPurchases" bson:"countPurchases"` // 购买数
CountContentPurchases int64 `json:"countContentPurchases" bson:"countContentPurchases"` // 子集累计购买数
CountBrowse int64 `json:"countBrowse" bson:"countBrowse"` // 浏览数
CountCollect int64 `json:"countCollect" bson:"countCollect"` // 收藏数
CountLike int64 `json:"countLike" bson:"countLike"` // 喜欢数
CountDisLike int64 `json:"countDisLike" bson:"countDisLike"` // 不喜欢数
HasFollow bool `json:"hasFollow" bson:"hasFollow"` // 是否关注
CountView int64 `json:"countView" bson:"countView"` // 展现数
CountShare int64 `json:"countShare" bson:"countShare"` // 分享数,短剧推荐互动分使用
Hot float64 `json:"hot" bson:"hot"` // 热度值
Number int64 `json:"number" bson:"number"` // 编号
Anchor string `json:"anchor" bson:"anchor"` // 作者
CountPurchasesRate float32 `json:"countPurchasesRate" bson:"countPurchasesRate"` // 成交率
IsDelete bool `json:"isDelete" bson:"isDelete"` // 是否删除
UpdatedAct string `json:"updatedAct" bson:"updatedAct"` // 操作用户账号
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 文档创建时间
UpdateTime time.Time `json:"updateTime" bson:"updateTime"` // 文档更新时间
ContentUpdateTime time.Time `json:"contentUpdateTime" bson:"contentUpdateTime"` // 子集最新更新时间 用于连载排行榜
LatestPublishedAt time.Time `json:"latestPublishedAt" bson:"latestPublishedAt"` // 最新上架或子集更新时间,用于“最新”列表排序
MediaCenterId uint `json:"mediaCenterId" bson:"mediaCenterId,omitempty"` // 在媒资库中的唯一标识
SyncTime int64 `json:"syncTime" bson:"syncTime,omitempty"` // 下一次需要同步的时间点位
//SellType int `json:"sellType" bson:"sellType"` // 商品售卖类型(0单集售卖 1整部售卖)
}
type DefaultContent struct {
Id primitive.ObjectID `json:"id" bson:"id"`
Name string `json:"name" bson:"name"`
Cover string `json:"cover" bson:"cover"`
UrlSet []string `json:"urlSet" bson:"urlSet"` // 地址集(多个资源地址用 例如漫画)
}
type ESMedia struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` // 文档id
Title string `json:"title" bson:"title"` // 标题
HorizontalCover string `json:"horizontalCover" bson:"horizontalCover"` // 横版封面
VerticalCover string `json:"verticalCover" bson:"verticalCover"` // 竖版封面
Tags []primitive.ObjectID `json:"tags" bson:"tags"` // 标签
Summary string `json:"summary" bson:"summary"` // 简介
TotalEpisode int `json:"totalEpisode" bson:"totalEpisode"` // 总集数
UpdateStatus int `json:"updateStatus" bson:"updateStatus"` // 更新状态
MediaType string `json:"mediaType" bson:"mediaType"` // 媒体类型 "video":视频,"image":图片
Kind int `json:"kind" bson:"kind"` // 种类(1、哩番,2、3D,3、同人动画,4、单行本,5、连载漫画,6、韩漫 7.有声小说 8.剧场)
PermissionIconHide bool `json:"permissionIconHide" bson:"permissionIconHide"` // 售卖类型标识隐藏
Permission int `json:"permission" bson:"permission"` // 收听权限 0:会员 1:金币购买 2:免费
Price int64 `json:"price" bson:"price"` // 价格(整部购买的类型 小说 cos 写真)
Direction int64 `json:"direction" bson:"direction"` // 排版方向 0横 1竖(冗余字段)
FreeTime int `json:"freeTime" bson:"freeTime"` // 免费试看时长 单位 s
MID primitive.ObjectID `json:"mId" bson:"mId"` // 模块ID
ModuleName string `json:"moduleName" bson:"moduleName"` // 模块名称
SectionName string `json:"sectionName" bson:"sectionName"` // 专题名称
SID primitive.ObjectID `json:"sId" bson:"sId"` // 专题ID
SectionSort int `json:"sectionSort" bson:"sectionSort"` // 专题排序
CountLike int64 `json:"countLike" bson:"countLike"` // 喜欢数
CountBrowse int64 `json:"countBrowse" bson:"countBrowse"` // 浏览数
CountCollect int64 `json:"countCollect" bson:"countCollect"` // 收藏数
Hot float64 `json:"hot" bson:"hot"` // 热度值
Choice primitive.ObjectID `json:"choice" bson:"choice"` // 精选
ChoiceSort int `json:"choiceSort" bson:"choiceSort"` // 精选专题排序
Number int64 `json:"number" bson:"number"` // 编号
SortCode int `json:"sortCode" bson:"sortCode"` // 排序
Status int `json:"status" bson:"status"` // 状态
IsDelete bool `json:"isDelete" bson:"isDelete"` // 是否删除
UpdatedAct string `json:"updatedAct" bson:"updatedAct"` // 操作用户账号
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 文档创建时间
UpdateTime time.Time `json:"updateTime" bson:"updateTime"` // 文档更新时间
}
type ESMediaSource struct {
ID primitive.ObjectID `json:"_id"`
Source ESMedia `json:"_source"`
}
type ESVideoSourceWithTotal struct {
Hits []ESMediaSource `json:"hits"`
Total Total `json:"total"`
}
type Total struct {
Relation string `json:"relation"`
Value int `json:"value"`
}
+48
View File
@@ -0,0 +1,48 @@
package mediamod
import (
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type moduleLatestContentAt struct {
ModuleID primitive.ObjectID `bson:"_id"`
LatestCreatedAt time.Time `bson:"latestCreatedAt"`
LatestContentUpdated time.Time `bson:"latestContentUpdated"`
}
// LatestContentAtByModules 返回动漫、漫画等媒体亚模块最近一次新增或子集更新时间。
func LatestContentAtByModules(moduleIDs []primitive.ObjectID) (map[string]time.Time, error) {
result := make(map[string]time.Time, len(moduleIDs))
if len(moduleIDs) == 0 {
return result, nil
}
pipeline := []bson.M{
{"$match": bson.M{
"status": 1,
"isDelete": false,
"mId": bson.M{"$in": moduleIDs},
}},
{"$group": bson.M{
"_id": "$mId",
"latestCreatedAt": bson.M{"$max": "$createdAt"},
"latestContentUpdated": bson.M{"$max": "$contentUpdateTime"},
}},
}
var rows []moduleLatestContentAt
if err := coll(nil).Aggregate(&rows, pipeline); err != nil {
return nil, err
}
for _, row := range rows {
latest := row.LatestCreatedAt
if row.LatestContentUpdated.After(latest) {
latest = row.LatestContentUpdated
}
if !row.ModuleID.IsZero() && !latest.IsZero() {
result[row.ModuleID.Hex()] = latest
}
}
return result, nil
}
+200
View File
@@ -0,0 +1,200 @@
package mediamod
import (
"91porn-server/common/constant"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type MediaType int
type KindType int
const (
_ = iota
RiFan // 1、哩番
ThreeD // 2、3D
FanAnimation // 3、同人动画
Offprint // 4、单行本
ComicStrip // 5、连载漫画
KoreanCartoon // 6、韩漫
AudioNovel // 7、有声小说
Theater // 8、剧场
)
const (
_ = iota
Animation // 1、动漫
Cartoon // 2、漫画
Novel // 3、小说
)
const (
Default = iota // 0 默认
Update // 1、更新中
Finish // 2、已完结
)
const (
SellTypeUnit = 0 // 单集购买
SellTypeSet = 1 // 整部购买
MediaTypeVideo = constant.Cartoon // 视频
MediaTypeImage = constant.Comics // 图片
MediaTypeText = constant.Text // 音频小说
MediaTypeDrama = constant.Drama // 短剧
)
type SendBaseInfo2AWsReq struct {
SourceID string `form:"sourceID" json:"sourceID"`
Md5 string `form:"md5" json:"md5"`
Title string `form:"title" json:"title"`
PlayTime uint `form:"playTime" json:"playTime"`
MediaSize int `form:"mediaSize" json:"mediaSize"`
Filename string `form:"filename" json:"filename"`
Tags []primitive.ObjectID `form:"tags" json:"tags" binding:"required"`
}
type TagDetail struct {
Id primitive.ObjectID `json:"id"` // 标签id
Name string `json:"name"` // 标签名
}
type WebExportMedia struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty" xlsx:"ID"` // 文档id
Title string `json:"title" bson:"title" xlsx:"标题"` // 标题
Kind string `json:"kind" bson:"kind" xlsx:"种类"` // 种类(1、哩番,2、3D,3、同人动画,4、单行本,5、连载漫画,6、韩漫 7、小说 )
Direction string `json:"direction" bson:"direction" xlsx:"排版方向"` // 排版方向 0横 1竖(冗余字段)
TotalEpisode int `json:"totalEpisode" bson:"totalEpisode" xlsx:"总集数"` // 总集数
UpdateStatus string `json:"updateStatus" bson:"updateStatus" xlsx:"更新状态"` // 更新状态
Status string `json:"status" bson:"status" xlsx:"状态"` // 状态 0 下架 1 上架
ModuleName string `json:"moduleName" bson:"moduleName" xlsx:"模块名称"` // 模块名称
SectionName string `json:"sectionName" bson:"sectionName" xlsx:"专题名称"` // 专题名称
Tags string `json:"tags" bson:"tags" xlsx:"标签"` // 标签
MediaType string `json:"mediaType" bson:"mediaType" xlsx:"类型"` // 媒体类型 "video":视频,"image":图片,"text":小说
FreeTime int `json:"freeTime" bson:"freeTime" xlsx:"免费时长"` // 免费试看时长 单位 s
Price int64 `json:"price" bson:"price" xlsx:"价格"` // 价格(整部购买的类型 小说 cos 写真)
CountBrowse int64 `json:"countBrowse" bson:"countBrowse" xlsx:"浏览数"` // 浏览数
CountCollect int64 `json:"countCollect" bson:"countCollect" xlsx:"收藏数"` // 收藏数
CountComment int64 `json:"countComment" bson:"countComment" xlsx:"评论数"` // 评论数
CountLike int64 `json:"countLike" bson:"countLike" xlsx:"喜欢数"` // 喜欢数
CountPurchases int64 `json:"countPurchases" bson:"countPurchases" xlsx:"购买数"` // 购买数
CountView int64 `json:"countView" bson:"countView" xlsx:"展现数"` // 展现数
Permission string `json:"permission" bson:"permission" xlsx:"观看权限"` // 收听权限 0:会员 1:金币购买 2:免费
PermissionIconHide bool `json:"permissionIconHide" bson:"permissionIconHide" xlsx:"售卖类型标识隐藏"` // 售卖类型标识隐藏
Summary string `json:"summary" bson:"summary" xlsx:"简介"` // 简介
UpdatedAct string `json:"updatedAct" bson:"updatedAct" xlsx:"操作人"` // 操作用户账号
CreatedAt string `json:"createdAt" bson:"createdAt" xlsx:"创建时间"` // 文档创建时间
UpdateTime string `json:"updateTime" bson:"updateTime" xlsx:"更新时间"` // 文档更新时间
}
func MediaTypeName(mediaType string) string {
var name string
switch mediaType {
case "video":
name = "动漫"
case "image":
name = "漫画"
case "text":
name = "小说"
case "drama":
name = "短剧"
}
return name
}
func PermissionName(status int) string {
var name string
// 观看权限 0:会员 1:金币购买 2:免费
switch status {
case 0:
name = "会员"
case 1:
name = "金币购买"
case 2:
name = "免费"
default:
name = "未知"
}
return name
}
func SellTypeName(status int) string {
var name string
// 商品售卖类型(0单集售卖 1整部售卖)
switch status {
case 0:
name = "单集售卖"
case 1:
name = "整部售卖"
default:
name = "未知"
}
return name
}
func StatusName(status int) string {
var name string
// 状态 1 上架 2 下架
switch status {
case 1:
name = "上架"
case 2:
name = "下架"
default:
name = "未知"
}
return name
}
func UpdateStatusName(updateStatus int) string {
var name string
// 排版方向 0横 1竖(冗余字段)
switch updateStatus {
case 0, 1:
name = "连载中"
case 2:
name = "已完结"
default:
name = "未知"
}
return name
}
func DirectionName(direction int64) string {
var name string
// 排版方向 0横 1竖(冗余字段)
switch direction {
case 0:
name = "横版"
case 1:
name = "竖版"
default:
name = "未知"
}
return name
}
func KindName(kind int) string {
var name string
// 1、哩番,2、3D,3、同人动画,4、单行本,5、连载漫画,6、韩漫 7、小说
switch kind {
case 1:
name = "哩番"
case 2:
name = "3D"
case 3:
name = "同人动画"
case 4:
name = "单行本"
case 5:
name = "连载漫画"
case 6:
name = "韩漫"
case 7:
name = "小说"
case 8:
name = "剧场"
default:
name = "未知"
}
return name
}