185 lines
4.5 KiB
Go
185 lines
4.5 KiB
Go
package officialWebsitectrl
|
|
|
|
import (
|
|
"91porn-server/common"
|
|
"91porn-server/common/stderr"
|
|
"91porn-server/models/v/tagmod"
|
|
"91porn-server/models/v/vidmod"
|
|
officialwebsiteser "91porn-server/web/service/officialWebsiteser"
|
|
"91porn-server/web/service/vidser"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
type VideoListFromVidResp struct {
|
|
VInfos []*VideoResp `json:"vInfos"` // 帖子列表
|
|
Total int64 `json:"total"` // 帖子总量
|
|
}
|
|
|
|
type VideoResp struct {
|
|
*vidmod.WebVideo
|
|
AddedInfoOfficialWebsite bool `json:"added_info_official_website"`
|
|
}
|
|
|
|
func ListVideoFromVid(ctx *gin.Context) {
|
|
req := vidmod.ListReq{}
|
|
if err := ctx.ShouldBind(&req); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, nil)
|
|
return
|
|
}
|
|
m, sort, err := assembleConditions(req)
|
|
if err != stderr.Success {
|
|
common.ServeJSON(ctx, err, err)
|
|
return
|
|
}
|
|
code, data := vidser.GetVidList(m, sort, req.PageNumber, req.PageSize, req.IsPush)
|
|
|
|
videoList := make([]*VideoResp, 0)
|
|
var ids []primitive.ObjectID
|
|
for _, v := range data.VInfos {
|
|
ids = append(ids, v.ID)
|
|
videoList = append(videoList, &VideoResp{
|
|
WebVideo: v,
|
|
AddedInfoOfficialWebsite: false,
|
|
})
|
|
}
|
|
if len(ids) == 0 {
|
|
common.ServeJSON(ctx, code, videoList)
|
|
return
|
|
}
|
|
|
|
checkData, checkErr := officialwebsiteser.CheckVideoExistByVid(ids)
|
|
if checkErr != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbQueryError, nil)
|
|
return
|
|
}
|
|
for i := range videoList {
|
|
for j := range checkData {
|
|
if videoList[i].WebVideo.ID == checkData[j].ID {
|
|
videoList[i].AddedInfoOfficialWebsite = true
|
|
break
|
|
}
|
|
}
|
|
}
|
|
common.ServeJSON(ctx, code, &VideoListFromVidResp{
|
|
VInfos: videoList,
|
|
Total: data.Total,
|
|
})
|
|
}
|
|
|
|
func assembleConditions(req vidmod.ListReq) (m map[string]interface{}, sort vidser.SortModeList, err stderr.Code) {
|
|
sort = vidser.SortModeList{{Field: "createdAt", Value: -1}}
|
|
m = make(map[string]interface{})
|
|
if req.ShowType != nil {
|
|
m["showType"] = *req.ShowType
|
|
}
|
|
if req.Status != 4 {
|
|
if req.Status == 7 {
|
|
m["status"] = map[string]int{"$gt": 0}
|
|
} else {
|
|
m["status"] = req.Status
|
|
}
|
|
}
|
|
if req.IsFree == 0 {
|
|
m["coins"] = map[string]int{"$gt": 0}
|
|
}
|
|
if req.IsFree == 1 {
|
|
m["coins"] = map[string]int{"$eq": 0}
|
|
}
|
|
if req.IsUserUp == 2 {
|
|
m["publisherID"] = map[string]int{"$lt": 115000}
|
|
}
|
|
if req.IsUserUp == 1 {
|
|
m["publisherID"] = map[string]int{"$gt": 115000}
|
|
}
|
|
if len(req.Title) != 0 {
|
|
m["title"] = map[string]string{"$regex": req.Title, "$options": "i"}
|
|
}
|
|
if req.UID > 0 {
|
|
m["publisherID"] = req.UID
|
|
}
|
|
if req.Chosen == 1 {
|
|
m["chosen"] = true
|
|
}
|
|
if req.Chosen == 2 {
|
|
m["chosen"] = false
|
|
}
|
|
if req.FreeArea == 1 {
|
|
m["freeArea"] = true
|
|
}
|
|
if req.FreeArea == 2 {
|
|
m["freeArea"] = false
|
|
}
|
|
if !req.End.IsZero() {
|
|
m["createdAt"] = map[string]time.Time{"$gte": req.Start, "$lt": req.End}
|
|
}
|
|
if req.ReviewAccount != "" {
|
|
m["reviewAccount"] = req.ReviewAccount
|
|
}
|
|
if len(req.Tag) != 0 {
|
|
id, err := tagmod.GetTagIDByName(req.Tag)
|
|
if err != nil {
|
|
return m, sort, stderr.ErrDbQueryError
|
|
}
|
|
m["tags"] = id
|
|
//sort = vidser.SortModeList{{Field: "tagSort." + id.Hex(), Value: -1}, {Field: "createdAt", Value: -1}}
|
|
}
|
|
if len(req.ID) != 0 {
|
|
oid, err := primitive.ObjectIDFromHex(req.ID)
|
|
if err != nil {
|
|
return m, sort, stderr.ErrParamError
|
|
}
|
|
m["_id"] = oid
|
|
}
|
|
//通过初始价格判断是否是马甲账号
|
|
if req.IsPretendAcc == 1 {
|
|
m["coins"] = vidmod.PretendAccInitCoins
|
|
}
|
|
if req.IsPretendAcc == 2 {
|
|
//i := make(map[string]int64)
|
|
//i["$ne"] = vidmod.PretendAccInitCoins
|
|
m["coins"] = map[string]int64{"$ne": vidmod.PretendAccInitCoins}
|
|
}
|
|
m["deleteAt"] = bson.M{"$exists": false}
|
|
if req.NewsType != "" {
|
|
m["newsType"] = req.NewsType
|
|
}
|
|
|
|
if req.LiaoBaTop != nil {
|
|
if *req.LiaoBaTop {
|
|
sort = vidser.LiaoBaTopSortModeList()
|
|
m["liaoBaTopSort"] = bson.M{"$gt": 0}
|
|
} else {
|
|
m["liaoBaTopSort"] = 0
|
|
}
|
|
}
|
|
if req.SectionID != "" {
|
|
m["sectionID"] = req.SectionID
|
|
}
|
|
m["isSortedUnderModule"] = req.IsSortedUnderModule
|
|
if req.IsSortedUnderModule {
|
|
sort = nil
|
|
}
|
|
if req.IsRecommended != nil {
|
|
if *req.IsRecommended {
|
|
m["recoWeight"] = bson.M{"$gte": 0}
|
|
} else {
|
|
m["recoWeight"] = bson.M{"$lt": 0}
|
|
}
|
|
}
|
|
if req.Key == "likeRate" || req.Key == "purchaseRate" {
|
|
m[req.Key] = req.Value
|
|
}
|
|
if req.IsHappinessPlazaTop != nil && *req.IsHappinessPlazaTop {
|
|
if *req.IsHappinessPlazaTop {
|
|
m["happinessPlazaTop"] = bson.M{"$gt": 0}
|
|
} else {
|
|
m["happinessPlazaTop"] = bson.M{"$lte": 0}
|
|
}
|
|
}
|
|
return m, sort, stderr.Success
|
|
}
|