micro_roadshow.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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 VideoIds query string false "视频IDs"
  24. // @Param ActivityVideoId query int false "活动视频ID"
  25. // @Param Filter query int false "筛选条件 0:全部 1:视频 2:音频"
  26. // @Success 200 {object} models.HomeListResp
  27. // @router /list [get]
  28. func (this *MicroRoadShowController) List() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. user := this.User
  35. if user == nil {
  36. br.Msg = "请登录"
  37. br.ErrMsg = "请登录,用户信息为空"
  38. br.Ret = 408
  39. return
  40. }
  41. pageSize, _ := this.GetInt("PageSize")
  42. currentIndex, _ := this.GetInt("CurrentIndex")
  43. keywords := this.GetString("KeyWord")
  44. audioId, _ := this.GetInt("AudioId")
  45. videoId, _ := this.GetInt("VideoId")
  46. audioIds := this.GetString("AudioIds")
  47. videoIds := this.GetString("VideoIds")
  48. activityVideoId, _ := this.GetInt("ActivityVideoId")
  49. filter, _ := this.GetInt("Filter", 0)
  50. if pageSize <= 0 {
  51. pageSize = utils.PageSize20
  52. }
  53. if currentIndex <= 0 {
  54. currentIndex = 1
  55. }
  56. // 微路演列表
  57. list, total, e := services.GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activityVideoId, filter, keywords, audioIds, videoIds)
  58. if e != nil {
  59. br.Msg = "获取失败"
  60. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  61. return
  62. }
  63. // 用户权限
  64. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  65. if e != nil {
  66. br.Msg = "获取失败"
  67. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  68. return
  69. }
  70. // 获取默认图配置
  71. audioMap, videoMap, audioShareMap, videoShareMap, e := services.GetMicroRoadShowDefaultImgConfig()
  72. if e != nil {
  73. br.Msg = "获取失败"
  74. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  75. return
  76. }
  77. for i := range list {
  78. // 权限
  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 list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  87. au.HasPermission = 2
  88. }
  89. }
  90. // 无权限的弹框提示
  91. if au.HasPermission != 1 {
  92. if au.OperationMode == services.UserPermissionOperationModeCall {
  93. if list[i].Type == 1 {
  94. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  95. } else {
  96. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  97. }
  98. } else {
  99. if list[i].Type == 1 {
  100. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  101. } else {
  102. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  103. }
  104. }
  105. }
  106. list[i].AuthInfo = au
  107. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  108. // 默认图
  109. if list[i].BackgroundImg == "" {
  110. if list[i].Type == 1 {
  111. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  112. } else {
  113. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  114. }
  115. }
  116. // 分享图
  117. if list[i].ShareImg == "" {
  118. if list[i].Type == 1 {
  119. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  120. } else {
  121. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  122. }
  123. }
  124. //修改产业视频的标题
  125. if list[i].Type == 3 && list[i].IndustryName != "" {
  126. list[i].Title = "5min" + "【" + list[i].IndustryName + "】" + "逻辑解析"
  127. }
  128. }
  129. resp := new(models.MicroRoadShowListResp)
  130. page := paging.GetPaging(currentIndex, pageSize, total)
  131. resp.List = list
  132. resp.Paging = page
  133. br.Ret = 200
  134. br.Success = true
  135. br.Msg = "获取成功"
  136. br.Data = resp
  137. }
  138. // @Title 记录用户浏览音频回放接口
  139. // @Description 记录用户浏览音频回放接口
  140. // @Param request body models.ActivityIdRep true "type json string"
  141. // @Success Ret=200 {object} models.AppointmentResp
  142. // @router /videoHistory/add [post]
  143. func (this *MicroRoadShowController) VideoHistoryAdd() {
  144. br := new(models.BaseResponse).Init()
  145. defer func() {
  146. this.Data["json"] = br
  147. this.ServeJSON()
  148. }()
  149. user := this.User
  150. if user == nil {
  151. br.Msg = "请登录"
  152. br.ErrMsg = "请登录,用户信息为空"
  153. br.Ret = 408
  154. return
  155. }
  156. uid := user.UserId
  157. var req models.AddVideoHistoryReq
  158. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  159. if err != nil {
  160. br.Msg = "参数解析异常!"
  161. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  162. return
  163. }
  164. videoId := req.VideoId
  165. playSeconds := req.PlaySeconds
  166. sourceType := req.SourceType
  167. if sourceType == 0 {
  168. sourceType = 1
  169. }
  170. var sellerName string
  171. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  172. if err != nil {
  173. br.Msg = "报名失败!"
  174. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  175. return
  176. }
  177. if sourceType == 1 {
  178. item := models.CygxMicroRoadshowVideoHistory{
  179. VideoId: videoId,
  180. UserId: uid,
  181. Mobile: user.Mobile,
  182. Email: user.Email,
  183. CompanyId: user.CompanyId,
  184. CompanyName: user.CompanyName,
  185. RealName: user.RealName,
  186. SellerName: sellerName,
  187. PlaySeconds: strconv.Itoa(playSeconds),
  188. CreateTime: time.Now(),
  189. ModifyTime: time.Now(),
  190. }
  191. if playSeconds != 0 {
  192. lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
  193. if err != nil {
  194. br.Msg = "操作失败"
  195. br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
  196. return
  197. }
  198. err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
  199. if err != nil {
  200. br.Msg = "更新失败"
  201. br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
  202. return
  203. }
  204. } else {
  205. err = models.AddCygxMicroRoadshowVideoHistory(&item)
  206. if err != nil {
  207. br.Msg = "操作失败"
  208. br.ErrMsg = "操作失败,Err:" + err.Error()
  209. return
  210. }
  211. err = models.UpdateCygxActivityVideoCounts(videoId)
  212. if err != nil {
  213. br.Msg = "更新失败"
  214. br.ErrMsg = "更新失败,Err:" + err.Error()
  215. return
  216. }
  217. }
  218. } else if sourceType == 2 {
  219. err = services.AddActivityVideoHistory(user, videoId)
  220. if err != nil {
  221. br.Msg = "更新失败"
  222. br.ErrMsg = "更新失败,AddActivityVideoHistory Err:" + err.Error()
  223. return
  224. }
  225. }
  226. br.Ret = 200
  227. br.Success = true
  228. br.Msg = "操作成功"
  229. return
  230. }
  231. // @Title 微路演新增留言
  232. // @Description 微路演新增留言接口
  233. // @Param request body models.ActivityIdRep true "type json string"
  234. // @Success Ret=200 {object} models.AppointmentResp
  235. // @router /comment/add [post]
  236. func (this *MicroRoadShowController) CommentAdd() {
  237. br := new(models.BaseResponse).Init()
  238. defer func() {
  239. this.Data["json"] = br
  240. this.ServeJSON()
  241. }()
  242. user := this.User
  243. if user == nil {
  244. br.Msg = "请登录"
  245. br.ErrMsg = "请登录,用户信息为空"
  246. br.Ret = 408
  247. return
  248. }
  249. uid := user.UserId
  250. var req models.AddVideoCommnetReq
  251. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  252. if err != nil {
  253. br.Msg = "参数解析异常!"
  254. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  255. return
  256. }
  257. sourceType := req.SourceType
  258. if sourceType == 0 {
  259. sourceType = 1
  260. }
  261. //var sellerName string
  262. //sellerName, err = models.GetCompanySellerName(user.CompanyId)
  263. if err != nil {
  264. br.Msg = "报名失败!"
  265. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  266. return
  267. }
  268. item := models.CygxArticleComment{
  269. UserId: uid,
  270. CreateTime: time.Now(),
  271. Mobile: user.Mobile,
  272. Email: user.Email,
  273. CompanyId: user.CompanyId,
  274. CompanyName: user.CompanyName,
  275. Content: req.Content,
  276. Title: req.Title,
  277. }
  278. if sourceType == 1 {
  279. item.IndustryId = req.Id
  280. } else if sourceType == 2 {
  281. item.ActivityId = req.Id
  282. }
  283. _, err = models.AddArticleComment(&item)
  284. if err != nil {
  285. br.Msg = "提交失败"
  286. br.ErrMsg = "提交留言失败,Err:" + err.Error()
  287. return
  288. }
  289. br.Ret = 200
  290. br.Success = true
  291. br.Msg = "操作成功"
  292. return
  293. }
  294. // @Title 收藏
  295. // @Description 收藏
  296. // @Param request body models.ArticleCollectReq true "type json string"
  297. // @Success 200 {object} models.FontsCollectResp
  298. // @router /collect [post]
  299. func (this *ArticleController) Collect() {
  300. br := new(models.BaseResponse).Init()
  301. defer func() {
  302. this.Data["json"] = br
  303. this.ServeJSON()
  304. }()
  305. user := this.User
  306. if user == nil {
  307. br.Msg = "请重新登录"
  308. br.Ret = 408
  309. return
  310. }
  311. uid := user.UserId
  312. var req models.ArticleCollectReq
  313. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  314. if err != nil {
  315. br.Msg = "参数解析异常!"
  316. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  317. return
  318. }
  319. articleId := req.ArticleId
  320. detail, err := models.GetArticleDetailById(articleId)
  321. if err != nil {
  322. br.Msg = "获取信息失败"
  323. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  324. return
  325. }
  326. count, err := models.GetArticleCollectCount(uid, articleId)
  327. if err != nil {
  328. br.Msg = "获取数据失败!"
  329. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  330. return
  331. }
  332. resp := new(models.ArticleCollectResp)
  333. if count <= 0 {
  334. item := new(models.CygxArticleCollect)
  335. item.ArticleId = req.ArticleId
  336. item.UserId = uid
  337. item.CreateTime = time.Now()
  338. item.Mobile = user.Mobile
  339. item.Email = user.Email
  340. item.CompanyId = user.CompanyId
  341. item.CompanyName = user.CompanyName
  342. item.RealName = user.RealName
  343. _, err = models.AddCygxArticleCollect(item)
  344. if err != nil {
  345. br.Msg = "收藏失败"
  346. br.ErrMsg = "收藏失败,Err:" + err.Error()
  347. return
  348. }
  349. br.Msg = "收藏成功"
  350. resp.Status = 1
  351. // 文章收藏消息发送
  352. go services.ArticleUserRemind(user, detail, 2)
  353. } else {
  354. err = models.RemoveArticleCollect(uid, articleId)
  355. if err != nil {
  356. br.Msg = "取消收藏失败"
  357. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  358. return
  359. }
  360. br.Msg = "已取消收藏"
  361. resp.Status = 2
  362. }
  363. collectTotal, err := models.GetArticleCollectUsersCount(articleId)
  364. if err != nil {
  365. br.Msg = "获取数据失败"
  366. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  367. return
  368. }
  369. resp.CollectCount = collectTotal
  370. br.Ret = 200
  371. br.Success = true
  372. br.Data = resp
  373. }