micro_roadshow.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/utils"
  7. )
  8. // GetMicroRoadShowDefaultImgConfig 获取微路演默认图/分享图配置
  9. func GetMicroRoadShowDefaultImgConfig() (audioMap, videoMap, audioShareMap, videoShareMap map[int]string, err error) {
  10. audioMap = make(map[int]string, 0)
  11. videoMap = make(map[int]string, 0)
  12. audioShareMap = make(map[int]string, 0)
  13. videoShareMap = make(map[int]string, 0)
  14. key := models.MicroRoadshowDefaultImgKey
  15. conf, e := models.GetConfigByCode(key)
  16. if e != nil {
  17. err = errors.New("获取微路演默认图配置失败, Err: " + e.Error())
  18. return
  19. }
  20. if conf.ConfigValue == "" {
  21. err = errors.New("获取微路演默认图配置有误")
  22. return
  23. }
  24. list := new(models.MicroRoadShowDefaultImgList)
  25. if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
  26. err = errors.New("微路演默认图配置配置值解析失败, Err: " + e.Error())
  27. return
  28. }
  29. audioList := list.Audio
  30. for i := range audioList {
  31. audioMap[audioList[i].ChartPermissionId] = audioList[i].ImgUrl
  32. audioShareMap[audioList[i].ChartPermissionId] = audioList[i].ShareImg
  33. }
  34. videoList := list.Video
  35. for i := range videoList {
  36. videoMap[videoList[i].ChartPermissionId] = videoList[i].ImgUrl
  37. videoShareMap[videoList[i].ChartPermissionId] = videoList[i].ShareImg
  38. }
  39. return
  40. }
  41. func GetindustryVideo(user *models.WxUserItem, industrialManagementId int) (industryVideo *models.MicroVideoSimpleInfo, AuthInfo *models.UserPermissionAuthInfo, err error) {
  42. total, e := models.GetMicroRoadshowVideoByIndustryIdCount(industrialManagementId)
  43. if e != nil {
  44. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryIdCount " + e.Error())
  45. return
  46. }
  47. if total == 0 {
  48. return
  49. }
  50. // 用户权限
  51. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  52. if e != nil {
  53. err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
  54. return
  55. }
  56. videoSimple := new(models.MicroVideoSimpleInfo)
  57. // 权限
  58. var au *models.UserPermissionAuthInfo
  59. video, e := models.GetMicroRoadshowVideoByIndustryId(industrialManagementId)
  60. if e != nil {
  61. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  62. return
  63. } else {
  64. videoSimple.Id = video.VideoId
  65. videoSimple.Title = "5min【" + video.IndustryName + "】逻辑解析"
  66. videoSimple.BackgroundImg = video.ImgUrl
  67. videoSimple.DetailImgUrl = video.DetailImgUrl
  68. if videoSimple.BackgroundImg == "" {
  69. // 获取默认图配置
  70. _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
  71. if e != nil {
  72. err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  73. return
  74. }
  75. videoSimple.BackgroundImg = videoMap[video.ChartPermissionId]
  76. }
  77. videoSimple.PlaySeconds = video.VideoDuration
  78. videoSimple.ResourceUrl = video.VideoUrl
  79. au = new(models.UserPermissionAuthInfo)
  80. au.SellerName = authInfo.SellerName
  81. au.SellerMobile = authInfo.SellerMobile
  82. au.HasPermission = authInfo.HasPermission
  83. au.OperationMode = authInfo.OperationMode
  84. if au.HasPermission == 1 {
  85. // 非宏观权限进一步判断是否有权限
  86. if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
  87. au.HasPermission = 2
  88. }
  89. }
  90. // 无权限的弹框提示
  91. if au.HasPermission != 1 {
  92. if au.OperationMode == UserPermissionOperationModeCall {
  93. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  94. } else {
  95. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  96. }
  97. videoSimple.ResourceUrl = ""
  98. }
  99. }
  100. industryVideo = videoSimple
  101. AuthInfo = au
  102. return
  103. }
  104. //GetindustryVideoDetailById 通过视频ID获取视频详情
  105. func GetindustryVideoDetailById(user *models.WxUserItem, videoId int) (industryVideo *models.MicroVideoSimpleInfo, AuthInfo *models.UserPermissionAuthInfo, err error) {
  106. total, e := models.GetMicroRoadshowVideoByIndustryIdCount(videoId)
  107. if e != nil {
  108. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryIdCount " + e.Error())
  109. return
  110. }
  111. if total == 0 {
  112. err = errors.New("视频不存在,或已取消发布")
  113. return
  114. }
  115. // 用户权限
  116. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  117. if e != nil {
  118. err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
  119. return
  120. }
  121. videoSimple := new(models.MicroVideoSimpleInfo)
  122. // 权限
  123. var au *models.UserPermissionAuthInfo
  124. video, e := models.GetMicroRoadshowVideoById(videoId)
  125. if e != nil {
  126. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  127. return
  128. } else {
  129. videoSimple.Id = video.VideoId
  130. videoSimple.Title = "5min【" + video.IndustryName + "】逻辑解析"
  131. videoSimple.BackgroundImg = video.ImgUrl
  132. videoSimple.DetailImgUrl = video.DetailImgUrl
  133. if videoSimple.BackgroundImg == "" {
  134. // 获取默认图配置
  135. _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
  136. if e != nil {
  137. err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  138. return
  139. }
  140. videoSimple.BackgroundImg = videoMap[video.ChartPermissionId]
  141. }
  142. videoSimple.PlaySeconds = video.VideoDuration
  143. videoSimple.ResourceUrl = video.VideoUrl
  144. au = new(models.UserPermissionAuthInfo)
  145. au.SellerName = authInfo.SellerName
  146. au.SellerMobile = authInfo.SellerMobile
  147. au.HasPermission = authInfo.HasPermission
  148. au.OperationMode = authInfo.OperationMode
  149. if au.HasPermission == 1 {
  150. // 非宏观权限进一步判断是否有权限
  151. if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
  152. au.HasPermission = 2
  153. }
  154. }
  155. // 无权限的弹框提示
  156. if au.HasPermission != 1 {
  157. if au.OperationMode == UserPermissionOperationModeCall {
  158. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  159. } else {
  160. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  161. }
  162. videoSimple.ResourceUrl = ""
  163. }
  164. }
  165. industryVideo = videoSimple
  166. AuthInfo = au
  167. return
  168. }
  169. //GetMicroRoadshowVideoMap 获取已经发布的微路演的产业ID
  170. func GetMicroRoadshowVideoMap() (items map[int]int, err error) {
  171. list, e := models.GetMicroRoadshowVideoList()
  172. if e != nil && e.Error() != utils.ErrNoRow() {
  173. err = errors.New("获取已经发布的微路演的产业失败,GetMicroRoadshowVideoList " + e.Error())
  174. return
  175. }
  176. mapindustrialId := make(map[int]int)
  177. for _, v := range list {
  178. mapindustrialId[v.IndustryId] = v.IndustryId
  179. }
  180. items = mapindustrialId
  181. return
  182. }