Browse Source

统计博客的评论和收藏

layui
yirenyishi 6 years ago
parent
commit
9a197a41ad
  1. 4
      README.md
  2. 4
      controllers/CommentController.go
  3. 4
      controllers/LikeController.go
  4. 6
      service/UserService.go
  5. 2
      static/css/us.css
  6. 8
      views/index.html
  7. 6
      views/us.html

4
README.md

@ -6,6 +6,4 @@
* go get github.com/go-sql-driver/mysql * go get github.com/go-sql-driver/mysql
* go get github.com/mattn/go-sqlite3 * go get github.com/olivere/elastic
* go get github.com/Unknwon/com

4
controllers/CommentController.go

@ -46,7 +46,7 @@ func (this *CommentController) Save() {
this.Data["json"] = models.ReurnError(500, "保存失败") this.Data["json"] = models.ReurnError(500, "保存失败")
} }
this.ServeJSON() this.ServeJSON()
service.CountComments(uid.(int64)) service.CountComments(uid.(int64),blogId)
return return
} }
@ -78,6 +78,6 @@ func (this *CommentController) Del() {
this.Data["json"] = models.ReurnError(500, "保存失败") this.Data["json"] = models.ReurnError(500, "保存失败")
} }
this.ServeJSON() this.ServeJSON()
service.CountComments(uid.(int64)) service.CountComments(uid.(int64),id)
return return
} }

4
controllers/LikeController.go

@ -27,7 +27,7 @@ func (this *LikeController) Save() {
this.Data["json"] = models.ReurnSuccess("") this.Data["json"] = models.ReurnSuccess("")
} }
this.ServeJSON() this.ServeJSON()
service.CountLike(uid.(int64)) service.CountLike(uid.(int64),id)
return return
} }
@ -47,6 +47,6 @@ func (this *LikeController) Delete() {
this.Data["json"] = models.ReurnSuccess("") this.Data["json"] = models.ReurnSuccess("")
} }
this.ServeJSON() this.ServeJSON()
service.CountLike(uid.(int64)) service.CountLike(uid.(int64),id)
return return
} }

6
service/UserService.go

@ -53,16 +53,18 @@ func CountBrows(uid int64) {
o.Raw("UPDATE `auth_user` SET `blog_browes` = (select SUM(browses) browses from blog where user_id = ?) WHERE `id` = ? ", uid, uid).QueryRow(&browses) //获取总条数 o.Raw("UPDATE `auth_user` SET `blog_browes` = (select SUM(browses) browses from blog where user_id = ?) WHERE `id` = ? ", uid, uid).QueryRow(&browses) //获取总条数
return return
} }
func CountComments(uid int64) { func CountComments(uid int64,bid int64) {
o := orm.NewOrm() o := orm.NewOrm()
browses := 0 browses := 0
o.Raw("UPDATE `auth_user` SET `blog_comment` = (select count(id) num from comment where cuser_id = ?) WHERE `id` = ? ", uid, uid).QueryRow(&browses) //获取总条数 o.Raw("UPDATE `auth_user` SET `blog_comment` = (select count(id) num from comment where cuser_id = ?) WHERE `id` = ? ", uid, uid).QueryRow(&browses) //获取总条数
o.Raw("UPDATE `blog` SET `comments` = (select count(id) num from comment where blog_id = ?) WHERE `id` = ? ", bid, bid).QueryRow(&browses) //获取总条数
return return
} }
func CountLike(uid int64) { func CountLike(uid int64,bid int64) {
o := orm.NewOrm() o := orm.NewOrm()
browses := 0 browses := 0
o.Raw("UPDATE `auth_user` SET `blog_like` = (select count(id) num from tb_like where user_id = ?) WHERE `id` = ?", uid, uid).QueryRow(&browses) o.Raw("UPDATE `auth_user` SET `blog_like` = (select count(id) num from tb_like where user_id = ?) WHERE `id` = ?", uid, uid).QueryRow(&browses)
o.Raw("UPDATE `blog` SET `likes` = (select count(id) num from tb_like where blog_id = ?) WHERE `id` = ?", bid, bid).QueryRow(&browses)
return return
} }

2
static/css/us.css

@ -4,6 +4,6 @@ a {
.us-root{ .us-root{
display: flex; display: flex;
margin: 0 5%; margin-left: 5%;
font-size: 16px; font-size: 16px;
} }

8
views/index.html

@ -15,13 +15,13 @@
<div style="flex: 1"> <div style="flex: 1">
<h5>最新发布</h5> <h5>最新发布</h5>
{{range .TimeBlog}} {{range .TimeBlog}}
<p><a href="/blog/{{.Id}}">{{.Title}}</a></p> <p><a href="/blog/{{.Id}}" target="_blank">{{.Title}}</a></p>
{{end}} {{end}}
</div> </div>
<div style="flex: 1"> <div style="flex: 1">
<h5>流量王者</h5> <h5>流量王者</h5>
{{range .BrowsBlog}} {{range .BrowsBlog}}
<p><a href="/blog/{{.Id}}">{{.Title}}</a></p> <p><a href="/blog/{{.Id}}" target="_blank">{{.Title}}</a></p>
{{end}} {{end}}
</div> </div>
</div> </div>
@ -29,13 +29,13 @@
<div style="flex: 1"> <div style="flex: 1">
<h5>收藏排行</h5> <h5>收藏排行</h5>
{{range .LikeBlog}} {{range .LikeBlog}}
<p><a href="/blog/{{.Id}}">{{.Title}}</a></p> <p><a href="/blog/{{.Id}}" target="_blank">{{.Title}}</a></p>
{{end}} {{end}}
</div> </div>
<div style="flex: 1"> <div style="flex: 1">
<h5>人气最旺</h5> <h5>人气最旺</h5>
{{range .CommBlog}} {{range .CommBlog}}
<p><a href="/blog/{{.Id}}">{{.Title}}</a></p> <p><a href="/blog/{{.Id}}" target="_blank">{{.Title}}</a></p>
{{end}} {{end}}
</div> </div>
</div> </div>

6
views/us.html

@ -10,7 +10,7 @@
<p>个人随笔2.0(golang)版本正式上线</p> <p>个人随笔2.0(golang)版本正式上线</p>
</div> </div>
<div class="us-root"> <div class="us-root">
<div style="width: 620px"> <div style="width: 450px">
<p>·项目源码: <a href="https://git.coding.net/yirenyishi/beeblog.git" target="_blank">点击查看</a></p> <p>·项目源码: <a href="https://git.coding.net/yirenyishi/beeblog.git" target="_blank">点击查看</a></p>
<p>·项目框架: </p> <p>·项目框架: </p>
<div style="margin-left: 15px"> <div style="margin-left: 15px">
@ -29,8 +29,8 @@
</div> </div>
</div> </div>
<div style="flex: 1"> <div style="flex: 1">
<img src="/static/img/alipay.png" alt="" width="350"> <img src="/static/img/alipay.png" alt="" width="320">
<img src="/static/img/weixin.png" alt="" width="350"> <img src="/static/img/weixin.png" alt="" width="320">
</div> </div>
</div> </div>
<div style="margin-top: 30px"> <div style="margin-top: 30px">

Loading…
Cancel
Save