You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

55 lines
1.7 KiB

package user
import (
"strings"
"unicode/utf8"
"yunyan/comm"
"yunyan/lego/sys/log"
"yunyan/pb"
)
// feedbackMessageMax 与客户端输入框上限(500)之间留出余量。
// 超限直接拒,不截断——截断后用户以为整段都交上去了。
const feedbackMessageMax = 2000
// normalizeFeedbackMessage 去掉首尾空白并校验长度。第二个返回值非空表示拒绝原因。
func normalizeFeedbackMessage(s string) (string, string) {
s = strings.TrimSpace(s)
if s == "" {
return "", "请填写反馈内容"
}
if utf8.RuneCountInString(s) > feedbackMessageMax {
return "", "反馈内容过长"
}
return s, ""
}
// @Summary 用户反馈
// @Description 用户反馈
// @Tags User
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param user body pb.UserFeedbackReq true "用户反馈"
// @Success 200 {object} comm.HttpResult{data=pb.UserFeedbackResp} "成功返回"
// @Router /api/home/user_feedback [post]
func (this *apiComp) Feedback(session comm.IUserSession, req *pb.UserFeedbackReq) (resp *pb.UserFeedbackResp, errdata *pb.ErrorData) {
resp = &pb.UserFeedbackResp{}
uid := session.GetUserId()
if uid == "" {
errdata = &pb.ErrorData{Code: pb.ErrorCode_NoLogin, Message: pb.ErrorCode_NoLogin.String()}
return
}
message, reason := normalizeFeedbackMessage(req.GetMessage())
if reason != "" {
errdata = &pb.ErrorData{Code: pb.ErrorCode_ReqParameterError, Message: reason}
return
}
if err := this.module.feedbackmodel.insert(uid, message); err != nil {
this.module.Error("用户反馈写入失败", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err.Error()})
errdata = &pb.ErrorData{Code: pb.ErrorCode_DBError, Message: pb.ErrorCode_DBError.String()}
return
}
return
}