Browse Source

首页-最新

hsun 2 years ago
parent
commit
ce33ea9826
4 changed files with 557 additions and 85 deletions
  1. 328 65
      controllers/home.go
  2. 22 20
      models/article.go
  3. 97 0
      models/micro_roadshow.go
  4. 110 0
      services/micro_roadshow.go

+ 328 - 65
controllers/home.go

@@ -326,6 +326,293 @@ func (this *BaseHomeController) ListHomePublic() {
 	br.Data = resp
 }
 
+// @Title 首页列表接口v6版本
+// @Description 首页列表接口v6版本
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   ChartPermissionId   query   int  true       "品类id,最新传0"
+// @Param   CtagId   query   int  true       "图表子类ID"
+// @Param   ListType   query   int  true       "列表类型,1最新,2 纪要 ,3图表 默认1"
+// @Success 200 {object} models.HomeArtAndChartListResp
+// @router /artAndChart/list [get]
+//func (this *HomeController) ListHomeArtAndChartV6() {
+//	br := new(models.BaseResponse).Init()
+//	defer func() {
+//		this.Data["json"] = br
+//		this.ServeJSON()
+//	}()
+//	user := this.User
+//	if user == nil {
+//		br.Msg = "请登录"
+//		br.ErrMsg = "请登录,用户信息为空"
+//		br.Ret = 408
+//		return
+//	}
+//	pageSize, _ := this.GetInt("PageSize")
+//	currentIndex, _ := this.GetInt("CurrentIndex")
+//	chartPermissionId, _ := this.GetInt("ChartPermissionId")
+//	ctagId, _ := this.GetInt("CtagId")
+//	listType, _ := this.GetInt("ListType")
+//
+//	var startSize int
+//	if pageSize <= 0 {
+//		pageSize = utils.PageSize20
+//	}
+//	if currentIndex <= 0 {
+//		currentIndex = 1
+//	}
+//	if listType <= 0 {
+//		listType = 1
+//	}
+//	startSize = paging.StartIndex(currentIndex, pageSize)
+//
+//	var condition string
+//	var pars []interface{}
+//	var total, chartTotal int
+//	resp := new(models.HomeArtAndChartListResp)
+//	page := paging.GetPaging(currentIndex, pageSize, total)
+//	resp.HaveResearch = true
+//	var chartList []*models.HomeChartListResp
+//	var err error
+//	if listType == 1 {
+//		if currentIndex <= 2 {
+//			listCtagId := [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
+//			var chartIds string
+//			for _, v := range listCtagId {
+//				chartListTwo, err := models.GetChartList(`AND  ctag_id = `+strconv.Itoa(v), pars, 0, 2)
+//				if err != nil {
+//					br.Msg = "获取信息失败"
+//					br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+//					return
+//				}
+//				for _, vChart := range chartListTwo {
+//					chartIds += strconv.Itoa(vChart.ChartId) + ","
+//				}
+//			}
+//			chartIds = strings.TrimRight(chartIds, ",")
+//			condition += ` AND chart_id IN (` + chartIds + `) `
+//			chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
+//			if err != nil {
+//				br.Msg = "获取信息失败"
+//				br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+//				return
+//			}
+//
+//		}
+//	} else if listType == 3 {
+//		if chartPermissionId > 0 {
+//			condition += ` AND a.ptag_id =? `
+//			pars = append(pars, chartPermissionId)
+//		}
+//		if ctagId > 0 {
+//			condition += ` AND a.ctag_id =? `
+//			pars = append(pars, ctagId)
+//		}
+//		chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
+//		if err != nil {
+//			br.Msg = "获取信息失败"
+//			br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+//			return
+//		}
+//		chartTotal, err = models.GetChartCount(condition, pars)
+//		if err != nil {
+//			br.Msg = "获取信息失败"
+//			br.Msg = "获取帖子总数失败,Err:" + err.Error()
+//			return
+//		}
+//	}
+//	for k, v := range chartList {
+//		if v.PtagName != "" {
+//			chartList[k].CtagNamePc = v.PtagName
+//		}
+//		if v.CtagName != "" {
+//			chartList[k].CtagNamePc += "," + v.CtagName
+//		}
+//		if v.PtagNameTwo != "" {
+//			chartList[k].CtagNamePc += "," + v.PtagNameTwo
+//		}
+//		if v.CtagNameTwo != "" {
+//			chartList[k].CtagNamePc += "," + v.CtagNameTwo
+//		}
+//		chartList[k].IsNeedJump = true
+//		chartList[k].Source = 2
+//	}
+//	resp.ChartList = chartList
+//
+//	if listType != 3 {
+//		userType, _, err := services.GetUserType(user.CompanyId)
+//		if err != nil {
+//			br.Msg = "获取信息失败"
+//			br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+//			return
+//		}
+//		condition = ` AND is_summary = 1  `
+//		if chartPermissionId > 0 {
+//			categoryId, err := models.GetCategoryId(chartPermissionId)
+//			if err != nil && err.Error() != utils.ErrNoRow() {
+//				br.Msg = "获取信息失败"
+//				br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
+//				return
+//			}
+//			categoryinfo, err := models.GetChartPermissionById(chartPermissionId)
+//			if err != nil {
+//				br.Msg = "获取信息失败"
+//				br.ErrMsg = "获取信息失败,Err:" + err.Error()
+//				return
+//			}
+//			if userType == 1 && strings.Contains(categoryinfo.PermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
+//				resp.HaveResearch = false
+//				resp.Paging = page
+//				br.Ret = 200
+//				br.Success = true
+//				br.Msg = "获取成功"
+//				br.Data = resp
+//				return
+//			}
+//			page = paging.GetPaging(currentIndex, pageSize, total)
+//			if categoryId != "" {
+//				condition += ` AND category_id IN(` + categoryId + `)`
+//				//condition += ` OR ( category_name  LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%' AND publish_status = 1 AND is_summary = 1 )`
+//			} else {
+//				condition += ` AND  category_name   LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
+//			}
+//		}
+//		//永续客户无法查看研选分类的内容
+//		if userType == 1 {
+//			condition += ` AND  category_name  NOT LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
+//		}
+//		total, err = models.GetHomeCount(condition, pars)
+//		if err != nil {
+//			br.Msg = "获取信息失败"
+//			br.Msg = "获取帖子总数失败,Err:" + err.Error()
+//			return
+//		}
+//
+//		list, err := models.GetHomeList(condition, pars, startSize, pageSize)
+//		if err != nil {
+//			br.Msg = "获取信息失败"
+//			br.Msg = "获取帖子数据失败,Err:" + err.Error()
+//			return
+//		}
+//		//研选的五张图片
+//		detailResearch, err := models.GetConfigByCode("category_research_img_url")
+//		if err != nil {
+//			br.Msg = "获取数据失败"
+//			br.ErrMsg = "获取数据研选分类图片失败,Err:" + err.Error()
+//			return
+//		}
+//		researchList := strings.Split(detailResearch.ConfigValue, "{|}")
+//		//对应分类的所图片
+//		detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
+//		if err != nil {
+//			br.Msg = "获取数据失败"
+//			br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
+//			return
+//		}
+//		categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
+//		mapCategoryUrl := make(map[string]string)
+//		var categoryId string
+//		var imgUrlChart string
+//		for _, v := range categoryUrlList {
+//			vslice := strings.Split(v, "_")
+//			categoryId = vslice[0]
+//			imgUrlChart = vslice[len(vslice)-1]
+//			mapCategoryUrl[categoryId] = imgUrlChart
+//		}
+//
+//		for k, v := range list {
+//			item := list[k]
+//			//如果文章一开始的内容是图片,优先展示第一张图片
+//			imgurl, _ := services.FixArticleImgUrl(html.UnescapeString(list[k].Body))
+//			newBody, _ := services.GetReportContentTextSubByarticle(item.Body, item.Annotation, item.ArticleId)
+//			list[k].Body = newBody
+//			if imgurl != "" {
+//				list[k].BodyHtml = imgurl
+//			}
+//			list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDateTimeNoSecond) //时间字符串格式转时间格式
+//			if strings.Contains(item.CategoryName, utils.CHART_PERMISSION_NAME_YANXUAN) {
+//				list[k].IsResearch = true
+//			}
+//			if item.Pv > 999 {
+//				list[k].Pv = 999
+//			}
+//			//如果是研选系列的任意取五张图片的中的一张
+//			if v.CategoryId == "0" {
+//				knum := v.ArticleId % 5
+//				list[k].ImgUrlPc = researchList[knum]
+//			} else {
+//				list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
+//			}
+//			if list[k].ArticleId < utils.SummaryArticleId {
+//				list[k].HttpUrl = utils.StrategyPlatform + strconv.Itoa(v.ArticleId)
+//				list[k].IsNeedJump = true
+//			}
+//			list[k].Source = 1
+//		}
+//		resp.List = list
+//	}
+//	if chartTotal > total {
+//		total = chartTotal
+//	}
+//	page = paging.GetPaging(currentIndex, pageSize, total)
+//	resp.Paging = page
+//	br.Ret = 200
+//	br.Success = true
+//	br.Msg = "获取成功"
+//	br.Data = resp
+//}
+
+// @Title 首页/搜索头部导航接口
+// @Description 首页/搜索头部导航接口
+// @Param   SearchPage  query  int  false  "是否为搜索页面"
+// @Success 200 {object} models.HomeListResp
+// @router /header_tab [get]
+func (this *HomeController) HeaderTab() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	searchPage, _ := this.GetInt("SearchPage")
+
+	key := models.HomeHeaderTabConfigKey
+	conf, e := models.GetConfigByCode(key)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取首页头部导航失败, Err: " + e.Error()
+		return
+	}
+	if conf.ConfigValue == "" {
+		br.Msg = "获取失败"
+		br.ErrMsg = "首页头部导航配置值有误"
+		return
+	}
+
+	list := new(models.HomeHeaderTabList)
+	if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "首页头部导航配置值解析失败, Err: " + e.Error()
+		return
+	}
+	resp := list.Home
+	if searchPage == 1 {
+		resp = list.SearchPage
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+
 // @Title 首页列表接口v6版本
 // @Description 首页列表接口v6版本
 // @Param   PageSize   query   int  true       "每页数据条数"
@@ -374,6 +661,8 @@ func (this *HomeController) ListHomeArtAndChart() {
 	resp.HaveResearch = true
 	var chartList []*models.HomeChartListResp
 	var err error
+
+	// 最新
 	if listType == 1 {
 		if currentIndex <= 2 {
 			listCtagId := [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
@@ -397,9 +686,11 @@ func (this *HomeController) ListHomeArtAndChart() {
 				br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
 				return
 			}
-
 		}
-	} else if listType == 3 {
+	}
+
+	// 图表
+	if listType == 3 {
 		if chartPermissionId > 0 {
 			condition += ` AND a.ptag_id =? `
 			pars = append(pars, chartPermissionId)
@@ -439,6 +730,7 @@ func (this *HomeController) ListHomeArtAndChart() {
 	}
 	resp.ChartList = chartList
 
+	// 最新/纪要
 	if listType != 3 {
 		userType, _, err := services.GetUserType(user.CompanyId)
 		if err != nil {
@@ -454,13 +746,13 @@ func (this *HomeController) ListHomeArtAndChart() {
 				br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
 				return
 			}
-			categoryinfo, err := models.GetChartPermissionById(chartPermissionId)
+			categoryInfo, err := models.GetChartPermissionById(chartPermissionId)
 			if err != nil {
 				br.Msg = "获取信息失败"
 				br.ErrMsg = "获取信息失败,Err:" + err.Error()
 				return
 			}
-			if userType == 1 && strings.Contains(categoryinfo.PermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
+			if userType == 1 && strings.Contains(categoryInfo.PermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
 				resp.HaveResearch = false
 				resp.Paging = page
 				br.Ret = 200
@@ -481,19 +773,36 @@ func (this *HomeController) ListHomeArtAndChart() {
 		if userType == 1 {
 			condition += ` AND  category_name  NOT LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
 		}
-		total, err = models.GetHomeCount(condition, pars)
-		if err != nil {
-			br.Msg = "获取信息失败"
-			br.Msg = "获取帖子总数失败,Err:" + err.Error()
-			return
-		}
 
-		list, err := models.GetHomeList(condition, pars, startSize, pageSize)
-		if err != nil {
-			br.Msg = "获取信息失败"
-			br.Msg = "获取帖子数据失败,Err:" + err.Error()
-			return
+		list := make([]*models.HomeArticle, 0)
+		// 7.6-与音频作联合查询, 整体进行发布时间的排序(代码写的嘎嘎烂, 将就着用吧=_=!)
+		if listType == 1 {
+			var unionPars []interface{}
+			unionList, unionTotal, e := services.GetHomeNewestList(0, 0, condition, unionPars)
+			if e != nil {
+				br.Msg = "获取信息失败"
+				br.Msg = "获取纪要音频联合列表失败, Err: " + e.Error()
+				return
+			}
+			total = unionTotal
+			list = unionList
+		} else {
+			total, err = models.GetHomeCount(condition, pars)
+			if err != nil {
+				br.Msg = "获取信息失败"
+				br.Msg = "获取帖子总数失败,Err:" + err.Error()
+				return
+			}
+
+			homeList, err := models.GetHomeList(condition, pars, startSize, pageSize)
+			if err != nil {
+				br.Msg = "获取信息失败"
+				br.Msg = "获取帖子数据失败,Err:" + err.Error()
+				return
+			}
+			list = homeList
 		}
+
 		//研选的五张图片
 		detailResearch, err := models.GetConfigByCode("category_research_img_url")
 		if err != nil {
@@ -521,6 +830,9 @@ func (this *HomeController) ListHomeArtAndChart() {
 		}
 
 		for k, v := range list {
+			if v.HomeType != 0 {
+				continue
+			}
 			item := list[k]
 			//如果文章一开始的内容是图片,优先展示第一张图片
 			imgurl, _ := services.FixArticleImgUrl(html.UnescapeString(list[k].Body))
@@ -554,6 +866,7 @@ func (this *HomeController) ListHomeArtAndChart() {
 	if chartTotal > total {
 		total = chartTotal
 	}
+
 	page = paging.GetPaging(currentIndex, pageSize, total)
 	resp.Paging = page
 	br.Ret = 200
@@ -561,53 +874,3 @@ func (this *HomeController) ListHomeArtAndChart() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
-
-// @Title 首页/搜索头部导航接口
-// @Description 首页/搜索头部导航接口
-// @Param   SearchPage  query  int  false  "是否为搜索页面"
-// @Success 200 {object} models.HomeListResp
-// @router /header_tab [get]
-func (this *HomeController) HeaderTab() {
-	br := new(models.BaseResponse).Init()
-	defer func() {
-		this.Data["json"] = br
-		this.ServeJSON()
-	}()
-	user := this.User
-	if user == nil {
-		br.Msg = "请登录"
-		br.ErrMsg = "请登录,用户信息为空"
-		br.Ret = 408
-		return
-	}
-	searchPage, _ := this.GetInt("SearchPage")
-
-	key := models.HomeHeaderTabConfigKey
-	conf, e := models.GetConfigByCode(key)
-	if e != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取首页头部导航失败, Err: " + e.Error()
-		return
-	}
-	if conf.ConfigValue == "" {
-		br.Msg = "获取失败"
-		br.ErrMsg = "首页头部导航配置值有误"
-		return
-	}
-
-	list := new(models.HomeHeaderTabList)
-	if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = "首页头部导航配置值解析失败, Err: " + e.Error()
-		return
-	}
-	resp := list.Home
-	if searchPage == 1 {
-		resp = list.SearchPage
-	}
-
-	br.Ret = 200
-	br.Success = true
-	br.Msg = "获取成功"
-	br.Data = resp
-}

+ 22 - 20
models/article.go

@@ -82,26 +82,28 @@ func AddCygxArticle(item *CygxArticle) (lastId int64, err error) {
 }
 
 type HomeArticle struct {
-	ArticleId        int    `description:"文章id"`
-	Title            string `description:"标题"`
-	TitleEn          string `description:"英文标题 "`
-	UpdateFrequency  string `description:"更新周期"`
-	CreateDate       string `description:"创建时间"`
-	PublishDate      string `description:"发布时间"`
-	Body             string `description:"内容"`
-	BodyHtml         string `description:"内容带有HTML标签"`
-	Abstract         string `description:"摘要"`
-	CategoryName     string `description:"一级分类"`
-	SubCategoryName  string `description:"二级分类"`
-	ExpertBackground string `description:"专家背景"`
-	IsResearch       bool   `description:"是否属于研选"`
-	Pv               int    `description:"PV"`
-	ImgUrlPc         string `description:"图片链接"`
-	CategoryId       string `description:"文章分类"`
-	HttpUrl          string `description:"文章链接跳转地址"`
-	IsNeedJump       bool   `description:"是否需要跳转链接地址"`
-	Source           int    `description:"来源  1:文章, 2:图表"`
-	Annotation       string `description:"核心观点"`
+	ArticleId        int                 `description:"文章id"`
+	Title            string              `description:"标题"`
+	TitleEn          string              `description:"英文标题 "`
+	UpdateFrequency  string              `description:"更新周期"`
+	CreateDate       string              `description:"创建时间"`
+	PublishDate      string              `description:"发布时间"`
+	Body             string              `description:"内容"`
+	BodyHtml         string              `description:"内容带有HTML标签"`
+	Abstract         string              `description:"摘要"`
+	CategoryName     string              `description:"一级分类"`
+	SubCategoryName  string              `description:"二级分类"`
+	ExpertBackground string              `description:"专家背景"`
+	IsResearch       bool                `description:"是否属于研选"`
+	Pv               int                 `description:"PV"`
+	ImgUrlPc         string              `description:"图片链接"`
+	CategoryId       string              `description:"文章分类"`
+	HttpUrl          string              `description:"文章链接跳转地址"`
+	IsNeedJump       bool                `description:"是否需要跳转链接地址"`
+	Source           int                 `description:"来源  1:文章, 2:图表"`
+	Annotation       string              `description:"核心观点"`
+	HomeType         int                 `description:"数据类型:0-纪要(默认); 1-微路演音频"`
+	MicroAudio       *MicroAudioUnionList `description:"微路演音频"`
 }
 
 type ArticleDetail struct {

+ 97 - 0
models/micro_roadshow.go

@@ -125,3 +125,100 @@ func AddCygxMicroRoadshowVideoHistory(item *CygxMicroRoadshowVideoHistory) (err
 	_, err = o.Insert(item)
 	return
 }
+
+// MicroAudioUnionList 微路演音频联合列表
+type MicroAudioUnionList struct {
+	Id                       int    `description:"音视频ID"`
+	AudioTitle               string `description:"标题"`
+	AudioResourceUrl         string `description:"链接"`
+	AudioType                int    `description:"类型: 1-音频; 2-视频"`
+	AudioPublishTime         string `description:"发布时间"`
+	AudioImgUrl              string `description:"背景图"`
+	AudioChartPermissionId   int    `description:"行业ID"`
+	AudioChartPermissionName string `description:"行业名称"`
+	AudioPlaySeconds         string `description:"音视频时长"`
+	AudioActivityId          int    `description:"活动ID"`
+	AuthInfo                 *UserPermissionAuthInfo
+}
+
+// HomeNewestUnionList 首页最新纪要-音频联合查询结果
+type HomeNewestUnionList struct {
+	ArticleId        int    `description:"文章id"`
+	Title            string `description:"标题"`
+	TitleEn          string `description:"英文标题 "`
+	UpdateFrequency  string `description:"更新周期"`
+	CreateDate       string `description:"创建时间"`
+	PublishDate      string `description:"发布时间"`
+	Body             string `description:"内容"`
+	BodyHtml         string `description:"内容带有HTML标签"`
+	Abstract         string `description:"摘要"`
+	CategoryName     string `description:"一级分类"`
+	SubCategoryName  string `description:"二级分类"`
+	ExpertBackground string `description:"专家背景"`
+	IsResearch       bool   `description:"是否属于研选"`
+	Pv               int    `description:"PV"`
+	ImgUrlPc         string `description:"图片链接"`
+	CategoryId       string `description:"文章分类"`
+	HttpUrl          string `description:"文章链接跳转地址"`
+	IsNeedJump       bool   `description:"是否需要跳转链接地址"`
+	Source           int    `description:"来源  1:文章, 2:图表"`
+	Annotation       string `description:"核心观点"`
+	HomeType         int    `description:"数据类型:0-纪要(默认); 1-微路演音频"`
+	MicroAudioUnionList
+}
+
+// GetHomeNewestListUnionList 首页最新纪要-音频联合查询
+func GetHomeNewestListUnionList(condition string, pars []interface{}, startSize, pageSize int) (list []*HomeNewestUnionList, err error) {
+	sql := `SELECT
+				id, article_id, title, title_en, update_frequency, create_date, publish_date, body, abstract, category_name, sub_category_name, expert_background, category_id, source, annotation,
+				(SELECT count(1) FROM cygx_article_history_record_newpv as h WHERE h.article_id = art.article_id ) as pv,
+				0 AS home_type, "" AS audio_title, "" AS audio_resource_url, 0 AS audio_type, "" AS audio_publish_time, 0 AS audio_chart_permission_id, "" AS audio_chart_permission_name,
+				"" AS audio_play_seconds, "" AS audio_img_url, 0 AS audio_activity_id
+			FROM
+				cygx_article AS art
+			WHERE
+				art.publish_status = 1 `
+	if condition != `` {
+		sql += condition
+	}
+	sql += ` UNION ALL
+			
+			SELECT
+				a.activity_voice_id, 0, "", "", "", "", b.activity_time, "", "", "", "", "", 0, 0, "",
+				0, 1, a.voice_name, a.voice_url, 1, b.activity_time,
+				b.chart_permission_id, b.chart_permission_name, a.voice_play_seconds AS audio_play_seconds, a.img_url AS audio_img_url, a.activity_id AS audio_activity_id
+			FROM
+				cygx_activity_voice AS a
+			JOIN cygx_activity AS b ON a.activity_id = b.activity_id`
+	sql += ` ORDER BY publish_date DESC`
+	sql += ` LIMIT ?,?`
+	_, err = orm.NewOrm().Raw(sql, pars, startSize, pageSize).QueryRows(&list)
+	return
+}
+
+// GetHomeNewestListUnionCount 首页最新纪要-音频联合查询总数
+func GetHomeNewestListUnionCount(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+				COUNT(1) AS count
+			FROM
+				(
+					SELECT
+						art.id
+					FROM
+						cygx_article AS art
+					WHERE
+						art.publish_status = 1 `
+	if condition != `` {
+		sql += condition
+	}
+	sql += ` UNION ALL
+				SELECT
+					a.activity_voice_id
+				FROM
+					cygx_activity_voice AS a
+				JOIN cygx_activity AS b ON a.activity_id = b.activity_id
+			) z `
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}

+ 110 - 0
services/micro_roadshow.go

@@ -192,4 +192,114 @@ func GetMicroRoadShowDefaultImgConfig() (audioMap, videoMap map[int]string, err
 		videoMap[videoList[i].ChartPermissionId] = videoList[i].ImgUrl
 	}
 	return
+}
+
+// GetHomeNewestList 获取首页最新列表
+func GetHomeNewestList(userId, companyId int, condition string, pars []interface{}) (resp []*models.HomeArticle, total int, err error) {
+	resp = make([]*models.HomeArticle, 0)
+	unionList, e := models.GetHomeNewestListUnionList(condition, pars, 0, 20)
+	if e != nil {
+		err = errors.New("获取首页最新列表失败")
+		return
+	}
+	unionTotal, e := models.GetHomeNewestListUnionCount(condition, pars)
+	if e != nil {
+		err = errors.New("获取首页最新列表总数失败")
+		return
+	}
+	total = unionTotal
+
+	// 用户权限
+	authInfo, permissionArr, e := GetUserRaiPermissionInfo(userId, companyId)
+	if e != nil {
+		err = errors.New("获取用户权限失败, Err: " + e.Error())
+		return
+	}
+
+	// 获取默认图配置
+	audioMap, videoMap, e := GetMicroRoadShowDefaultImgConfig()
+	if e != nil {
+		err = errors.New("获取微路演默认图配置失败, Err: " + e.Error())
+		return
+	}
+
+	// 此处没有直接使用HomeArticle结构体而是多加了一层, 纯粹是为了方便前端区分纪要和微路演音频=_=!
+	for _, v := range unionList {
+		item := new(models.HomeArticle)
+		item.HomeType = v.HomeType
+		// 纪要
+		if item.HomeType == 0 {
+			item.ArticleId = v.ArticleId
+			item.Title = v.Title
+			item.TitleEn = v.TitleEn
+			item.UpdateFrequency = v.UpdateFrequency
+			item.CreateDate = v.CreateDate
+			item.PublishDate = v.PublishDate
+			item.Body = v.Body
+			item.BodyHtml = v.BodyHtml
+			item.Abstract = v.Abstract
+			item.CategoryName = v.CategoryName
+			item.SubCategoryName = v.SubCategoryName
+			item.ExpertBackground = v.ExpertBackground
+			item.IsResearch = v.IsResearch
+			item.Pv = v.Pv
+			item.ImgUrlPc = v.ImgUrlPc
+			item.CategoryId = v.CategoryId
+			item.HttpUrl = v.HttpUrl
+			item.IsNeedJump = v.IsNeedJump
+			item.Source = v.Source
+			item.Annotation = v.Annotation
+		}
+		// 音频
+		if v.HomeType == 1 {
+			ad := new(models.MicroAudioUnionList)
+			ad.Id = v.Id
+			ad.AudioTitle = v.AudioTitle
+			ad.AudioResourceUrl = v.AudioResourceUrl
+			ad.AudioType = v.AudioType
+			ad.AudioPublishTime = v.AudioPublishTime
+			ad.AudioImgUrl = v.AudioImgUrl
+			ad.AudioChartPermissionId = v.AudioChartPermissionId
+			ad.AudioChartPermissionName = v.AudioChartPermissionName
+			ad.AudioPlaySeconds = v.AudioPlaySeconds
+			ad.AudioPlaySeconds = v.AudioPlaySeconds
+			ad.AudioActivityId = v.AudioActivityId
+			item.MicroAudio = ad
+			// 默认图
+			if ad.AudioImgUrl == "" {
+				if ad.AudioType == 1 {
+					ad.AudioImgUrl = audioMap[ad.AudioChartPermissionId]
+				} else {
+					ad.AudioImgUrl = videoMap[ad.AudioChartPermissionId]
+				}
+			}
+			// 权限
+			au := new(models.UserPermissionAuthInfo)
+			au.SellerName = authInfo.SellerName
+			au.SellerMobile = authInfo.SellerMobile
+			au.HasPermission = authInfo.HasPermission
+			if authInfo.HasPermission == 1 {
+				if !utils.InArrayByStr(permissionArr, ad.AudioChartPermissionName) {
+					au.HasPermission = 2
+				}
+			}
+			if authInfo.HasPermission == 2 {
+				if ad.AudioType == 1 {
+					au.PopupMsg = UserPermissionPopupMsgCallActivity
+				} else {
+					au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
+				}
+			}
+			if authInfo.HasPermission == 3 {
+				if ad.AudioType == 1 {
+					au.PopupMsg = UserPermissionPopupMsgApplyActivity
+				} else {
+					au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
+				}
+			}
+			ad.AuthInfo = au
+		}
+		resp = append(resp, item)
+	}
+	return
 }