report_selection.go 13 KB

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