198 Star 566 Fork 255

lock-li/opms

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
commentLaud.go 2.43 KB
一键复制 编辑 原始数据 按行查看 历史
www 提交于 2016-10-31 21:48 +08:00 . new version 1.2 for notice,check work etc.
package albums
import (
"fmt"
"opms/controllers"
. "opms/models/albums"
. "opms/models/messages"
"opms/utils"
)
type AddCommentController struct {
controllers.BaseController
}
func (this *AddCommentController) Post() {
albumid, _ := this.GetInt64("albumid")
if albumid <= 0 {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "参数出错"}
this.ServeJSON()
return
}
content := this.GetString("comment")
if "" == content {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "请填写评论内容"}
this.ServeJSON()
return
}
var err error
var comment AlbumsComment
comment.Id = utils.SnowFlakeId()
comment.Userid = this.BaseController.UserUserId
comment.Albumid = albumid
comment.Content = content
err = AddAlbumComment(comment)
if err == nil {
//消息通知
album, _ := GetAlbum(albumid)
var msg Messages
msg.Id = utils.SnowFlakeId()
msg.Userid = this.BaseController.UserUserId
msg.Touserid = album.Userid
msg.Type = 1
msg.Subtype = 12
msg.Title = album.Title
msg.Url = "/album/" + fmt.Sprintf("%d", albumid)
AddMessages(msg)
this.Data["json"] = map[string]interface{}{"code": 1, "message": "评价添加成功"}
} else {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "添加失败"}
}
this.ServeJSON()
}
type AjaxLaudController struct {
controllers.BaseController
}
func (this *AjaxLaudController) Post() {
albumid, _ := this.GetInt64("albumid")
if albumid <= 0 {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "参数出错"}
this.ServeJSON()
return
}
laudexit, _ := GetAlbumLaud(albumid)
if laudexit.Userid == this.BaseController.UserUserId {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "已经点过赞"}
this.ServeJSON()
}
var err error
var laud AlbumsLaud
laud.Id = utils.SnowFlakeId()
laud.Userid = this.BaseController.UserUserId
laud.Albumid = albumid
err = AddAlbumLaud(laud)
if err == nil {
//消息通知
album, _ := GetAlbum(albumid)
var msg Messages
msg.Id = utils.SnowFlakeId()
msg.Userid = this.BaseController.UserUserId
msg.Touserid = album.Userid
msg.Type = 2
msg.Subtype = 22
msg.Title = album.Title
msg.Url = "/album/" + fmt.Sprintf("%d", albumid)
AddMessages(msg)
this.Data["json"] = map[string]interface{}{"code": 1, "message": "点赞成功"}
} else {
this.Data["json"] = map[string]interface{}{"code": 0, "message": "点赞失败"}
}
this.ServeJSON()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/lock-upme/opms.git
git@gitee.com:lock-upme/opms.git
lock-upme
opms
opms
558463a10cc0

搜索帮助