@@ -0,0 +1,33 @@
|
||||
package video_activity_service
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/models/commod"
|
||||
"91porn-server/models/v/videoactivitymod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// SubmitCond 提交参数
|
||||
type SubmitCond struct {
|
||||
BackgroundImage string `json:"backgroundImage" binding:"required"` // 背景图
|
||||
EndTime time.Time `json:"endTime" binding:"required"` // 结束时间
|
||||
Desc string `json:"desc"` // 详情描述
|
||||
Status videoactivitymod.StatusType `json:"status" binding:"required"` // 状态
|
||||
}
|
||||
|
||||
// EditCond 修改参数
|
||||
type EditCond struct {
|
||||
ID primitive.ObjectID `json:"id" binding:"required"` // 文档ID
|
||||
BackgroundImage *string `json:"backgroundImage"` // 背景图
|
||||
EndTime *time.Time `json:"endTime"` // 结束时间
|
||||
Desc *string `json:"desc"` // 详情描述
|
||||
Status *videoactivitymod.StatusType `json:"status"` // 状态
|
||||
}
|
||||
|
||||
// QueryAllCond 查询参数
|
||||
type QueryAllCond struct {
|
||||
Status *int `form:"status"` // 状态
|
||||
commod.Page
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user