report_selection.go 12 KB

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