report_selection.go 14 KB

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