micro_roadshow.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/services"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "time"
  10. )
  11. // 微路演
  12. type MicroRoadShowController struct {
  13. BaseAuthController
  14. }
  15. // @Title 微路演列表
  16. // @Description 微路演列表接口
  17. // @Param PageSize query int true "每页数据条数"
  18. // @Param CurrentIndex query int true "当前页页码,从1开始"
  19. // @Param KeyWord query string false "搜索关键词"
  20. // @Param AudioId query int false "音频ID"
  21. // @Param VideoId query int false "视频ID"
  22. // @Param AudioIds query string false "活动音频IDs"
  23. // @Param ActivityVideoIds query string false "活动视频IDs"
  24. // @Param VideoIds query string false "视频IDs"
  25. // @Param ActivityVideoId query int false "活动视频ID"
  26. // @Param Filter query int false "筛选条件 0:全部 1:视频 2:音频"
  27. // @Success 200 {object} models.HomeListResp
  28. // @router /list [get]
  29. func (this *MicroRoadShowController) List() {
  30. br := new(models.BaseResponse).Init()
  31. defer func() {
  32. this.Data["json"] = br
  33. this.ServeJSON()
  34. }()
  35. user := this.User
  36. if user == nil {
  37. br.Msg = "请登录"
  38. br.ErrMsg = "请登录,用户信息为空"
  39. br.Ret = 408
  40. return
  41. }
  42. pageSize, _ := this.GetInt("PageSize")
  43. currentIndex, _ := this.GetInt("CurrentIndex")
  44. keywords := this.GetString("KeyWord")
  45. audioId, _ := this.GetInt("AudioId")
  46. videoId, _ := this.GetInt("VideoId")
  47. audioIds := this.GetString("AudioIds")
  48. videoIds := this.GetString("VideoIds")
  49. activityVideoIds := this.GetString("ActivityVideoIds")
  50. activityVideoId, _ := this.GetInt("ActivityVideoId")
  51. filter, _ := this.GetInt("Filter", 0)
  52. if pageSize <= 0 {
  53. pageSize = utils.PageSize20
  54. }
  55. if currentIndex <= 0 {
  56. currentIndex = 1
  57. }
  58. // 微路演列表
  59. list, total, e := services.GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activityVideoId, filter, keywords, audioIds, videoIds, activityVideoIds)
  60. if e != nil {
  61. br.Msg = "获取失败"
  62. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  63. return
  64. }
  65. for _, item := range list {
  66. if item.Type == 1 {
  67. //音频
  68. count, err := models.GetVoiceCollectCount(user.UserId, item.Id)
  69. if err != nil {
  70. br.Msg = "获取数据失败!"
  71. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  72. return
  73. }
  74. if count > 0 {
  75. item.IsCollect = true
  76. }
  77. } else if item.Type == 2 {
  78. //活动视频
  79. count, err := models.GetActivityVideoCollectCount(user.UserId, item.Id)
  80. if err != nil {
  81. br.Msg = "获取数据失败!"
  82. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  83. return
  84. }
  85. if count > 0 {
  86. item.IsCollect = true
  87. }
  88. } else if item.Type == 3 {
  89. //微路演视频
  90. count, err := models.GetVideoCollectCount(user.UserId, item.Id)
  91. if err != nil {
  92. br.Msg = "获取数据失败!"
  93. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  94. return
  95. }
  96. if count > 0 {
  97. item.IsCollect = true
  98. }
  99. }
  100. }
  101. // 用户权限
  102. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  103. if e != nil {
  104. br.Msg = "获取失败"
  105. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  106. return
  107. }
  108. // 获取默认图配置
  109. audioMap, videoMap, audioShareMap, videoShareMap, e := services.GetMicroRoadShowDefaultImgConfig()
  110. if e != nil {
  111. br.Msg = "获取失败"
  112. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  113. return
  114. }
  115. for i := range list {
  116. // 权限
  117. au := new(models.UserPermissionAuthInfo)
  118. au.SellerName = authInfo.SellerName
  119. au.SellerMobile = authInfo.SellerMobile
  120. au.HasPermission = authInfo.HasPermission
  121. au.OperationMode = authInfo.OperationMode
  122. if au.HasPermission == 1 {
  123. // 非宏观权限进一步判断是否有权限
  124. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  125. au.HasPermission = 2
  126. }
  127. }
  128. // 无权限的弹框提示
  129. if au.HasPermission != 1 {
  130. if au.OperationMode == services.UserPermissionOperationModeCall {
  131. if list[i].Type == 1 {
  132. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  133. } else {
  134. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  135. }
  136. } else {
  137. if list[i].Type == 1 {
  138. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  139. } else {
  140. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  141. }
  142. }
  143. }
  144. list[i].AuthInfo = au
  145. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  146. // 默认图
  147. if list[i].BackgroundImg == "" {
  148. if list[i].Type == 1 {
  149. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  150. } else {
  151. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  152. }
  153. }
  154. // 分享图
  155. if list[i].ShareImg == "" {
  156. if list[i].Type == 1 {
  157. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  158. } else {
  159. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  160. }
  161. }
  162. //修改产业视频的标题
  163. if list[i].Type == 3 && list[i].IndustryName != "" {
  164. list[i].Title = "5min" + "【" + list[i].IndustryName + "】" + "逻辑解析"
  165. }
  166. }
  167. resp := new(models.MicroRoadShowListResp)
  168. page := paging.GetPaging(currentIndex, pageSize, total)
  169. resp.List = list
  170. resp.Paging = page
  171. br.Ret = 200
  172. br.Success = true
  173. br.Msg = "获取成功"
  174. br.Data = resp
  175. }
  176. // @Title 记录用户浏览音频回放接口
  177. // @Description 记录用户浏览音频回放接口
  178. // @Param request body models.ActivityIdRep true "type json string"
  179. // @Success Ret=200 {object} models.AppointmentResp
  180. // @router /videoHistory/add [post]
  181. func (this *MicroRoadShowController) VideoHistoryAdd() {
  182. br := new(models.BaseResponse).Init()
  183. defer func() {
  184. this.Data["json"] = br
  185. this.ServeJSON()
  186. }()
  187. user := this.User
  188. if user == nil {
  189. br.Msg = "请登录"
  190. br.ErrMsg = "请登录,用户信息为空"
  191. br.Ret = 408
  192. return
  193. }
  194. uid := user.UserId
  195. var req models.AddVideoHistoryReq
  196. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  197. if err != nil {
  198. br.Msg = "参数解析异常!"
  199. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  200. return
  201. }
  202. videoId := req.VideoId
  203. playSeconds := req.PlaySeconds
  204. sourceType := req.SourceType
  205. if sourceType == 0 {
  206. sourceType = 1
  207. }
  208. var sellerName string
  209. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  210. if err != nil {
  211. br.Msg = "报名失败!"
  212. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  213. return
  214. }
  215. if sourceType == 1 {
  216. item := models.CygxMicroRoadshowVideoHistory{
  217. VideoId: videoId,
  218. UserId: uid,
  219. Mobile: user.Mobile,
  220. Email: user.Email,
  221. CompanyId: user.CompanyId,
  222. CompanyName: user.CompanyName,
  223. RealName: user.RealName,
  224. SellerName: sellerName,
  225. PlaySeconds: strconv.Itoa(playSeconds),
  226. CreateTime: time.Now(),
  227. ModifyTime: time.Now(),
  228. }
  229. if playSeconds != 0 {
  230. lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
  231. if err != nil {
  232. br.Msg = "操作失败"
  233. br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
  234. return
  235. }
  236. err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
  237. if err != nil {
  238. br.Msg = "更新失败"
  239. br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
  240. return
  241. }
  242. } else {
  243. err = models.AddCygxMicroRoadshowVideoHistory(&item)
  244. if err != nil {
  245. br.Msg = "操作失败"
  246. br.ErrMsg = "操作失败,Err:" + err.Error()
  247. return
  248. }
  249. err = models.UpdateCygxActivityVideoCounts(videoId)
  250. if err != nil {
  251. br.Msg = "更新失败"
  252. br.ErrMsg = "更新失败,Err:" + err.Error()
  253. return
  254. }
  255. }
  256. } else if sourceType == 2 {
  257. err = services.AddActivityVideoHistory(user, videoId)
  258. if err != nil {
  259. br.Msg = "更新失败"
  260. br.ErrMsg = "更新失败,AddActivityVideoHistory Err:" + err.Error()
  261. return
  262. }
  263. }
  264. br.Ret = 200
  265. br.Success = true
  266. br.Msg = "操作成功"
  267. return
  268. }
  269. // @Title 微路演新增留言
  270. // @Description 微路演新增留言接口
  271. // @Param request body models.AddVideoCommnetReq true "type json string"
  272. // @Success Ret=200 {object} models.AppointmentResp
  273. // @router /comment/add [post]
  274. func (this *MicroRoadShowController) CommentAdd() {
  275. br := new(models.BaseResponse).Init()
  276. defer func() {
  277. this.Data["json"] = br
  278. this.ServeJSON()
  279. }()
  280. user := this.User
  281. if user == nil {
  282. br.Msg = "请登录"
  283. br.ErrMsg = "请登录,用户信息为空"
  284. br.Ret = 408
  285. return
  286. }
  287. uid := user.UserId
  288. var req models.AddVideoCommnetReq
  289. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  290. if err != nil {
  291. br.Msg = "参数解析异常!"
  292. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  293. return
  294. }
  295. sourceType := req.SourceType
  296. if sourceType == 0 {
  297. sourceType = 1
  298. }
  299. //var sellerName string
  300. //sellerName, err = models.GetCompanySellerName(user.CompanyId)
  301. if err != nil {
  302. br.Msg = "报名失败!"
  303. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  304. return
  305. }
  306. item := models.CygxArticleComment{
  307. UserId: uid,
  308. CreateTime: time.Now(),
  309. Mobile: user.Mobile,
  310. Email: user.Email,
  311. CompanyId: user.CompanyId,
  312. CompanyName: user.CompanyName,
  313. Content: req.Content,
  314. Title: req.Title,
  315. }
  316. if sourceType == 1 {
  317. item.IndustryId = req.Id
  318. } else if sourceType == 2 {
  319. item.ActivityId = req.Id
  320. }
  321. _, err = models.AddArticleComment(&item)
  322. if err != nil {
  323. br.Msg = "提交失败"
  324. br.ErrMsg = "提交留言失败,Err:" + err.Error()
  325. return
  326. }
  327. br.Ret = 200
  328. br.Success = true
  329. br.Msg = "操作成功"
  330. return
  331. }
  332. // @Title 微路演收藏
  333. // @Description 微路演收藏
  334. // @Param request body models.MicroRoadshowCollectReq true "type json string"
  335. // @Success 200 {object} models.FontsCollectResp
  336. // @router /collect [post]
  337. func (this *MicroRoadShowController) Collect() {
  338. br := new(models.BaseResponse).Init()
  339. defer func() {
  340. this.Data["json"] = br
  341. this.ServeJSON()
  342. }()
  343. user := this.User
  344. if user == nil {
  345. br.Msg = "请重新登录"
  346. br.Ret = 408
  347. return
  348. }
  349. uid := user.UserId
  350. var req models.MicroRoadshowCollectReq
  351. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  352. if err != nil {
  353. br.Msg = "参数解析异常!"
  354. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  355. return
  356. }
  357. if req.SourceType == 1 {
  358. _, err := models.GetCygxActivityVoiceById(req.Id)
  359. if err != nil {
  360. br.Msg = "获取信息失败"
  361. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  362. return
  363. }
  364. count, err := models.GetVoiceCollectCount(uid, req.Id)
  365. if err != nil {
  366. br.Msg = "获取数据失败!"
  367. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  368. return
  369. }
  370. resp := new(models.ArticleCollectResp)
  371. if count <= 0 {
  372. item := new(models.CygxArticleCollect)
  373. item.ActivityVoiceId = req.Id
  374. item.UserId = uid
  375. item.CreateTime = time.Now()
  376. item.Mobile = user.Mobile
  377. item.Email = user.Email
  378. item.CompanyId = user.CompanyId
  379. item.CompanyName = user.CompanyName
  380. item.RealName = user.RealName
  381. _, err = models.AddCygxArticleCollect(item)
  382. if err != nil {
  383. br.Msg = "收藏失败"
  384. br.ErrMsg = "收藏失败,Err:" + err.Error()
  385. return
  386. }
  387. br.Msg = "收藏成功"
  388. resp.Status = 1
  389. // 文章收藏消息发送
  390. //go services.ArticleUserRemind(user, detail, 2)
  391. } else {
  392. err = models.RemoveVoiceCollect(uid, req.Id)
  393. if err != nil {
  394. br.Msg = "取消收藏失败"
  395. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  396. return
  397. }
  398. br.Msg = "已取消收藏"
  399. resp.Status = 2
  400. }
  401. collectTotal, err := models.GetVoiceCollectUsersCount(req.Id)
  402. if err != nil {
  403. br.Msg = "获取数据失败"
  404. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  405. return
  406. }
  407. resp.CollectCount = collectTotal
  408. br.Ret = 200
  409. br.Success = true
  410. br.Data = resp
  411. } else if req.SourceType == 2 {
  412. _, err := models.GetCygxActivityVideoById(req.Id)
  413. if err != nil {
  414. br.Msg = "获取信息失败"
  415. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  416. return
  417. }
  418. count, err := models.GetActivityVideoCollectCount(uid, req.Id)
  419. if err != nil {
  420. br.Msg = "获取数据失败!"
  421. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  422. return
  423. }
  424. resp := new(models.ArticleCollectResp)
  425. if count <= 0 {
  426. item := new(models.CygxArticleCollect)
  427. item.ActivityVideoId = req.Id
  428. item.UserId = uid
  429. item.CreateTime = time.Now()
  430. item.Mobile = user.Mobile
  431. item.Email = user.Email
  432. item.CompanyId = user.CompanyId
  433. item.CompanyName = user.CompanyName
  434. item.RealName = user.RealName
  435. _, err = models.AddCygxArticleCollect(item)
  436. if err != nil {
  437. br.Msg = "收藏失败"
  438. br.ErrMsg = "收藏失败,Err:" + err.Error()
  439. return
  440. }
  441. br.Msg = "收藏成功"
  442. resp.Status = 1
  443. // 文章收藏消息发送
  444. //go services.ArticleUserRemind(user, detail, 2)
  445. } else {
  446. err = models.RemoveActivityVideoCollect(uid, req.Id)
  447. if err != nil {
  448. br.Msg = "取消收藏失败"
  449. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  450. return
  451. }
  452. br.Msg = "已取消收藏"
  453. resp.Status = 2
  454. }
  455. collectTotal, err := models.GetActivityVideoCollectUsersCount(req.Id)
  456. if err != nil {
  457. br.Msg = "获取数据失败"
  458. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  459. return
  460. }
  461. resp.CollectCount = collectTotal
  462. br.Ret = 200
  463. br.Success = true
  464. br.Data = resp
  465. } else if req.SourceType == 3 {
  466. _, err := models.GetMicroRoadshowVideoById(req.Id)
  467. if err != nil {
  468. br.Msg = "获取信息失败"
  469. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  470. return
  471. }
  472. count, err := models.GetVideoCollectCount(uid, req.Id)
  473. if err != nil {
  474. br.Msg = "获取数据失败!"
  475. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  476. return
  477. }
  478. resp := new(models.ArticleCollectResp)
  479. if count <= 0 {
  480. item := new(models.CygxArticleCollect)
  481. item.VideoId = req.Id
  482. item.UserId = uid
  483. item.CreateTime = time.Now()
  484. item.Mobile = user.Mobile
  485. item.Email = user.Email
  486. item.CompanyId = user.CompanyId
  487. item.CompanyName = user.CompanyName
  488. item.RealName = user.RealName
  489. _, err = models.AddCygxArticleCollect(item)
  490. if err != nil {
  491. br.Msg = "收藏失败"
  492. br.ErrMsg = "收藏失败,Err:" + err.Error()
  493. return
  494. }
  495. br.Msg = "收藏成功"
  496. resp.Status = 1
  497. // 文章收藏消息发送
  498. //go services.ArticleUserRemind(user, detail, 2)
  499. } else {
  500. err = models.RemoveVideoCollect(uid, req.Id)
  501. if err != nil {
  502. br.Msg = "取消收藏失败"
  503. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  504. return
  505. }
  506. br.Msg = "已取消收藏"
  507. resp.Status = 2
  508. }
  509. collectTotal, err := models.GetVideoCollectUsersCount(req.Id)
  510. if err != nil {
  511. br.Msg = "获取数据失败"
  512. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  513. return
  514. }
  515. resp.CollectCount = collectTotal
  516. br.Ret = 200
  517. br.Success = true
  518. br.Data = resp
  519. }
  520. }