micro_roadshow.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "strings"
  10. )
  11. // GetMicroRoadShowDefaultImgConfig 获取微路演默认图/分享图配置
  12. func GetMicroRoadShowDefaultImgConfig() (audioMap, videoMap, audioShareMap, videoShareMap map[int]string, err error) {
  13. audioMap = make(map[int]string, 0)
  14. videoMap = make(map[int]string, 0)
  15. audioShareMap = make(map[int]string, 0)
  16. videoShareMap = make(map[int]string, 0)
  17. key := models.MicroRoadshowDefaultImgKey
  18. conf, e := models.GetConfigByCode(key)
  19. if e != nil {
  20. err = errors.New("获取微路演默认图配置失败, Err: " + e.Error())
  21. return
  22. }
  23. if conf.ConfigValue == "" {
  24. err = errors.New("获取微路演默认图配置有误")
  25. return
  26. }
  27. list := new(models.MicroRoadShowDefaultImgList)
  28. if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
  29. err = errors.New("微路演默认图配置配置值解析失败, Err: " + e.Error())
  30. return
  31. }
  32. audioList := list.Audio
  33. for i := range audioList {
  34. audioMap[audioList[i].ChartPermissionId] = audioList[i].ImgUrl
  35. audioShareMap[audioList[i].ChartPermissionId] = audioList[i].ShareImg
  36. }
  37. videoList := list.Video
  38. for i := range videoList {
  39. videoMap[videoList[i].ChartPermissionId] = videoList[i].ImgUrl
  40. videoShareMap[videoList[i].ChartPermissionId] = videoList[i].ShareImg
  41. }
  42. return
  43. }
  44. // GetHomeNewestList 获取首页最新列表
  45. func GetHomeNewestList(userId, companyId, startSize, pageSize int, condition string, pars []interface{}) (resp []*models.HomeArticle, total int, err error) {
  46. resp = make([]*models.HomeArticle, 0)
  47. unionList, e := models.GetHomeNewestListUnionList(condition, pars, startSize, pageSize)
  48. if e != nil {
  49. err = errors.New("获取首页最新列表失败")
  50. return
  51. }
  52. unionTotal, e := models.GetHomeNewestListUnionCount(condition, pars)
  53. if e != nil {
  54. err = errors.New("获取首页最新列表总数失败")
  55. return
  56. }
  57. total = unionTotal
  58. // 用户权限
  59. authInfo, permissionArr, e := GetUserRaiPermissionInfo(userId, companyId)
  60. if e != nil {
  61. err = errors.New("获取用户权限失败, Err: " + e.Error())
  62. return
  63. }
  64. // 获取默认图配置
  65. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  66. if e != nil {
  67. err = errors.New("获取微路演默认图配置失败, Err: " + e.Error())
  68. return
  69. }
  70. // 此处没有直接使用HomeArticle结构体而是多加了一层, 纯粹是为了方便前端区分纪要和微路演音频=_=!
  71. for _, v := range unionList {
  72. item := new(models.HomeArticle)
  73. item.HomeType = v.HomeType
  74. // 纪要
  75. if item.HomeType == 0 {
  76. item.ArticleId = v.ArticleId
  77. item.Title = v.Title
  78. item.TitleEn = v.TitleEn
  79. item.UpdateFrequency = v.UpdateFrequency
  80. item.CreateDate = v.CreateDate
  81. item.PublishDate = v.PublishDate
  82. item.Body = v.Body
  83. item.BodyHtml = v.BodyHtml
  84. item.Abstract = v.Abstract
  85. item.CategoryName = v.CategoryName
  86. item.SubCategoryName = v.SubCategoryName
  87. item.ExpertBackground = v.ExpertBackground
  88. item.IsResearch = v.IsResearch
  89. item.Pv = v.Pv
  90. item.ImgUrlPc = v.ImgUrlPc
  91. item.CategoryId = v.CategoryId
  92. item.HttpUrl = v.HttpUrl
  93. item.IsNeedJump = v.IsNeedJump
  94. item.Source = v.Source
  95. item.Annotation = v.Annotation
  96. }
  97. // 音频
  98. if v.HomeType == 1 {
  99. ad := new(models.MicroAudioUnionList)
  100. ad.Id = v.Id
  101. ad.AudioTitle = v.AudioTitle
  102. ad.AudioResourceUrl = v.AudioResourceUrl
  103. ad.AudioType = v.AudioType
  104. ad.AudioPublishTime = utils.StrTimeToTime(v.AudioPublishTime).Format(utils.FormatDate)
  105. ad.AudioImgUrl = v.AudioImgUrl
  106. ad.AudioChartPermissionId = v.AudioChartPermissionId
  107. ad.AudioChartPermissionName = v.AudioChartPermissionName
  108. ad.AudioPlaySeconds = v.AudioPlaySeconds
  109. ad.AudioPlaySeconds = v.AudioPlaySeconds
  110. ad.AudioActivityId = v.AudioActivityId
  111. item.MicroAudio = ad
  112. // 默认图
  113. if ad.AudioImgUrl == "" {
  114. if ad.AudioType == 1 {
  115. ad.AudioImgUrl = audioMap[ad.AudioChartPermissionId]
  116. } else {
  117. ad.AudioImgUrl = videoMap[ad.AudioChartPermissionId]
  118. }
  119. }
  120. // 分享图
  121. if ad.AudioType == 1 {
  122. ad.AudioShareImg = audioShareMap[ad.AudioChartPermissionId]
  123. } else {
  124. ad.AudioShareImg = videoShareMap[ad.AudioChartPermissionId]
  125. }
  126. // 权限
  127. au := new(models.UserPermissionAuthInfo)
  128. au.SellerName = authInfo.SellerName
  129. au.SellerMobile = authInfo.SellerMobile
  130. au.HasPermission = authInfo.HasPermission
  131. au.OperationMode = authInfo.OperationMode
  132. if au.HasPermission == 1 {
  133. // 非宏观权限进一步判断是否有权限
  134. if ad.AudioChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, ad.AudioChartPermissionName) {
  135. au.HasPermission = 2
  136. }
  137. }
  138. // 无权限的弹框提示
  139. if au.HasPermission != 1 {
  140. if au.OperationMode == UserPermissionOperationModeCall {
  141. if ad.AudioType == 1 {
  142. au.PopupMsg = UserPermissionPopupMsgCallActivity
  143. } else {
  144. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  145. }
  146. } else {
  147. if ad.AudioType == 1 {
  148. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  149. } else {
  150. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  151. }
  152. }
  153. }
  154. ad.AuthInfo = au
  155. }
  156. resp = append(resp, item)
  157. }
  158. return
  159. }
  160. // GetMicroRoadShowPageList 获取微路演列表添加活动视频 更新与8.1版本
  161. func GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activityVideoId, filter int, keywords, audioIds, videoIds, activityVideoIds string) (respList []*models.MicroRoadShowPageList, total int, err error) {
  162. var e error
  163. // 根据每页数据量获取音视频配比
  164. startSize := utils.StartIndex(currentIndex, pageSize)
  165. videoList := make([]*models.MicroRoadShowPageList, 0)
  166. if keywords != "" {
  167. keywords = "%" + keywords + "%"
  168. }
  169. //音频的查询
  170. var audioCond string
  171. var audioPars []interface{}
  172. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  173. //if videoId > 0 || activityVideoId > 0 || filter == 1 {
  174. // audioCond = ""
  175. //} else {
  176. // 活动已发布且已结束
  177. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  178. //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间
  179. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  180. //audioCond += ` AND b.activity_time > ? `
  181. //audioPars = append(audioPars, endTime)
  182. if keywords != "" {
  183. audioCond += ` AND ( a.voice_name LIKE ? OR b.label LIKE ? )`
  184. audioPars = append(audioPars, keywords, keywords)
  185. }
  186. if audioId > 0 {
  187. audioCond += ` AND a.activity_voice_id = ?`
  188. audioPars = append(audioPars, audioId)
  189. }
  190. if audioIds != "" {
  191. sliceId := strings.Split(audioIds, ",")
  192. var idSqlStr string
  193. for _, v := range sliceId {
  194. idSqlStr += "'" + v + "',"
  195. }
  196. idSqlStr = strings.TrimRight(idSqlStr, ",")
  197. audioCond += ` AND a.activity_voice_id IN (` + idSqlStr + `)`
  198. }
  199. //}
  200. //视频的处理
  201. var videoCond string
  202. var videoCondAct string
  203. var videoPars []interface{}
  204. var videoParsAct []interface{}
  205. //if audioId > 0 || filter == 2 {
  206. // videoCond = ""
  207. //} else {
  208. if keywords != "" {
  209. videoCond += ` AND video_name LIKE ?`
  210. videoPars = append(videoPars, keywords)
  211. videoCondAct += ` AND video_name LIKE ?`
  212. videoParsAct = append(videoParsAct, keywords)
  213. }
  214. if videoId > 0 {
  215. videoCond += ` AND video_id = ?`
  216. videoPars = append(videoPars, videoId)
  217. }
  218. if activityVideoId > 0 {
  219. videoCondAct += ` AND video_id = ?`
  220. videoParsAct = append(videoParsAct, activityVideoId)
  221. }
  222. if activityVideoIds != "" {
  223. sliceId := strings.Split(activityVideoIds, ",")
  224. var idSqlStr string
  225. for _, v := range sliceId {
  226. idSqlStr += "'" + v + "',"
  227. }
  228. idSqlStr = strings.TrimRight(idSqlStr, ",")
  229. videoCondAct += ` AND v.video_id IN (` + idSqlStr + `)`
  230. }
  231. //如果传了路演的或者活动的视频ID只查询一个
  232. if videoId > 0 {
  233. videoCondAct += ` AND video_id = 0 `
  234. audioCond += ` AND a.activity_voice_id = 0 `
  235. }
  236. if activityVideoId > 0 {
  237. videoCond += ` AND video_id = 0 `
  238. audioCond += ` AND a.activity_voice_id = 0 `
  239. }
  240. if audioId > 0 {
  241. videoCondAct += ` AND video_id = 0 `
  242. videoCond += ` AND video_id = 0 `
  243. }
  244. if filter == 1 {
  245. audioCond += ` AND a.activity_voice_id = 0 `
  246. } else if filter == 2 {
  247. videoCondAct += ` AND video_id = 0 `
  248. videoCond += ` AND video_id = 0 `
  249. }
  250. if videoIds != "" {
  251. sliceId := strings.Split(videoIds, ",")
  252. var idSqlStr string
  253. for _, v := range sliceId {
  254. idSqlStr += "'" + v + "',"
  255. }
  256. idSqlStr = strings.TrimRight(idSqlStr, ",")
  257. videoCond += ` AND video_id IN (` + idSqlStr + `)`
  258. }
  259. videoCond += ` AND publish_status = 1`
  260. //}
  261. total, videoList, e = models.GetMicroRoadShowVideoPageListV8(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars, audioId, videoId, activityVideoId, filter)
  262. if e != nil {
  263. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  264. return
  265. }
  266. respList = videoList
  267. return
  268. }
  269. // GetMicroRoadShowPageListIkWord 添加IK分词联想词 获取微路演列表添加活动视频 更新与8.1版本
  270. func CountMicroRoadShowPageListIkWord(audioId, videoId, activityVideoId, filter int, keywordArr []string, audioIds, videoIds, activityVideoIds string) (total int, err error) {
  271. var e error
  272. var keywords string
  273. if len(keywordArr) > 0 {
  274. keywords = KeyWordArrSqlRegexpAll(keywordArr)
  275. }
  276. //if keywords == "" {
  277. // return
  278. //}
  279. //音频的查询
  280. var audioCond string
  281. var audioPars []interface{}
  282. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  283. //if videoId > 0 || activityVideoId > 0 || filter == 1 {
  284. // audioCond += ` AND a.activity_voice_id = 0 `
  285. //} else {
  286. // 活动已发布且已结束
  287. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  288. if keywords != "" {
  289. audioCond += ` AND (a.voice_name REGEXP ? OR b.label REGEXP ? ) `
  290. audioPars = append(audioPars, keywords, keywords)
  291. }
  292. if audioId > 0 {
  293. audioCond += ` AND a.activity_voice_id = ?`
  294. audioPars = append(audioPars, audioId)
  295. }
  296. if audioIds != "" {
  297. sliceId := strings.Split(audioIds, ",")
  298. var idSqlStr string
  299. for _, v := range sliceId {
  300. idSqlStr += "'" + v + "',"
  301. }
  302. idSqlStr = strings.TrimRight(idSqlStr, ",")
  303. audioCond += ` AND a.activity_voice_id IN (` + idSqlStr + `)`
  304. }
  305. //}
  306. //视频的处理
  307. var videoCond string
  308. var videoCondAct string
  309. var videoPars []interface{}
  310. var videoParsAct []interface{}
  311. //if audioId > 0 || filter == 2 {
  312. // videoCond = ""
  313. //} else {
  314. if keywords != "" {
  315. videoCond += ` AND video_name REGEXP ?`
  316. videoPars = append(videoPars, keywords)
  317. videoCondAct += ` AND video_name REGEXP ?`
  318. videoParsAct = append(videoParsAct, keywords)
  319. }
  320. if videoId > 0 {
  321. videoCond += ` AND video_id = ?`
  322. videoPars = append(videoPars, videoId)
  323. }
  324. if activityVideoId > 0 {
  325. videoCondAct += ` AND video_id = ?`
  326. videoParsAct = append(videoParsAct, activityVideoId)
  327. }
  328. if activityVideoIds != "" {
  329. sliceId := strings.Split(activityVideoIds, ",")
  330. var idSqlStr string
  331. for _, v := range sliceId {
  332. idSqlStr += "'" + v + "',"
  333. }
  334. idSqlStr = strings.TrimRight(idSqlStr, ",")
  335. videoCondAct += ` AND v.video_id IN (` + idSqlStr + `)`
  336. }
  337. //如果传了路演的或者活动的视频ID只查询一个
  338. if videoId > 0 {
  339. videoCondAct += ` AND video_id = 0 `
  340. audioCond += ` AND a.activity_voice_id = 0 `
  341. }
  342. if activityVideoId > 0 {
  343. videoCond += ` AND video_id = 0 `
  344. audioCond += ` AND a.activity_voice_id = 0 `
  345. }
  346. if audioId > 0 {
  347. videoCondAct += ` AND video_id = 0 `
  348. videoCond += ` AND video_id = 0 `
  349. }
  350. if filter == 1 {
  351. audioCond += ` AND a.activity_voice_id = 0 `
  352. } else if filter == 2 {
  353. videoCondAct += ` AND video_id = 0 `
  354. videoCond += ` AND video_id = 0 `
  355. }
  356. if videoIds != "" {
  357. sliceId := strings.Split(videoIds, ",")
  358. var idSqlStr string
  359. for _, v := range sliceId {
  360. idSqlStr += "'" + v + "',"
  361. }
  362. idSqlStr = strings.TrimRight(idSqlStr, ",")
  363. videoCond += ` AND video_id IN (` + idSqlStr + `)`
  364. }
  365. videoCond += ` AND publish_status = 1`
  366. //}
  367. total, e = models.CountMicroRoadShowVideoPageList(videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars)
  368. if e != nil {
  369. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  370. return
  371. }
  372. return
  373. }
  374. // GetMicroRoadShowPageListIkWord 添加IK分词联想词 获取微路演列表添加活动视频 更新与8.1版本
  375. func GetMicroRoadShowPageListIkWord(startSize, pageSize, audioId, videoId, activityVideoId, filter int, keywordArr []string, audioIds, videoIds, activityVideoIds string) (respList []*models.MicroRoadShowPageList, err error) {
  376. videoList := make([]*models.MicroRoadShowPageList, 0)
  377. var e error
  378. var keywords string
  379. if len(keywordArr) > 1 {
  380. keywords = KeyWordArrSqlRegexp(keywordArr)
  381. }
  382. //音频的查询
  383. var audioCond string
  384. var audioPars []interface{}
  385. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  386. //if videoId > 0 || activityVideoId > 0 || filter == 1 {
  387. // audioCond += ` AND a.activity_voice_id = 0 `
  388. //} else {
  389. // 活动已发布且已结束
  390. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  391. if keywords != "" {
  392. audioCond += ` AND a.voice_name REGEXP ? OR b.label REGEXP ?`
  393. audioPars = append(audioPars, keywords, keywords)
  394. }
  395. if audioId > 0 {
  396. audioCond += ` AND a.activity_voice_id = ?`
  397. audioPars = append(audioPars, audioId)
  398. }
  399. if audioIds != "" {
  400. sliceId := strings.Split(audioIds, ",")
  401. var idSqlStr string
  402. for _, v := range sliceId {
  403. idSqlStr += "'" + v + "',"
  404. }
  405. idSqlStr = strings.TrimRight(idSqlStr, ",")
  406. audioCond += ` AND a.activity_voice_id IN (` + idSqlStr + `)`
  407. }
  408. //}
  409. //视频的处理
  410. var videoCond string
  411. var videoCondAct string
  412. var videoPars []interface{}
  413. var videoParsAct []interface{}
  414. //if audioId > 0 || filter == 2 {
  415. // videoCond = ""
  416. //} else {
  417. if keywords != "" {
  418. videoCond += ` AND video_name REGEXP ?`
  419. videoPars = append(videoPars, keywords)
  420. videoCondAct += ` AND video_name REGEXP ?`
  421. videoParsAct = append(videoParsAct, keywords)
  422. }
  423. if videoId > 0 {
  424. videoCond += ` AND video_id = ?`
  425. videoPars = append(videoPars, videoId)
  426. }
  427. if activityVideoId > 0 {
  428. videoCondAct += ` AND video_id = ?`
  429. videoParsAct = append(videoParsAct, activityVideoId)
  430. }
  431. if activityVideoIds != "" {
  432. sliceId := strings.Split(activityVideoIds, ",")
  433. var idSqlStr string
  434. for _, v := range sliceId {
  435. idSqlStr += "'" + v + "',"
  436. }
  437. idSqlStr = strings.TrimRight(idSqlStr, ",")
  438. videoCondAct += ` AND v.video_id IN (` + idSqlStr + `)`
  439. }
  440. //如果传了路演的或者活动的视频ID只查询一个
  441. if videoId > 0 {
  442. videoCondAct += ` AND video_id = 0 `
  443. audioCond += ` AND a.activity_voice_id = 0 `
  444. }
  445. if activityVideoId > 0 {
  446. videoCond += ` AND video_id = 0 `
  447. audioCond += ` AND a.activity_voice_id = 0 `
  448. }
  449. if audioId > 0 {
  450. videoCondAct += ` AND video_id = 0 `
  451. videoCond += ` AND video_id = 0 `
  452. }
  453. if filter == 1 {
  454. audioCond += ` AND a.activity_voice_id = 0 `
  455. } else if filter == 2 {
  456. videoCondAct += ` AND video_id = 0 `
  457. videoCond += ` AND video_id = 0 `
  458. }
  459. if videoIds != "" {
  460. sliceId := strings.Split(videoIds, ",")
  461. var idSqlStr string
  462. for _, v := range sliceId {
  463. idSqlStr += "'" + v + "',"
  464. }
  465. idSqlStr = strings.TrimRight(idSqlStr, ",")
  466. videoCond += ` AND video_id IN (` + idSqlStr + `)`
  467. }
  468. videoCond += ` AND publish_status = 1`
  469. //}
  470. videoList, e = models.GetMicroRoadShowVideoPageListIkWord(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars, audioId, videoId, activityVideoId, filter)
  471. if e != nil {
  472. err = errors.New("获取微路演音视频列表失败分词, Err: " + e.Error())
  473. return
  474. }
  475. respList = videoList
  476. return
  477. }
  478. // 我的收藏
  479. func GetMicroRoadShowMycollect(pageSize, currentIndex int, audioIds, videoIds, activityVideoIds string) (respList []*models.MicroRoadShowPageList, total int, err error) {
  480. var e error
  481. // 根据每页数据量获取音视频配比
  482. startSize := utils.StartIndex(currentIndex, pageSize)
  483. videoList := make([]*models.MicroRoadShowPageList, 0)
  484. //音频的查询
  485. var audioCond string
  486. var audioPars []interface{}
  487. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  488. // 活动已发布且已结束
  489. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  490. if audioIds != "" {
  491. sliceId := strings.Split(audioIds, ",")
  492. var idSqlStr string
  493. for _, v := range sliceId {
  494. idSqlStr += "'" + v + "',"
  495. }
  496. idSqlStr = strings.TrimRight(idSqlStr, ",")
  497. audioCond += ` AND a.activity_voice_id IN (` + idSqlStr + `)`
  498. } else {
  499. audioCond += ` AND a.activity_voice_id = 0 `
  500. }
  501. //视频的处理
  502. var videoCond string
  503. var videoCondAct string
  504. if activityVideoIds != "" {
  505. sliceId := strings.Split(activityVideoIds, ",")
  506. var idSqlStr string
  507. for _, v := range sliceId {
  508. idSqlStr += "'" + v + "',"
  509. }
  510. idSqlStr = strings.TrimRight(idSqlStr, ",")
  511. videoCondAct += ` AND v.video_id IN (` + idSqlStr + `)`
  512. } else {
  513. videoCondAct += ` AND v.video_id = 0 `
  514. }
  515. var videoPars []interface{}
  516. var videoParsAct []interface{}
  517. if videoIds != "" {
  518. sliceId := strings.Split(videoIds, ",")
  519. var idSqlStr string
  520. for _, v := range sliceId {
  521. idSqlStr += "'" + v + "',"
  522. }
  523. idSqlStr = strings.TrimRight(idSqlStr, ",")
  524. videoCond += ` AND video_id IN (` + idSqlStr + `)`
  525. } else {
  526. videoCond += ` AND video_id = 0 `
  527. }
  528. videoCond += ` AND publish_status = 1`
  529. total, videoList, e = models.GetMicroRoadShowVideoPageListV8(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars, 0, 0, 0, 0)
  530. if e != nil {
  531. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  532. return
  533. }
  534. respList = videoList
  535. return
  536. }
  537. // GetMicroRoadshowVideoMap 获取已经发布的微路演的产业ID
  538. func GetMicroRoadshowVideoMap() (items map[int]int, err error) {
  539. list, e := models.GetMicroRoadshowVideoList()
  540. if e != nil && e.Error() != utils.ErrNoRow() {
  541. err = errors.New("获取已经发布的微路演的产业失败,GetMicroRoadshowVideoList " + e.Error())
  542. return
  543. }
  544. mapindustrialId := make(map[int]int)
  545. for _, v := range list {
  546. mapindustrialId[v.IndustryId] = v.IndustryId
  547. }
  548. items = mapindustrialId
  549. return
  550. }
  551. func GetindustryVideo(user *models.WxUserItem, industrialManagementId int) (industryVideo *models.MicroVideoSimpleInfo, AuthInfo *models.UserPermissionAuthInfo, err error) {
  552. total, e := models.GetMicroRoadshowVideoByIndustryIdCount(industrialManagementId)
  553. if e != nil {
  554. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryIdCount " + e.Error())
  555. return
  556. }
  557. if total == 0 {
  558. return
  559. }
  560. // 用户权限
  561. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  562. if e != nil {
  563. err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
  564. return
  565. }
  566. videoSimple := new(models.MicroVideoSimpleInfo)
  567. // 权限
  568. var au *models.UserPermissionAuthInfo
  569. video, e := models.GetMicroRoadshowVideoByIndustryId(industrialManagementId)
  570. if e != nil {
  571. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  572. return
  573. } else {
  574. videoSimple.Id = video.VideoId
  575. videoSimple.Title = "5min【" + video.IndustryName + "】逻辑解析"
  576. videoSimple.BackgroundImg = video.ImgUrl
  577. videoSimple.DetailImgUrl = video.DetailImgUrl
  578. if videoSimple.BackgroundImg == "" {
  579. // 获取默认图配置
  580. _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
  581. if e != nil {
  582. err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  583. return
  584. }
  585. videoSimple.BackgroundImg = videoMap[video.ChartPermissionId]
  586. }
  587. videoSimple.PlaySeconds = video.VideoDuration
  588. videoSimple.ResourceUrl = video.VideoUrl
  589. au = new(models.UserPermissionAuthInfo)
  590. au.SellerName = authInfo.SellerName
  591. au.SellerMobile = authInfo.SellerMobile
  592. au.HasPermission = authInfo.HasPermission
  593. au.OperationMode = authInfo.OperationMode
  594. if au.HasPermission == 1 {
  595. // 非宏观权限进一步判断是否有权限
  596. if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
  597. au.HasPermission = 2
  598. }
  599. }
  600. // 无权限的弹框提示
  601. if au.HasPermission != 1 {
  602. if au.OperationMode == UserPermissionOperationModeCall {
  603. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  604. } else {
  605. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  606. }
  607. videoSimple.ResourceUrl = ""
  608. }
  609. }
  610. industryVideo = videoSimple
  611. AuthInfo = au
  612. return
  613. }
  614. // 用户微路演视频回放操作操作行为,模板消息推送
  615. func MicroRoadshowVideoUserRmind(user *models.WxUserItem, videoId int) (err error) {
  616. defer func() {
  617. if err != nil {
  618. go utils.SendAlarmMsg("用户音视频回放操作操作行为,模板消息推送失败"+err.Error(), 2)
  619. }
  620. }()
  621. countUser, err := models.GetUserRemind(user.UserId)
  622. if err != nil {
  623. return err
  624. }
  625. if countUser == 0 {
  626. return err
  627. }
  628. var first string
  629. var keyword1 string
  630. var keyword2 string
  631. var keyword3 string
  632. var keyword4 string
  633. var remark string
  634. //获取销售手机号
  635. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  636. if err != nil && err.Error() != utils.ErrNoRow() {
  637. return err
  638. }
  639. if sellerItemQy != nil {
  640. openIdList, e := models.GetWxOpenIdByMobileList(sellerItemQy.Mobile)
  641. if e != nil {
  642. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  643. return
  644. }
  645. videoInfo, e := models.GetMicroRoadshowVideoByVideoId(videoId)
  646. if e != nil {
  647. err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
  648. return
  649. }
  650. if videoInfo == nil {
  651. return
  652. }
  653. first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放微路演详视频")
  654. keyword1 = videoInfo.VideoName
  655. keyword2 = "--"
  656. remark = "点击查看微路演详情"
  657. openIdArr := make([]string, 0)
  658. for _, v := range openIdList {
  659. openIdArr = append(openIdArr, v.OpenId)
  660. }
  661. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_INDUSTRYR_EPORT + strconv.Itoa(videoInfo.IndustryId)
  662. sendInfo := new(SendWxTemplate)
  663. sendInfo.First = first
  664. sendInfo.Keyword1 = keyword1
  665. sendInfo.Keyword2 = keyword2
  666. sendInfo.Keyword3 = keyword3
  667. sendInfo.Keyword4 = keyword4
  668. sendInfo.Remark = remark
  669. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  670. sendInfo.RedirectUrl = redirectUrl
  671. sendInfo.RedirectTarget = 3
  672. sendInfo.Resource = strconv.Itoa(videoId)
  673. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  674. sendInfo.OpenIdArr = openIdArr
  675. err = PublicSendTemplateMsg(sendInfo)
  676. if err != nil {
  677. return
  678. }
  679. }
  680. return
  681. }