浏览代码

Merge branch 'yb_pc2.0' into debug

# Conflicts:
#	init_serve/router.go
ziwen 3 年之前
父节点
当前提交
269942fd5a

+ 150 - 0
controller/pc/pc.go

@@ -0,0 +1,150 @@
+package pc
+
+import (
+	"github.com/gin-gonic/gin"
+	"hongze/hongze_yb/controller/response"
+	models "hongze/hongze_yb/models/response/pc"
+	"hongze/hongze_yb/models/tables/rddp/banner"
+	"hongze/hongze_yb/models/tables/rddp/classify"
+	"hongze/hongze_yb/models/tables/rddp/report"
+	"hongze/hongze_yb/services/pc"
+	userService "hongze/hongze_yb/services/user"
+	"strconv"
+)
+
+// Banner 首页banner图
+func Banner(c *gin.Context)  {
+	banner,err := banner.GetHomeBannerList()
+	if err != nil {
+		response.Fail(err.Error(), c)
+		return
+	}
+	response.OkData("查询成功", banner, c )
+	return
+}
+
+// LatestRelease 上新公告
+func LatestRelease(c *gin.Context)  {
+	classifyIdString := c.DefaultQuery("ClassifyId","")
+	if classifyIdString == "" {
+		response.Fail("请输入classifyId", c)
+		return
+	}
+
+	classifyId, err := strconv.Atoi(classifyIdString)
+	if err != nil {
+		response.Fail("请输入正确classifyId", c)
+		return
+	}
+	classifyInfo, err := classify.GetByClassifyId(classifyId)
+	if err != nil {
+		response.Fail("分类查询出错", c)
+		return
+	}
+
+	response.OkData("查询成功", classifyInfo, c )
+	return
+}
+
+// ClassifyDetail 专栏详情
+func ClassifyDetail(c *gin.Context)  {
+	reqClassifyIdSecond := c.DefaultQuery("classify_id_second", "")
+	if reqClassifyIdSecond == "" {
+		response.Fail("请输入二级分类标识", c)
+		return
+	}
+
+	classifyIdSecond, err := strconv.Atoi(reqClassifyIdSecond)
+	if err != nil {
+		response.Fail("请输入正确的二级分类标识", c)
+		return
+	}
+	userinfo := userService.GetInfoByClaims(c)
+
+	detail, err := pc.GetClassifyDetail(userinfo, classifyIdSecond)
+	if err != nil {
+		response.Fail(err.Error(), c)
+		return
+	}
+	response.OkData("查询成功", detail, c )
+	return
+}
+
+// ClassifyDetailBanner 专栏详情banner图
+func ClassifyDetailBanner(c *gin.Context)  {
+	reqReportId := c.DefaultQuery("reportId", "")
+	if reqReportId == "" {
+		response.Fail("请输入二级分类标识", c)
+		return
+	}
+	reportId, err := strconv.Atoi(reqReportId)
+	if err != nil {
+		response.Fail("报告ID格式有误", c)
+		return
+	}
+	reportInfo, err := report.GetByReportId(reportId)
+	if err != nil {
+		response.Fail("报告查询出错", c)
+		return
+	}
+	if reportInfo.Id == 0 {
+		response.Fail("报告不存在", c)
+		return
+	}
+
+	if reportInfo.State != 2 {
+		response.Fail("报告未发布", c)
+		return
+	}
+
+	classifyInfo, err := classify.GetByClassifyId(reportInfo.ClassifyIdSecond)
+	if err != nil {
+		response.Fail("分类查询出错", c)
+		return
+	}
+	response.OkData("查询成功", classifyInfo, c )
+	return
+}
+
+// Recommend 专栏详情页更多推荐
+func Recommend(c *gin.Context)  {
+	reqReportId := c.DefaultQuery("reportId", "")
+	if reqReportId == "" {
+		response.Fail("请输入二级分类标识", c)
+		return
+	}
+	reportId, err := strconv.Atoi(reqReportId)
+	if err != nil {
+		response.Fail("报告ID格式有误", c)
+		return
+	}
+	reportInfo, err := report.GetByReportId(reportId)
+	if err != nil {
+		response.Fail("报告查询出错", c)
+		return
+	}
+	if reportInfo.Id == 0 {
+		response.Fail("报告不存在", c)
+		return
+	}
+
+	if reportInfo.State != 2 {
+		response.Fail("报告未发布", c)
+		return
+	}
+
+	reportType := 0
+	if reportInfo.ClassifyNameFirst == "权益研报" {
+		reportType = 1
+	} else {
+		reportType = 2
+	}
+	recommendList, err := models.GetRecommendList(reportId, reportType)
+	if err != nil {
+		response.Fail("获取报告详情失败"+err.Error(), c)
+		return
+	}
+
+	response.OkData("查询成功", recommendList, c )
+	return
+}

