package yb import ( "encoding/json" "github.com/rdlucklib/rdluck_tools/paging" "hongze/hongze_mobile_admin/controllers" ybRequest "hongze/hongze_mobile_admin/models/request/yb" ybResponse "hongze/hongze_mobile_admin/models/response/yb" "hongze/hongze_mobile_admin/services/yb" "hongze/hongze_mobile_admin/utils" ) type CommunityQuestionCommentController struct { controllers.BaseAuth } // List // @Title 获取问答评论列表 // @Description 获取问答评论列表 // @Param CommunityQuestionCommentId query int false "评论id" // @Param HotStatus query int false "精选状态 -1:全部 0-未精选,1-已精选" // @Param Keyword query string false "关键字搜索" // @Success 200 {object} yb.CommunityQuestionCommentListResp // @router /community/question/comment/list [get] func (c *CommunityQuestionCommentController) List() { //sysUser := c.AdminWx // 权限校验 //msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId) //if err != nil { // c.FailWithMessage(msg, err.Error()) // return //} condition := "" pars := make([]interface{}, 0) // 来源 source, _ := c.GetInt("Source", 1) if source <= 0 { source = 1 } // 评论ID communityQuestionCommentId, _ := c.GetInt("CommunityQuestionCommentId", 0) if communityQuestionCommentId > 0 { condition += ` AND a.community_question_comment_id = ? ` pars = append(pars, communityQuestionCommentId) } else { //精选状态状态 hotStatus, _ := c.GetInt("HotStatus", 0) if hotStatus >= 0 { condition += ` AND a.is_hot = ? ` pars = append(pars, hotStatus) } //关键字 keyword := c.GetString("Keyword", "") if keyword != "" { condition += ` AND a.content like "%` + keyword + `%"` } } var startSize int pageSize, _ := c.GetInt("PageSize") currentIndex, _ := c.GetInt("CurrentIndex") if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = paging.StartIndex(currentIndex, pageSize) total, list, err := yb.GetCommunityQuestionCommentList(condition, pars, startSize, pageSize, source) if err != nil { c.FailWithMessage("获取问答列表失败", "QuestionList ErrMsg:"+err.Error()) return } page := paging.GetPaging(currentIndex, pageSize, total) c.OkDetailed(ybResponse.CommunityQuestionCommentListResp{ Paging: page, List: list, }, "获取成功") } // Delete // @Title 删除评论 // @Description 删除评论 // @Param QuestionId query int false "问题ID" // @Success 200 string "操作成功" // @router /community/question/comment/delete [post] func (c *CommunityQuestionCommentController) Delete() { //sysUser := c.AdminWx // 权限校验 //msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId) //if err != nil { // c.FailWithMessage(msg, err.Error()) // return //} var req ybRequest.QuestionCommentDeleteReq if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil { c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error()) return } if err, errMsg := yb.SoftDeleteQuestionComment(req.CommunityQuestionCommentId); err != nil { c.FailWithMessage(errMsg, "DeleteQuestion,Err:"+err.Error()) return } c.OkWithMessage("删除成功") } // Hot // @Title 设置/取消 问题评论精选 // @Description 设置/取消 问题评论精选 // @Success 200 string "操作成功" // @router /community/question/comment/hot [post] func (c *CommunityQuestionCommentController) Hot() { //sysUser := c.AdminWx // 权限校验 //msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId) //if err != nil { // c.FailWithMessage(msg, err.Error()) // return //} var req ybRequest.QuestionCommentHotReq if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil { c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error()) return } if err, errMsg := yb.SetHotQuestionComment(req.CommunityQuestionCommentId); err != nil { c.FailWithMessage(errMsg, "DeleteQuestion,Err:"+err.Error()) return } c.OkWithMessage("操作成功") }