Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package feedbackser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
"videoweb/app/api/proto"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/models/feedbackmod"
|
||||
)
|
||||
|
||||
const (
|
||||
feedbackMaxContentLen = 500
|
||||
feedbackMaxContactLen = 100
|
||||
feedbackMaxScreenshotNum = 9
|
||||
feedbackSubmitMessage = "反馈提交成功"
|
||||
)
|
||||
|
||||
const ( //问题类型,1-功能建议、2-播放问题、3-账号问题、4-其他
|
||||
FeedbackTypeFeature int32 = 1
|
||||
FeedbackTypePlay int32 = 2
|
||||
FeedbackTypeAccount int32 = 3
|
||||
FeedbackTypeOther int32 = 4
|
||||
)
|
||||
|
||||
// AddFeedback 提交用户意见反馈
|
||||
func AddFeedback(ctx context.Context, userId int64, req *proto.FeedbackReq) (*proto.FeedbackResp, *srvdef.SrvErr) {
|
||||
if req == nil || userId <= 0 {
|
||||
return nil, srvdef.New(srvdef.ErrParamError, "", "")
|
||||
}
|
||||
if !isValidFeedbackType(req.Type) {
|
||||
return nil, srvdef.New(srvdef.ErrParamError, "问题类型无效")
|
||||
}
|
||||
content := strings.TrimSpace(req.Content)
|
||||
if content == "" || utf8.RuneCountInString(content) > feedbackMaxContentLen {
|
||||
return nil, srvdef.New(srvdef.ErrParamError, "描述内容不能为空且不能超过500字")
|
||||
}
|
||||
contact := strings.TrimSpace(req.Contact)
|
||||
if utf8.RuneCountInString(contact) > feedbackMaxContactLen {
|
||||
return nil, srvdef.New(srvdef.ErrParamError, "联系方式不能超过100字")
|
||||
}
|
||||
screenshots := normalizeScreenshots(req.Screenshots)
|
||||
if len(screenshots) > feedbackMaxScreenshotNum {
|
||||
return nil, srvdef.New(srvdef.ErrParamError, "问题截图不能超过9张")
|
||||
}
|
||||
now := time.Now()
|
||||
doc := &feedbackmod.Feedback{
|
||||
UserId: userId,
|
||||
FeedbackType: req.Type,
|
||||
Content: content,
|
||||
Screenshots: screenshots,
|
||||
Contact: contact,
|
||||
Status: 0,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
if err := feedbackmod.InsertOneFeedback(ctx, doc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &proto.FeedbackResp{Message: feedbackSubmitMessage}, nil
|
||||
}
|
||||
|
||||
func isValidFeedbackType(feedbackType int32) bool {
|
||||
return feedbackType >= FeedbackTypeFeature && feedbackType <= FeedbackTypeOther
|
||||
}
|
||||
|
||||
func normalizeScreenshots(rawScreenshots []string) []string {
|
||||
screenshots := make([]string, 0, len(rawScreenshots))
|
||||
for _, screenshot := range rawScreenshots {
|
||||
screenshot = strings.TrimSpace(screenshot)
|
||||
if screenshot != "" {
|
||||
screenshots = append(screenshots, screenshot)
|
||||
}
|
||||
}
|
||||
return screenshots
|
||||
}
|
||||
Reference in New Issue
Block a user