comment.go 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636
  1. package yb
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/cache"
  7. "hongze/hz_crm_api/controllers"
  8. "hongze/hz_crm_api/models"
  9. "hongze/hz_crm_api/models/yb"
  10. "hongze/hz_crm_api/models/yb/request"
  11. ybResp "hongze/hz_crm_api/models/yb/response"
  12. ybService "hongze/hz_crm_api/services/yb"
  13. "hongze/hz_crm_api/utils"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. type CommentController struct {
  19. controllers.BaseAuthController
  20. }
  21. // ReportList
  22. // @Title 获取留言管理下的报告列表
  23. // @Description 获取留言管理下的报告列表
  24. // @Param Keyword query string false "搜索关键字 string"
  25. // @Param SysIsRead query string false "管理员是否已读 0-未读,1-已读"
  26. // @Param ClassifyNameFirst query string false "报告一级分类名称"
  27. // @Param ReportId query int false "报告id"
  28. // @Success 200 {object} ybResp.CommentReportResp
  29. // @router /comment/report/list [get]
  30. func (this *CommentController) ReportList() {
  31. br := new(models.BaseResponse).Init()
  32. defer func() {
  33. this.Data["json"] = br
  34. this.ServeJSON()
  35. }()
  36. sysUser := this.SysUser
  37. if sysUser == nil {
  38. br.Msg = "请登录"
  39. br.ErrMsg = "请登录,SysUser is Empty"
  40. br.Ret = 408
  41. return
  42. }
  43. pageSize, _ := this.GetInt("PageSize")
  44. currentIndex, _ := this.GetInt("CurrentIndex")
  45. var startSize int
  46. if pageSize <= 0 {
  47. pageSize = utils.PageSize20
  48. }
  49. if currentIndex <= 0 {
  50. currentIndex = 1
  51. }
  52. startSize = paging.StartIndex(currentIndex, pageSize)
  53. // 判断查询权限
  54. brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
  55. if brMsg != "" {
  56. br.Msg = brMsg
  57. br.ErrMsg = brErrMsg
  58. return
  59. }
  60. //构建查询条件查询有留言的 reportId
  61. condition := ""
  62. var pars []interface{}
  63. reqUnRead := this.GetString("UnRead", "")
  64. if reqUnRead != "" {
  65. if reqUnRead != "1" {
  66. br.Msg = "请输入正确的未读标识"
  67. return
  68. }
  69. condition += " AND c.sys_is_read = 0"
  70. }
  71. reqKeyword := this.GetString("Keyword")
  72. if reqKeyword != "" {
  73. if strings.Contains("匿名用户", reqKeyword) {
  74. condition += " AND c.is_show_name = 0"
  75. } else if strings.Contains(reqKeyword, "匿名用户") {
  76. reqKeywordNum := reqKeyword[12:]
  77. condition += " AND c.is_show_name = 0 AND (c.user_id+3333) = ?"
  78. pars = append(pars, reqKeywordNum)
  79. } else {
  80. reqKeyword = "%" + reqKeyword + "%"
  81. condition += " AND (u.nick_name LIKE ? OR c.content LIKE ?) AND c.is_show_name = 1"
  82. pars = append(pars, reqKeyword, reqKeyword)
  83. }
  84. }
  85. // 指定报告id
  86. reportId, _ := this.GetInt("ReportId")
  87. if reportId > 0 {
  88. condition += " AND c.report_id = ? "
  89. pars = append(pars, reportId)
  90. }
  91. commentList, err := yb.GetCommentReportIdsByCondition(condition, pars)
  92. if err != nil {
  93. br.Msg = "获取报告ID失败!"
  94. br.ErrMsg = "获取报告ID失败,Err:" + err.Error()
  95. return
  96. }
  97. var reportIdsAllStr string
  98. reportIdsAllMap := make(map[int][]int)
  99. //报告id列表,用作排序
  100. reportIdMap := make(map[int]int)
  101. reportIdList := make([]int, 0)
  102. for _, v := range commentList {
  103. if _, ok := reportIdMap[v.ReportId]; !ok {
  104. reportIdMap[v.ReportId] = v.ReportId
  105. reportIdList = append(reportIdList, v.ReportId)
  106. }
  107. chapters := make([]int, 0)
  108. var ok bool
  109. if chapters, ok = reportIdsAllMap[v.ReportId]; ok {
  110. if v.ReportChapterId > 0 {
  111. chapters = append(chapters, v.ReportChapterId)
  112. reportIdsAllMap[v.ReportId] = chapters
  113. }
  114. } else {
  115. reportIdsAllStr += "," + strconv.Itoa(v.ReportId)
  116. }
  117. if v.ReportChapterId > 0 {
  118. chapters = append(chapters, v.ReportChapterId)
  119. reportIdsAllMap[v.ReportId] = chapters
  120. }
  121. }
  122. //根据reportId查询报告列表
  123. reportCondition := ""
  124. var reportPars []interface{}
  125. if reportIdsAllStr == "" {
  126. //没有查到相关的报告ID
  127. page := paging.GetPaging(currentIndex, pageSize, 0)
  128. resp := ybResp.CommentReportResp{
  129. Paging: page,
  130. }
  131. br.Ret = 200
  132. br.Success = true
  133. br.Msg = "获取成功"
  134. br.Data = resp
  135. return
  136. }
  137. reportIdsAllStr = strings.Trim(reportIdsAllStr, ",")
  138. reportCondition += " and id in (" + reportIdsAllStr + ")"
  139. classifyIdFirst := this.GetString("ClassifyIdFirst", "")
  140. if classifyIdFirst != "" {
  141. reportCondition += " AND classify_id_first = ? "
  142. reportPars = append(reportPars, classifyIdFirst)
  143. }
  144. classifyIdSecond := this.GetString("ClassifyIdSecond", "")
  145. if classifyIdSecond != "" {
  146. reportCondition += " AND classify_id_second = ? "
  147. reportPars = append(reportPars, classifyIdSecond)
  148. }
  149. //reportIdList
  150. orderBy := ``
  151. if len(reportIdList) > 0 {
  152. orderByIdStr := ``
  153. for _, reportId := range reportIdList {
  154. orderByIdStr += fmt.Sprintf("'%d',", reportId)
  155. }
  156. orderByIdStr = strings.TrimSuffix(orderByIdStr, ",")
  157. orderBy = `ORDER BY FIELD(id,` + orderByIdStr + `)`
  158. }
  159. reportList, err := models.GetCommentReportByReportIdOrderBy(reportCondition, reportPars, startSize, pageSize, orderBy)
  160. if err != nil {
  161. br.Msg = "获取报告列表失败!"
  162. br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
  163. return
  164. }
  165. //汇总列表中的reportId,reportChapterId
  166. var reportIdListStr string
  167. var reportChapterIdStr string
  168. for _, v := range reportList {
  169. reportIdListStr += "," + strconv.Itoa(v.Id)
  170. if chapters, ok := reportIdsAllMap[v.Id]; ok {
  171. for _, chapterId := range chapters {
  172. reportChapterIdStr += "," + strconv.Itoa(chapterId)
  173. }
  174. }
  175. }
  176. if reportIdListStr != "" {
  177. reportIdListStr = strings.Trim(reportIdListStr, ",")
  178. }
  179. if reportChapterIdStr != "" {
  180. reportChapterIdStr = strings.Trim(reportChapterIdStr, ",")
  181. }
  182. //查询留言总数和未读数
  183. reportTotalMap := make(map[int]int)
  184. reportChapterTotalMap := make(map[int]int)
  185. reportChapterUnreadTotalMap := make(map[int]int)
  186. reportUnreadTotalMap := make(map[int]int)
  187. var commentStatList []*yb.ReportCommentNum
  188. if reportIdListStr != "" || reportChapterIdStr != "" {
  189. commentStatList, err = yb.StatReportCommentNum(reportIdListStr, reportChapterIdStr, condition, pars)
  190. if err != nil {
  191. br.Msg = "获取报告留言统计数据失败!"
  192. br.ErrMsg = "获取报告留言统计数据失败,Err:" + err.Error()
  193. return
  194. }
  195. for _, stat := range commentStatList {
  196. reportTotalMap[stat.ReportId] += stat.Num
  197. reportChapterTotalMap[stat.ReportChapterId] += stat.Num
  198. if stat.SysIsRead == 0 {
  199. reportUnreadTotalMap[stat.ReportId] += stat.Num
  200. reportChapterUnreadTotalMap[stat.ReportChapterId] += stat.Num
  201. }
  202. }
  203. }
  204. //查询章节列表,
  205. reportChapterMap := make(map[int][]*ybResp.CommentReportChapterItem)
  206. //{
  207. // var reportChapter []*models.ReportChapter
  208. // if reportChapterIdStr != "" {
  209. // reportChapter, err = models.GetChapterSimpleListByChapterIds(reportChapterIdStr)
  210. // } else {
  211. // if reportIdListStr != "" {
  212. // reportChapter, err = models.GetChapterSimpleListByReportIds(reportIdListStr)
  213. // }
  214. // }
  215. //
  216. // if err != nil {
  217. // br.Msg = "获取报告章节列表失败!"
  218. // br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
  219. // return
  220. // }
  221. // for _, chapter := range reportChapter {
  222. // tmp := new(ybResp.CommentReportChapterItem)
  223. // tmp.ReportChapterId = chapter.ReportChapterId
  224. // tmp.Title = chapter.Title
  225. // tmp.PublishTime = chapter.PublishTime.Format(utils.FormatDateTime)
  226. // tmp.CreateTime = chapter.CreateTime
  227. // tmp.TypeName = chapter.TypeName
  228. // if num, ok := reportChapterTotalMap[chapter.ReportChapterId]; ok {
  229. // tmp.CommentNum = num
  230. // }
  231. // if num, ok := reportChapterUnreadTotalMap[chapter.ReportChapterId]; ok {
  232. // tmp.CommentUnreadNum = num
  233. // }
  234. // reportChapterMap[chapter.ReportId] = append(reportChapterMap[chapter.ReportId], tmp)
  235. // }
  236. //}
  237. //fmt.Println(reportIdList)
  238. //fmt.Println(len(reportIdList))
  239. // 处理返回值
  240. var list []*ybResp.CommentReportItem
  241. for _, item := range reportList {
  242. tmp := new(ybResp.CommentReportItem)
  243. tmp.ReportId = item.Id
  244. tmp.CreateTime = item.CreateTime
  245. tmp.PublishTime = item.PublishTime.Format(utils.FormatDateTime)
  246. tmp.State = item.State
  247. if item.State != 2 {
  248. tmp.PublishTime = ""
  249. }
  250. tmp.Title = item.Title
  251. tmp.ClassifyNameFirst = item.ClassifyNameFirst
  252. tmp.ClassifyNameSecond = item.ClassifyNameSecond
  253. tmp.ClassifyIdFirst = item.ClassifyIdFirst
  254. tmp.ClassifyIdSecond = item.ClassifyIdSecond
  255. if chapters, ok := reportChapterMap[item.Id]; ok {
  256. tmp.ReportChapterList = chapters
  257. }
  258. if num, ok := reportTotalMap[item.Id]; ok {
  259. tmp.CommentNum = num
  260. }
  261. if num, ok := reportUnreadTotalMap[item.Id]; ok {
  262. tmp.CommentUnreadNum = num
  263. }
  264. list = append(list, tmp)
  265. //commentReportItemMap[item.Id] = tmp
  266. }
  267. // 获取列表
  268. total, err := models.GetCommentReportTotalByReportId(reportCondition, reportPars)
  269. if err != nil {
  270. br.Msg = "获取报告列表总数失败!"
  271. br.ErrMsg = "获取报告列表总数失败,Err:" + err.Error()
  272. return
  273. }
  274. page := paging.GetPaging(currentIndex, pageSize, int(total))
  275. resp := ybResp.CommentReportResp{
  276. List: list,
  277. Paging: page,
  278. }
  279. br.Ret = 200
  280. br.Success = true
  281. br.Msg = "获取成功"
  282. br.Data = resp
  283. }
  284. func (this *CommentController) ReportListBak() {
  285. br := new(models.BaseResponse).Init()
  286. defer func() {
  287. this.Data["json"] = br
  288. this.ServeJSON()
  289. }()
  290. sysUser := this.SysUser
  291. if sysUser == nil {
  292. br.Msg = "请登录"
  293. br.ErrMsg = "请登录,SysUser is Empty"
  294. br.Ret = 408
  295. return
  296. }
  297. pageSize, _ := this.GetInt("PageSize")
  298. currentIndex, _ := this.GetInt("CurrentIndex")
  299. var startSize int
  300. if pageSize <= 0 {
  301. pageSize = utils.PageSize20
  302. }
  303. if currentIndex <= 0 {
  304. currentIndex = 1
  305. }
  306. startSize = paging.StartIndex(currentIndex, pageSize)
  307. // 判断查询权限
  308. brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
  309. if brMsg != "" {
  310. br.Msg = brMsg
  311. br.ErrMsg = brErrMsg
  312. return
  313. }
  314. //构建查询条件查询有留言的 reportId
  315. condition := ""
  316. var pars []interface{}
  317. reqUnRead := this.GetString("UnRead", "")
  318. if reqUnRead != "" {
  319. if reqUnRead != "1" {
  320. br.Msg = "请输入正确的未读标识"
  321. return
  322. }
  323. condition += " AND c.sys_is_read = 0"
  324. }
  325. reqKeyword := this.GetString("Keyword")
  326. if reqKeyword != "" {
  327. if strings.Contains("匿名用户", reqKeyword) {
  328. condition += " AND c.is_show_name = 0"
  329. } else if strings.Contains(reqKeyword, "匿名用户") {
  330. reqKeywordNum := reqKeyword[12:]
  331. condition += " AND c.is_show_name = 0 AND (c.user_id+3333) = ?"
  332. pars = append(pars, reqKeywordNum)
  333. } else {
  334. reqKeyword = "%" + reqKeyword + "%"
  335. condition += " AND (u.nick_name LIKE ? OR c.content LIKE ?) AND c.is_show_name = 1"
  336. pars = append(pars, reqKeyword, reqKeyword)
  337. }
  338. }
  339. // 指定报告id
  340. reportId, _ := this.GetInt("ReportId")
  341. if reportId > 0 {
  342. condition += " AND c.report_id = ? "
  343. pars = append(pars, reportId)
  344. }
  345. commentList, err := yb.GetCommentReportIdsByCondition(condition, pars)
  346. if err != nil {
  347. br.Msg = "获取报告ID失败!"
  348. br.ErrMsg = "获取报告ID失败,Err:" + err.Error()
  349. return
  350. }
  351. var reportIdsAllStr string
  352. reportIdsAllMap := make(map[int][]int)
  353. for _, v := range commentList {
  354. chapters := make([]int, 0)
  355. var ok bool
  356. if chapters, ok = reportIdsAllMap[v.ReportId]; ok {
  357. if v.ReportChapterId > 0 {
  358. chapters = append(chapters, v.ReportChapterId)
  359. reportIdsAllMap[v.ReportId] = chapters
  360. }
  361. } else {
  362. reportIdsAllStr += "," + strconv.Itoa(v.ReportId)
  363. }
  364. if v.ReportChapterId > 0 {
  365. chapters = append(chapters, v.ReportChapterId)
  366. reportIdsAllMap[v.ReportId] = chapters
  367. }
  368. }
  369. //根据reportId查询报告列表
  370. reportCondition := ""
  371. var reportPars []interface{}
  372. if reportIdsAllStr == "" {
  373. //没有查到相关的报告ID
  374. page := paging.GetPaging(currentIndex, pageSize, 0)
  375. resp := ybResp.CommentReportResp{
  376. Paging: page,
  377. }
  378. br.Ret = 200
  379. br.Success = true
  380. br.Msg = "获取成功"
  381. br.Data = resp
  382. return
  383. }
  384. reportIdsAllStr = strings.Trim(reportIdsAllStr, ",")
  385. reportCondition += " and id in (" + reportIdsAllStr + ")"
  386. classifyIdFirst := this.GetString("ClassifyIdFirst", "")
  387. if classifyIdFirst != "" {
  388. reportCondition += " AND classify_id_first = ?"
  389. reportPars = append(reportPars, classifyIdFirst)
  390. }
  391. classifyIdSecond := this.GetString("ClassifyIdSecond", "")
  392. if classifyIdSecond != "" {
  393. reportCondition += " AND classify_id_second = ?"
  394. reportPars = append(reportPars, classifyIdSecond)
  395. }
  396. reportList, err := models.GetCommentReportByReportId(reportCondition, reportPars, startSize, pageSize)
  397. if err != nil {
  398. br.Msg = "获取报告列表失败!"
  399. br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
  400. return
  401. }
  402. //汇总列表中的reportId,reportChapterId
  403. var reportIdListStr string
  404. var reportChapterIdStr string
  405. for _, v := range reportList {
  406. reportIdListStr += "," + strconv.Itoa(v.Id)
  407. if chapters, ok := reportIdsAllMap[v.Id]; ok {
  408. for _, chapterId := range chapters {
  409. reportChapterIdStr += "," + strconv.Itoa(chapterId)
  410. }
  411. }
  412. }
  413. if reportIdListStr != "" {
  414. reportIdListStr = strings.Trim(reportIdListStr, ",")
  415. }
  416. if reportChapterIdStr != "" {
  417. reportChapterIdStr = strings.Trim(reportChapterIdStr, ",")
  418. }
  419. //查询留言总数和未读数
  420. reportTotalMap := make(map[int]int)
  421. reportChapterTotalMap := make(map[int]int)
  422. reportChapterUnreadTotalMap := make(map[int]int)
  423. reportUnreadTotalMap := make(map[int]int)
  424. var commentStatList []*yb.ReportCommentNum
  425. if reportIdListStr != "" || reportChapterIdStr != "" {
  426. commentStatList, err = yb.StatReportCommentNum(reportIdListStr, reportChapterIdStr, condition, pars)
  427. if err != nil {
  428. br.Msg = "获取报告留言统计数据失败!"
  429. br.ErrMsg = "获取报告留言统计数据失败,Err:" + err.Error()
  430. return
  431. }
  432. for _, stat := range commentStatList {
  433. reportTotalMap[stat.ReportId] += stat.Num
  434. reportChapterTotalMap[stat.ReportChapterId] += stat.Num
  435. if stat.SysIsRead == 0 {
  436. reportUnreadTotalMap[stat.ReportId] += stat.Num
  437. reportChapterUnreadTotalMap[stat.ReportChapterId] += stat.Num
  438. }
  439. }
  440. }
  441. //查询章节列表,
  442. reportChapterMap := make(map[int][]*ybResp.CommentReportChapterItem)
  443. //{
  444. // var reportChapter []*models.ReportChapter
  445. // if reportChapterIdStr != "" {
  446. // reportChapter, err = models.GetChapterSimpleListByChapterIds(reportChapterIdStr)
  447. // } else {
  448. // if reportIdListStr != "" {
  449. // reportChapter, err = models.GetChapterSimpleListByReportIds(reportIdListStr)
  450. // }
  451. // }
  452. //
  453. // if err != nil {
  454. // br.Msg = "获取报告章节列表失败!"
  455. // br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
  456. // return
  457. // }
  458. // for _, chapter := range reportChapter {
  459. // tmp := new(ybResp.CommentReportChapterItem)
  460. // tmp.ReportChapterId = chapter.ReportChapterId
  461. // tmp.Title = chapter.Title
  462. // tmp.PublishTime = chapter.PublishTime.Format(utils.FormatDateTime)
  463. // tmp.CreateTime = chapter.CreateTime
  464. // tmp.TypeName = chapter.TypeName
  465. // if num, ok := reportChapterTotalMap[chapter.ReportChapterId]; ok {
  466. // tmp.CommentNum = num
  467. // }
  468. // if num, ok := reportChapterUnreadTotalMap[chapter.ReportChapterId]; ok {
  469. // tmp.CommentUnreadNum = num
  470. // }
  471. // reportChapterMap[chapter.ReportId] = append(reportChapterMap[chapter.ReportId], tmp)
  472. // }
  473. //}
  474. // 处理返回值
  475. var list []*ybResp.CommentReportItem
  476. for _, item := range reportList {
  477. tmp := new(ybResp.CommentReportItem)
  478. tmp.ReportId = item.Id
  479. tmp.CreateTime = item.CreateTime
  480. tmp.PublishTime = item.PublishTime.Format(utils.FormatDateTime)
  481. tmp.State = item.State
  482. if item.State != 2 {
  483. tmp.PublishTime = ""
  484. }
  485. tmp.Title = item.Title
  486. tmp.ClassifyNameFirst = item.ClassifyNameFirst
  487. tmp.ClassifyNameSecond = item.ClassifyNameSecond
  488. tmp.ClassifyIdFirst = item.ClassifyIdFirst
  489. tmp.ClassifyIdSecond = item.ClassifyIdSecond
  490. if chapters, ok := reportChapterMap[item.Id]; ok {
  491. tmp.ReportChapterList = chapters
  492. }
  493. if num, ok := reportTotalMap[item.Id]; ok {
  494. tmp.CommentNum = num
  495. }
  496. if num, ok := reportUnreadTotalMap[item.Id]; ok {
  497. tmp.CommentUnreadNum = num
  498. }
  499. list = append(list, tmp)
  500. }
  501. // 获取列表
  502. total, err := models.GetCommentReportTotalByReportId(reportCondition, reportPars)
  503. if err != nil {
  504. br.Msg = "获取报告列表总数失败!"
  505. br.ErrMsg = "获取报告列表总数失败,Err:" + err.Error()
  506. return
  507. }
  508. page := paging.GetPaging(currentIndex, pageSize, int(total))
  509. resp := ybResp.CommentReportResp{
  510. List: list,
  511. Paging: page,
  512. }
  513. br.Ret = 200
  514. br.Success = true
  515. br.Msg = "获取成功"
  516. br.Data = resp
  517. }
  518. // CommentList
  519. // @Title 获取留言管理下的报告列表
  520. // @Description 获取留言管理下的报告列表
  521. // @Param ReportId query string true "报告ID"
  522. // @Param ReportChapterId query string true "报告章节ID"
  523. // @Success 200 {object} ybResp.CommentListResp
  524. // @router /comment/list [get]
  525. func (this *CommentController) CommentList() {
  526. br := new(models.BaseResponse).Init()
  527. defer func() {
  528. this.Data["json"] = br
  529. this.ServeJSON()
  530. }()
  531. sysUser := this.SysUser
  532. if sysUser == nil {
  533. br.Msg = "请登录"
  534. br.ErrMsg = "请登录,SysUser is Empty"
  535. br.Ret = 408
  536. return
  537. }
  538. pageSize, _ := this.GetInt("PageSize")
  539. currentIndex, _ := this.GetInt("CurrentIndex")
  540. var startSize int
  541. if pageSize <= 0 {
  542. pageSize = utils.PageSize20
  543. }
  544. if currentIndex <= 0 {
  545. currentIndex = 1
  546. }
  547. startSize = paging.StartIndex(currentIndex, pageSize)
  548. // 判断查询权限
  549. brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
  550. if brMsg != "" {
  551. br.Msg = brMsg
  552. br.ErrMsg = brErrMsg
  553. return
  554. }
  555. //根据搜索条件查询留言列表
  556. var (
  557. err error
  558. hotTopType int
  559. reportId int
  560. reportChapterId int
  561. )
  562. condition := ""
  563. var pars []interface{}
  564. reqUnRead := this.GetString("UnRead", "")
  565. if reqUnRead != "" {
  566. if reqUnRead != "1" {
  567. br.Msg = "请输入正确的未读标识"
  568. return
  569. }
  570. condition += " AND c.sys_is_read = 0"
  571. }
  572. reqKeyword := this.GetString("Keyword")
  573. if reqKeyword != "" {
  574. if strings.Contains("匿名用户", reqKeyword) {
  575. condition += " AND c.is_show_name = 0"
  576. } else if strings.Contains(reqKeyword, "匿名用户") {
  577. reqKeywordNum := reqKeyword[12:]
  578. condition += " AND c.is_show_name = 0 AND (c.user_id+3333) = ?"
  579. pars = append(pars, reqKeywordNum)
  580. } else {
  581. reqKeyword = "%" + reqKeyword + "%"
  582. condition += " AND (u.nick_name LIKE ? OR c.content LIKE ?) AND c.is_show_name = 1"
  583. pars = append(pars, reqKeyword, reqKeyword)
  584. }
  585. }
  586. reqReportId := this.GetString("ReportId", "")
  587. if reqReportId == "" {
  588. br.Msg = "请输入报告ID"
  589. br.ErrMsg = "请输入报告ID"
  590. return
  591. }
  592. reportId, err = strconv.Atoi(reqReportId)
  593. if err != nil {
  594. br.Msg = "请输入正确的报告ID"
  595. br.ErrMsg = "请输入正确的报告ID:" + err.Error()
  596. return
  597. }
  598. condition += " AND c.report_id=?"
  599. pars = append(pars, reportId)
  600. reqReportChapterId := this.GetString("ReportChapterId", "")
  601. if reqReportChapterId != "" {
  602. reportChapterId, err = strconv.Atoi(reqReportChapterId)
  603. if err != nil {
  604. br.Msg = "请输入正确的章节ID"
  605. br.ErrMsg = "请输入正确的章节ID:" + err.Error()
  606. return
  607. }
  608. condition += " AND c.report_chapter_id=?"
  609. pars = append(pars, reportChapterId)
  610. }
  611. //空为全部,1精选,2置顶
  612. reqHotTopType := this.GetString("HotTopType", "")
  613. orderStr := ""
  614. numCondition := condition
  615. if reqHotTopType != "" {
  616. hotTopType, err = strconv.Atoi(reqHotTopType)
  617. if err != nil {
  618. br.Msg = "请输入正确的置顶标识"
  619. br.ErrMsg = "请输入正确的置顶标识:" + err.Error()
  620. return
  621. }
  622. if hotTopType == 2 {
  623. condition += " and c.is_top = 1"
  624. orderStr = " ORDER BY c.top_time DESC , c.comment_id DESC"
  625. } else if hotTopType == 1 {
  626. condition += " and c.is_hot = 1"
  627. orderStr = " ORDER BY c.hot_time DESC , c.comment_id DESC"
  628. } else {
  629. br.Msg = "请输入正确的置顶标识"
  630. return
  631. }
  632. }
  633. commentList, err := yb.GetCommentListByByCondition(condition, pars, orderStr, startSize, pageSize)
  634. if err != nil {
  635. br.Msg = "获取留言列表失败!"
  636. br.ErrMsg = "获取留言列表失败,Err:" + err.Error()
  637. return
  638. }
  639. var commentIds string
  640. var userIds string
  641. for _, v := range commentList {
  642. commentIds += "," + strconv.Itoa(int(v.CommentId))
  643. userIds += "," + strconv.Itoa(int(v.UserId))
  644. }
  645. // 查询所有的回复列表
  646. replyListMap := make(map[uint64][]*ybResp.ReplyItem)
  647. if len(commentIds) > 0 {
  648. commentIds = "(" + strings.Trim(commentIds, ",") + ")"
  649. replyList, tErr := yb.GetReplyListByReplyCommentIds(reportId, reportChapterId, commentIds)
  650. if tErr != nil {
  651. br.Msg = "获取回复列表失败"
  652. br.ErrMsg = "获取回复列表失败,Err:" + tErr.Error()
  653. return
  654. }
  655. for _, v := range replyList {
  656. t := new(ybResp.ReplyItem)
  657. t.CommentId = v.CommentId
  658. t.Content = v.Content
  659. t.AdminId = v.AdminId
  660. t.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  661. t.AdminName = "弘则研究"
  662. t.AdminImgUrl = utils.DEFAULT_HONGZE_SYS_LOGO
  663. t.ReplyCommentId = v.ReplyCommentId
  664. replyListMap[v.ReplyCommentId] = append(replyListMap[v.ReplyCommentId], t)
  665. }
  666. }
  667. // 查询留言相关的用户
  668. var userOthers []*models.WxUser
  669. if len(userIds) > 0 {
  670. userOthers, err = models.GetWxUserListByUserIds(strings.Trim(userIds, ","))
  671. if err != nil {
  672. br.Msg = "查询留言用户出错"
  673. br.ErrMsg = "查询留言用户出错,Err:" + err.Error()
  674. return
  675. }
  676. }
  677. usersMap := make(map[uint64]*models.WxUser)
  678. for _, v := range userOthers {
  679. usersMap[uint64(v.UserId)] = v
  680. }
  681. var list []*ybResp.CommentItemResp
  682. for _, v := range commentList {
  683. tmp := new(ybResp.CommentItemResp)
  684. tmp.CommentId = v.CommentId
  685. tmp.UserId = v.UserId
  686. tmp.NickName = "匿名用户" + strconv.Itoa(int(3333+v.UserId))
  687. tmp.HeadImgUrl = utils.DEFAULT_HONGZE_USER_LOGO
  688. if info, ok := usersMap[v.UserId]; ok && v.IsShowName == 1 {
  689. tmp.NickName = info.NickName
  690. tmp.HeadImgUrl = info.Headimgurl
  691. }
  692. tmp.Content = v.Content
  693. tmp.IsHot = v.IsHot
  694. tmp.IsTop = v.IsTop
  695. tmp.HotTopTime = v.HotTopTime
  696. tmp.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  697. tmp.Enabled = v.Enabled
  698. tmp.SourceAgent = v.SourceAgent
  699. if existList, ok := replyListMap[v.CommentId]; ok {
  700. tmp.ReplyList = existList
  701. }
  702. list = append(list, tmp)
  703. }
  704. // 获取列表分页总数
  705. total, err := yb.GetCommentListTotalByByCondition(condition, pars)
  706. if err != nil {
  707. br.Msg = "获取留言列表总数失败!"
  708. br.ErrMsg = "获取留言列表总数失败,Err:" + err.Error()
  709. return
  710. }
  711. //查询留言总数和精选总数,置顶总数
  712. var statNum ybResp.CommentStatNum
  713. if hotTopType == 0 {
  714. statNum.AllNum = total
  715. } else {
  716. statNum.AllNum, err = yb.GetCommentListTotalByByCondition(numCondition, pars)
  717. if err != nil {
  718. br.Msg = "获取留言列表总数失败!"
  719. br.ErrMsg = "获取留言列表总数失败,Err:" + err.Error()
  720. return
  721. }
  722. }
  723. if hotTopType == 2 {
  724. statNum.TopNum = total
  725. } else {
  726. topCondition := numCondition + " and c.is_top = 1"
  727. statNum.TopNum, err = yb.GetCommentListTotalByByCondition(topCondition, pars)
  728. if err != nil {
  729. br.Msg = "获取置顶留言列表总数失败!"
  730. br.ErrMsg = "获取置顶留言列表总数失败,Err:" + err.Error()
  731. return
  732. }
  733. }
  734. if hotTopType == 1 {
  735. statNum.HotNum = total
  736. } else {
  737. hotCondition := numCondition + " and c.is_hot = 1"
  738. statNum.HotNum, err = yb.GetCommentListTotalByByCondition(hotCondition, pars)
  739. if err != nil {
  740. br.Msg = "获取精选留言列表总数失败!"
  741. br.ErrMsg = "获取精选留言列表总数失败,Err:" + err.Error()
  742. return
  743. }
  744. }
  745. // 设置留言已读
  746. updateComments, err := yb.GetCommentIdsByCondition(condition, pars)
  747. if err != nil {
  748. br.Msg = "获取留言列表失败!"
  749. br.ErrMsg = "获取留言列表失败,Err:" + err.Error()
  750. return
  751. }
  752. updateIds := ""
  753. for _, v := range updateComments {
  754. updateIds += "," + strconv.Itoa(int(v.CommentId))
  755. }
  756. if updateIds != "" {
  757. updateIds = strings.Trim(updateIds, ",")
  758. err = yb.UpdateCommentSysIsReadByCommentIds(sysUser.AdminId, updateIds)
  759. if err != nil {
  760. br.Msg = "设置留言已读失败!"
  761. br.ErrMsg = "设置留言已读失败,Err:" + err.Error()
  762. return
  763. }
  764. }
  765. page := paging.GetPaging(currentIndex, pageSize, int(total))
  766. resp := ybResp.CommentListResp{
  767. List: list,
  768. Paging: page,
  769. StatNum: statNum,
  770. }
  771. br.Ret = 200
  772. br.Success = true
  773. br.Msg = "获取成功"
  774. br.Data = resp
  775. return
  776. }
  777. // AddReply
  778. // @Title 新增回复
  779. // @Description 新增回复
  780. // @Param request body request.AddReplyCommentReq true "type json string"
  781. // @Success Ret=200 操作成功
  782. // @router /comment/reply/add [post]
  783. func (this *CommentController) AddReply() {
  784. br := new(models.BaseResponse).Init()
  785. defer func() {
  786. this.Data["json"] = br
  787. this.ServeJSON()
  788. }()
  789. sysUser := this.SysUser
  790. if sysUser == nil {
  791. br.Msg = "请登录"
  792. br.ErrMsg = "请登录,SysUser Is Empty"
  793. br.Ret = 408
  794. return
  795. }
  796. var req request.AddReplyCommentReq
  797. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  798. if err != nil {
  799. br.Msg = "参数解析异常!"
  800. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  801. return
  802. }
  803. if req.CommentId <= 0 {
  804. br.Msg = "请输入正确的留言ID!"
  805. br.ErrMsg = "请输入正确的留言ID!"
  806. return
  807. }
  808. if req.Content == "" {
  809. br.Msg = "请输入回复的内容!"
  810. br.ErrMsg = "请输入回复的内容!"
  811. return
  812. }
  813. brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
  814. if brMsg != "" {
  815. br.Msg = brMsg
  816. br.ErrMsg = brErrMsg
  817. return
  818. }
  819. //查询评论状态,如果已被用户删除则不允许新增回复
  820. commentInfo, err := yb.GetCommentUserByCommentId(req.CommentId)
  821. if err != nil {
  822. if err.Error() == utils.ErrNoRow() {
  823. br.Msg = "留言不存在"
  824. br.ErrMsg = "留言不存在"
  825. return
  826. }
  827. br.Msg = "查询留言失败!"
  828. br.ErrMsg = "查询留言失败,Err:" + err.Error()
  829. return
  830. }
  831. if commentInfo.Enabled == 0 {
  832. br.Msg = "留言已被删除,不可回复"
  833. br.ErrMsg = "留言已被删除,不可回复"
  834. return
  835. }
  836. if commentInfo.Type != 1 {
  837. br.Msg = "只允许对留言回复"
  838. br.ErrMsg = "只允许对留言回复"
  839. return
  840. }
  841. replyNum, err := yb.GetReplyTotalByCommentId(req.CommentId)
  842. if err != nil {
  843. br.Msg = "查询回复次数失败 !"
  844. br.ErrMsg = "查询回复次数失败,Err:" + err.Error()
  845. return
  846. }
  847. ConfigReplyMax, err := cache.GetYbConfigIntValueByCode("reply_max_num")
  848. if err != nil {
  849. br.Msg = "查询配置信息失败 !"
  850. br.ErrMsg = "查询配置信息失败,Err:" + err.Error()
  851. return
  852. }
  853. if int(replyNum) >= ConfigReplyMax {
  854. br.Msg = "超过回复条数限制"
  855. br.ErrMsg = "超过回复条数限制"
  856. return
  857. }
  858. //新增回复
  859. now := time.Now()
  860. reply := &yb.Comment{
  861. AdminId: uint64(sysUser.AdminId),
  862. Content: req.Content,
  863. ReportId: commentInfo.ReportId,
  864. ReportChapterId: commentInfo.ReportChapterId,
  865. ReplyCommentId: commentInfo.CommentId,
  866. Type: 2,
  867. Enabled: 1,
  868. OldReportId: commentInfo.OldReportId,
  869. OldReportChapterId: commentInfo.OldReportChapterId,
  870. CreateTime: now,
  871. ModifyTime: now,
  872. }
  873. replyId, err := yb.AddComment(reply)
  874. if err != nil {
  875. br.Msg = "新增回复失败!"
  876. br.ErrMsg = "新增回失败,Err:" + err.Error()
  877. return
  878. }
  879. // 新增消息通知
  880. sendMessage := &yb.Message{
  881. UserId: commentInfo.UserId,
  882. Type: 1, //消息类型:1-留言回复通知,2-精选留言通知
  883. Enabled: 1,
  884. CommentId: uint64(replyId),
  885. ContentFirst: "您的留言:" + commentInfo.Content,
  886. ContentSecond: "作者回复:" + req.Content,
  887. ReportId: commentInfo.ReportId,
  888. ReportChapterId: commentInfo.ReportChapterId,
  889. OldReportId: commentInfo.OldReportId,
  890. OldReportChapterId: commentInfo.OldReportChapterId,
  891. CreateTime: time.Now(),
  892. ModifyTime: time.Now(),
  893. }
  894. err = yb.AddMessage(sendMessage)
  895. if err != nil {
  896. br.Msg = "新增消息失败!"
  897. br.ErrMsg = "新增消息失败,Err:" + err.Error()
  898. return
  899. }
  900. //回复列表
  901. var replyList []*ybResp.ReplyItem
  902. replyAll, tErr := yb.GetReplyByReplyCommentId(commentInfo.CommentId)
  903. if tErr != nil {
  904. br.Msg = "获取回复列表失败"
  905. br.ErrMsg = "获取回复列表失败,Err:" + tErr.Error()
  906. return
  907. }
  908. for _, v := range replyAll {
  909. t := new(ybResp.ReplyItem)
  910. t.CommentId = v.CommentId
  911. t.Content = v.Content
  912. t.AdminId = v.AdminId
  913. t.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  914. t.AdminName = "弘则研究"
  915. t.AdminImgUrl = utils.DEFAULT_HONGZE_SYS_LOGO
  916. t.ReplyCommentId = v.ReplyCommentId
  917. replyList = append(replyList, t)
  918. }
  919. //评论信息
  920. tmp := new(ybResp.CommentItemResp)
  921. tmp.CommentId = commentInfo.CommentId
  922. tmp.UserId = commentInfo.UserId
  923. tmp.NickName = "匿名用户" + strconv.Itoa(int(3333+commentInfo.UserId))
  924. tmp.HeadImgUrl = utils.DEFAULT_HONGZE_USER_LOGO
  925. if commentInfo.IsShowName == 1 {
  926. tmp.NickName = commentInfo.NickName
  927. tmp.HeadImgUrl = commentInfo.Headimgurl
  928. }
  929. tmp.Content = commentInfo.Content
  930. tmp.IsHot = commentInfo.IsHot
  931. tmp.IsTop = commentInfo.IsTop
  932. tmp.HotTopTime = commentInfo.HotTopTime
  933. tmp.CreateTime = commentInfo.CreateTime.Format(utils.FormatDateTime)
  934. tmp.Enabled = commentInfo.Enabled
  935. tmp.SourceAgent = commentInfo.SourceAgent
  936. tmp.ReplyList = replyList
  937. data := tmp
  938. br.Ret = 200
  939. br.Success = true
  940. br.Msg = "回复成功"
  941. br.Data = data
  942. return
  943. }
  944. // DeleteComment
  945. // @Title 删除留言
  946. // @Description 删除留言
  947. // @Param request body request.CommentReq true "type json string"
  948. // @Success Ret=200 操作成功
  949. // @router /comment/del [post]
  950. func (this *CommentController) DeleteComment() {
  951. br := new(models.BaseResponse).Init()
  952. defer func() {
  953. this.Data["json"] = br
  954. this.ServeJSON()
  955. }()
  956. sysUser := this.SysUser
  957. if sysUser == nil {
  958. br.Msg = "请登录"
  959. br.ErrMsg = "请登录,SysUser Is Empty"
  960. br.Ret = 408
  961. return
  962. }
  963. var req request.CommentReq
  964. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  965. if err != nil {
  966. br.Msg = "参数解析异常!"
  967. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  968. return
  969. }
  970. if req.CommentId <= 0 {
  971. br.Msg = "请输入正确的留言ID!"
  972. br.ErrMsg = "请输入正确的留言ID!"
  973. return
  974. }
  975. brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
  976. if brMsg != "" {
  977. br.Msg = brMsg
  978. br.ErrMsg = brErrMsg
  979. return
  980. }
  981. //查询评论状态,
  982. commentInfo, err := yb.GetCommentByCommentId(req.CommentId)
  983. if err != nil {
  984. if err.Error() == utils.ErrNoRow() {
  985. br.Msg = "留言不存在或者已删除"
  986. br.ErrMsg = "留言不存在或者已删除"
  987. return
  988. }
  989. br.Msg = "查询留言失败!"
  990. br.ErrMsg = "查询留言失败,Err:" + err.Error()
  991. return
  992. }
  993. if commentInfo.Type != 1 {
  994. br.Msg = "只允许删除留言"
  995. br.ErrMsg = "只允许删除留言"
  996. return
  997. }
  998. err = yb.DeleteComment(req.CommentId)
  999. if err != nil {
  1000. br.Msg = "删除留言操作失败!"
  1001. br.ErrMsg = "删除留言操作失败,Err:" + err.Error()
  1002. return
  1003. }
  1004. br.Ret = 200
  1005. br.Success = true
  1006. br.Msg = "操作成功"
  1007. return
  1008. }
  1009. // DeleteReply
  1010. // @Title 删除回复
  1011. // @Description 删除回复
  1012. // @Param request body request.CommentReq true "type json string"
  1013. // @Success Ret=200 操作成功
  1014. // @router /comment/reply/del [post]
  1015. func (this *CommentController) DeleteReply() {
  1016. br := new(models.BaseResponse).Init()
  1017. defer func() {
  1018. this.Data["json"] = br
  1019. this.ServeJSON()
  1020. }()
  1021. sysUser := this.SysUser
  1022. if sysUser == nil {
  1023. br.Msg = "请登录"
  1024. br.ErrMsg = "请登录,SysUser Is Empty"
  1025. br.Ret = 408
  1026. return
  1027. }
  1028. var req request.CommentReq
  1029. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1030. if err != nil {
  1031. br.Msg = "参数解析异常!"
  1032. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1033. return
  1034. }
  1035. if req.CommentId <= 0 {
  1036. br.Msg = "请输入正确的回复ID!"
  1037. br.ErrMsg = "请输入正确的回复ID!"
  1038. return
  1039. }
  1040. brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
  1041. if brMsg != "" {
  1042. br.Msg = brMsg
  1043. br.ErrMsg = brErrMsg
  1044. return
  1045. }
  1046. //查询评论状态,
  1047. commentInfo, err := yb.GetCommentByCommentId(req.CommentId)
  1048. if err != nil {
  1049. if err.Error() == utils.ErrNoRow() {
  1050. br.Msg = "留言不存在或者已删除"
  1051. br.ErrMsg = "留言不存在或者已删除"
  1052. return
  1053. }
  1054. br.Msg = "查询留言失败!"
  1055. br.ErrMsg = "查询留言失败,Err:" + err.Error()
  1056. return
  1057. }
  1058. if commentInfo.Type != 2 {
  1059. br.Msg = "只允许删除回复"
  1060. br.ErrMsg = "只允许删除回复"
  1061. return
  1062. }
  1063. err = yb.DeleteCommentReply(req.CommentId)
  1064. if err != nil {
  1065. br.Msg = "删除回复操作失败!"
  1066. br.ErrMsg = "删除回复操作失败,Err:" + err.Error()
  1067. return
  1068. }
  1069. br.Ret = 200
  1070. br.Success = true
  1071. br.Msg = "操作成功"
  1072. return
  1073. }
  1074. // SetHot
  1075. // @Title 设置留言精选/取消留言精选
  1076. // @Description 设置留言精选
  1077. // @Param request body request.CommentReq true "type json string"
  1078. // @Success Ret=200 操作成功
  1079. // @router /comment/hot [post]
  1080. func (this *CommentController) SetHot() {
  1081. br := new(models.BaseResponse).Init()
  1082. defer func() {
  1083. this.Data["json"] = br
  1084. this.ServeJSON()
  1085. }()
  1086. sysUser := this.SysUser
  1087. if sysUser == nil {
  1088. br.Msg = "请登录"
  1089. br.ErrMsg = "请登录,SysUser Is Empty"
  1090. br.Ret = 408
  1091. return
  1092. }
  1093. var req request.CommentReq
  1094. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1095. if err != nil {
  1096. br.Msg = "参数解析异常!"
  1097. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1098. return
  1099. }
  1100. if req.CommentId <= 0 {
  1101. br.Msg = "请输入正确的留言ID!"
  1102. br.ErrMsg = "请输入正确的留言ID!"
  1103. return
  1104. }
  1105. brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
  1106. if brMsg != "" {
  1107. br.Msg = brMsg
  1108. br.ErrMsg = brErrMsg
  1109. return
  1110. }
  1111. //查询评论状态,
  1112. commentInfo, err := yb.GetCommentByCommentId(req.CommentId)
  1113. if err != nil {
  1114. if err.Error() == utils.ErrNoRow() {
  1115. br.Msg = "留言不存在"
  1116. br.ErrMsg = "留言不存在"
  1117. return
  1118. }
  1119. br.Msg = "查询留言失败!"
  1120. br.ErrMsg = "查询留言失败,Err:" + err.Error()
  1121. return
  1122. }
  1123. if commentInfo.Enabled == 0 {
  1124. br.Msg = "留言已被删除,不可回复"
  1125. br.ErrMsg = "留言已被删除,不可回复"
  1126. return
  1127. }
  1128. if commentInfo.Type != 1 {
  1129. br.Msg = "只允许对留言操作"
  1130. br.ErrMsg = "只允许对留言操作"
  1131. return
  1132. }
  1133. now := time.Now()
  1134. if commentInfo.IsHot == 0 {
  1135. //精选操作
  1136. var notifyMsgFlag bool
  1137. tmpTime := commentInfo.HotTime.Format(utils.FormatDateTime)
  1138. if tmpTime == "0001-01-01 00:00:00" { //首次精选才会发送通知
  1139. notifyMsgFlag = true
  1140. }
  1141. commentInfo.HotTopTime = now
  1142. commentInfo.ModifyTime = now
  1143. commentInfo.HotTime = now
  1144. commentInfo.IsHot = 1
  1145. err = commentInfo.Update([]string{"is_hot", "hot_time", "hot_top_time", "modify_time"})
  1146. if err != nil {
  1147. br.Msg = "留言精选操作失败!"
  1148. br.ErrMsg = "留言精选操作失败,Err:" + err.Error()
  1149. return
  1150. }
  1151. // 新增消息通知
  1152. if notifyMsgFlag {
  1153. sendMessage := &yb.Message{
  1154. UserId: commentInfo.UserId,
  1155. Type: 2, //消息类型:1-留言回复通知,2-精选留言通知
  1156. Enabled: 1,
  1157. CommentId: commentInfo.CommentId,
  1158. ContentFirst: "您的留言:" + commentInfo.Content,
  1159. ContentSecond: "入选为精选留言",
  1160. ReportId: commentInfo.ReportId,
  1161. ReportChapterId: commentInfo.ReportChapterId,
  1162. OldReportId: commentInfo.OldReportId,
  1163. OldReportChapterId: commentInfo.OldReportChapterId,
  1164. CreateTime: time.Now(),
  1165. ModifyTime: time.Now(),
  1166. }
  1167. err = yb.AddMessage(sendMessage)
  1168. if err != nil {
  1169. br.Msg = "新增消息失败!"
  1170. br.ErrMsg = "新增消息失败,Err:" + err.Error()
  1171. return
  1172. }
  1173. }
  1174. } else {
  1175. //取消精选操作,同时取消置顶
  1176. commentInfo.IsHot = 0
  1177. commentInfo.IsTop = 0
  1178. commentInfo.ModifyTime = now
  1179. err = commentInfo.Update([]string{"is_hot", "modify_time", "is_top"})
  1180. if err != nil {
  1181. br.Msg = "取消精选操作失败!"
  1182. br.ErrMsg = "取消精选操作失败,Err:" + err.Error()
  1183. return
  1184. }
  1185. }
  1186. data := ybResp.CommentHotResp{
  1187. CommentId: int64(commentInfo.CommentId),
  1188. IsHot: commentInfo.IsHot,
  1189. }
  1190. br.Ret = 200
  1191. br.Success = true
  1192. br.Msg = "操作成功"
  1193. br.Data = data
  1194. return
  1195. }
  1196. // SetTop
  1197. // @Title 设置留言置顶
  1198. // @Description 设置留言置顶
  1199. // @Param request body request.CommentReq true "type json string"
  1200. // @Success Ret=200 操作成功
  1201. // @router /comment/top [post]
  1202. func (this *CommentController) SetTop() {
  1203. br := new(models.BaseResponse).Init()
  1204. defer func() {
  1205. this.Data["json"] = br
  1206. this.ServeJSON()
  1207. }()
  1208. sysUser := this.SysUser
  1209. if sysUser == nil {
  1210. br.Msg = "请登录"
  1211. br.ErrMsg = "请登录,SysUser Is Empty"
  1212. br.Ret = 408
  1213. return
  1214. }
  1215. var req request.CommentReq
  1216. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1217. if err != nil {
  1218. br.Msg = "参数解析异常!"
  1219. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1220. return
  1221. }
  1222. if req.CommentId <= 0 {
  1223. br.Msg = "请输入正确的留言ID!"
  1224. br.ErrMsg = "请输入正确的留言ID!"
  1225. return
  1226. }
  1227. brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
  1228. if brMsg != "" {
  1229. br.Msg = brMsg
  1230. br.ErrMsg = brErrMsg
  1231. return
  1232. }
  1233. //查询评论状态
  1234. commentInfo, err := yb.GetCommentByCommentId(req.CommentId)
  1235. if err != nil {
  1236. if err.Error() == utils.ErrNoRow() {
  1237. br.Msg = "留言不存在"
  1238. br.ErrMsg = "留言不存在"
  1239. return
  1240. }
  1241. br.Msg = "查询留言失败!"
  1242. br.ErrMsg = "查询留言失败,Err:" + err.Error()
  1243. return
  1244. }
  1245. if commentInfo.Enabled == 0 {
  1246. br.Msg = "留言已被删除,不可回复"
  1247. br.ErrMsg = "留言已被删除,不可回复"
  1248. return
  1249. }
  1250. if commentInfo.Type != 1 {
  1251. br.Msg = "只允许对留言操作"
  1252. br.ErrMsg = "只允许对留言操作"
  1253. return
  1254. }
  1255. now := time.Now()
  1256. if commentInfo.IsTop == 0 {
  1257. //置顶操作
  1258. var notifyMsgFlag bool
  1259. updateStr := []string{"is_top", "hot_top_time", "top_time", "modify_time"}
  1260. if commentInfo.IsHot == 0 {
  1261. tmpTime := commentInfo.HotTime.Format(utils.FormatDateTime)
  1262. if tmpTime == "0001-01-01 00:00:00" {
  1263. notifyMsgFlag = true
  1264. }
  1265. commentInfo.IsHot = 1
  1266. commentInfo.HotTime = now
  1267. updateStr = append(updateStr, "is_hot")
  1268. updateStr = append(updateStr, "hot_time")
  1269. }
  1270. commentInfo.IsTop = 1
  1271. commentInfo.HotTopTime = now
  1272. commentInfo.TopTime = now
  1273. commentInfo.ModifyTime = now
  1274. err = commentInfo.Update(updateStr)
  1275. if err != nil {
  1276. br.Msg = "留言置顶操作失败!"
  1277. br.ErrMsg = "留言置顶操作失败,Err:" + err.Error()
  1278. return
  1279. }
  1280. //发送精选通知
  1281. if notifyMsgFlag {
  1282. sendMessage := &yb.Message{
  1283. UserId: commentInfo.UserId,
  1284. Type: 2, //消息类型:1-留言回复通知,2-精选留言通知
  1285. Enabled: 1,
  1286. CommentId: commentInfo.CommentId,
  1287. ContentFirst: "您的留言:" + commentInfo.Content,
  1288. ContentSecond: "入选为精选留言",
  1289. ReportId: commentInfo.ReportId,
  1290. ReportChapterId: commentInfo.ReportChapterId,
  1291. CreateTime: time.Now(),
  1292. ModifyTime: time.Now(),
  1293. }
  1294. err = yb.AddMessage(sendMessage)
  1295. if err != nil {
  1296. br.Msg = "新增消息失败!"
  1297. br.ErrMsg = "新增消息失败,Err:" + err.Error()
  1298. return
  1299. }
  1300. }
  1301. } else {
  1302. //取消置顶操作
  1303. commentInfo.IsTop = 0
  1304. commentInfo.ModifyTime = now
  1305. err = commentInfo.Update([]string{"is_top", "modify_time"})
  1306. if err != nil {
  1307. br.Msg = "取消置顶操作失败!"
  1308. br.ErrMsg = "取消置顶操作失败,Err:" + err.Error()
  1309. return
  1310. }
  1311. }
  1312. data := ybResp.CommentTopResp{
  1313. CommentId: int64(commentInfo.CommentId),
  1314. IsTop: commentInfo.IsTop,
  1315. }
  1316. br.Ret = 200
  1317. br.Success = true
  1318. br.Msg = "操作成功"
  1319. br.Data = data
  1320. return
  1321. }
  1322. // AllCommentList
  1323. // @Title 获取所有未处理的留言列表
  1324. // @Description 获取所有未处理的留言列表
  1325. // @Success 200 {object} ybResp.CommentListResp
  1326. // @router /comment/all_list [get]
  1327. func (this *CommentController) AllCommentList() {
  1328. br := new(models.BaseResponse).Init()
  1329. defer func() {
  1330. this.Data["json"] = br
  1331. this.ServeJSON()
  1332. }()
  1333. sysUser := this.SysUser
  1334. if sysUser == nil {
  1335. br.Msg = "请登录"
  1336. br.ErrMsg = "请登录,SysUser is Empty"
  1337. br.Ret = 408
  1338. return
  1339. }
  1340. currentIndex := 1
  1341. pageSize := 10000
  1342. var startSize int
  1343. startSize = paging.StartIndex(currentIndex, pageSize)
  1344. // 判断查询权限
  1345. brMsg, _ := ybService.CheckCommentPermission(sysUser.AdminId)
  1346. if brMsg != "" {
  1347. br.Ret = 200
  1348. br.Success = true
  1349. br.Data = ybResp.AllCommentResp{
  1350. List: make([]ybResp.CommentItemResp, 0),
  1351. IsShow: false,
  1352. }
  1353. return
  1354. }
  1355. condition := ""
  1356. var pars []interface{}
  1357. condition += " AND c.sys_is_read = ? AND type = 1 "
  1358. pars = append(pars, 0)
  1359. orderStr := " ORDER BY c.create_time DESC , c.comment_id DESC"
  1360. commentList, err := yb.GetCommentListByByCondition(condition, pars, orderStr, startSize, pageSize)
  1361. if err != nil {
  1362. br.Msg = "获取留言列表失败!"
  1363. br.ErrMsg = "获取留言列表失败,Err:" + err.Error()
  1364. return
  1365. }
  1366. var userIds string
  1367. for _, v := range commentList {
  1368. userIds += "," + strconv.Itoa(int(v.UserId))
  1369. }
  1370. // 查询留言相关的用户
  1371. var userOthers []*models.WxUser
  1372. if len(userIds) > 0 {
  1373. userOthers, err = models.GetWxUserListByUserIds(strings.Trim(userIds, ","))
  1374. if err != nil {
  1375. br.Msg = "查询留言用户出错"
  1376. br.ErrMsg = "查询留言用户出错,Err:" + err.Error()
  1377. return
  1378. }
  1379. }
  1380. usersMap := make(map[uint64]*models.WxUser)
  1381. for _, v := range userOthers {
  1382. usersMap[uint64(v.UserId)] = v
  1383. }
  1384. var list []ybResp.CommentItemResp
  1385. for _, v := range commentList {
  1386. tmp := ybResp.CommentItemResp{
  1387. CommentId: v.CommentId,
  1388. ReportId: v.ReportId,
  1389. UserId: v.UserId,
  1390. Content: v.Content,
  1391. IsTop: v.IsTop,
  1392. IsHot: v.IsHot,
  1393. HotTopTime: v.HotTopTime,
  1394. SourceAgent: v.SourceAgent,
  1395. NickName: "匿名用户" + strconv.Itoa(int(3333+v.UserId)),
  1396. HeadImgUrl: utils.DEFAULT_HONGZE_USER_LOGO,
  1397. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1398. Enabled: v.Enabled,
  1399. ReplyList: make([]*ybResp.ReplyItem, 0),
  1400. }
  1401. if info, ok := usersMap[v.UserId]; ok && v.IsShowName == 1 {
  1402. tmp.NickName = info.NickName
  1403. tmp.HeadImgUrl = info.Headimgurl
  1404. }
  1405. list = append(list, tmp)
  1406. }
  1407. br.Ret = 200
  1408. br.Success = true
  1409. br.Msg = "获取成功"
  1410. br.Data = ybResp.AllCommentResp{
  1411. List: list,
  1412. IsShow: true,
  1413. }
  1414. return
  1415. }
  1416. // ProductCommentList
  1417. // @Title 获取评论合集列表
  1418. // @Description 获取评论合集列表
  1419. // @Param CommunityId query string true "评论ID"
  1420. // @Param ProductType query string false "板块类型"
  1421. // @Param KeyWord query string false "留言关键词"
  1422. // @Param PageSize query string false "页码"
  1423. // @param CurrentIndex query string false "每页展示的记录数"
  1424. // @Success 200 {object} ybResp.LikeListResp
  1425. // @router /product/comment/list [get]
  1426. func (this *CommentController) ProductCommentList() {
  1427. br := new(models.BaseResponse).Init()
  1428. defer func() {
  1429. this.Data["json"] = br
  1430. this.ServeJSON()
  1431. }()
  1432. sysUser := this.SysUser
  1433. if sysUser == nil {
  1434. br.Msg = "请登录"
  1435. br.ErrMsg = "请登录,SysUser is Empty"
  1436. br.Ret = 408
  1437. return
  1438. }
  1439. pageSize, _ := this.GetInt("PageSize")
  1440. currentIndex, _ := this.GetInt("CurrentIndex")
  1441. var startSize int
  1442. if pageSize <= 0 {
  1443. pageSize = utils.PageSize20
  1444. }
  1445. if currentIndex <= 0 {
  1446. currentIndex = 1
  1447. }
  1448. startSize = paging.StartIndex(currentIndex, pageSize)
  1449. productType := this.GetString("ProductType", "")
  1450. keyWord := this.GetString("KeyWord", "")
  1451. createDate := this.GetString("CreateDate", "")
  1452. list, total, err, errMsg := ybService.GetProductComments(sysUser.AdminId, productType, keyWord, createDate, startSize, pageSize)
  1453. if err != nil {
  1454. br.Msg = errMsg
  1455. br.ErrMsg = err.Error()
  1456. return
  1457. }
  1458. page := paging.GetPaging(currentIndex, pageSize, int(total))
  1459. resp := ybResp.ProductCommentResp{
  1460. List: list,
  1461. Paging: page,
  1462. }
  1463. br.Ret = 200
  1464. br.Success = true
  1465. br.Msg = "获取成功"
  1466. br.Data = resp
  1467. return
  1468. }
  1469. // OtherProductList
  1470. // @Title 获取其他分产品的筛选列表
  1471. // @Description 获取其他分产品的筛选列表
  1472. // @Success 200 {object} ybResp.OtherProductTypeListResp
  1473. // @router /comment/product [get]
  1474. func (this *CommentController) OtherProductList() {
  1475. br := new(models.BaseResponse).Init()
  1476. defer func() {
  1477. this.Data["json"] = br
  1478. this.ServeJSON()
  1479. }()
  1480. sysUser := this.SysUser
  1481. if sysUser == nil {
  1482. br.Msg = "请登录"
  1483. br.ErrMsg = "请登录,SysUser Is Empty"
  1484. br.Ret = 408
  1485. return
  1486. }
  1487. resp := make([]ybResp.OtherProductTypeListResp, 0)
  1488. reportItem := ybResp.OtherProductTypeListResp{
  1489. ProductType: 1,
  1490. ProductName: "研报",
  1491. }
  1492. questionItem := ybResp.OtherProductTypeListResp{
  1493. ProductType: 2,
  1494. ProductName: "问答社区",
  1495. }
  1496. videoItem := ybResp.OtherProductTypeListResp{
  1497. ProductType: 3,
  1498. ProductName: "视频社区",
  1499. }
  1500. roadVideoItem := ybResp.OtherProductTypeListResp{
  1501. ProductType: 4,
  1502. ProductName: "线上路演",
  1503. }
  1504. resp = append(resp, reportItem, questionItem, videoItem, roadVideoItem)
  1505. br.Ret = 200
  1506. br.Success = true
  1507. br.Msg = "获取成功"
  1508. br.Data = resp
  1509. }
  1510. // DeleteProductComment
  1511. // @Title 删除板块留言
  1512. // @Description 删除留言
  1513. // @Param request body request.CommentProductDelReq true "type json string"
  1514. // @Success Ret=200 操作成功
  1515. // @router /product/comment/del [post]
  1516. func (this *CommentController) DeleteProductComment() {
  1517. br := new(models.BaseResponse).Init()
  1518. defer func() {
  1519. this.Data["json"] = br
  1520. this.ServeJSON()
  1521. }()
  1522. sysUser := this.SysUser
  1523. if sysUser == nil {
  1524. br.Msg = "请登录"
  1525. br.ErrMsg = "请登录,SysUser Is Empty"
  1526. br.Ret = 408
  1527. return
  1528. }
  1529. var req request.CommentProductDelReq
  1530. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1531. if err != nil {
  1532. br.Msg = "参数解析异常!"
  1533. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1534. return
  1535. }
  1536. if req.CommentId <= 0 {
  1537. br.Msg = "请输入正确的留言ID!"
  1538. br.ErrMsg = "请输入正确的留言ID!"
  1539. return
  1540. }
  1541. err, errMsg := ybService.DelProductComments(req)
  1542. if err != nil {
  1543. br.Msg = errMsg
  1544. br.ErrMsg = err.Error()
  1545. return
  1546. }
  1547. br.Ret = 200
  1548. br.Success = true
  1549. br.Msg = "删除成功"
  1550. return
  1551. }