1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084 |
- package yb
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hz_crm_api/controllers"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/company"
- ybModels "hongze/hz_crm_api/models/yb"
- "hongze/hz_crm_api/models/yb/request"
- ybResp "hongze/hz_crm_api/models/yb/response"
- "hongze/hz_crm_api/services/yb"
- "hongze/hz_crm_api/utils"
- "strconv"
- "strings"
- )
- type CommunityQuestionController struct {
- controllers.BaseAuthController
- }
- // QuestionList
- // @Title 获取问答列表
- // @Description 获取问答列表
- // @Param ReplyStatus query int false "提问状态 1-待分配 2-待回答 3-已回答"
- // @Param ReplierIds query string false "回复人ID,多个用英文逗号分割"
- // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'ClickNum':点击量"
- // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
- // @Success 200 {object} response.CommunityQuestionListResp
- // @router /community/question/list [get]
- func (this *CommunityQuestionController) QuestionList() {
- br := new(models.BaseResponse).Init()
- br.IsSendEmail = false
- 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
- }
- // 权限校验
- msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
- if err != nil {
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- condition := ""
- pars := make([]interface{}, 0)
- replyStatus, _ := this.GetInt("ReplyStatus", 0)
- if replyStatus > 0 {
- condition += ` AND q.reply_status = ?`
- pars = append(pars, replyStatus)
- }
- replierIds := this.GetString("ReplierIds", "")
- if replierIds != "" {
- condition += ` AND q.replier_admin_id IN (` + replierIds + `)`
- }
- // 排序相关
- sortParam := this.GetString("SortParam")
- sortType := this.GetString("SortType")
- orderStr := ""
- if sortType != "" && strings.ToLower(sortType) != "desc" && strings.ToLower(sortType) != "asc" {
- br.Msg = "请输入正确的排序类型"
- return
- }
- if sortParam == "ClickNum" {
- orderStr = " ORDER BY l.click_num"
- if sortType != "" {
- orderStr += " " + sortType
- } else {
- orderStr += " DESC"
- }
- orderStr += ", q.create_time DESC"
- }
- var startSize int
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- total, resp, err := yb.GetQuestionList(condition, pars, orderStr, startSize, pageSize)
- if err != nil {
- br.Msg = "获取问答列表失败"
- br.ErrMsg = "QuestionList ErrMsg:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // QuestionDistribute
- // @Title 分配回复人
- // @Description 获取问答列表
- // @Param ReplyStatus query int false "提问状态 1-待分配 2-待回答 3-已回答"
- // @Param ReplierIds query string false "回复人ID,多个用英文逗号分割"
- // @Success 200 string "操作成功"
- // @router /community/question/distribute [post]
- func (this *CommunityQuestionController) QuestionDistribute() {
- br := new(models.BaseResponse).Init()
- br.IsSendEmail = false
- 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
- }
- // 权限校验
- msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
- if err != nil {
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- var req request.QuestionDistributeReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- errMsg, err := yb.DistributeQuestion(req.QuestionId, req.AdminId, req.ResearchGroupFirstId, req.ResearchGroupSecondId, sysUser.AdminId)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = "DistributeQuestion ErrMsg:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = errMsg
- }
- // QuestionDelete
- // @Title 删除提问
- // @Description 删除提问
- // @Param QuestionId query int false "问题ID"
- // @Success 200 string "操作成功"
- // @router /community/question/delete [post]
- func (this *CommunityQuestionController) QuestionDelete() {
- br := new(models.BaseResponse).Init()
- br.IsSendEmail = false
- 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
- }
- // 权限校验
- msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
- if err != nil {
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- var req request.QuestionDeleteReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if err := yb.SoftDeleteQuestion(req.QuestionId); err != nil {
- br.Msg = "删除提问失败"
- br.ErrMsg = "DeleteQuestion ErrMsg:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // SendTemplateMsg
- // @Title 推送模板消息给回复人
- // @Description 推送模板消息给回复人
- // @Param QuestionId query int false "问题ID"
- // @Success 200 string "操作成功"
- // @router /community/question/send_template_msg [post]
- func (this *CommunityQuestionController) SendDistributeTemplateMsg() {
- br := new(models.BaseResponse).Init()
- br.IsSendEmail = false
- 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
- }
- // 权限校验
- msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
- if err != nil {
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- var req request.QuestionMsgSendReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "SendDistributeTemplateMsg 参数解析异常:" + err.Error()
- return
- }
- errMsg, err := yb.SendMsgToReplier(req.QuestionId)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = "SendDistributeTemplateMsg ErrMsg:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // QuestionEdit
- // @Title 编辑问题
- // @Description 编辑问题
- // @Param QuestionId query int true "问题ID"
- // @Param QuestionContent query string true "问题内容"
- // @Success 200 string "操作成功"
- // @router /community/question/edit [post]
- func (this *CommunityQuestionController) QuestionEdit() {
- br := new(models.BaseResponse).Init()
- br.IsSendEmail = false
- 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
- }
- // 权限校验
- msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
- if err != nil {
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- var req request.QuestionEditReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.QuestionId <= 0 {
- br.Msg = "问题ID有误"
- return
- }
- if req.QuestionContent == "" {
- br.Msg = "内容不可为空"
- return
- }
- contentRune := []rune(req.QuestionContent)
- if len(contentRune) > 28 {
- br.Msg = "问题字数不可超过28个字符"
- return
- }
- errMsg, err := yb.EditQuestion(req.QuestionId, req.QuestionContent)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = "QuestionEdit ErrMsg:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // QuestionClickLogList
- // @Title 获取点击量列表
- // @Description 获取点击量列表
- // @Param QuestionId query int false "问题ID"
- // @Success 200 {object} response.QuestionClickLogListResp
- // @router /community/question/click/logs [get]
- func (this *CommunityQuestionController) QuestionClickLogList() {
- 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
- }
- questionId, _ := this.GetInt("QuestionId")
- if questionId <= 0 {
- br.Msg = "请输入正确的提问ID"
- return
- }
- var startSize int
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- total, resp, err := yb.GetQuestionClickLogList(questionId, startSize, pageSize)
- if err != nil {
- br.Msg = "获取问答列表失败"
- br.ErrMsg = "QuestionList ErrMsg:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // UserInfo
- // @Title 获取提问者基本信息
- // @Description 获取提问者基本信息
- // @Param UserId query int false "用户ID"
- // @Success 200 {object} response.CommunityQuestionListResp
- // @router /community/question/user [get]
- func (this *CommunityQuestionController) UserInfo() {
- 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
- }
- questionId, _ := this.GetInt("QuestionId")
- if questionId <= 0 {
- br.Msg = "请输入正确的提问ID"
- return
- }
- resp, err := yb.GetQuestionCompanyUser(questionId)
- if err != nil {
- br.Msg = "用户不存在或者查询出错"
- br.ErrMsg = "UserInfo ErrMsg:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- // LikeTeaseListWithQuestion
- // @Title 获取已被点赞/吐槽的问答列表
- // @Description 获取已被点赞/吐槽的问答列表
- // @Param SortParam query string false "排序关键词:Num"
- // @Param SortType query string false "排序顺序:asc、desc"
- // @Param DataType query string false "类型:like、tease"
- // @Param PageSize query string false "每页展示的记录数"
- // @param CurrentIndex query string false "页码"
- // @param Source query int false "来源:1-问答社区; 2-视频社区"
- // @Success 200 {object} ybResp.LikeReportListResp
- // @router /community/question/like_tease_question_list [get]
- func (this *CommunityQuestionController) LikeTeaseListWithQuestion() {
- 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
- }
- // 来源(默认问答社区)
- source, _ := this.GetInt("Source")
- if source <= 0 {
- source = 1
- }
- 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 := yb.CheckCommentPermission(sysUser.AdminId)
- if brMsg != "" {
- br.Msg = brMsg
- br.ErrMsg = brErrMsg
- return
- }
- // 数据类型,默认是点赞列表
- reqDataType := this.GetString("DataType")
- if reqDataType == `` {
- reqDataType = "like"
- }
- var opType int8 //类型. 1-点赞 2-吐槽
- switch reqDataType {
- case "like":
- opType = 1
- case "tease":
- opType = 2
- default:
- br.Msg = "错误的数据类型:" + reqDataType
- br.ErrMsg = "错误的数据类型:" + reqDataType
- return
- }
- //排序
- orderStr := ""
- reqSortParam := this.GetString("SortParam", "")
- switch reqSortParam {
- case "Num":
- orderStr = ` num `
- default:
- orderStr = ` community_question_id ` // 默认问答倒序
- }
- reqSortType := this.GetString("SortType")
- if reqSortType == `` {
- reqSortType = "desc"
- }
- orderStr = orderStr + " " + reqSortType
- total := 0
- list := make([]*ybModels.StatCommunityQuestionLikeTeaseItem, 0)
- // 问答社区
- if source == 1 {
- qaTotal, e := ybModels.GetYbCommunityQuestionLikeTeaseTotal(opType)
- if e != nil {
- br.Msg = "获取数据汇总数失败!"
- br.ErrMsg = "获取数据汇总数失败,Err:" + e.Error()
- return
- }
- total = int(qaTotal)
- qaList, e := ybModels.GetYbCommunityQuestionLikeTeaseQuestion(opType, orderStr, startSize, pageSize)
- if e != nil {
- br.Msg = "获取问答数据列表失败!"
- br.ErrMsg = "获取问答数据列表失败,Err:" + e.Error()
- return
- }
- list = qaList
- }
- // 视频社区
- if source == 2 {
- vdTotal, e := ybModels.GetYbCommunityVideoLikeTeaseTotal(opType)
- if e != nil {
- br.Msg = "获取视频数据汇总数失败!"
- br.ErrMsg = "获取视频数据汇总数失败,Err:" + e.Error()
- return
- }
- total = int(vdTotal)
- vdList, e := ybModels.GetYbCommunityVideoLikeTeaseList(opType, orderStr, startSize, pageSize)
- if e != nil {
- br.Msg = "获取视频数据列表失败!"
- br.ErrMsg = "获取视频数据列表失败,Err:" + e.Error()
- return
- }
- // 标签分类及名称
- tagList, e := models.GetVarietyTagList()
- if e != nil {
- br.Msg = "获取视频标签列表失败"
- br.ErrMsg = "获取视频标签列表失败, Err:" + e.Error()
- return
- }
- tagMap := make(map[int]*models.VarietyTag, 0)
- for i := range tagList {
- tagMap[tagList[i].VarietyTagId] = tagList[i]
- }
- for i := range vdList {
- t := tagMap[vdList[i].VarietyTagId]
- if t != nil {
- vdList[i].VarietyClassifyTag = fmt.Sprintf("%s-%s", t.VarietyClassifyName, t.TagName)
- }
- }
- list = vdList
- }
- // 线上路演
- if source == 3 {
- rvTotal, e := ybModels.GetYbRoadVideoLikeTeaseTotal(opType)
- if e != nil {
- br.Msg = "获取线上路演数据汇总数失败!"
- br.ErrMsg = "获取线上路演数据汇总数失败,Err:" + e.Error()
- return
- }
- total = int(rvTotal)
- rvList, e := ybModels.GetYbRoadVideoLikeTeaseList(opType, orderStr, startSize, pageSize)
- if e != nil {
- br.Msg = "获取线上路演点赞吐槽列表失败!"
- br.ErrMsg = "获取线上路演点赞吐槽列表失败,Err:" + e.Error()
- return
- }
- // 线上路演品种
- cpList, e := models.GetChartPermissionList()
- if e != nil {
- br.Msg = "获取路演视频品种失败!"
- br.ErrMsg = "获取路演视频品种失败,Err:" + e.Error()
- return
- }
- cpMap := make(map[int]string, 0)
- for i := range cpList {
- cpMap[cpList[i].ChartPermissionId] = cpList[i].PermissionName
- }
- for i := range rvList {
- if rvList[i].VarietyClassifyTag == "" {
- continue
- }
- ids := utils.JoinStr2IntArr(strings.ReplaceAll(rvList[i].VarietyClassifyTag, `'`, ``), ",")
- if len(ids) == 0 {
- continue
- }
- cpArr := make([]string, 0)
- for s := range ids {
- if cpMap[ids[s]] != "" {
- cpArr = append(cpArr, cpMap[ids[s]])
- }
- }
- rvList[i].VarietyClassifyTag = strings.Join(cpArr, ",")
- }
- list = rvList
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- data := &ybResp.LikeTeaseListWithQuestionResp{
- List: list,
- Paging: page,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- br.Data = data
- return
- }
- // LikeTeaseList
- // @Title 获取某个问答的点赞/吐槽列表
- // @Description 获取某个问答的点赞/吐槽列表
- // @Param CommunityQuestionId query string true "问答ID"
- // @Param DataType query string false "类型:like、tease"
- // @Param PageSize query string false "页码"
- // @param CurrentIndex query string false "每页展示的记录数"
- // @param Source query int false "来源:1-问答社区; 2-视频社区"
- // @Success 200 {object} ybResp.LikeListResp
- // @router /community/question/like_tease_list [get]
- func (this *CommunityQuestionController) LikeTeaseList() {
- 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
- }
- // 来源(默认问答社区)
- source, _ := this.GetInt("Source")
- if source <= 0 {
- source = 1
- }
- 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 := yb.CheckCommentPermission(sysUser.AdminId)
- if brMsg != "" {
- br.Msg = brMsg
- br.ErrMsg = brErrMsg
- return
- }
- //根据搜索条件查询留言列表
- var (
- err error
- communityQuestionId int
- )
- reqCommunityQuestionId := this.GetString("CommunityQuestionId", "")
- if reqCommunityQuestionId == "" {
- br.Msg = "请输入问答ID"
- br.ErrMsg = "请输入问答ID"
- return
- }
- communityQuestionId, err = strconv.Atoi(reqCommunityQuestionId)
- if err != nil {
- br.Msg = "请输入问答ID"
- br.ErrMsg = "请输入问答ID:" + err.Error()
- return
- }
- // 数据类型,默认是点赞列表
- reqDataType := this.GetString("DataType")
- if reqDataType == `` {
- reqDataType = "like"
- }
- var opType int //类型. 1-点赞 2-吐槽
- switch reqDataType {
- case "like":
- opType = 1
- case "tease":
- opType = 2
- default:
- br.Msg = "错误的数据类型:" + reqDataType
- br.ErrMsg = "错误的数据类型:" + reqDataType
- return
- }
- // 获取数据列表
- total, list, err := ybModels.GetYbCommunityQuestionLikeTeaseQuestionListById(communityQuestionId, opType, source, startSize, pageSize)
- if err != nil {
- br.Msg = "获取点赞列表失败!"
- br.ErrMsg = "获取点赞列表失败,Err:" + err.Error()
- return
- }
- var userIds string
- companyIdList := make([]int, 0)
- for _, v := range list {
- 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)
- companyIdMap := make(map[int]int)
- for _, v := range userOthers {
- usersMap[uint64(v.UserId)] = v
- if _, ok := companyIdMap[v.CompanyId]; !ok { //避免company_id重复append
- companyIdList = append(companyIdList, v.CompanyId)
- companyIdMap[v.CompanyId] = v.CompanyId
- }
- }
- // 查询点赞/吐槽相关用户的公司
- companyProductMap := make(map[int]*company.CompanyProduct)
- {
- if len(companyIdList) > 0 {
- var companyProductOthers []*company.CompanyProduct
- companyProductOthers, err = company.GetCompanyProductsByCompanyIdsAndProductId(companyIdList, 1)
- if err != nil {
- br.Msg = "查询客户出错"
- br.ErrMsg = "查询客户出错,Err:" + err.Error()
- return
- }
- for _, v := range companyProductOthers {
- companyProductMap[v.CompanyId] = v
- }
- }
- }
- for _, v := range list {
- if info, ok := usersMap[v.UserId]; ok {
- v.NickName = info.NickName
- //v.RealName = utils.DealRealName(info.RealName)
- v.RealName = info.RealName
- //客户信息
- if companyProductInfo, ok := companyProductMap[info.CompanyId]; ok {
- v.CompanyId = companyProductInfo.CompanyId
- v.CompanyName = companyProductInfo.CompanyName
- v.CompanyFiccStatus = companyProductInfo.Status
- }
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp := ybResp.LikeTeaseListListResp{
- List: list,
- Paging: page,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- // CommentList
- // @Title 获取社区问答评论列表
- // @Description 获取社区问答评论列表
- // @Param CommunityQuestionId query string true "问答ID"
- // @Param HotStatus query string false "精选状态,全部:-1;未精选:0;精选:1"
- // @Param PageSize query string false "页码"
- // @param CurrentIndex query string false "每页展示的记录数"
- // @Success 200 {object} ybResp.LikeListResp
- // @router /community/question/comment/list [get]
- func (this *CommunityQuestionController) 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 := yb.CheckCommentPermission(sysUser.AdminId)
- //if brMsg != "" {
- // br.Msg = brMsg
- // br.ErrMsg = brErrMsg
- // return
- //}
- condition := ""
- pars := make([]interface{}, 0)
- //精选状态
- hotStatus := this.GetString("HotStatus", "") //精选状态,全部:-1;未精选:0;精选:1
- switch hotStatus {
- case "0":
- condition += ` AND is_hot = ? `
- pars = append(pars, 0)
- //is = 1
- case "1":
- condition += ` AND is_hot = ? `
- pars = append(pars, 1)
- }
- // 获取数据列表
- total, list, err := ybModels.GetCommunityQuestionCommentList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取点赞列表失败!"
- br.ErrMsg = "获取点赞列表失败,Err:" + err.Error()
- return
- }
- var userIds string
- companyIdList := make([]int, 0)
- for _, v := range list {
- 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)
- companyIdMap := make(map[int]int)
- for _, v := range userOthers {
- usersMap[uint64(v.UserId)] = v
- if _, ok := companyIdMap[v.CompanyId]; !ok { //避免company_id重复append
- companyIdList = append(companyIdList, v.CompanyId)
- companyIdMap[v.CompanyId] = v.CompanyId
- }
- }
- // 查询点赞/吐槽相关用户的公司
- companyProductMap := make(map[int]*company.CompanyProduct)
- {
- if len(companyIdList) > 0 {
- var companyProductOthers []*company.CompanyProduct
- companyProductOthers, err = company.GetCompanyProductsByCompanyIdsAndProductId(companyIdList, 1)
- if err != nil {
- br.Msg = "查询客户出错"
- br.ErrMsg = "查询客户出错,Err:" + err.Error()
- return
- }
- for _, v := range companyProductOthers {
- companyProductMap[v.CompanyId] = v
- }
- }
- }
- for _, v := range list {
- if info, ok := usersMap[v.UserId]; ok {
- v.NickName = info.NickName
- //v.RealName = utils.DealRealName(info.RealName)
- v.RealName = info.RealName
- //客户信息
- if companyProductInfo, ok := companyProductMap[info.CompanyId]; ok {
- v.CompanyId = companyProductInfo.CompanyId
- v.CompanyName = companyProductInfo.CompanyName
- v.CompanyFiccStatus = companyProductInfo.Status
- }
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- resp := ybResp.CommunityQuestionCommentResp{
- List: list,
- Paging: page,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- // CommentDelete
- // @Title 删除评论
- // @Description 删除评论
- // @Param QuestionId query int false "问题ID"
- // @Success 200 string "操作成功"
- // @router /community/question/comment/delete [post]
- func (this *CommunityQuestionController) CommentDelete() {
- 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
- }
- // 判断查询权限
- //brMsg, brErrMsg := yb.CheckCommentPermission(sysUser.AdminId)
- //if brMsg != "" {
- // br.Msg = brMsg
- // br.ErrMsg = brErrMsg
- // return
- //}
- var req request.QuestionCommentDeleteReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if err, errMsg := yb.SoftDeleteQuestionComment(req.CommunityQuestionCommentId); err != nil {
- br.Msg = errMsg
- br.ErrMsg = "DeleteQuestion,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
- // CommentHot
- // @Title 设置/取消 问题评论精选
- // @Description 设置/取消 问题评论精选
- // @Success 200 string "操作成功"
- // @router /community/question/comment/hot [post]
- func (this *CommunityQuestionController) CommentHot() {
- 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
- }
- // 判断查询权限
- //brMsg, brErrMsg := yb.CheckCommentPermission(sysUser.AdminId)
- //if brMsg != "" {
- // br.Msg = brMsg
- // br.ErrMsg = brErrMsg
- // return
- //}
- var req request.QuestionCommentHotReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if err, errMsg := yb.SetHotQuestionComment(req.CommunityQuestionCommentId); err != nil {
- br.Msg = errMsg
- br.ErrMsg = "CommentHot,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // QuestionDetail
- // @Title 问答详情
- // @Description 问答详情
- // @Param QuestionId query int false "问答ID"
- // @Success 200 {object} response.CommunityQuestionListResp
- // @router /community/question/detail [get]
- func (this *CommunityQuestionController) QuestionDetail() {
- br := new(models.BaseResponse).Init()
- br.IsSendEmail = false
- 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
- }
- questionId, _ := this.GetInt("QuestionId", 0)
- if questionId <= 0 {
- br.Msg = "参数有误"
- return
- }
- // 权限校验
- msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
- if err != nil {
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- // 获取问答
- item, e := ybModels.GetQuestionById(questionId)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取问答信息失败, Err: " + e.Error()
- return
- }
- // 获取问答流程
- processes, e := ybModels.GetCommunityQuestionProcessItemList(questionId)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取问答流程失败, Err: " + e.Error()
- return
- }
- resp := new(ybModels.CommunityQuestionDetail)
- resp.CommunityQuestionId = item.CommunityQuestionId
- resp.Mobile = item.Mobile
- resp.RealName = item.RealName
- resp.QuestionContent = item.QuestionContent
- resp.ResearchGroupFirstName = item.ResearchGroupFirstName
- resp.ResearchGroupSecondName = item.ResearchGroupSecondName
- resp.VarietyTagName = item.VarietyTagName
- resp.ReplyStatus = item.ReplyStatus
- resp.MsgSendStatus = item.MsgSendStatus
- resp.ReplyTime = item.ReplyTime.Format(utils.FormatDateTime)
- resp.CreateTime = item.CreateTime.Format(utils.FormatDateTime)
- resp.StopReason = item.StopReason
- resp.ProcessList = processes
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // QuestionTransfer
- // @Title 转移并通知
- // @Description 转移并通知
- // @Param request body request.QuestionTransferReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /community/question/transfer [post]
- func (this *CommunityQuestionController) QuestionTransfer() {
- br := new(models.BaseResponse).Init()
- br.IsSendEmail = false
- 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
- }
- // 权限校验
- msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
- if err != nil {
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- var req request.QuestionTransferReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- errMsg, err := yb.TransferQuestion(req.QuestionId, req.AdminId, req.ResearchGroupFirstId, req.ResearchGroupSecondId, sysUser.AdminId, sysUser.RealName)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = "DistributeQuestion ErrMsg:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|