Explorar el Código

上新公告,最新资讯

ziwen hace 2 años
padre
commit
a6b34bcf4e

+ 16 - 4
controller/pc/pc.go

@@ -5,9 +5,9 @@ import (
 	"hongze/hongze_yb/controller/response"
 	pcModels "hongze/hongze_yb/models/response/pc"
 	"hongze/hongze_yb/models/tables/customer_comment"
-	"hongze/hongze_yb/models/tables/rddp/banner"
 	"hongze/hongze_yb/models/tables/rddp/classify"
 	"hongze/hongze_yb/models/tables/rddp/report"
+	"hongze/hongze_yb/models/tables/yb_activity"
 	"hongze/hongze_yb/models/tables/yb_pc_suncode"
 	"hongze/hongze_yb/services"
 	"hongze/hongze_yb/services/pc"
@@ -46,14 +46,26 @@ func LatestNews(c *gin.Context) {
 	return
 }
 
-// Banner 首页banner图
+// Banner 上新公告banner图
 func Banner(c *gin.Context) {
-	banner, err := banner.GetHomeBannerList()
+	var  resp pcModels.LatestReleaseResp
+	activityItem,err := yb_activity.GetLatestActivity()
 	if err != nil {
 		response.Fail(err.Error(), c)
 		return
 	}
-	response.OkData("查询成功", banner, c)
+	reportItem,err := report.GetLatestReport()
+	if err != nil {
+		response.Fail(err.Error(), c)
+		return
+	}
+	if activityItem.CreateTime.Before(reportItem.PublishTime) {
+		resp.ActivityOrReport = 0
+		resp.Activity = activityItem
+		resp.ImgUrl = "https://hongze.oss-accelerate.aliyuncs.com/static/images/202101/20210115/3HJfHLehkVwv0Rxl4Wz747i3aqx8.png"
+	}
+
+	response.OkData("查询成功", resp, c)
 	return
 }
 

+ 6 - 0
models/response/pc/classify.go

@@ -3,6 +3,7 @@ package pc
 import (
 	"hongze/hongze_yb/models/response"
 	"hongze/hongze_yb/models/tables/rddp/customer_comment"
+	"hongze/hongze_yb/models/tables/yb_activity"
 )
 
 type ClassifyListItem struct {
@@ -52,3 +53,8 @@ func (c ClassifyFirstList) Swap(i, j int) {
 	c[i], c[j] = c[j], c[i]
 }
 
+type LatestReleaseResp struct {
+	ActivityOrReport int `description:"活动或专栏:0,活动,1,专栏" json:"redirect_type"`
+	Activity         *yb_activity.YbActivity
+	ImgUrl           string
+}

+ 7 - 6
models/response/pc/report.go

@@ -54,12 +54,13 @@ func GetRecommendList(reportId, reportType, secondId int) (items []*Report, err
 }
 
 type LatestReport struct {
-	Id                int       `orm:"column(id)" description:"报告Id" json:"_"`
-	ClassifyNameFirst string    `description:"一级分类名称" json:"classify_name_first"`
-	Title             string    `description:"标题" json:"title"`
-	State             int       `description:"1:未发布,2:已发布" json:"state"`
-	PublishTime       time.Time `description:"发布时间" json:"publish_time"`
-	Stage             int       `description:"期数" json:"stage"`
+	Id                 int       `orm:"column(id)" description:"报告Id" json:"_"`
+	ClassifyNameFirst  string    `description:"一级分类名称" json:"classify_name_first"`
+	ClassifyNameSecond string    `description:"二级分类名称" json:"classify_name_second"`
+	Title              string    `description:"标题" json:"title"`
+	State              int       `description:"1:未发布,2:已发布" json:"state"`
+	PublishTime        time.Time `description:"发布时间" json:"publish_time"`
+	Stage              int       `description:"期数" json:"stage"`
 }
 
 func GetLatestStage(classifyNames []string) (items []*LatestReport, err error) {

+ 30 - 2
models/tables/rddp/report/query.go

@@ -3,6 +3,7 @@ package report
 import (
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/models/response"
+	"hongze/hongze_yb/models/response/pc"
 	"hongze/hongze_yb/utils"
 )
 
@@ -314,7 +315,7 @@ WHERE
 }
 
 // GetLatestReportByPermission 根据权限相关的分类查询最新的三篇专栏报告
-func GetLatestReportByPermission(classifyIdSeconds []int) (list []*response.ReportCollectListItem, err error)  {
+func GetLatestReportByPermission(classifyIdSeconds []int) (list []*pc.LatestReport, err error)  {
 	sql := `SELECT
 id AS report_id,
 0 AS report_chapter_id,
@@ -325,6 +326,7 @@ classify_name_second,
 0 as report_chapter_type_id,
 title,
 content_sub,
+stage,
 publish_time 
 FROM
 	report
@@ -333,8 +335,34 @@ WHERE
 	AND classify_name_first != "周报" 
 	AND classify_id_second in ?
 	AND state = 2
-	ORDER BY publish_time DESC, report_id desc LIMIT 3
+	ORDER BY publish_time DESC LIMIT 3
 	`
 	err = global.MYSQL["rddp"].Raw(sql, classifyIdSeconds).Scan(&list).Error
 	return
+}
+
+// GetLatestReport 获取最新专栏信息
+func GetLatestReport() (list *pc.LatestReport, err error)  {
+	sql := `SELECT
+id AS report_id,
+0 AS report_chapter_id,
+classify_id_first,
+classify_id_second,
+classify_name_first,
+classify_name_second,
+0 as report_chapter_type_id,
+title,
+content_sub,
+stage,
+publish_time 
+FROM
+	report
+WHERE
+	classify_name_first != "晨报" 
+	AND classify_name_first != "周报" 
+	AND state = 2
+	ORDER BY publish_time DESC LIMIT 1
+	`
+	err = global.MYSQL["rddp"].Raw(sql).First(&list).Error
+	return
 }

+ 7 - 0
models/tables/yb_activity/query.go

@@ -104,4 +104,11 @@ func GetListCountByIds(activityIds []int) (total int64, err error)  {
 		Where("activity_id in (?) and is_delete = 0 and publish_status = 1", activityIds).
 		Count(&total).Error
 	return
+}
+
+
+// GetLatestActivity 获取最新的活动
+func GetLatestActivity() (activity *YbActivity, err error)  {
+	err = global.DEFAULT_MYSQL.Model(YbActivity{}).Where("is_delete = 0 and publish_status = 1").Order("create_time desc").First(&activity).Error
+	return
 }

+ 12 - 4
services/pc/report.go

@@ -4,7 +4,6 @@ import (
 	"errors"
 	"fmt"
 	"hongze/hongze_yb/global"
-	"hongze/hongze_yb/models/response"
 	"hongze/hongze_yb/models/response/pc"
 	"hongze/hongze_yb/models/tables/chart_permission"
 	"hongze/hongze_yb/models/tables/chart_permission_search_key_word_mapping"
@@ -77,7 +76,7 @@ func GetClassifyDetail(user user.UserInfo, classifyIdSecond int) (detail *pc.Cla
 }
 
 // GetLatestReportList 首页最新资讯
-func GetLatestReportList(user user.UserInfo, chartPermissionId int) (ret []*response.ReportCollectListItem, err error) {
+func GetLatestReportList(user user.UserInfo, chartPermissionId int) (ret []*pc.LatestReport, err error) {
 	var errMsg string
 	defer func() {
 		if err != nil {
@@ -115,7 +114,7 @@ func GetLatestReportList(user user.UserInfo, chartPermissionId int) (ret []*resp
 		}
 	}
 
-	var reportList []*response.ReportCollectListItem
+	var reportList []*pc.LatestReport
 	if len(classifySecondIds) > 0 {
 		reportList, err = report.GetLatestReportByPermission(classifySecondIds)
 		if err != nil {
@@ -124,7 +123,16 @@ func GetLatestReportList(user user.UserInfo, chartPermissionId int) (ret []*resp
 			return
 		}
 	}
-
+	//文章不足三篇时用下一品种补全
+	//if len(reportList) < 3 {
+	//
+	//	reportList, err = report.GetLatestReportByPermission(classifySecondIds)
+	//	if err != nil {
+	//		errMsg = err.Error()
+	//		err = errors.New("查询报告信息出错")
+	//		return
+	//	}
+	//}
 	ret = reportList
 	return
 }