mirror of
https://github.com/ProudMuBai/GoFilm.git
synced 2026-02-14 14:34:43 +08:00
pc tag search finish
This commit is contained in:
@@ -188,6 +188,7 @@ func FilmTagSearch(c *gin.Context) {
|
||||
current, _ := strconv.Atoi(currentStr)
|
||||
page := model.Page{PageSize: 49, Current: current}
|
||||
logic.IL.GetFilmsByTags(params, &page)
|
||||
// 获取当前分类Title
|
||||
// 返回对应信息
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
@@ -208,3 +209,29 @@ func FilmTagSearch(c *gin.Context) {
|
||||
"page": page,
|
||||
})
|
||||
}
|
||||
|
||||
// FilmClassify 影片分类首页数据展示
|
||||
func FilmClassify(c *gin.Context) {
|
||||
pidStr := c.DefaultQuery("Pid", "")
|
||||
if pidStr == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "缺少分类信息",
|
||||
})
|
||||
return
|
||||
}
|
||||
// 1. 顶部Title数据
|
||||
pid, _ := strconv.ParseInt(pidStr, 10, 64)
|
||||
title := logic.IL.GetPidCategory(pid)
|
||||
// 2. 设置分页信息
|
||||
page := model.Page{PageSize: 21, Current: 1}
|
||||
// 3. 获取当前分类下的 最新上映, 排行榜, 最近更新 影片信息
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"data": gin.H{
|
||||
"title": title,
|
||||
"content": logic.IL.GetFilmClassify(pid, &page),
|
||||
},
|
||||
"page": page,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -204,9 +204,19 @@ func (i *IndexLogic) GetFilmsByTags(st model.SearchTagsVO, page *model.Page) []m
|
||||
// 获取满足条件的影片id 列表
|
||||
sl := model.GetSearchInfosByTags(st, page)
|
||||
// 通过key 获取对应影片的基本信息
|
||||
var list []model.MovieBasicInfo
|
||||
for _, s := range sl {
|
||||
list = append(list, model.GetBasicInfoByKey(fmt.Sprintf(config.MovieBasicInfoKey, s.Cid, s.Mid)))
|
||||
}
|
||||
return list
|
||||
return model.GetBasicInfoBySearchInfos(sl...)
|
||||
}
|
||||
|
||||
// GetFilmClassify 通过Pid返回当前所属分类下的首页展示数据
|
||||
func (i *IndexLogic) GetFilmClassify(pid int64, page *model.Page) map[string]interface{} {
|
||||
res := make(map[string]interface{})
|
||||
// 最新上映 (上映时间)
|
||||
res["news"] = model.GetMovieListBySort(0, pid, page)
|
||||
// 排行榜 (暂定为热度排行)
|
||||
res["top"] = model.GetMovieListBySort(1, pid, page)
|
||||
// 最近更新 (更新时间)
|
||||
res["recent"] = model.GetMovieListBySort(2, pid, page)
|
||||
|
||||
return res
|
||||
|
||||
}
|
||||
|
||||
@@ -232,6 +232,18 @@ func GetDetailByKey(key string) MovieDetail {
|
||||
return detail
|
||||
}
|
||||
|
||||
// GetBasicInfoBySearchInfos 通过searchInfo 获取影片的基本信息
|
||||
func GetBasicInfoBySearchInfos(infos ...SearchInfo) []MovieBasicInfo {
|
||||
var list []MovieBasicInfo
|
||||
for _, s := range infos {
|
||||
data := []byte(db.Rdb.Get(db.Cxt, fmt.Sprintf(config.MovieBasicInfoKey, s.Cid, s.Mid)).Val())
|
||||
basic := MovieBasicInfo{}
|
||||
_ = json.Unmarshal(data, &basic)
|
||||
list = append(list, basic)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
/*
|
||||
对附属播放源入库时的name|dbID进行处理,保证唯一性
|
||||
1. 去除name中的所有空格
|
||||
|
||||
@@ -310,6 +310,14 @@ func TunCateSearchTable() {
|
||||
}
|
||||
}
|
||||
|
||||
// GetPage 获取分页相关数据
|
||||
func GetPage(db *gorm.DB, page *Page) {
|
||||
var count int64
|
||||
db.Count(&count)
|
||||
page.Total = int(count)
|
||||
page.PageCount = int((page.Total + page.PageSize - 1) / page.PageSize)
|
||||
}
|
||||
|
||||
// ================================= API 数据接口信息处理 =================================
|
||||
|
||||
// GetMovieListByPid 通过Pid 分类ID 获取对应影片的数据信息
|
||||
@@ -563,11 +571,28 @@ func GetSearchInfosByTags(st SearchTagsVO, page *Page) []SearchInfo {
|
||||
|
||||
}
|
||||
|
||||
func GetPage(db *gorm.DB, page *Page) {
|
||||
var count int64
|
||||
db.Count(&count)
|
||||
page.Total = int(count)
|
||||
page.PageCount = int((page.Total + page.PageSize - 1) / page.PageSize)
|
||||
// GetMovieListBySort 通过排序类型返回对应的影片基本信息
|
||||
func GetMovieListBySort(t int, pid int64, page *Page) []MovieBasicInfo {
|
||||
var sl []SearchInfo
|
||||
qw := db.Mdb.Model(&SearchInfo{}).Where("pid", pid).Limit(page.PageSize).Offset((page.Current) - 10*page.PageSize)
|
||||
// 针对不同排序类型返回对应的分页数据
|
||||
switch t {
|
||||
case 0:
|
||||
// 最新上映 (上映时间)
|
||||
qw.Order("year DESC, release_date DESC")
|
||||
case 1:
|
||||
// 排行榜 (暂定为热度排行)
|
||||
qw.Order("year DESC, hits DESC")
|
||||
case 2:
|
||||
// 最近更新 (更新时间)
|
||||
qw.Order("year DESC, update_stamp DESC")
|
||||
}
|
||||
if err := qw.Find(&sl).Error; err != nil {
|
||||
log.Println(err)
|
||||
return nil
|
||||
}
|
||||
return GetBasicInfoBySearchInfos(sl...)
|
||||
|
||||
}
|
||||
|
||||
// ================================= 接口数据缓存 =================================
|
||||
|
||||
@@ -19,7 +19,8 @@ func SetupRouter() *gin.Engine {
|
||||
r.GET(`/filmPlayInfo`, controller.FilmPlayInfo)
|
||||
r.GET(`/searchFilm`, controller.SearchFilm)
|
||||
r.GET(`/filmCategory`, controller.FilmCategory)
|
||||
r.GET(`/filmClassified`, controller.FilmTagSearch)
|
||||
r.GET(`/filmClassify`, controller.FilmClassify)
|
||||
r.GET(`/filmClassifySearch`, controller.FilmTagSearch)
|
||||
|
||||
// 触发spider
|
||||
spiderRoute := r.Group(`/spider`)
|
||||
|
||||
Reference in New Issue
Block a user