@@ -0,0 +1,53 @@
|
||||
package videogoldcoinmod
|
||||
|
||||
import (
|
||||
"91porn-server/models/v/vidmod"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"time"
|
||||
)
|
||||
|
||||
type QueryVideoGoldCoinCond struct {
|
||||
Page int64 `form:"pageNumber" binding:"required"` // 当前页码
|
||||
Limit int64 `form:"pageSize" binding:"required"` // 每页条数
|
||||
}
|
||||
|
||||
type QueryVideoGoldCoinRes struct {
|
||||
List []*APPVideoGoldCoin `json:"list" bson:"list"` // 视频列表
|
||||
ActivityDetail ActivityDetail `json:"activityDetail" bson:"activityDetail"` // 活动详情
|
||||
HasNext bool `json:"hasNext" bson:"hasNext"` // 是否还有下一页
|
||||
Total int64 `json:"total" bson:"total"` // 视频总数
|
||||
}
|
||||
|
||||
type ActivityDetail struct {
|
||||
StartTime time.Time `json:"startTime" bson:"startTime,omitempty"` // 支付尾款开始时间
|
||||
EndTime time.Time `json:"endTime" bson:"endTime,omitempty"` // 支付尾款/活动 结束时间
|
||||
BalancePayment bool `json:"balancePayment" bson:"balancePayment"` // 是否有尾款支付
|
||||
ActivityTime time.Time `json:"activityTime" bson:"activityTime,omitempty"` // 活动时间
|
||||
AdvanceAmount int64 `bson:"advanceAmount" json:"advanceAmount"` // 预付金额
|
||||
BalanceAmount int64 `bson:"balanceAmount" json:"balanceAmount"` // 尾款金额
|
||||
Status int `json:"status" bson:"status"` // 预售订单状态
|
||||
TotalCount int64 `json:"totalCount" bson:"totalCount,omitempty"` // 会员卡总数
|
||||
}
|
||||
|
||||
type APPVideoGoldCoin struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` // id
|
||||
VidId primitive.ObjectID `json:"vidId" bson:"vidId"` // 帖子id
|
||||
VidTitle string `json:"vidTitle" bson:"vidTitle"` // 视频标题
|
||||
SourceURL string `json:"sourceURL" bson:"sourceURL"` // 视频资源地址Path
|
||||
Cover string `json:"cover" bson:"cover"` // 封面图
|
||||
SeriesCover []string `json:"seriesCover" bson:"seriesCover"` // 帖子套图
|
||||
Coins int64 `json:"coins" bson:"coins"` // 定价
|
||||
Detail *vidmod.VideoInfo `json:"detail" bson:"detail"` // 详细数据
|
||||
}
|
||||
|
||||
func (receiver *QueryVideoGoldCoinCond) Filter() bson.M {
|
||||
var query = bson.M{}
|
||||
query["status"] = 1
|
||||
return query
|
||||
}
|
||||
|
||||
func (receiver QueryVideoGoldCoinCond) Options() *options.FindOptions {
|
||||
return options.Find().SetSkip((receiver.Page - 1) * receiver.Limit).SetLimit(receiver.Limit + 1).SetSort(bson.M{"sortCode": -1})
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package videogoldcoinmod
|
||||
|
||||
import (
|
||||
"91porn-server/common/db"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models"
|
||||
"errors"
|
||||
"fmt"
|
||||
"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.VideoGoldCoin
|
||||
|
||||
func coll(t *db.MongoTool) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(table)
|
||||
}
|
||||
return t.Coll(table)
|
||||
}
|
||||
|
||||
// initIndex 索引设置
|
||||
func initIndex() {
|
||||
many := []mongo.IndexModel{ //batch set indexes //value is the type 1 or -1
|
||||
{
|
||||
Keys: bson.D{{"createdAt", -1}},
|
||||
},
|
||||
}
|
||||
_, err := coll(nil).CreateIndex(many)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("user model set index err ==>[%+v]", err))
|
||||
}
|
||||
}
|
||||
|
||||
func Init() {
|
||||
mdb = db.Init(table)
|
||||
initIndex()
|
||||
}
|
||||
|
||||
func InsertOne(mt *db.MongoTool, cfg VideoGoldCoin) error {
|
||||
if _, err := coll(mt).InsertOne(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// QueryAllList 分页查询文档
|
||||
func QueryAllList(filter primitive.M, opts ...*options.FindOptions) (out []*VideoGoldCoin, 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
|
||||
}
|
||||
}
|
||||
|
||||
// Edit 修改文档
|
||||
func Edit(filter, update primitive.M) error {
|
||||
result, err := coll(nil).UpdateOne(filter, update)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Edit", table, "UpdateOne", err),
|
||||
log.Any("filter", filter),
|
||||
log.Any("update", update),
|
||||
)
|
||||
return err
|
||||
}
|
||||
if result.ModifiedCount == 0 {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Edit", table, "result.ModifiedCount", "ModifiedCount is zero"),
|
||||
log.Any("filter", filter),
|
||||
log.Any("update", update),
|
||||
)
|
||||
return errors.New("result is null")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetVideoList 获取金币视频列表
|
||||
func GetVideoList(skip, limit int64, cond bson.M, opts ...*options.FindOptions) (back []*APPVideoGoldCoin, total int64, hasNext bool, err error) {
|
||||
// 获取总条数
|
||||
total, err = coll(nil).Count(cond)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "getVideoList", table, "Find", err),
|
||||
log.Any("skip", skip),
|
||||
log.Any("limit", limit),
|
||||
log.Any("cond", cond))
|
||||
return
|
||||
}
|
||||
if total == 0 {
|
||||
return
|
||||
}
|
||||
err = coll(nil).Find(&back, cond, opts...)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "getVideoList", table, "Find", err),
|
||||
log.Any("skip", skip),
|
||||
log.Any("limit", limit),
|
||||
log.Any("cond", cond),
|
||||
)
|
||||
return
|
||||
}
|
||||
if len(back) > int(limit) {
|
||||
hasNext = true
|
||||
back = back[:limit]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func InsertMany(records []VideoGoldCoin) error {
|
||||
opts := options.InsertMany().SetOrdered(false)
|
||||
_, err := coll(nil).InsertMany(records, opts)
|
||||
if !db.IsMongoDupKey(err) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func IsExistByVideoID(videoID primitive.ObjectID) (bool, error) {
|
||||
count, err := coll(nil).Count(bson.M{"_id": videoID})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if count > 0 {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// Remove 删除
|
||||
func Remove(filter primitive.M) (err error) {
|
||||
_, err = coll(nil).DeleteOne(filter)
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Remove", table, "DeleteOne", err),
|
||||
log.Any("filter", filter),
|
||||
)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package videogoldcoinmod
|
||||
|
||||
import (
|
||||
"91porn-server/common/db"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
mdb *db.MongoDB
|
||||
)
|
||||
|
||||
type VideoGoldCoin struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` // id
|
||||
PublisherID uint64 `json:"publisherID" bson:"publisherID"` // 上传者ID
|
||||
Portrait string `json:"portrait" bson:"portrait"` // 上传者头像
|
||||
Name string `json:"name" bson:"name"` // 上传者姓名
|
||||
VidId primitive.ObjectID `json:"vidId" bson:"vidId"` // 帖子id
|
||||
Status int `json:"status" bson:"status"` // 状态,1 上架 2 下架 默认为 1
|
||||
Reason string `json:"reason" bson:"reason,omitempty"` // 下架理由
|
||||
VidType string `json:"vidType" bson:"vidType"` // 帖子类型
|
||||
VidTitle string `json:"vidTitle" bson:"vidTitle"` // 视频标题
|
||||
Coins int64 `json:"coins" bson:"coins"` // 定价
|
||||
SourceURL string `json:"sourceURL" bson:"sourceURL"` // 视频资源地址Path
|
||||
Cover string `json:"cover" bson:"cover"` // 封面图
|
||||
SeriesCover []string `json:"seriesCover" bson:"seriesCover"` // 帖子套图
|
||||
SortCode int `json:"sortCode" bson:"sortCode"` // 排序号
|
||||
OperateAccount string `json:"operateAccount" bson:"operateAccount,omitempty"` // 操作者
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt,omitempty"` // 创建时间
|
||||
UpdateTime time.Time `json:"updateTime" bson:"updateTime,omitempty"` // 更新时间
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
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}
|
||||
}
|
||||
Reference in New Issue
Block a user