report_selection.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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.SubjectName == "" {
  160. v2.ShowName = v2.IndustrialManagementNames
  161. } else {
  162. v2.ShowName = v2.SubjectName
  163. }
  164. }
  165. if v2.ThirdName != "" {
  166. v2.ShowName = v2.ThirdName
  167. }
  168. subjectItem := new(models.ReportSelectionChartLogSubjectName)
  169. subjectItem.SubjectName = v2.SubjectName
  170. subjectItem.IsNew = v2.IsNew
  171. subjectItem.IndustrialSubjectId = v2.IndustrialSubjectId
  172. subjectItem.IndustrialManagementId, _ = strconv.Atoi(v2.IndustrialManagementId)
  173. subjectItem.IndustrialManagementName = v2.IndustrialManagementNames
  174. subjectItem.ThirdId = v2.ThirdId
  175. if v2.ThirdName != "" {
  176. subjectItem.SubjectName = v2.ThirdName
  177. } else {
  178. if subjectItem.SubjectName == "" {
  179. subjectItem.SubjectName = subjectItem.IndustrialManagementName
  180. }
  181. }
  182. subjectItem.Md5String = utils.MD5(fmt.Sprint("IN_ID", v2.IndustrialManagementId, "S_ID", v2.IndustrialSubjectId, "T_ID", v2.ThirdId))
  183. v2.Md5String = subjectItem.Md5String
  184. itemSubject.ListSubject = append(itemSubject.ListSubject, subjectItem)
  185. //itemSubject.ListSubject = append(itemSubject.ListSubject, &models.ReportSelectionChartLogSubjectName{SubjectName: v2.SubjectName, IsNew: v2.IsNew, IndustrialSubjectId: v2.IndustrialSubjectId})
  186. }
  187. item.BodyChartSummary = mapChartLog[v.PermissionName]
  188. item.List = listSonLog
  189. item.PermissionName = PermissionNameMap[v.ChartPermissionId]
  190. item.IcoLink = PermissionIcoMap[v.ChartPermissionId]
  191. items = append(items, item)
  192. itemsSubject = append(itemsSubject, itemSubject)
  193. //itemLogs = make([]*models.CygxReportSelectionLogDetail, 0)
  194. }
  195. existMap[v.ChartPermissionId] = v.ChartPermissionId
  196. }
  197. resp.List = items
  198. resp.ListPermissionSubject = itemsSubject
  199. resp.Detail = detail
  200. br.Ret = 200
  201. br.Success = true
  202. br.Msg = "获取成功"
  203. br.Data = resp
  204. }
  205. // @Title 标的点击记录
  206. // @Description 标的点击记录接口
  207. // @Param request body models.AddCygxReportSelectionSubjectHistoryReq true "type json string"
  208. // @router /click/history [post]
  209. func (this *ReportSelectionController) ClickHistory() {
  210. br := new(models.BaseResponse).Init()
  211. defer func() {
  212. this.Data["json"] = br
  213. this.ServeJSON()
  214. }()
  215. user := this.User
  216. if user == nil {
  217. br.Msg = "请重新登录"
  218. br.Ret = 408
  219. return
  220. }
  221. var req models.AddCygxReportSelectionSubjectHistoryReq
  222. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  223. if err != nil {
  224. br.Msg = "参数解析异常!"
  225. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  226. return
  227. }
  228. if req.ArticleId <= 0 {
  229. br.Msg = "文章不存在"
  230. br.ErrMsg = "文章不存在,文章ID错误"
  231. return
  232. }
  233. if req.IndustrialSubjectId+req.IndustrialManagementId+req.ThirdId <= 0 {
  234. br.Msg = "标的ID不存在"
  235. br.ErrMsg = "产业或标的ID不存在"
  236. return
  237. }
  238. item := models.CygxReportSelectionSubjectHistory{
  239. UserId: user.UserId,
  240. ArticleId: req.ArticleId,
  241. CreateTime: time.Now(),
  242. ModifyTime: time.Now(),
  243. Mobile: user.Mobile,
  244. Email: user.Email,
  245. CompanyId: user.CompanyId,
  246. CompanyName: user.CompanyName,
  247. IndustrialSubjectId: req.IndustrialSubjectId,
  248. IndustrialManagementId: req.IndustrialManagementId,
  249. ThirdId: req.ThirdId,
  250. RegisterPlatform: utils.REGISTER_PLATFORM,
  251. }
  252. err = models.AddCygxReportSelectionSubjectHistory(&item)
  253. if err != nil {
  254. br.Msg = "记录失败"
  255. br.ErrMsg = "记录失败,Err:" + err.Error()
  256. return
  257. }
  258. br.Ret = 200
  259. br.Success = true
  260. br.Msg = "记录成功"
  261. }
  262. // @Title 上传文章阅读时间
  263. // @Description 上传文章阅读时间接口
  264. // @Param request body models.AddStopTimeRep true "type json string"
  265. // @Success 200 {object} models.ArticleDetailResp
  266. // @router /addStopTime [post]
  267. func (this *ReportSelectionController) AddStopTime() {
  268. br := new(models.BaseResponse).Init()
  269. defer func() {
  270. this.Data["json"] = br
  271. this.ServeJSON()
  272. }()
  273. user := this.User
  274. if user == nil {
  275. br.Msg = "请登录"
  276. br.ErrMsg = "请登录,用户信息为空"
  277. br.Ret = 408
  278. return
  279. }
  280. var req models.AddReportSelectionStopTimeRep
  281. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  282. if err != nil {
  283. br.Msg = "参数解析异常!"
  284. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  285. return
  286. }
  287. uid := user.UserId
  288. articleId := req.ArticleId
  289. stopTime := req.StopTime
  290. outType := req.OutType
  291. source := req.Source
  292. var reportType string
  293. if source == 1 {
  294. reportType = "bgjx"
  295. } else if source == 2 {
  296. reportType = "bzyjhz"
  297. } else if source == 3 {
  298. reportType = "szjyhz"
  299. }
  300. hasPermission, err := services.GetUserhasPermission(user)
  301. if err != nil {
  302. br.Msg = "获取信息失败"
  303. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  304. }
  305. if hasPermission == 1 {
  306. historyRecord := new(models.CygxReportHistoryRecord)
  307. historyRecord.UserId = uid
  308. historyRecord.ArticleId = articleId
  309. historyRecord.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  310. historyRecord.Mobile = user.Mobile
  311. historyRecord.Email = user.Email
  312. historyRecord.CompanyId = user.CompanyId
  313. historyRecord.CompanyName = user.CompanyName
  314. historyRecord.StopTime = stopTime
  315. historyRecord.OutType = outType
  316. historyRecord.ReportType = reportType
  317. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  318. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  319. if err != nil && err.Error() != utils.ErrNoRow() {
  320. br.Msg = "获取信息失败"
  321. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  322. return
  323. }
  324. historyRecord.RealName = user.RealName
  325. if sellerItem != nil {
  326. historyRecord.SellerName = sellerItem.RealName
  327. }
  328. go services.AddCygxReportHistoryRecord(historyRecord)
  329. }
  330. br.Ret = 200
  331. br.Success = true
  332. br.Msg = "操作成功"
  333. }
  334. // @Title 报告精选申请路演
  335. // @Description 报告精选申请路演
  336. // @Param request body cygx.CygxBannerIdReq true "type json string"
  337. // @Success 200 Ret=200 提交成功
  338. // @router /report_selection_log/apply [post]
  339. func (this *ReportSelectionController) ReportSelectionLogApply() {
  340. br := new(models.BaseResponse).Init()
  341. defer func() {
  342. this.Data["json"] = br
  343. this.ServeJSON()
  344. }()
  345. user := this.User
  346. if user == nil {
  347. br.Msg = "请登录"
  348. br.ErrMsg = "请登录,用户信息为空"
  349. br.Ret = 408
  350. return
  351. }
  352. var req models.CygxReportSelectionLogApplyReq
  353. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  354. if err != nil {
  355. br.Msg = "参数解析异常!"
  356. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  357. return
  358. }
  359. articleId := req.ArticleId
  360. subjectName := req.SubjectName
  361. var condition string
  362. var pars []interface{}
  363. condition += ` AND article_id = ? AND subject_name = ? AND user_id = ? `
  364. pars = append(pars, articleId, subjectName, user.UserId)
  365. totalApply, err := models.GetCygxReportSelectionLogApplyCount(condition, pars)
  366. if err != nil {
  367. br.Msg = "申请失败!"
  368. br.ErrMsg = "申请失败,Err:" + err.Error()
  369. return
  370. }
  371. if totalApply > 0 {
  372. br.Msg = "您已提交过此公司的路演申请,请等待销售与您联系!"
  373. return
  374. }
  375. logDetail, err := models.GetCygxReportSelectionLogDetail(articleId, subjectName)
  376. if err != nil {
  377. br.Msg = "申请失败!"
  378. br.ErrMsg = "申请失败,Err:" + err.Error()
  379. return
  380. }
  381. item := new(models.CygxReportSelectionLogApply)
  382. item.UserId = user.UserId
  383. item.CreateTime = time.Now()
  384. item.ModifyTime = time.Now()
  385. item.Mobile = user.Mobile
  386. item.Email = user.Email
  387. item.CompanyId = user.CompanyId
  388. item.CompanyName = user.CompanyName
  389. item.ArticleId = logDetail.ArticleId
  390. item.SubjectName = logDetail.SubjectName
  391. item.IndustrialSubjectId = logDetail.IndustrialSubjectId
  392. item.RegisterPlatform = utils.REGISTER_PLATFORM
  393. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  394. if err != nil && err.Error() != utils.ErrNoRow() {
  395. return
  396. }
  397. item.RealName = user.RealName
  398. if sellerItem != nil {
  399. item.SellerName = sellerItem.RealName
  400. }
  401. _, err = models.AddCygxReportSelectionLogApply(item)
  402. if err != nil {
  403. br.Msg = "申请失败"
  404. br.ErrMsg = "申请失败,Err:" + err.Error()
  405. return
  406. }
  407. go services.SendCygxReportSelectionLogApplyTemplateMsg(user, logDetail.SubjectName)
  408. br.Ret = 200
  409. br.Success = true
  410. br.Msg = "记录成功"
  411. }