+ 2 - 0
init_serve/router.go

@@ -52,5 +52,7 @@ func InitRouter() (r *gin.Engine) {
 	routers.InitReport(r)
 	// 设置静态文件夹件路径
 	r.StaticFS("/static", http.Dir("./static"))
+	//pc相关路由
+	routers.InitPc(r)
 	return
 }

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

@@ -0,0 +1,28 @@
+package pc
+
+import (
+	"hongze/hongze_yb/models/response"
+	"hongze/hongze_yb/models/tables/rddp/customer_comment"
+)
+
+type ClassifyListItem struct {
+	ClassifyIdSecond   int    `json:"classify_id_second"`
+	ClassifyNameSecond string `json:"classify_name_second"`
+	ParentId           int    `json:"parent_id"`
+	ReportAuthor       string `json:"report_author"`
+	AuthorDescript     string `json:"author_descript"`
+	HomeImgUrl         string `json:"home_img_url"`
+	Stage              int    `description:"期数" json:"stage"`
+	ProductName        string `json:"product_name"`
+}
+
+type ClassifyDetail struct {
+	ClassifyListItem
+	Comments []*customer_comment.CustomerComment
+	AvatarImgUrl    string               `json:"avatar_img_url"`
+	Abstract        string               `json:"abstract"`
+	Descript        string               `json:"descript"`
+	PermissionCheck *response.PermissionCheckInfo `json:"permission_check"`
+	AuthOk          bool                 `json:"auth_ok"`
+	VipTitle        string               `json:"vip_title"'`
+}

+ 48 - 0
models/response/pc/report.go

@@ -0,0 +1,48 @@
+package pc
+
+import (
+	"fmt"
+	"hongze/hongze_yb/global"
+	"time"
+)
+
+type RecommendReport struct {
+	Id                 int       `description:"报告Id"`
+	AddType            int       `description:"新增方式:1:新增报告,2:继承报告"`
+	ClassifyIdFirst    int       `description:"一级分类id"`
+	ClassifyNameFirst  string    `description:"一级分类名称"`
+	ClassifyIdSecond   int       `description:"二级分类id"`
+	ClassifyNameSecond string    `description:"二级分类名称"`
+	Title              string    `description:"标题"`
+	Abstract           string    `description:"摘要"`
+	Author             string    `description:"作者"`
+	Frequency          string    `description:"频度"`
+	CreateTime         string    `description:"创建时间"`
+	ModifyTime         time.Time `description:"修改时间"`
+	State              int       `description:"1:未发布,2:已发布"`
+	PublishTime        string    `description:"发布时间"`
+	Stage              int       `description:"期数"`
+	MsgIsSend          int       `description:"消息是否已发送,0:否,1:是"`
+	Content            string    `description:"内容"`
+	VideoUrl           string    `description:"音频文件URL"`
+	VideoName          string    `description:"音频文件名称"`
+	VideoPlaySeconds   string    `description:"音频播放时长"`
+	VideoSize          string    `description:"音频文件大小,单位M"`
+	ContentSub         string    `description:"内容前两个章节"`
+	ClassifyName       string    `description:"分类名称"`
+	HasPermission      int       `description:"报告权限:0:无权限,1:有权限"`
+	TitleType          string    `description:"标题类型,FICC或者权益"`
+}
+
+func GetRecommendList(reportId, reportType int) (items []*RecommendReport, err error) {
+	sql := `SELECT * FROM report WHERE state=2 AND id<> %v`
+	sql = fmt.Sprintf(sql,reportId)
+	if reportType == 1 {
+		sql += ` AND classify_name_first='权益研报' `
+	} else {
+		sql += ` AND classify_name_first<>'权益研报' `
+	}
+	sql += ` ORDER BY publish_time DESC LIMIT 3`
+	err = global.MYSQL["rddp"].Raw(sql).Scan(&items).Error
+	return
+}

+ 26 - 0
models/tables/rddp/banner/banner.go

@@ -0,0 +1,26 @@
+package banner
+
+import "time"
+
+type Banner struct {
+	Id             int       `orm:"column(id);pk"`
+	ClassifyId     int       `description:"分类id"`
+	ImageUrl       string    `description:"图片路径"`
+	BannerType     int       `description:"类型 1:轮播图,2:头部海报"`
+	CreateTime     time.Time `description:"创建时间"`
+	ModifyTime     time.Time `description:"修改时间"`
+	ClassifyName   string    `description:"分类名称"`
+	JumpUrl        string    `description:"跳转地址"`
+	Abstract       string    `description:"栏目简介"`
+	Descript       string    `description:"分享描述"`
+	ReportAuthor   string    `description:"栏目作者"`
+	AuthorDescript string    `description:"作者简介"`
+	ColumnImgUrl   string    `description:"栏目配图"`
+	HeadImgUrl     string    `description:"头部banner"`
+	AvatarImgUrl   string    `description:"头像"`
+	ReportImgUrl   string    `description:"报告配图"`
+}
+
+func (c *Banner) TableName() string  {
+	return "banner"
+}

