123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- package services
- import (
- "encoding/json"
- "errors"
- "hongze/hongze_clpt/models"
- "hongze/hongze_clpt/utils"
- )
- // GetMicroRoadShowDefaultImgConfig 获取微路演默认图/分享图配置
- func GetMicroRoadShowDefaultImgConfig() (audioMap, videoMap, audioShareMap, videoShareMap map[int]string, err error) {
- audioMap = make(map[int]string, 0)
- videoMap = make(map[int]string, 0)
- audioShareMap = make(map[int]string, 0)
- videoShareMap = make(map[int]string, 0)
- key := models.MicroRoadshowDefaultImgKey
- conf, e := models.GetConfigByCode(key)
- if e != nil {
- err = errors.New("获取微路演默认图配置失败, Err: " + e.Error())
- return
- }
- if conf.ConfigValue == "" {
- err = errors.New("获取微路演默认图配置有误")
- return
- }
- list := new(models.MicroRoadShowDefaultImgList)
- if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
- err = errors.New("微路演默认图配置配置值解析失败, Err: " + e.Error())
- return
- }
- audioList := list.Audio
- for i := range audioList {
- audioMap[audioList[i].ChartPermissionId] = audioList[i].ImgUrl
- audioShareMap[audioList[i].ChartPermissionId] = audioList[i].ShareImg
- }
- videoList := list.Video
- for i := range videoList {
- videoMap[videoList[i].ChartPermissionId] = videoList[i].ImgUrl
- videoShareMap[videoList[i].ChartPermissionId] = videoList[i].ShareImg
- }
- return
- }
- func GetindustryVideo(user *models.WxUserItem, industrialManagementId int) (industryVideo *models.MicroVideoSimpleInfo, AuthInfo *models.UserPermissionAuthInfo, err error) {
- total, e := models.GetMicroRoadshowVideoByIndustryIdCount(industrialManagementId)
- if e != nil {
- err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryIdCount " + e.Error())
- return
- }
- if total == 0 {
- return
- }
- // 用户权限
- authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
- if e != nil {
- err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
- return
- }
- videoSimple := new(models.MicroVideoSimpleInfo)
- // 权限
- var au *models.UserPermissionAuthInfo
- video, e := models.GetMicroRoadshowVideoByIndustryId(industrialManagementId)
- if e != nil {
- err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
- return
- } else {
- videoSimple.Id = video.VideoId
- videoSimple.Title = "5min【" + video.IndustryName + "】逻辑解析"
- videoSimple.BackgroundImg = video.ImgUrl
- videoSimple.DetailImgUrl = video.DetailImgUrl
- if videoSimple.BackgroundImg == "" {
- // 获取默认图配置
- _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
- if e != nil {
- err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
- return
- }
- videoSimple.BackgroundImg = videoMap[video.ChartPermissionId]
- }
- videoSimple.PlaySeconds = video.VideoDuration
- videoSimple.ResourceUrl = video.VideoUrl
- au = new(models.UserPermissionAuthInfo)
- au.SellerName = authInfo.SellerName
- au.SellerMobile = authInfo.SellerMobile
- au.HasPermission = authInfo.HasPermission
- au.OperationMode = authInfo.OperationMode
- if au.HasPermission == 1 {
- // 非宏观权限进一步判断是否有权限
- if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
- au.HasPermission = 2
- }
- }
- // 无权限的弹框提示
- if au.HasPermission != 1 {
- if au.OperationMode == UserPermissionOperationModeCall {
- au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
- } else {
- au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
- }
- videoSimple.ResourceUrl = ""
- }
- }
- industryVideo = videoSimple
- AuthInfo = au
- return
- }
- //GetindustryVideoDetailById 通过视频ID获取视频详情
- func GetindustryVideoDetailById(user *models.WxUserItem, videoId int) (industryVideo *models.MicroVideoSimpleInfo, AuthInfo *models.UserPermissionAuthInfo, err error) {
- total, e := models.GetMicroRoadshowVideoByIndustryIdCount(videoId)
- if e != nil {
- err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryIdCount " + e.Error())
- return
- }
- if total == 0 {
- err = errors.New("视频不存在,或已取消发布")
- return
- }
- // 用户权限
- authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
- if e != nil {
- err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
- return
- }
- videoSimple := new(models.MicroVideoSimpleInfo)
- // 权限
- var au *models.UserPermissionAuthInfo
- video, e := models.GetMicroRoadshowVideoById(videoId)
- if e != nil {
- err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
- return
- } else {
- videoSimple.Id = video.VideoId
- videoSimple.Title = "5min【" + video.IndustryName + "】逻辑解析"
- videoSimple.BackgroundImg = video.ImgUrl
- videoSimple.DetailImgUrl = video.DetailImgUrl
- if videoSimple.BackgroundImg == "" {
- // 获取默认图配置
- _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
- if e != nil {
- err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
- return
- }
- videoSimple.BackgroundImg = videoMap[video.ChartPermissionId]
- }
- videoSimple.PlaySeconds = video.VideoDuration
- videoSimple.ResourceUrl = video.VideoUrl
- au = new(models.UserPermissionAuthInfo)
- au.SellerName = authInfo.SellerName
- au.SellerMobile = authInfo.SellerMobile
- au.HasPermission = authInfo.HasPermission
- au.OperationMode = authInfo.OperationMode
- if au.HasPermission == 1 {
- // 非宏观权限进一步判断是否有权限
- if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
- au.HasPermission = 2
- }
- }
- // 无权限的弹框提示
- if au.HasPermission != 1 {
- if au.OperationMode == UserPermissionOperationModeCall {
- au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
- } else {
- au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
- }
- videoSimple.ResourceUrl = ""
- }
- }
- industryVideo = videoSimple
- AuthInfo = au
- return
- }
- //GetMicroRoadshowVideoMap 获取已经发布的微路演的产业ID
- func GetMicroRoadshowVideoMap() (items map[int]int, err error) {
- list, e := models.GetMicroRoadshowVideoList()
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("获取已经发布的微路演的产业失败,GetMicroRoadshowVideoList " + e.Error())
- return
- }
- mapindustrialId := make(map[int]int)
- for _, v := range list {
- mapindustrialId[v.IndustryId] = v.IndustryId
- }
- items = mapindustrialId
- return
- }
|