Files
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

85 lines
2.5 KiB
Go

package video_activity_service
import (
"time"
"91porn-server/common/stderr"
"91porn-server/models/v/videoactivitymod"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
)
func Submit(cond *SubmitCond) stderr.Code {
if err := videoactivitymod.SubmitDocument(videoactivitymod.VideoActivity{
BackgroundImage: cond.BackgroundImage,
EndTime: cond.EndTime,
Desc: cond.Desc,
Status: cond.Status,
CreateTime: time.Now(),
}); err != nil {
return stderr.ErrDbInsertError
}
return stderr.Success
}
func Edit(cond *EditCond) stderr.Code {
filter := bson.M{"_id": cond.ID}
update := bson.M{}
if cond.BackgroundImage != nil {
update["backgroundImage"] = cond.BackgroundImage
}
if cond.EndTime != nil {
update["endTime"] = cond.EndTime
}
if cond.Desc != nil {
update["desc"] = cond.Desc
}
if cond.Status != nil && (*cond.Status == videoactivitymod.Enable || *cond.Status == videoactivitymod.Unused) {
update["status"] = cond.Status
}
if err := videoactivitymod.EditDocument(filter, bson.M{"$set": update}); err != nil {
return stderr.ErrDbUpdateError
}
return stderr.Success
}
func QueryAll(cond *QueryAllCond) (interface{}, stderr.Code) {
var (
data = map[string]interface{}{
"list": []interface{}{},
"count": 0,
}
filter = bson.M{"status": bson.M{"$in": []videoactivitymod.StatusType{videoactivitymod.Enable, videoactivitymod.Unused}}}
)
if cond.Status != nil && (videoactivitymod.StatusType(*cond.Status) == videoactivitymod.Enable || videoactivitymod.StatusType(*cond.Status) == videoactivitymod.Unused) {
filter["status"] = cond.Status
}
count, err := videoactivitymod.CountDocument(filter)
if err != nil {
return nil, stderr.ErrDbQueryError
}
if count == 0 {
return data, stderr.Success
}
list, err := videoactivitymod.QueryAllDocument(filter, options.Find().SetLimit(int64(cond.PageSize)).SetSkip(int64((cond.PageNumber-1)*cond.PageSize)).SetSort(bson.M{"createTime": -1}))
if err != nil {
return nil, stderr.ErrDbQueryError
}
data["count"] = count
data["list"] = list
return data, stderr.Success
}
func Box() (interface{}, stderr.Code) {
filter := bson.M{"status": videoactivitymod.Enable, "endTime": bson.M{"$gte": time.Now()}}
list, err := videoactivitymod.QueryAllDocument(filter, options.Find().SetSort(bson.M{"createTime": -1}))
if err != nil {
return nil, stderr.ErrDbQueryError
}
if len(list) == 0 {
return make([]interface{}, 0), stderr.Success
}
return list, stderr.Success
}