+ 11 - 0
models/tables/rddp/banner/query.go

@@ -0,0 +1,11 @@
+package banner
+
+import (
+	"hongze/hongze_yb/global"
+)
+
+// GetHomeBannerList 获取最新的轮播图
+func GetHomeBannerList() (item *Banner, err error) {
+	err = global.MYSQL["rddp"].Model(Banner{}).Where("banner_type=1").Order("modify_time DESC").First(&item).Error
+	return
+}

+ 13 - 0
models/tables/rddp/customer_comment/customer_comment.go

@@ -0,0 +1,13 @@
+package customer_comment
+
+type CustomerComment struct {
+	Id           int
+	HeadImgUrl   string
+	CustomerName string
+	CompanyName  string
+	Comment      string
+}
+
+func (c *CustomerComment) TableName() string  {
+	return "customer_comment"
+}

+ 9 - 0
models/tables/rddp/customer_comment/query.go

@@ -0,0 +1,9 @@
+package customer_comment
+
+import "hongze/hongze_yb/global"
+
+// GetCustomerComment 获取客户评价
+func GetCustomerComment() (item []*CustomerComment, err error) {
+	err = global.MYSQL["rddp"].Model(CustomerComment{}).Find(&item).Error
+	return
+}

+ 16 - 0
routers/pc.go

@@ -0,0 +1,16 @@
+package routers
+
+import (
+	"github.com/gin-gonic/gin"
+	"hongze/hongze_yb/controller/pc"
+	"hongze/hongze_yb/middleware"
+)
+
+func InitPc(r *gin.Engine)  {
+	rGroup := r.Group("pc").Use(middleware.Token())
+	rGroup.GET("/banner", pc.Banner)
+	rGroup.GET("/latest_release", pc.LatestRelease)
+	rGroup.GET("/detail", pc.ClassifyDetail)
+	rGroup.GET("/detail_banner", pc.ClassifyDetailBanner)
+	rGroup.GET("/recommend", pc.Recommend)
+}

+ 74 - 0
services/pc/report.go

@@ -0,0 +1,74 @@
+package pc
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/models/response/pc"
+	"hongze/hongze_yb/models/tables/chart_permission_search_key_word_mapping"
+	"hongze/hongze_yb/models/tables/rddp/classify"
+	"hongze/hongze_yb/models/tables/rddp/customer_comment"
+	"hongze/hongze_yb/services/company"
+	"hongze/hongze_yb/services/user"
+	"hongze/hongze_yb/utils"
+)
+
+func GetClassifyDetail(user user.UserInfo, classifyIdSecond int) (detail *pc.ClassifyDetail, err error)  {
+	var errMsg string
+	defer func() {
+		if err != nil {
+			global.LOG.Critical(fmt.Sprintf("GetClassifyDetail: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
+		}
+	}()
+	classifyInfo, err := classify.GetByClassifyId(classifyIdSecond)
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("分类查询出错")
+		return
+	}
+
+	if classifyInfo.Id == 0 {
+		err = errors.New("分类不存在")
+		return
+	}
+	if classifyInfo.ParentId == 0 {
+		err = errors.New("只允许查询二级分类")
+		return
+	}
+	//查询权限, 查询当前分类下的最新的报告,
+	permissionIds, err := chart_permission_search_key_word_mapping.GetChartPermissionIdsByKeyWord(classifyInfo.ClassifyName)
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("分类权限查询出错")
+		return
+	}
+	authOk, permissionCheckInfo, _, err := company.GetCheckPermission(user.CompanyID, int(user.UserID), permissionIds)
+	if err != nil && err != utils.ErrNoRow {
+		errMsg = err.Error()
+		err = errors.New("权限查询出错")
+		return
+	}
+
+	comments,err := customer_comment.GetCustomerComment()
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("客户评价查询出错")
+		return
+	}
+
+	detail = new(pc.ClassifyDetail)
+	detail.ClassifyIdSecond = classifyInfo.Id
+	detail.ParentId = classifyInfo.ParentId
+	detail.AuthorDescript = classifyInfo.AuthorDescript
+	detail.ReportAuthor = classifyInfo.ReportAuthor
+	detail.AvatarImgUrl = classifyInfo.AvatarImgUrl
+	detail.ClassifyNameSecond = classifyInfo.ClassifyName
+	detail.Abstract = classifyInfo.Abstract
+	detail.Descript = classifyInfo.Descript
+	detail.VipTitle = classifyInfo.VipTitle
+	detail.PermissionCheck = &permissionCheckInfo
+	detail.AuthOk = authOk
+	detail.Comments = comments
+
+	return
+}