93 lines
2.6 KiB
Go
93 lines
2.6 KiB
Go
package videogoldcoinmod
|
|
|
|
import (
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
"time"
|
|
)
|
|
|
|
type AddCond struct {
|
|
VideoId string `json:"videoId" bson:"videoId" binding:"required"` // 视频ID
|
|
}
|
|
|
|
func (receiver *AddCond) Generate(addAct string) VideoGoldCoin {
|
|
now := time.Now()
|
|
return VideoGoldCoin{
|
|
Status: 1,
|
|
OperateAccount: addAct,
|
|
CreatedAt: now,
|
|
}
|
|
}
|
|
|
|
type QueryAllCond struct {
|
|
Page int64 `form:"pageNumber" binding:"required"` // 查询页码
|
|
Limit int64 `form:"pageSize" binding:"required"` // 页码大小
|
|
Uid *int `form:"uid"` // 用户ID
|
|
VidTitle *string `form:"vidTitle"` // 视频标题
|
|
VidType *string `form:"vidType"` // 视频类型
|
|
Status *int `form:"status"` // 上架状态 1 上架 2 下架
|
|
}
|
|
|
|
type QueryAllRes struct {
|
|
List []*VideoGoldCoin `json:"list"`
|
|
Total int64 `json:"total"`
|
|
}
|
|
|
|
func (receiver *QueryAllCond) Filter() bson.M {
|
|
var query = bson.M{}
|
|
if receiver.Uid != nil {
|
|
query["publisherID"] = receiver.Uid
|
|
}
|
|
if receiver.VidTitle != nil {
|
|
query["vidTitle"] = bson.M{"$regex": receiver.VidTitle}
|
|
}
|
|
if receiver.Status != nil {
|
|
query["status"] = receiver.Status
|
|
}
|
|
if receiver.VidType != nil {
|
|
query["vidType"] = receiver.VidType
|
|
}
|
|
return query
|
|
}
|
|
|
|
func (receiver QueryAllCond) Options() *options.FindOptions {
|
|
return options.Find().SetSkip((receiver.Page - 1) * receiver.Limit).SetLimit(receiver.Limit).SetSort(bson.M{"createdAt": -1})
|
|
}
|
|
|
|
type EditCond struct {
|
|
ID primitive.ObjectID `json:"id" binding:"required"` // 文档
|
|
Status *int `json:"status" bson:"status"` // 状态 1 上架 2 下架
|
|
SortCode *int `json:"sortCode" bson:"sortCode"` // 排序号
|
|
Reason *string `json:"reason" bson:"reason"` // 拒绝原因
|
|
}
|
|
|
|
func (receiver *EditCond) Filter() bson.M {
|
|
return bson.M{"_id": receiver.ID}
|
|
}
|
|
|
|
func (receiver *EditCond) Update(updateAct string) bson.M {
|
|
var update = bson.M{}
|
|
if receiver.Reason != nil {
|
|
update["reason"] = receiver.Reason
|
|
}
|
|
if receiver.SortCode != nil {
|
|
update["sortCode"] = receiver.SortCode
|
|
}
|
|
if receiver.Status != nil {
|
|
update["status"] = receiver.Status
|
|
}
|
|
|
|
update["operateAccount"] = updateAct
|
|
update["updateTime"] = time.Now()
|
|
return bson.M{"$set": update}
|
|
}
|
|
|
|
type DeleteCond struct {
|
|
ID primitive.ObjectID `json:"id" binding:"required"` // 文档
|
|
}
|
|
|
|
func (receiver *DeleteCond) Filter() bson.M {
|
|
return bson.M{"_id": receiver.ID}
|
|
}
|