report_selection.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_clpt/models"
  5. "hongze/hongze_clpt/services"
  6. "hongze/hongze_clpt/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. // 报告
  12. type ReportSelectionController struct {
  13. BaseAuthController
  14. }
  15. // @Title 获取报告精选详情
  16. // @Description 获取报告精选详情接口
  17. // @Param ArticleId query int true "报告ID"
  18. // @Param IsBestNew query bool false "是否获取最新的一篇报告"
  19. // @Success 200 {object} models.ReportSelectionLetailResp
  20. // @router /detail [get]
  21. func (this *ReportSelectionController) Detail() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. user := this.User
  28. if user == nil {
  29. br.Msg = "请重新登录"
  30. br.Ret = 408
  31. return
  32. }
  33. //uid := user.UserId
  34. articleId, _ := this.GetInt("ArticleId")
  35. isBestNew, _ := this.GetBool("IsBestNew")
  36. if isBestNew {
  37. tbdb := "cygx_report_selection"
  38. condition := ` AND publish_status = 1 `
  39. var pars []interface{}
  40. list, err := models.GetReportSelectionListPublic(condition, "1", tbdb, pars, 0, 1)
  41. if err != nil {
  42. br.Msg = "获取失败"
  43. br.ErrMsg = "获取失败,Err:" + err.Error()
  44. return
  45. }
  46. for _, v := range list {
  47. articleId = v.ArticleId
  48. }
  49. }
  50. if articleId < 1 {
  51. br.Msg = "获取信息失败"
  52. br.ErrMsg = "报告ID错误" + strconv.Itoa(articleId)
  53. return
  54. }
  55. PermissionNameMap, err := services.GetPermissionNameMap()
  56. if err != nil {
  57. br.Msg = "获取失败"
  58. br.ErrMsg = "获取失败 GetPermissionNameMap,Err:" + err.Error()
  59. return
  60. }
  61. PermissionIcoMap, err := services.GetPermissionNameIcoMap()
  62. if err != nil {
  63. br.Msg = "获取失败"
  64. br.ErrMsg = "获取失败 GetPermissionNameMap,Err:" + err.Error()
  65. return
  66. }
  67. resp := new(models.ReportSelectionLetailResp)
  68. //判断用户权限
  69. hasPermission, err := services.GetUserhasPermission(user)
  70. if err != nil {
  71. br.Msg = "获取信息失败"
  72. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  73. }
  74. detail, err := models.GetCygxReportSelectionInfoById(articleId)
  75. if err != nil {
  76. br.Msg = "获取信息失败"
  77. br.ErrMsg = "报告不存在,Err:" + err.Error() + "articleId:" + strconv.Itoa(articleId)
  78. return
  79. }
  80. //未设置全部可见的只能给弘则内部查看
  81. if detail.VisibleRange == 1 || user.CompanyId == utils.HZ_COMPANY_ID {
  82. resp.IsShow = true
  83. }
  84. resp.HasPermission = hasPermission
  85. if hasPermission != 1 || !resp.IsShow {
  86. br.Ret = 200
  87. br.Success = true
  88. br.Msg = "获取成功"
  89. resp.Detail = detail
  90. br.Data = resp
  91. return
  92. }
  93. if detail.ReportLink != "" {
  94. articleIdLink, _ := services.GetReportLinkToArticleid(detail.ReportLink)
  95. detail.CeLueArticleId = articleIdLink
  96. }
  97. articleStockMap, _ := services.GetArticleStockMap()
  98. detail.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
  99. existMap := make(map[int]int)
  100. var items []*models.ReportSelectionChartPermission
  101. var itemsSubject []*models.ReportSelectionChartLogPermission
  102. listLog, err := models.GetReportSelectionlogListAll(articleId)
  103. if err != nil {
  104. br.Msg = "获取失败"
  105. br.ErrMsg = "获取子类信息失败,Err:" + err.Error()
  106. return
  107. }
  108. detail.VideoPlaySeconds = utils.Mp3Time(detail.VideoPlaySeconds)
  109. //获取行业核心逻辑汇总
  110. listChartLog, err := models.GetCygxReportSelectionChartLogRepList(articleId)
  111. if err != nil {
  112. br.Msg = "获取失败"
  113. br.ErrMsg = "获取失败,Err:" + err.Error()
  114. return
  115. }
  116. mapChartLog := make(map[string]string)
  117. for _, v := range listChartLog {
  118. mapChartLog[v.ChartPermissionName] = v.BodyChartSummary
  119. }
  120. for _, v := range listLog {
  121. v.PermissionName = PermissionNameMap[v.ChartPermissionId]
  122. item := new(models.ReportSelectionChartPermission)
  123. itemSubject := new(models.ReportSelectionChartLogPermission)
  124. itemSubject.PermissionName = v.PermissionName
  125. if existMap[v.ChartPermissionId] == 0 {
  126. //item.PermissionName = v.PermissionName + "领域深度报告和调研"
  127. item.PermissionName = v.PermissionName
  128. item.ChartPermissionId = v.ChartPermissionId
  129. item.IcoLink = v.IcoLink
  130. listSonLog, err := models.GetReportSelectionlogSonListAll(articleId, v.ChartPermissionId)
  131. if err != nil && err.Error() != utils.ErrNoRow() {
  132. br.Msg = "获取信息失败"
  133. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  134. return
  135. }
  136. for k2, v2 := range listSonLog {
  137. if v2.IndustrialManagementId != "" {
  138. listIndustrial, err := models.GetIndustrialByIds(v2.IndustrialManagementId)
  139. if err != nil && err.Error() != utils.ErrNoRow() {
  140. br.Msg = "获取信息失败"
  141. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  142. return
  143. }
  144. //后台如果勾了隐藏那么这里就不展示 V11.3 2023-08-17
  145. if listSonLog[k2].IsShowOverviewArticle == 1 {
  146. listSonLog[k2].OverviewArticleId = articleStockMap[v2.SubjectName]
  147. } else {
  148. listSonLog[k2].OverviewArticleId = 0
  149. }
  150. listSonLog[k2].List = listIndustrial
  151. //listSonLog[k2].IsShowApplyButton = true
  152. if v2.Label != "" {
  153. CompanyLabelSlice := strings.Split(v2.Label, "{|}")
  154. for _, vCompanyLabel := range CompanyLabelSlice {
  155. v2.CompanyLabel = append(v2.CompanyLabel, vCompanyLabel+"#")
  156. }
  157. }
  158. }
  159. itemSubject.ListSubject = append(itemSubject.ListSubject, &models.ReportSelectionChartLogSubjectName{SubjectName: v2.SubjectName, IsNew: v2.IsNew, IndustrialSubjectId: v2.IndustrialSubjectId})
  160. }
  161. item.BodyChartSummary = mapChartLog[v.PermissionName]
  162. item.List = listSonLog
  163. item.PermissionName = PermissionNameMap[v.ChartPermissionId]
  164. item.IcoLink = PermissionIcoMap[v.ChartPermissionId]
  165. items = append(items, item)
  166. itemsSubject = append(itemsSubject, itemSubject)
  167. //itemLogs = make([]*models.CygxReportSelectionLogDetail, 0)
  168. }
  169. existMap[v.ChartPermissionId] = v.ChartPermissionId
  170. }
  171. //historyRecord := new(models.CygxReportHistoryRecord)
  172. //historyRecord.UserId = uid
  173. //historyRecord.ArticleId = articleId
  174. //historyRecord.CreateTime = time.Now()
  175. //historyRecord.Mobile = user.Mobile
  176. //historyRecord.Email = user.Email
  177. //historyRecord.CompanyId = user.CompanyId
  178. //historyRecord.CompanyName = user.CompanyName
  179. //historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  180. //historyRecord.ReportType = "bgjx"
  181. //sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  182. //if err != nil && err.Error() != utils.ErrNoRow() {
  183. // br.Msg = "获取信息失败"
  184. // br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  185. // return
  186. //}
  187. //historyRecord.RealName = user.RealName
  188. //if sellerItem != nil {
  189. // historyRecord.SellerName = sellerItem.RealName
  190. //}
  191. //go services.AddCygxReportHistoryRecord(user, articleId, "bgjx")
  192. resp.List = items
  193. resp.ListPermissionSubject = itemsSubject
  194. resp.Detail = detail
  195. br.Ret = 200
  196. br.Success = true
  197. br.Msg = "获取成功"
  198. br.Data = resp
  199. }
  200. // @Title 标的点击记录
  201. // @Description 标的点击记录接口
  202. // @Param request body models.AddCygxReportSelectionSubjectHistoryReq true "type json string"
  203. // @router /click/history [post]
  204. func (this *ReportSelectionController) ClickHistory() {
  205. br := new(models.BaseResponse).Init()
  206. defer func() {
  207. this.Data["json"] = br
  208. this.ServeJSON()
  209. }()
  210. user := this.User
  211. if user == nil {
  212. br.Msg = "请重新登录"
  213. br.Ret = 408
  214. return
  215. }
  216. var req models.AddCygxReportSelectionSubjectHistoryReq
  217. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  218. if err != nil {
  219. br.Msg = "参数解析异常!"
  220. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  221. return
  222. }
  223. if req.ArticleId <= 0 {
  224. br.Msg = "文章不存在"
  225. br.ErrMsg = "文章不存在,文章ID错误"
  226. return
  227. }
  228. if req.IndustrialSubjectId <= 0 {
  229. br.Msg = "标的ID不存在"
  230. br.ErrMsg = "标的ID不存在,标的ID错误"
  231. return
  232. }
  233. item := models.CygxReportSelectionSubjectHistory{
  234. UserId: user.UserId,
  235. ArticleId: req.ArticleId,
  236. CreateTime: time.Now(),
  237. ModifyTime: time.Now(),
  238. Mobile: user.Mobile,
  239. Email: user.Email,
  240. CompanyId: user.CompanyId,
  241. CompanyName: user.CompanyName,
  242. IndustrialSubjectId: req.IndustrialSubjectId,
  243. RegisterPlatform: utils.REGISTER_PLATFORM,
  244. }
  245. err = models.AddCygxReportSelectionSubjectHistory(&item)
  246. if err != nil {
  247. br.Msg = "记录失败"
  248. br.ErrMsg = "记录失败,Err:" + err.Error()
  249. return
  250. }
  251. br.Ret = 200
  252. br.Success = true
  253. br.Msg = "记录成功"
  254. }
  255. // @Title 上传文章阅读时间
  256. // @Description 上传文章阅读时间接口
  257. // @Param request body models.AddStopTimeRep true "type json string"
  258. // @Success 200 {object} models.ArticleDetailResp
  259. // @router /addStopTime [post]
  260. func (this *ReportSelectionController) AddStopTime() {
  261. br := new(models.BaseResponse).Init()
  262. defer func() {
  263. this.Data["json"] = br
  264. this.ServeJSON()
  265. }()
  266. user := this.User
  267. if user == nil {
  268. br.Msg = "请登录"
  269. br.ErrMsg = "请登录,用户信息为空"
  270. br.Ret = 408
  271. return
  272. }
  273. var req models.AddReportSelectionStopTimeRep
  274. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  275. if err != nil {
  276. br.Msg = "参数解析异常!"
  277. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  278. return
  279. }
  280. uid := user.UserId
  281. articleId := req.ArticleId
  282. stopTime := req.StopTime
  283. outType := req.OutType
  284. source := req.Source
  285. var reportType string
  286. if source == 1 {
  287. reportType = "bgjx"
  288. } else if source == 2 {
  289. reportType = "bzyjhz"
  290. } else if source == 3 {
  291. reportType = "szjyhz"
  292. }
  293. hasPermission, err := services.GetUserhasPermission(user)
  294. if err != nil {
  295. br.Msg = "获取信息失败"
  296. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  297. }
  298. if hasPermission == 1 {
  299. historyRecord := new(models.CygxReportHistoryRecord)
  300. historyRecord.UserId = uid
  301. historyRecord.ArticleId = articleId
  302. historyRecord.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  303. historyRecord.Mobile = user.Mobile
  304. historyRecord.Email = user.Email
  305. historyRecord.CompanyId = user.CompanyId
  306. historyRecord.CompanyName = user.CompanyName
  307. historyRecord.StopTime = stopTime
  308. historyRecord.OutType = outType
  309. historyRecord.ReportType = reportType
  310. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  311. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  312. if err != nil && err.Error() != utils.ErrNoRow() {
  313. br.Msg = "获取信息失败"
  314. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  315. return
  316. }
  317. historyRecord.RealName = user.RealName
  318. if sellerItem != nil {
  319. historyRecord.SellerName = sellerItem.RealName
  320. }
  321. go services.AddCygxReportHistoryRecord(historyRecord)
  322. }
  323. br.Ret = 200
  324. br.Success = true
  325. br.Msg = "操作成功"
  326. }
  327. // @Title 报告精选申请路演
  328. // @Description 报告精选申请路演
  329. // @Param request body cygx.CygxBannerIdReq true "type json string"
  330. // @Success 200 Ret=200 提交成功
  331. // @router /report_selection_log/apply [post]
  332. func (this *ReportSelectionController) ReportSelectionLogApply() {
  333. br := new(models.BaseResponse).Init()
  334. defer func() {
  335. this.Data["json"] = br
  336. this.ServeJSON()
  337. }()
  338. user := this.User
  339. if user == nil {
  340. br.Msg = "请登录"
  341. br.ErrMsg = "请登录,用户信息为空"
  342. br.Ret = 408
  343. return
  344. }
  345. var req models.CygxReportSelectionLogApplyReq
  346. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  347. if err != nil {
  348. br.Msg = "参数解析异常!"
  349. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  350. return
  351. }
  352. articleId := req.ArticleId
  353. subjectName := req.SubjectName
  354. var condition string
  355. var pars []interface{}
  356. condition += ` AND article_id = ? AND subject_name = ? AND user_id = ? `
  357. pars = append(pars, articleId, subjectName, user.UserId)
  358. totalApply, err := models.GetCygxReportSelectionLogApplyCount(condition, pars)
  359. if err != nil {
  360. br.Msg = "申请失败!"
  361. br.ErrMsg = "申请失败,Err:" + err.Error()
  362. return
  363. }
  364. if totalApply > 0 {
  365. br.Msg = "您已提交过此公司的路演申请,请等待销售与您联系!"
  366. return
  367. }
  368. logDetail, err := models.GetCygxReportSelectionLogDetail(articleId, subjectName)
  369. if err != nil {
  370. br.Msg = "申请失败!"
  371. br.ErrMsg = "申请失败,Err:" + err.Error()
  372. return
  373. }
  374. item := new(models.CygxReportSelectionLogApply)
  375. item.UserId = user.UserId
  376. item.CreateTime = time.Now()
  377. item.ModifyTime = time.Now()
  378. item.Mobile = user.Mobile
  379. item.Email = user.Email
  380. item.CompanyId = user.CompanyId
  381. item.CompanyName = user.CompanyName
  382. item.ArticleId = logDetail.ArticleId
  383. item.SubjectName = logDetail.SubjectName
  384. item.IndustrialSubjectId = logDetail.IndustrialSubjectId
  385. item.RegisterPlatform = utils.REGISTER_PLATFORM
  386. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  387. if err != nil && err.Error() != utils.ErrNoRow() {
  388. return
  389. }
  390. item.RealName = user.RealName
  391. if sellerItem != nil {
  392. item.SellerName = sellerItem.RealName
  393. }
  394. _, err = models.AddCygxReportSelectionLogApply(item)
  395. if err != nil {
  396. br.Msg = "申请失败"
  397. br.ErrMsg = "申请失败,Err:" + err.Error()
  398. return
  399. }
  400. go services.SendCygxReportSelectionLogApplyTemplateMsg(user, logDetail.SubjectName)
  401. br.Ret = 200
  402. br.Success = true
  403. br.Msg = "记录成功"
  404. }