MCPcopy Index your code
hub / github.com/TruthHun/DocHub / Comment

Method Comment

controllers/HomeControllers/ViewController.go:119–163  ·  view source on GitHub ↗

文档评论

()

Source from the content-addressed store, hash-verified

117
118//文档评论
119func (this *ViewController) Comment() {
120 id, _ := this.GetInt(":id")
121 score, _ := this.GetInt("Score")
122 answer := this.GetString("Answer")
123 if answer != this.Sys.Answer {
124 this.ResponseJson(false, "请输入正确的答案")
125 }
126 if id > 0 {
127 if this.IsLogin > 0 {
128 if score < 1 || score > 5 {
129 this.ResponseJson(false, "请给文档评分")
130 } else {
131 comment := models.DocumentComment{
132 Uid: this.IsLogin,
133 Did: id,
134 Content: this.GetString("Comment"),
135 TimeCreate: int(time.Now().Unix()),
136 Status: true,
137 Score: score * 10000,
138 }
139 cnt := strings.Count(comment.Content, "") - 1
140 if cnt > 255 || cnt < 8 {
141 this.ResponseJson(false, "评论内容限8-255个字符")
142 } else {
143 _, err := orm.NewOrm().Insert(&comment)
144 if err != nil {
145 this.ResponseJson(false, "发表评论失败:每人仅限给每个文档点评一次")
146 } else {
147 //文档评论人数增加
148 sql := fmt.Sprintf("UPDATE `%v` SET `Score`=(`Score`*`ScorePeople`+%v)/(`ScorePeople`+1),`ScorePeople`=`ScorePeople`+1 WHERE Id=%v", models.GetTableDocumentInfo(), comment.Score, comment.Did)
149 _, err := orm.NewOrm().Raw(sql).Exec()
150 if err != nil {
151 helper.Logger.Error(err.Error())
152 }
153 this.ResponseJson(true, "恭喜您,评论发表成功")
154 }
155 }
156 }
157 } else {
158 this.ResponseJson(false, "评论失败,您当前处于未登录状态,请先登录")
159 }
160 } else {
161 this.ResponseJson(false, "评论失败,参数不正确")
162 }
163}
164
165//获取评论列表
166func (this *ViewController) GetComment() {

Callers

nothing calls this directly

Calls 3

CountMethod · 0.80
InsertMethod · 0.80
ResponseJsonMethod · 0.45

Tested by

no test coverage detected