1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636 |
- package yb
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hz_crm_api/cache"
- "hongze/hz_crm_api/controllers"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/yb"
- "hongze/hz_crm_api/models/yb/request"
- ybResp "hongze/hz_crm_api/models/yb/response"
- ybService "hongze/hz_crm_api/services/yb"
- "hongze/hz_crm_api/utils"
- "strconv"
- "strings"
- "time"
- )
- type CommentController struct {
- controllers.BaseAuthController
- }
- // ReportList
- // @Title 获取留言管理下的报告列表
- // @Description 获取留言管理下的报告列表
- // @Param Keyword query string false "搜索关键字 string"
- // @Param SysIsRead query string false "管理员是否已读 0-未读,1-已读"
- // @Param ClassifyNameFirst query string false "报告一级分类名称"
- // @Param ReportId query int false "报告id"
- // @Success 200 {object} ybResp.CommentReportResp
- // @router /comment/report/list [get]
- func (this *CommentController) ReportList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- // 判断查询权限
- brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
- if brMsg != "" {
- br.Msg = brMsg
- br.ErrMsg = brErrMsg
- return
- }
- //构建查询条件查询有留言的 reportId
- condition := ""
- var pars []interface{}
- reqUnRead := this.GetString("UnRead", "")
- if reqUnRead != "" {
- if reqUnRead != "1" {
- br.Msg = "请输入正确的未读标识"
- return
- }
- condition += " AND c.sys_is_read = 0"
- }
- reqKeyword := this.GetString("Keyword")
- if reqKeyword != "" {
- if strings.Contains("匿名用户", reqKeyword) {
- condition += " AND c.is_show_name = 0"
- } else if strings.Contains(reqKeyword, "匿名用户") {
- reqKeywordNum := reqKeyword[12:]
- condition += " AND c.is_show_name = 0 AND (c.user_id+3333) = ?"
- pars = append(pars, reqKeywordNum)
- } else {
- reqKeyword = "%" + reqKeyword + "%"
- condition += " AND (u.nick_name LIKE ? OR c.content LIKE ?) AND c.is_show_name = 1"
- pars = append(pars, reqKeyword, reqKeyword)
- }
- }
- // 指定报告id
- reportId, _ := this.GetInt("ReportId")
- if reportId > 0 {
- condition += " AND c.report_id = ? "
- pars = append(pars, reportId)
- }
- commentList, err := yb.GetCommentReportIdsByCondition(condition, pars)
- if err != nil {
- br.Msg = "获取报告ID失败!"
- br.ErrMsg = "获取报告ID失败,Err:" + err.Error()
- return
- }
- var reportIdsAllStr string
- reportIdsAllMap := make(map[int][]int)
- //报告id列表,用作排序
- reportIdMap := make(map[int]int)
- reportIdList := make([]int, 0)
- for _, v := range commentList {
- if _, ok := reportIdMap[v.ReportId]; !ok {
- reportIdMap[v.ReportId] = v.ReportId
- reportIdList = append(reportIdList, v.ReportId)
- }
- chapters := make([]int, 0)
- var ok bool
- if chapters, ok = reportIdsAllMap[v.ReportId]; ok {
- if v.ReportChapterId > 0 {
- chapters = append(chapters, v.ReportChapterId)
- reportIdsAllMap[v.ReportId] = chapters
- }
- } else {
- reportIdsAllStr += "," + strconv.Itoa(v.ReportId)
- }
- if v.ReportChapterId > 0 {
- chapters = append(chapters, v.ReportChapterId)
- reportIdsAllMap[v.ReportId] = chapters
- }
- }
- //根据reportId查询报告列表
- reportCondition := ""
- var reportPars []interface{}
- if reportIdsAllStr == "" {
- //没有查到相关的报告ID
- page := paging.GetPaging(currentIndex, pageSize, 0)
- resp := ybResp.CommentReportResp{
- Paging: page,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- reportIdsAllStr = strings.Trim(reportIdsAllStr, ",")
- reportCondition += " and id in (" + reportIdsAllStr + ")"
- classifyIdFirst := this.GetString("ClassifyIdFirst", "")
- if classifyIdFirst != "" {
- reportCondition += " AND classify_id_first = ? "
- reportPars = append(reportPars, classifyIdFirst)
- }
- classifyIdSecond := this.GetString("ClassifyIdSecond", "")
- if classifyIdSecond != "" {
- reportCondition += " AND classify_id_second = ? "
- reportPars = append(reportPars, classifyIdSecond)
- }
- //reportIdList
- orderBy := ``
- if len(reportIdList) > 0 {
- orderByIdStr := ``
- for _, reportId := range reportIdList {
- orderByIdStr += fmt.Sprintf("'%d',", reportId)
- }
- orderByIdStr = strings.TrimSuffix(orderByIdStr, ",")
- orderBy = `ORDER BY FIELD(id,` + orderByIdStr + `)`
- }
- reportList, err := models.GetCommentReportByReportIdOrderBy(reportCondition, reportPars, startSize, pageSize, orderBy)
- if err != nil {
- br.Msg = "获取报告列表失败!"
- br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
- return
- }
- //汇总列表中的reportId,reportChapterId
- var reportIdListStr string
- var reportChapterIdStr string
- for _, v := range reportList {
- reportIdListStr += "," + strconv.Itoa(v.Id)
- if chapters, ok := reportIdsAllMap[v.Id]; ok {
- for _, chapterId := range chapters {
- reportChapterIdStr += "," + strconv.Itoa(chapterId)
- }
- }
- }
- if reportIdListStr != "" {
- reportIdListStr = strings.Trim(reportIdListStr, ",")
- }
- if reportChapterIdStr != "" {
- reportChapterIdStr = strings.Trim(reportChapterIdStr, ",")
- }
- //查询留言总数和未读数
- reportTotalMap := make(map[int]int)
- reportChapterTotalMap := make(map[int]int)
- reportChapterUnreadTotalMap := make(map[int]int)
- reportUnreadTotalMap := make(map[int]int)
- var commentStatList []*yb.ReportCommentNum
- if reportIdListStr != "" || reportChapterIdStr != "" {
- commentStatList, err = yb.StatReportCommentNum(reportIdListStr, reportChapterIdStr, condition, pars)
- if err != nil {
- br.Msg = "获取报告留言统计数据失败!"
- br.ErrMsg = "获取报告留言统计数据失败,Err:" + err.Error()
- return
- }
- for _, stat := range commentStatList {
- reportTotalMap[stat.ReportId] += stat.Num
- reportChapterTotalMap[stat.ReportChapterId] += stat.Num
- if stat.SysIsRead == 0 {
- reportUnreadTotalMap[stat.ReportId] += stat.Num
- reportChapterUnreadTotalMap[stat.ReportChapterId] += stat.Num
- }
- }
- }
- //查询章节列表,
- reportChapterMap := make(map[int][]*ybResp.CommentReportChapterItem)
- //{
- // var reportChapter []*models.ReportChapter
- // if reportChapterIdStr != "" {
- // reportChapter, err = models.GetChapterSimpleListByChapterIds(reportChapterIdStr)
- // } else {
- // if reportIdListStr != "" {
- // reportChapter, err = models.GetChapterSimpleListByReportIds(reportIdListStr)
- // }
- // }
- //
- // if err != nil {
- // br.Msg = "获取报告章节列表失败!"
- // br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
- // return
- // }
- // for _, chapter := range reportChapter {
- // tmp := new(ybResp.CommentReportChapterItem)
- // tmp.ReportChapterId = chapter.ReportChapterId
- // tmp.Title = chapter.Title
- // tmp.PublishTime = chapter.PublishTime.Format(utils.FormatDateTime)
- // tmp.CreateTime = chapter.CreateTime
- // tmp.TypeName = chapter.TypeName
- // if num, ok := reportChapterTotalMap[chapter.ReportChapterId]; ok {
- // tmp.CommentNum = num
- // }
- // if num, ok := reportChapterUnreadTotalMap[chapter.ReportChapterId]; ok {
- // tmp.CommentUnreadNum = num
- // }
- // reportChapterMap[chapter.ReportId] = append(reportChapterMap[chapter.ReportId], tmp)
- // }
- //}
- //fmt.Println(reportIdList)
- //fmt.Println(len(reportIdList))
- // 处理返回值
- var list []*ybResp.CommentReportItem
- for _, item := range reportList {
- tmp := new(ybResp.CommentReportItem)
- tmp.ReportId = item.Id
- tmp.CreateTime = item.CreateTime
- tmp.PublishTime = item.PublishTime.Format(utils.FormatDateTime)
- tmp.State = item.State
- if item.State != 2 {
- tmp.PublishTime = ""
- }
- tmp.Title = item.Title
- tmp.ClassifyNameFirst = item.ClassifyNameFirst
- tmp.ClassifyNameSecond = item.ClassifyNameSecond
- tmp.ClassifyIdFirst = item.ClassifyIdFirst
- tmp.ClassifyIdSecond = item.ClassifyIdSecond
- if chapters, ok := reportChapterMap[item.Id]; ok {
- tmp.ReportChapterList = chapters
- }
- if num, ok := reportTotalMap[item.Id]; ok {
- tmp.CommentNum = num
- }
- if num, ok := reportUnreadTotalMap[item.Id]; ok {
- tmp.CommentUnreadNum = num
- }
- list = append(list, tmp)
- //commentReportItemMap[item.Id] = tmp
- }
- // 获取列表
- total, err := models.GetCommentReportTotalByReportId(reportCondition, reportPars)
- if err != nil {
- br.Msg = "获取报告列表总数失败!"
- br.ErrMsg = "获取报告列表总数失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp := ybResp.CommentReportResp{
- List: list,
- Paging: page,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- func (this *CommentController) ReportListBak() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- // 判断查询权限
- brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
- if brMsg != "" {
- br.Msg = brMsg
- br.ErrMsg = brErrMsg
- return
- }
- //构建查询条件查询有留言的 reportId
- condition := ""
- var pars []interface{}
- reqUnRead := this.GetString("UnRead", "")
- if reqUnRead != "" {
- if reqUnRead != "1" {
- br.Msg = "请输入正确的未读标识"
- return
- }
- condition += " AND c.sys_is_read = 0"
- }
- reqKeyword := this.GetString("Keyword")
- if reqKeyword != "" {
- if strings.Contains("匿名用户", reqKeyword) {
- condition += " AND c.is_show_name = 0"
- } else if strings.Contains(reqKeyword, "匿名用户") {
- reqKeywordNum := reqKeyword[12:]
- condition += " AND c.is_show_name = 0 AND (c.user_id+3333) = ?"
- pars = append(pars, reqKeywordNum)
- } else {
- reqKeyword = "%" + reqKeyword + "%"
- condition += " AND (u.nick_name LIKE ? OR c.content LIKE ?) AND c.is_show_name = 1"
- pars = append(pars, reqKeyword, reqKeyword)
- }
- }
- // 指定报告id
- reportId, _ := this.GetInt("ReportId")
- if reportId > 0 {
- condition += " AND c.report_id = ? "
- pars = append(pars, reportId)
- }
- commentList, err := yb.GetCommentReportIdsByCondition(condition, pars)
- if err != nil {
- br.Msg = "获取报告ID失败!"
- br.ErrMsg = "获取报告ID失败,Err:" + err.Error()
- return
- }
- var reportIdsAllStr string
- reportIdsAllMap := make(map[int][]int)
- for _, v := range commentList {
- chapters := make([]int, 0)
- var ok bool
- if chapters, ok = reportIdsAllMap[v.ReportId]; ok {
- if v.ReportChapterId > 0 {
- chapters = append(chapters, v.ReportChapterId)
- reportIdsAllMap[v.ReportId] = chapters
- }
- } else {
- reportIdsAllStr += "," + strconv.Itoa(v.ReportId)
- }
- if v.ReportChapterId > 0 {
- chapters = append(chapters, v.ReportChapterId)
- reportIdsAllMap[v.ReportId] = chapters
- }
- }
- //根据reportId查询报告列表
- reportCondition := ""
- var reportPars []interface{}
- if reportIdsAllStr == "" {
- //没有查到相关的报告ID
- page := paging.GetPaging(currentIndex, pageSize, 0)
- resp := ybResp.CommentReportResp{
- Paging: page,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- reportIdsAllStr = strings.Trim(reportIdsAllStr, ",")
- reportCondition += " and id in (" + reportIdsAllStr + ")"
- classifyIdFirst := this.GetString("ClassifyIdFirst", "")
- if classifyIdFirst != "" {
- reportCondition += " AND classify_id_first = ?"
- reportPars = append(reportPars, classifyIdFirst)
- }
- classifyIdSecond := this.GetString("ClassifyIdSecond", "")
- if classifyIdSecond != "" {
- reportCondition += " AND classify_id_second = ?"
- reportPars = append(reportPars, classifyIdSecond)
- }
- reportList, err := models.GetCommentReportByReportId(reportCondition, reportPars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取报告列表失败!"
- br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
- return
- }
- //汇总列表中的reportId,reportChapterId
- var reportIdListStr string
- var reportChapterIdStr string
- for _, v := range reportList {
- reportIdListStr += "," + strconv.Itoa(v.Id)
- if chapters, ok := reportIdsAllMap[v.Id]; ok {
- for _, chapterId := range chapters {
- reportChapterIdStr += "," + strconv.Itoa(chapterId)
- }
- }
- }
- if reportIdListStr != "" {
- reportIdListStr = strings.Trim(reportIdListStr, ",")
- }
- if reportChapterIdStr != "" {
- reportChapterIdStr = strings.Trim(reportChapterIdStr, ",")
- }
- //查询留言总数和未读数
- reportTotalMap := make(map[int]int)
- reportChapterTotalMap := make(map[int]int)
- reportChapterUnreadTotalMap := make(map[int]int)
- reportUnreadTotalMap := make(map[int]int)
- var commentStatList []*yb.ReportCommentNum
- if reportIdListStr != "" || reportChapterIdStr != "" {
- commentStatList, err = yb.StatReportCommentNum(reportIdListStr, reportChapterIdStr, condition, pars)
- if err != nil {
- br.Msg = "获取报告留言统计数据失败!"
- br.ErrMsg = "获取报告留言统计数据失败,Err:" + err.Error()
- return
- }
- for _, stat := range commentStatList {
- reportTotalMap[stat.ReportId] += stat.Num
- reportChapterTotalMap[stat.ReportChapterId] += stat.Num
- if stat.SysIsRead == 0 {
- reportUnreadTotalMap[stat.ReportId] += stat.Num
- reportChapterUnreadTotalMap[stat.ReportChapterId] += stat.Num
- }
- }
- }
- //查询章节列表,
- reportChapterMap := make(map[int][]*ybResp.CommentReportChapterItem)
- //{
- // var reportChapter []*models.ReportChapter
- // if reportChapterIdStr != "" {
- // reportChapter, err = models.GetChapterSimpleListByChapterIds(reportChapterIdStr)
- // } else {
- // if reportIdListStr != "" {
- // reportChapter, err = models.GetChapterSimpleListByReportIds(reportIdListStr)
- // }
- // }
- //
- // if err != nil {
- // br.Msg = "获取报告章节列表失败!"
- // br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
- // return
- // }
- // for _, chapter := range reportChapter {
- // tmp := new(ybResp.CommentReportChapterItem)
- // tmp.ReportChapterId = chapter.ReportChapterId
- // tmp.Title = chapter.Title
- // tmp.PublishTime = chapter.PublishTime.Format(utils.FormatDateTime)
- // tmp.CreateTime = chapter.CreateTime
- // tmp.TypeName = chapter.TypeName
- // if num, ok := reportChapterTotalMap[chapter.ReportChapterId]; ok {
- // tmp.CommentNum = num
- // }
- // if num, ok := reportChapterUnreadTotalMap[chapter.ReportChapterId]; ok {
- // tmp.CommentUnreadNum = num
- // }
- // reportChapterMap[chapter.ReportId] = append(reportChapterMap[chapter.ReportId], tmp)
- // }
- //}
- // 处理返回值
- var list []*ybResp.CommentReportItem
- for _, item := range reportList {
- tmp := new(ybResp.CommentReportItem)
- tmp.ReportId = item.Id
- tmp.CreateTime = item.CreateTime
- tmp.PublishTime = item.PublishTime.Format(utils.FormatDateTime)
- tmp.State = item.State
- if item.State != 2 {
- tmp.PublishTime = ""
- }
- tmp.Title = item.Title
- tmp.ClassifyNameFirst = item.ClassifyNameFirst
- tmp.ClassifyNameSecond = item.ClassifyNameSecond
- tmp.ClassifyIdFirst = item.ClassifyIdFirst
- tmp.ClassifyIdSecond = item.ClassifyIdSecond
- if chapters, ok := reportChapterMap[item.Id]; ok {
- tmp.ReportChapterList = chapters
- }
- if num, ok := reportTotalMap[item.Id]; ok {
- tmp.CommentNum = num
- }
- if num, ok := reportUnreadTotalMap[item.Id]; ok {
- tmp.CommentUnreadNum = num
- }
- list = append(list, tmp)
- }
- // 获取列表
- total, err := models.GetCommentReportTotalByReportId(reportCondition, reportPars)
- if err != nil {
- br.Msg = "获取报告列表总数失败!"
- br.ErrMsg = "获取报告列表总数失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp := ybResp.CommentReportResp{
- List: list,
- Paging: page,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // CommentList
- // @Title 获取留言管理下的报告列表
- // @Description 获取留言管理下的报告列表
- // @Param ReportId query string true "报告ID"
- // @Param ReportChapterId query string true "报告章节ID"
- // @Success 200 {object} ybResp.CommentListResp
- // @router /comment/list [get]
- func (this *CommentController) CommentList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- // 判断查询权限
- brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
- if brMsg != "" {
- br.Msg = brMsg
- br.ErrMsg = brErrMsg
- return
- }
- //根据搜索条件查询留言列表
- var (
- err error
- hotTopType int
- reportId int
- reportChapterId int
- )
- condition := ""
- var pars []interface{}
- reqUnRead := this.GetString("UnRead", "")
- if reqUnRead != "" {
- if reqUnRead != "1" {
- br.Msg = "请输入正确的未读标识"
- return
- }
- condition += " AND c.sys_is_read = 0"
- }
- reqKeyword := this.GetString("Keyword")
- if reqKeyword != "" {
- if strings.Contains("匿名用户", reqKeyword) {
- condition += " AND c.is_show_name = 0"
- } else if strings.Contains(reqKeyword, "匿名用户") {
- reqKeywordNum := reqKeyword[12:]
- condition += " AND c.is_show_name = 0 AND (c.user_id+3333) = ?"
- pars = append(pars, reqKeywordNum)
- } else {
- reqKeyword = "%" + reqKeyword + "%"
- condition += " AND (u.nick_name LIKE ? OR c.content LIKE ?) AND c.is_show_name = 1"
- pars = append(pars, reqKeyword, reqKeyword)
- }
- }
- reqReportId := this.GetString("ReportId", "")
- if reqReportId == "" {
- br.Msg = "请输入报告ID"
- br.ErrMsg = "请输入报告ID"
- return
- }
- reportId, err = strconv.Atoi(reqReportId)
- if err != nil {
- br.Msg = "请输入正确的报告ID"
- br.ErrMsg = "请输入正确的报告ID:" + err.Error()
- return
- }
- condition += " AND c.report_id=?"
- pars = append(pars, reportId)
- reqReportChapterId := this.GetString("ReportChapterId", "")
- if reqReportChapterId != "" {
- reportChapterId, err = strconv.Atoi(reqReportChapterId)
- if err != nil {
- br.Msg = "请输入正确的章节ID"
- br.ErrMsg = "请输入正确的章节ID:" + err.Error()
- return
- }
- condition += " AND c.report_chapter_id=?"
- pars = append(pars, reportChapterId)
- }
- //空为全部,1精选,2置顶
- reqHotTopType := this.GetString("HotTopType", "")
- orderStr := ""
- numCondition := condition
- if reqHotTopType != "" {
- hotTopType, err = strconv.Atoi(reqHotTopType)
- if err != nil {
- br.Msg = "请输入正确的置顶标识"
- br.ErrMsg = "请输入正确的置顶标识:" + err.Error()
- return
- }
- if hotTopType == 2 {
- condition += " and c.is_top = 1"
- orderStr = " ORDER BY c.top_time DESC , c.comment_id DESC"
- } else if hotTopType == 1 {
- condition += " and c.is_hot = 1"
- orderStr = " ORDER BY c.hot_time DESC , c.comment_id DESC"
- } else {
- br.Msg = "请输入正确的置顶标识"
- return
- }
- }
- commentList, err := yb.GetCommentListByByCondition(condition, pars, orderStr, startSize, pageSize)
- if err != nil {
- br.Msg = "获取留言列表失败!"
- br.ErrMsg = "获取留言列表失败,Err:" + err.Error()
- return
- }
- var commentIds string
- var userIds string
- for _, v := range commentList {
- commentIds += "," + strconv.Itoa(int(v.CommentId))
- userIds += "," + strconv.Itoa(int(v.UserId))
- }
- // 查询所有的回复列表
- replyListMap := make(map[uint64][]*ybResp.ReplyItem)
- if len(commentIds) > 0 {
- commentIds = "(" + strings.Trim(commentIds, ",") + ")"
- replyList, tErr := yb.GetReplyListByReplyCommentIds(reportId, reportChapterId, commentIds)
- if tErr != nil {
- br.Msg = "获取回复列表失败"
- br.ErrMsg = "获取回复列表失败,Err:" + tErr.Error()
- return
- }
- for _, v := range replyList {
- t := new(ybResp.ReplyItem)
- t.CommentId = v.CommentId
- t.Content = v.Content
- t.AdminId = v.AdminId
- t.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
- t.AdminName = "弘则研究"
- t.AdminImgUrl = utils.DEFAULT_HONGZE_SYS_LOGO
- t.ReplyCommentId = v.ReplyCommentId
- replyListMap[v.ReplyCommentId] = append(replyListMap[v.ReplyCommentId], t)
- }
- }
- // 查询留言相关的用户
- var userOthers []*models.WxUser
- if len(userIds) > 0 {
- userOthers, err = models.GetWxUserListByUserIds(strings.Trim(userIds, ","))
- if err != nil {
- br.Msg = "查询留言用户出错"
- br.ErrMsg = "查询留言用户出错,Err:" + err.Error()
- return
- }
- }
- usersMap := make(map[uint64]*models.WxUser)
- for _, v := range userOthers {
- usersMap[uint64(v.UserId)] = v
- }
- var list []*ybResp.CommentItemResp
- for _, v := range commentList {
- tmp := new(ybResp.CommentItemResp)
- tmp.CommentId = v.CommentId
- tmp.UserId = v.UserId
- tmp.NickName = "匿名用户" + strconv.Itoa(int(3333+v.UserId))
- tmp.HeadImgUrl = utils.DEFAULT_HONGZE_USER_LOGO
- if info, ok := usersMap[v.UserId]; ok && v.IsShowName == 1 {
- tmp.NickName = info.NickName
- tmp.HeadImgUrl = info.Headimgurl
- }
- tmp.Content = v.Content
- tmp.IsHot = v.IsHot
- tmp.IsTop = v.IsTop
- tmp.HotTopTime = v.HotTopTime
- tmp.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
- tmp.Enabled = v.Enabled
- tmp.SourceAgent = v.SourceAgent
- if existList, ok := replyListMap[v.CommentId]; ok {
- tmp.ReplyList = existList
- }
- list = append(list, tmp)
- }
- // 获取列表分页总数
- total, err := yb.GetCommentListTotalByByCondition(condition, pars)
- if err != nil {
- br.Msg = "获取留言列表总数失败!"
- br.ErrMsg = "获取留言列表总数失败,Err:" + err.Error()
- return
- }
- //查询留言总数和精选总数,置顶总数
- var statNum ybResp.CommentStatNum
- if hotTopType == 0 {
- statNum.AllNum = total
- } else {
- statNum.AllNum, err = yb.GetCommentListTotalByByCondition(numCondition, pars)
- if err != nil {
- br.Msg = "获取留言列表总数失败!"
- br.ErrMsg = "获取留言列表总数失败,Err:" + err.Error()
- return
- }
- }
- if hotTopType == 2 {
- statNum.TopNum = total
- } else {
- topCondition := numCondition + " and c.is_top = 1"
- statNum.TopNum, err = yb.GetCommentListTotalByByCondition(topCondition, pars)
- if err != nil {
- br.Msg = "获取置顶留言列表总数失败!"
- br.ErrMsg = "获取置顶留言列表总数失败,Err:" + err.Error()
- return
- }
- }
- if hotTopType == 1 {
- statNum.HotNum = total
- } else {
- hotCondition := numCondition + " and c.is_hot = 1"
- statNum.HotNum, err = yb.GetCommentListTotalByByCondition(hotCondition, pars)
- if err != nil {
- br.Msg = "获取精选留言列表总数失败!"
- br.ErrMsg = "获取精选留言列表总数失败,Err:" + err.Error()
- return
- }
- }
- // 设置留言已读
- updateComments, err := yb.GetCommentIdsByCondition(condition, pars)
- if err != nil {
- br.Msg = "获取留言列表失败!"
- br.ErrMsg = "获取留言列表失败,Err:" + err.Error()
- return
- }
- updateIds := ""
- for _, v := range updateComments {
- updateIds += "," + strconv.Itoa(int(v.CommentId))
- }
- if updateIds != "" {
- updateIds = strings.Trim(updateIds, ",")
- err = yb.UpdateCommentSysIsReadByCommentIds(sysUser.AdminId, updateIds)
- if err != nil {
- br.Msg = "设置留言已读失败!"
- br.ErrMsg = "设置留言已读失败,Err:" + err.Error()
- return
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp := ybResp.CommentListResp{
- List: list,
- Paging: page,
- StatNum: statNum,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- // AddReply
- // @Title 新增回复
- // @Description 新增回复
- // @Param request body request.AddReplyCommentReq true "type json string"
- // @Success Ret=200 操作成功
- // @router /comment/reply/add [post]
- func (this *CommentController) AddReply() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.AddReplyCommentReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CommentId <= 0 {
- br.Msg = "请输入正确的留言ID!"
- br.ErrMsg = "请输入正确的留言ID!"
- return
- }
- if req.Content == "" {
- br.Msg = "请输入回复的内容!"
- br.ErrMsg = "请输入回复的内容!"
- return
- }
- brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
- if brMsg != "" {
- br.Msg = brMsg
- br.ErrMsg = brErrMsg
- return
- }
- //查询评论状态,如果已被用户删除则不允许新增回复
- commentInfo, err := yb.GetCommentUserByCommentId(req.CommentId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "留言不存在"
- br.ErrMsg = "留言不存在"
- return
- }
- br.Msg = "查询留言失败!"
- br.ErrMsg = "查询留言失败,Err:" + err.Error()
- return
- }
- if commentInfo.Enabled == 0 {
- br.Msg = "留言已被删除,不可回复"
- br.ErrMsg = "留言已被删除,不可回复"
- return
- }
- if commentInfo.Type != 1 {
- br.Msg = "只允许对留言回复"
- br.ErrMsg = "只允许对留言回复"
- return
- }
- replyNum, err := yb.GetReplyTotalByCommentId(req.CommentId)
- if err != nil {
- br.Msg = "查询回复次数失败 !"
- br.ErrMsg = "查询回复次数失败,Err:" + err.Error()
- return
- }
- ConfigReplyMax, err := cache.GetYbConfigIntValueByCode("reply_max_num")
- if err != nil {
- br.Msg = "查询配置信息失败 !"
- br.ErrMsg = "查询配置信息失败,Err:" + err.Error()
- return
- }
- if int(replyNum) >= ConfigReplyMax {
- br.Msg = "超过回复条数限制"
- br.ErrMsg = "超过回复条数限制"
- return
- }
- //新增回复
- now := time.Now()
- reply := &yb.Comment{
- AdminId: uint64(sysUser.AdminId),
- Content: req.Content,
- ReportId: commentInfo.ReportId,
- ReportChapterId: commentInfo.ReportChapterId,
- ReplyCommentId: commentInfo.CommentId,
- Type: 2,
- Enabled: 1,
- OldReportId: commentInfo.OldReportId,
- OldReportChapterId: commentInfo.OldReportChapterId,
- CreateTime: now,
- ModifyTime: now,
- }
- replyId, err := yb.AddComment(reply)
- if err != nil {
- br.Msg = "新增回复失败!"
- br.ErrMsg = "新增回失败,Err:" + err.Error()
- return
- }
- // 新增消息通知
- sendMessage := &yb.Message{
- UserId: commentInfo.UserId,
- Type: 1, //消息类型:1-留言回复通知,2-精选留言通知
- Enabled: 1,
- CommentId: uint64(replyId),
- ContentFirst: "您的留言:" + commentInfo.Content,
- ContentSecond: "作者回复:" + req.Content,
- ReportId: commentInfo.ReportId,
- ReportChapterId: commentInfo.ReportChapterId,
- OldReportId: commentInfo.OldReportId,
- OldReportChapterId: commentInfo.OldReportChapterId,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- err = yb.AddMessage(sendMessage)
- if err != nil {
- br.Msg = "新增消息失败!"
- br.ErrMsg = "新增消息失败,Err:" + err.Error()
- return
- }
- //回复列表
- var replyList []*ybResp.ReplyItem
- replyAll, tErr := yb.GetReplyByReplyCommentId(commentInfo.CommentId)
- if tErr != nil {
- br.Msg = "获取回复列表失败"
- br.ErrMsg = "获取回复列表失败,Err:" + tErr.Error()
- return
- }
- for _, v := range replyAll {
- t := new(ybResp.ReplyItem)
- t.CommentId = v.CommentId
- t.Content = v.Content
- t.AdminId = v.AdminId
- t.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
- t.AdminName = "弘则研究"
- t.AdminImgUrl = utils.DEFAULT_HONGZE_SYS_LOGO
- t.ReplyCommentId = v.ReplyCommentId
- replyList = append(replyList, t)
- }
- //评论信息
- tmp := new(ybResp.CommentItemResp)
- tmp.CommentId = commentInfo.CommentId
- tmp.UserId = commentInfo.UserId
- tmp.NickName = "匿名用户" + strconv.Itoa(int(3333+commentInfo.UserId))
- tmp.HeadImgUrl = utils.DEFAULT_HONGZE_USER_LOGO
- if commentInfo.IsShowName == 1 {
- tmp.NickName = commentInfo.NickName
- tmp.HeadImgUrl = commentInfo.Headimgurl
- }
- tmp.Content = commentInfo.Content
- tmp.IsHot = commentInfo.IsHot
- tmp.IsTop = commentInfo.IsTop
- tmp.HotTopTime = commentInfo.HotTopTime
- tmp.CreateTime = commentInfo.CreateTime.Format(utils.FormatDateTime)
- tmp.Enabled = commentInfo.Enabled
- tmp.SourceAgent = commentInfo.SourceAgent
- tmp.ReplyList = replyList
- data := tmp
- br.Ret = 200
- br.Success = true
- br.Msg = "回复成功"
- br.Data = data
- return
- }
- // DeleteComment
- // @Title 删除留言
- // @Description 删除留言
- // @Param request body request.CommentReq true "type json string"
- // @Success Ret=200 操作成功
- // @router /comment/del [post]
- func (this *CommentController) DeleteComment() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.CommentReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CommentId <= 0 {
- br.Msg = "请输入正确的留言ID!"
- br.ErrMsg = "请输入正确的留言ID!"
- return
- }
- brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
- if brMsg != "" {
- br.Msg = brMsg
- br.ErrMsg = brErrMsg
- return
- }
- //查询评论状态,
- commentInfo, err := yb.GetCommentByCommentId(req.CommentId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "留言不存在或者已删除"
- br.ErrMsg = "留言不存在或者已删除"
- return
- }
- br.Msg = "查询留言失败!"
- br.ErrMsg = "查询留言失败,Err:" + err.Error()
- return
- }
- if commentInfo.Type != 1 {
- br.Msg = "只允许删除留言"
- br.ErrMsg = "只允许删除留言"
- return
- }
- err = yb.DeleteComment(req.CommentId)
- if err != nil {
- br.Msg = "删除留言操作失败!"
- br.ErrMsg = "删除留言操作失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- // DeleteReply
- // @Title 删除回复
- // @Description 删除回复
- // @Param request body request.CommentReq true "type json string"
- // @Success Ret=200 操作成功
- // @router /comment/reply/del [post]
- func (this *CommentController) DeleteReply() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.CommentReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CommentId <= 0 {
- br.Msg = "请输入正确的回复ID!"
- br.ErrMsg = "请输入正确的回复ID!"
- return
- }
- brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
- if brMsg != "" {
- br.Msg = brMsg
- br.ErrMsg = brErrMsg
- return
- }
- //查询评论状态,
- commentInfo, err := yb.GetCommentByCommentId(req.CommentId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "留言不存在或者已删除"
- br.ErrMsg = "留言不存在或者已删除"
- return
- }
- br.Msg = "查询留言失败!"
- br.ErrMsg = "查询留言失败,Err:" + err.Error()
- return
- }
- if commentInfo.Type != 2 {
- br.Msg = "只允许删除回复"
- br.ErrMsg = "只允许删除回复"
- return
- }
- err = yb.DeleteCommentReply(req.CommentId)
- if err != nil {
- br.Msg = "删除回复操作失败!"
- br.ErrMsg = "删除回复操作失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- // SetHot
- // @Title 设置留言精选/取消留言精选
- // @Description 设置留言精选
- // @Param request body request.CommentReq true "type json string"
- // @Success Ret=200 操作成功
- // @router /comment/hot [post]
- func (this *CommentController) SetHot() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.CommentReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CommentId <= 0 {
- br.Msg = "请输入正确的留言ID!"
- br.ErrMsg = "请输入正确的留言ID!"
- return
- }
- brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
- if brMsg != "" {
- br.Msg = brMsg
- br.ErrMsg = brErrMsg
- return
- }
- //查询评论状态,
- commentInfo, err := yb.GetCommentByCommentId(req.CommentId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "留言不存在"
- br.ErrMsg = "留言不存在"
- return
- }
- br.Msg = "查询留言失败!"
- br.ErrMsg = "查询留言失败,Err:" + err.Error()
- return
- }
- if commentInfo.Enabled == 0 {
- br.Msg = "留言已被删除,不可回复"
- br.ErrMsg = "留言已被删除,不可回复"
- return
- }
- if commentInfo.Type != 1 {
- br.Msg = "只允许对留言操作"
- br.ErrMsg = "只允许对留言操作"
- return
- }
- now := time.Now()
- if commentInfo.IsHot == 0 {
- //精选操作
- var notifyMsgFlag bool
- tmpTime := commentInfo.HotTime.Format(utils.FormatDateTime)
- if tmpTime == "0001-01-01 00:00:00" { //首次精选才会发送通知
- notifyMsgFlag = true
- }
- commentInfo.HotTopTime = now
- commentInfo.ModifyTime = now
- commentInfo.HotTime = now
- commentInfo.IsHot = 1
- err = commentInfo.Update([]string{"is_hot", "hot_time", "hot_top_time", "modify_time"})
- if err != nil {
- br.Msg = "留言精选操作失败!"
- br.ErrMsg = "留言精选操作失败,Err:" + err.Error()
- return
- }
- // 新增消息通知
- if notifyMsgFlag {
- sendMessage := &yb.Message{
- UserId: commentInfo.UserId,
- Type: 2, //消息类型:1-留言回复通知,2-精选留言通知
- Enabled: 1,
- CommentId: commentInfo.CommentId,
- ContentFirst: "您的留言:" + commentInfo.Content,
- ContentSecond: "入选为精选留言",
- ReportId: commentInfo.ReportId,
- ReportChapterId: commentInfo.ReportChapterId,
- OldReportId: commentInfo.OldReportId,
- OldReportChapterId: commentInfo.OldReportChapterId,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- err = yb.AddMessage(sendMessage)
- if err != nil {
- br.Msg = "新增消息失败!"
- br.ErrMsg = "新增消息失败,Err:" + err.Error()
- return
- }
- }
- } else {
- //取消精选操作,同时取消置顶
- commentInfo.IsHot = 0
- commentInfo.IsTop = 0
- commentInfo.ModifyTime = now
- err = commentInfo.Update([]string{"is_hot", "modify_time", "is_top"})
- if err != nil {
- br.Msg = "取消精选操作失败!"
- br.ErrMsg = "取消精选操作失败,Err:" + err.Error()
- return
- }
- }
- data := ybResp.CommentHotResp{
- CommentId: int64(commentInfo.CommentId),
- IsHot: commentInfo.IsHot,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- br.Data = data
- return
- }
- // SetTop
- // @Title 设置留言置顶
- // @Description 设置留言置顶
- // @Param request body request.CommentReq true "type json string"
- // @Success Ret=200 操作成功
- // @router /comment/top [post]
- func (this *CommentController) SetTop() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.CommentReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CommentId <= 0 {
- br.Msg = "请输入正确的留言ID!"
- br.ErrMsg = "请输入正确的留言ID!"
- return
- }
- brMsg, brErrMsg := ybService.CheckCommentPermission(sysUser.AdminId)
- if brMsg != "" {
- br.Msg = brMsg
- br.ErrMsg = brErrMsg
- return
- }
- //查询评论状态
- commentInfo, err := yb.GetCommentByCommentId(req.CommentId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "留言不存在"
- br.ErrMsg = "留言不存在"
- return
- }
- br.Msg = "查询留言失败!"
- br.ErrMsg = "查询留言失败,Err:" + err.Error()
- return
- }
- if commentInfo.Enabled == 0 {
- br.Msg = "留言已被删除,不可回复"
- br.ErrMsg = "留言已被删除,不可回复"
- return
- }
- if commentInfo.Type != 1 {
- br.Msg = "只允许对留言操作"
- br.ErrMsg = "只允许对留言操作"
- return
- }
- now := time.Now()
- if commentInfo.IsTop == 0 {
- //置顶操作
- var notifyMsgFlag bool
- updateStr := []string{"is_top", "hot_top_time", "top_time", "modify_time"}
- if commentInfo.IsHot == 0 {
- tmpTime := commentInfo.HotTime.Format(utils.FormatDateTime)
- if tmpTime == "0001-01-01 00:00:00" {
- notifyMsgFlag = true
- }
- commentInfo.IsHot = 1
- commentInfo.HotTime = now
- updateStr = append(updateStr, "is_hot")
- updateStr = append(updateStr, "hot_time")
- }
- commentInfo.IsTop = 1
- commentInfo.HotTopTime = now
- commentInfo.TopTime = now
- commentInfo.ModifyTime = now
- err = commentInfo.Update(updateStr)
- if err != nil {
- br.Msg = "留言置顶操作失败!"
- br.ErrMsg = "留言置顶操作失败,Err:" + err.Error()
- return
- }
- //发送精选通知
- if notifyMsgFlag {
- sendMessage := &yb.Message{
- UserId: commentInfo.UserId,
- Type: 2, //消息类型:1-留言回复通知,2-精选留言通知
- Enabled: 1,
- CommentId: commentInfo.CommentId,
- ContentFirst: "您的留言:" + commentInfo.Content,
- ContentSecond: "入选为精选留言",
- ReportId: commentInfo.ReportId,
- ReportChapterId: commentInfo.ReportChapterId,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- err = yb.AddMessage(sendMessage)
- if err != nil {
- br.Msg = "新增消息失败!"
- br.ErrMsg = "新增消息失败,Err:" + err.Error()
- return
- }
- }
- } else {
- //取消置顶操作
- commentInfo.IsTop = 0
- commentInfo.ModifyTime = now
- err = commentInfo.Update([]string{"is_top", "modify_time"})
- if err != nil {
- br.Msg = "取消置顶操作失败!"
- br.ErrMsg = "取消置顶操作失败,Err:" + err.Error()
- return
- }
- }
- data := ybResp.CommentTopResp{
- CommentId: int64(commentInfo.CommentId),
- IsTop: commentInfo.IsTop,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- br.Data = data
- return
- }
- // AllCommentList
- // @Title 获取所有未处理的留言列表
- // @Description 获取所有未处理的留言列表
- // @Success 200 {object} ybResp.CommentListResp
- // @router /comment/all_list [get]
- func (this *CommentController) AllCommentList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser is Empty"
- br.Ret = 408
- return
- }
- currentIndex := 1
- pageSize := 10000
- var startSize int
- startSize = paging.StartIndex(currentIndex, pageSize)
- // 判断查询权限
- brMsg, _ := ybService.CheckCommentPermission(sysUser.AdminId)
- if brMsg != "" {
- br.Ret = 200
- br.Success = true
- br.Data = ybResp.AllCommentResp{
- List: make([]ybResp.CommentItemResp, 0),
- IsShow: false,
- }
- return
- }
- condition := ""
- var pars []interface{}
- condition += " AND c.sys_is_read = ? AND type = 1 "
- pars = append(pars, 0)
- orderStr := " ORDER BY c.create_time DESC , c.comment_id DESC"
- commentList, err := yb.GetCommentListByByCondition(condition, pars, orderStr, startSize, pageSize)
- if err != nil {
- br.Msg = "获取留言列表失败!"
- br.ErrMsg = "获取留言列表失败,Err:" + err.Error()
- return
- }
- var userIds string
- for _, v := range commentList {
- userIds += "," + strconv.Itoa(int(v.UserId))
- }
- // 查询留言相关的用户
- var userOthers []*models.WxUser
- if len(userIds) > 0 {
- userOthers, err = models.GetWxUserListByUserIds(strings.Trim(userIds, ","))
- if err != nil {
- br.Msg = "查询留言用户出错"
- br.ErrMsg = "查询留言用户出错,Err:" + err.Error()
- return
- }
- }
- usersMap := make(map[uint64]*models.WxUser)
- for _, v := range userOthers {
- usersMap[uint64(v.UserId)] = v
- }
- var list []ybResp.CommentItemResp
- for _, v := range commentList {
- tmp := ybResp.CommentItemResp{
- CommentId: v.CommentId,
- ReportId: v.ReportId,
- UserId: v.UserId,
- Content: v.Content,
- IsTop: v.IsTop,
- IsHot: v.IsHot,
- HotTopTime: v.HotTopTime,
- SourceAgent: v.SourceAgent,
- NickName: "匿名用户" + strconv.Itoa(int(3333+v.UserId)),
- HeadImgUrl: utils.DEFAULT_HONGZE_USER_LOGO,
- CreateTime: v.CreateTime.Format(utils.FormatDateTime),
- Enabled: v.Enabled,
- ReplyList: make([]*ybResp.ReplyItem, 0),
- }
- if info, ok := usersMap[v.UserId]; ok && v.IsShowName == 1 {
- tmp.NickName = info.NickName
- tmp.HeadImgUrl = info.Headimgurl
- }
- list = append(list, tmp)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = ybResp.AllCommentResp{
- List: list,
- IsShow: true,
- }
- return
- }
- // ProductCommentList
- // @Title 获取评论合集列表
- // @Description 获取评论合集列表
- // @Param CommunityId query string true "评论ID"
- // @Param ProductType query string false "板块类型"
- // @Param KeyWord query string false "留言关键词"
- // @Param PageSize query string false "页码"
- // @param CurrentIndex query string false "每页展示的记录数"
- // @Success 200 {object} ybResp.LikeListResp
- // @router /product/comment/list [get]
- func (this *CommentController) ProductCommentList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- productType := this.GetString("ProductType", "")
- keyWord := this.GetString("KeyWord", "")
- createDate := this.GetString("CreateDate", "")
- list, total, err, errMsg := ybService.GetProductComments(sysUser.AdminId, productType, keyWord, createDate, startSize, pageSize)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp := ybResp.ProductCommentResp{
- List: list,
- Paging: page,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- // OtherProductList
- // @Title 获取其他分产品的筛选列表
- // @Description 获取其他分产品的筛选列表
- // @Success 200 {object} ybResp.OtherProductTypeListResp
- // @router /comment/product [get]
- func (this *CommentController) OtherProductList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- resp := make([]ybResp.OtherProductTypeListResp, 0)
- reportItem := ybResp.OtherProductTypeListResp{
- ProductType: 1,
- ProductName: "研报",
- }
- questionItem := ybResp.OtherProductTypeListResp{
- ProductType: 2,
- ProductName: "问答社区",
- }
- videoItem := ybResp.OtherProductTypeListResp{
- ProductType: 3,
- ProductName: "视频社区",
- }
- roadVideoItem := ybResp.OtherProductTypeListResp{
- ProductType: 4,
- ProductName: "线上路演",
- }
- resp = append(resp, reportItem, questionItem, videoItem, roadVideoItem)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // DeleteProductComment
- // @Title 删除板块留言
- // @Description 删除留言
- // @Param request body request.CommentProductDelReq true "type json string"
- // @Success Ret=200 操作成功
- // @router /product/comment/del [post]
- func (this *CommentController) DeleteProductComment() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.CommentProductDelReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.CommentId <= 0 {
- br.Msg = "请输入正确的留言ID!"
- br.ErrMsg = "请输入正确的留言ID!"
- return
- }
- err, errMsg := ybService.DelProductComments(req)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- return
- }
|