Browse Source

升级beego V2

master
燕鹏 4 years ago
parent
commit
170d97145d
  1. 4
      controllers/BlogController.go
  2. 2
      controllers/CatController.go
  3. 6
      controllers/CommentController.go
  4. 31
      controllers/FileController.go
  5. 2
      controllers/IndexController.go
  6. 14
      controllers/LikeController.go
  7. 2
      controllers/MapController.go
  8. 2
      controllers/NoteController.go
  9. 5
      controllers/PageController.go
  10. 2
      controllers/UPageController.go
  11. 12
      controllers/UserController.go
  12. 8
      filter/Security.go
  13. 6
      go.mod
  14. 14
      main.go
  15. 15
      mcontrollers/MBlogController.go
  16. 29
      models/DataInit.go
  17. 2
      routers/BlogRouter.go
  18. 2
      routers/CatRouter.go
  19. 2
      routers/CommentRouter.go
  20. 2
      routers/LikeRouter.go
  21. 2
      routers/MBlogRouter.go
  22. 2
      routers/NoteRouter.go
  23. 2
      routers/UPageRouter.go
  24. 2
      routers/UserRouter.go
  25. 10
      routers/router.go
  26. 20
      service/BlogService.go
  27. 2
      service/CategoryService.go
  28. 10
      service/CommentService.go
  29. 4
      service/LikeService.go
  30. 2
      service/NoteService.go
  31. 9
      service/UserService.go
  32. 2
      utils/EsUtil.go

4
controllers/BlogController.go

@ -4,7 +4,7 @@ import (
"beeblog/models"
"beeblog/service"
"beeblog/utils"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
"strconv"
"time"
)
@ -51,7 +51,7 @@ func (this *BlogController) Save() {
catory := this.GetString("catory")
catoryId, _ := strconv.ParseInt(catory, 10, 64)
labels := this.GetStrings("labels[]")
blog := &models.Blog{Title: title, BlogHtml: blogHtml, BlogValue: blogValue,CategoryId: catoryId, UserId: uid.(int64), BlogDesc: blogDesc}
blog := &models.Blog{Title: title, BlogHtml: blogHtml, BlogValue: blogValue, CategoryId: catoryId, UserId: uid.(int64), BlogDesc: blogDesc}
err := blogService.SaveBlog(blog, labels)
if err == nil {
this.Data["json"] = models.ReurnData("", blog.Id)

2
controllers/CatController.go

@ -3,7 +3,7 @@ package controllers
import (
"beeblog/models"
"beeblog/service"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
)
type CatController struct {

6
controllers/CommentController.go

@ -1,9 +1,9 @@
package controllers
import (
"github.com/astaxie/beego"
"beeblog/models"
"beeblog/service"
beego "github.com/beego/beego/v2/server/web"
"strconv"
)
@ -49,7 +49,7 @@ func (this *CommentController) Save() {
this.Data["json"] = models.ReurnError(500, "保存失败")
}
this.ServeJSON()
userService.CountComments(uid.(int64),blogId)
userService.CountComments(uid.(int64), blogId)
return
}
@ -83,6 +83,6 @@ func (this *CommentController) Del() {
this.Data["json"] = models.ReurnError(500, "保存失败")
}
this.ServeJSON()
userService.CountComments(uid.(int64),id)
userService.CountComments(uid.(int64), id)
return
}

31
controllers/FileController.go

@ -1,15 +1,16 @@
package controllers
import (
"github.com/astaxie/beego"
"path"
"time"
"os"
"fmt"
"crypto/md5"
"math/rand"
"beeblog/models"
"beeblog/service"
"crypto/md5"
"fmt"
"github.com/beego/beego/v2/core/config"
beego "github.com/beego/beego/v2/server/web"
"math/rand"
"os"
"path"
"time"
)
type FileController struct {
@ -45,7 +46,8 @@ func (this *FileController) Upload() {
}
//创建目录
urlDir := time.Now().Format("2006/01/02/")
uploadDir := beego.AppConfig.String("uploadDir") + urlDir
uploadDir, _ := config.String("uploadDir")
uploadDir = uploadDir + urlDir
err := os.MkdirAll(uploadDir, 777)
if err != nil {
this.Data["json"] = models.ReurnError(500, "")
@ -55,7 +57,7 @@ func (this *FileController) Upload() {
//构造文件名称
rand.Seed(time.Now().UnixNano())
randNum := fmt.Sprintf("%d", rand.Intn(9999)+1000)
hashName := md5.Sum([]byte( time.Now().Format("2006_01_02_15_04_05_") + randNum ))
hashName := md5.Sum([]byte(time.Now().Format("2006_01_02_15_04_05_") + randNum))
fileName := fmt.Sprintf("%x", hashName) + ext
fpath := uploadDir + fileName
urlDir += fileName
@ -67,7 +69,8 @@ func (this *FileController) Upload() {
this.ServeJSON()
return
}
urlDir = beego.AppConfig.String("imgUrlPrefix") + urlDir
imgUrlPrefix, _ := config.String("imgUrlPrefix")
urlDir = imgUrlPrefix + urlDir
this.Data["json"] = models.ReurnData("", urlDir)
this.ServeJSON()
return
@ -106,7 +109,8 @@ func (this *FileController) HeadImgUpload() {
}
//创建目录
urlDir := time.Now().Format("2006/01/02/")
uploadDir := beego.AppConfig.String("uploadDir") + urlDir
uploadDir, _ := config.String("uploadDir")
uploadDir = uploadDir + urlDir
err := os.MkdirAll(uploadDir, 777)
if err != nil {
this.Data["json"] = models.ReurnError(500, "")
@ -116,7 +120,7 @@ func (this *FileController) HeadImgUpload() {
//构造文件名称
rand.Seed(time.Now().UnixNano())
randNum := fmt.Sprintf("%d", rand.Intn(9999)+1000)
hashName := md5.Sum([]byte( time.Now().Format("2006_01_02_15_04_05_") + randNum ))
hashName := md5.Sum([]byte(time.Now().Format("2006_01_02_15_04_05_") + randNum))
fileName := fmt.Sprintf("%x", hashName) + ext
fpath := uploadDir + fileName
urlDir += fileName
@ -128,7 +132,8 @@ func (this *FileController) HeadImgUpload() {
this.ServeJSON()
return
}
urlDir = beego.AppConfig.String("imgUrlPrefix") + urlDir
imgUrlPrefix, _ := config.String("imgUrlPrefix")
urlDir = imgUrlPrefix + urlDir
user := &models.User{Id: uid.(int64), Headimg: urlDir}
userSerivce := service.UserService{}
if _, err = userSerivce.EditHeadImg(user); err != nil {

2
controllers/IndexController.go

@ -1,8 +1,8 @@
package controllers
import (
"github.com/astaxie/beego"
"beeblog/service"
beego "github.com/beego/beego/v2/server/web"
)
type IndexController struct {

14
controllers/LikeController.go

@ -1,10 +1,10 @@
package controllers
import (
"strconv"
"beeblog/service"
"github.com/astaxie/beego"
"beeblog/models"
"beeblog/service"
beego "github.com/beego/beego/v2/server/web"
"strconv"
)
type LikeController struct {
@ -25,11 +25,11 @@ func (this *LikeController) Save() {
like := &models.Like{BlogId: id, UserId: uid.(int64)}
if _, err := likeService.SaveLike(like); err != nil {
this.Data["json"] = models.ReurnError(500, "保存失败")
}else{
} else {
this.Data["json"] = models.ReurnSuccess("")
}
this.ServeJSON()
userService.CountLike(uid.(int64),id)
userService.CountLike(uid.(int64), id)
return
}
@ -47,10 +47,10 @@ func (this *LikeController) Delete() {
like := &models.Like{BlogId: id, UserId: uid.(int64)}
if _, err := likeService.DelLike(like); err != nil {
this.Data["json"] = models.ReurnError(500, "保存失败")
}else{
} else {
this.Data["json"] = models.ReurnSuccess("")
}
this.ServeJSON()
userService.CountLike(uid.(int64),id)
userService.CountLike(uid.(int64), id)
return
}

2
controllers/MapController.go

@ -1,6 +1,6 @@
package controllers
import "github.com/astaxie/beego"
import beego "github.com/beego/beego/v2/server/web"
type MapController struct {
beego.Controller

2
controllers/NoteController.go

@ -3,7 +3,7 @@ package controllers
import (
"beeblog/models"
"beeblog/service"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
"strconv"
)

5
controllers/PageController.go

@ -1,16 +1,15 @@
package controllers
import (
"github.com/astaxie/beego"
"beeblog/service"
"beeblog/models"
"beeblog/service"
beego "github.com/beego/beego/v2/server/web"
)
type PageController struct {
beego.Controller
}
func (this *PageController) IframeUser() {
userService := service.UserService{}
uid := this.GetSession("userid")

2
controllers/UPageController.go

@ -1,6 +1,6 @@
package controllers
import "github.com/astaxie/beego"
import beego "github.com/beego/beego/v2/server/web"
type UPageController struct {
beego.Controller

12
controllers/UserController.go

@ -1,14 +1,14 @@
package controllers
import (
"github.com/astaxie/beego"
"beeblog/service"
"beeblog/models"
"strings"
"beeblog/service"
"crypto/md5"
"time"
"strconv"
"encoding/hex"
beego "github.com/beego/beego/v2/server/web"
"strconv"
"strings"
"time"
)
type UserController struct {
@ -295,7 +295,7 @@ func (this *UserController) Regist() {
return
}
h := md5.New()
h.Write([]byte(strconv.FormatInt(time.Now().Unix(), 10) + beego.AppConfig.String("host")))
h.Write([]byte(strconv.FormatInt(time.Now().Unix(), 10) + "aiprose:nelson"))
salt := hex.EncodeToString(h.Sum(nil))
h = md5.New()
h.Write([]byte(userpwd + salt))

8
filter/Security.go

@ -1,10 +1,10 @@
package filter
import (
"github.com/astaxie/beego/context"
"github.com/astaxie/beego/logs"
"beeblog/models"
"encoding/json"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web/context"
)
var LogFilter = func(ctx *context.Context) {
@ -13,9 +13,9 @@ var LogFilter = func(ctx *context.Context) {
var FilterAdmin = func(ctx *context.Context) {
if ctx.Input.Session("userid") != nil {
ctx.Output.SetStatus(200)
ctx.Output.Header("Access-Control-Allow-Origin","*")
ctx.Output.Header("Access-Control-Allow-Origin", "*")
result := models.ReurnError(401, "")
if b,err := json.Marshal(result); err != nil {
if b, err := json.Marshal(result); err != nil {
ctx.Output.Body(b)
}
return

6
go.mod

@ -1,10 +1,10 @@
module beeblog
require (
github.com/astaxie/beego v1.12.0
github.com/beego/bee/v2 v2.0.2 // indirect
github.com/beego/beego/v2 v2.0.1
github.com/fortytw2/leaktest v1.3.0 // indirect
github.com/go-sql-driver/mysql v1.4.1
github.com/google/go-cmp v0.3.1 // indirect
github.com/go-sql-driver/mysql v1.5.0
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e // indirect
github.com/olivere/elastic v6.2.22+incompatible
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect

14
main.go

@ -4,10 +4,10 @@ import (
"beeblog/filter"
"beeblog/models"
_ "beeblog/routers"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
"github.com/astaxie/beego/plugins/cors"
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/logs"
beego "github.com/beego/beego/v2/server/web"
"github.com/beego/beego/v2/server/web/filter/cors"
)
func init() {
@ -17,8 +17,8 @@ func init() {
}
func main() {
orm.Debug = false
orm.RunSyncdb("default", false, true)
beego.AddFuncMap("NAdd",NAdd)
beego.AddFuncMap("NAdd", NAdd)
logs.SetLogger(logs.AdapterFile, `{"filename":"/opt/logs/aiprose.log","level":1}`)
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
@ -31,6 +31,6 @@ func main() {
beego.Run()
}
func NAdd(n1 int, n2 int) int{
func NAdd(n1 int, n2 int) int {
return n1 + n2
}

15
mcontrollers/MBlogController.go

@ -3,7 +3,7 @@ package mcontrollers
import (
"beeblog/models"
"beeblog/service"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
"strconv"
"time"
)
@ -12,7 +12,6 @@ type MBlogController struct {
beego.Controller
}
func (this *MBlogController) Get() {
blogService := service.BlogService{}
userService := service.UserService{}
@ -24,14 +23,13 @@ func (this *MBlogController) Get() {
this.ServeJSON()
return
}
this.Data["json"] = models.ReurnData("",blog)
this.Data["json"] = models.ReurnData("", blog)
this.ServeJSON()
userService.CountBrows(blog.UserId)
blogService.EditBlogBrows(id)
return
}
func (this *MBlogController) BlogsPage() {
blogService := service.BlogService{}
num, _ := this.GetInt("num")
@ -53,12 +51,11 @@ func (this *MBlogController) BlogsPage() {
this.ServeJSON()
return
}
this.Data["json"] = models.ReurnData("",pages)
this.Data["json"] = models.ReurnData("", pages)
this.ServeJSON()
return
}
func (this *MBlogController) EditPage() {
blogService := service.BlogService{}
uid := this.GetSession("userid")
@ -98,7 +95,7 @@ func (this *MBlogController) Save() {
blog := &models.Blog{Title: title, BlogHtml: blogHtml, CategoryId: catoryId, UserId: uid.(int64)}
err := blogService.SaveBlog(blog, labels)
if err == nil {
this.Data["json"] = models.ReurnData("",blog.Id)
this.Data["json"] = models.ReurnData("", blog.Id)
} else {
this.Data["json"] = models.ReurnError(500, "保存失败")
}
@ -116,13 +113,13 @@ func (this *MBlogController) Edit() {
this.ServeJSON()
return
}
id,_ := this.GetInt64("id")
id, _ := this.GetInt64("id")
title := this.GetString("title")
blogHtml := this.GetString("blogHtml")
catory := this.GetString("catory")
catoryId, _ := strconv.ParseInt(catory, 10, 64)
labels := this.GetStrings("labels[]")
blog,err :=blogService.GetBlog(id)
blog, err := blogService.GetBlog(id)
if err != nil {
this.Data["json"] = models.ReurnError(500, "保存失败")
this.ServeJSON()

29
models/DataInit.go

@ -1,29 +1,18 @@
package models
import (
"github.com/astaxie/beego"
//"github.com/Unknwon/com"
//"os"
//"path"
"github.com/astaxie/beego/orm"
//_ "github.com/mattn/go-sqlite3"
"fmt"
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/config"
_ "github.com/go-sql-driver/mysql"
)
const (
_DB_NAME = "data/beeblog.db"
_SQLITE3_DRIVER = "sqlite3"
)
func RegistDB() {
//if !com.IsExist(_DB_NAME){
// os.MkdirAll(path.Dir(_DB_NAME),os.ModePerm)
// os.Create(_DB_NAME)
//}
//orm.RegisterModel(new(Attachment),new(Topic))
//orm.RegisterDriver(_SQLITE3_DRIVER,orm.DRSqlite)
//orm.RegisterDataBase("default",_SQLITE3_DRIVER,_DB_NAME,10)
dbUrl, _ := config.String("dburl")
fmt.Println(dbUrl)
orm.RegisterDriver("mysql", orm.DRMySQL)
orm.RegisterDataBase("default", "mysql", "root:"+dbUrl+"/beeblog?charset=utf8&loc=Local")
orm.RegisterModel(new(User), new(Blog), new(NLabel), new(Note), new(NoteColl), new(Category), new(Like), new(Comment))
orm.RegisterDataBase("default", "mysql", "root:"+beego.AppConfig.String("dburl")+"/beeblog?charset=utf8&loc=Local", 30)
//orm.RunSyncdb("default", false, true)
}

2
routers/BlogRouter.go

@ -2,7 +2,7 @@ package routers
import (
"beeblog/controllers"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
)
func init() {

2
routers/CatRouter.go

@ -2,7 +2,7 @@ package routers
import (
"beeblog/controllers"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
)
func init() {

2
routers/CommentRouter.go

@ -1,8 +1,8 @@
package routers
import (
"github.com/astaxie/beego"
"beeblog/controllers"
beego "github.com/beego/beego/v2/server/web"
)
func init() {

2
routers/LikeRouter.go

@ -2,7 +2,7 @@ package routers
import (
"beeblog/controllers"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
)
func init() {

2
routers/MBlogRouter.go

@ -2,7 +2,7 @@ package routers
import (
"beeblog/mcontrollers"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
)
func init() {

2
routers/NoteRouter.go

@ -1,8 +1,8 @@
package routers
import (
"github.com/astaxie/beego"
"beeblog/controllers"
beego "github.com/beego/beego/v2/server/web"
)
func init() {

2
routers/UPageRouter.go

@ -2,7 +2,7 @@ package routers
import (
"beeblog/controllers"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
)
func init() {

2
routers/UserRouter.go

@ -2,7 +2,7 @@ package routers
import (
"beeblog/controllers"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
)
func init() {

10
routers/router.go

@ -2,16 +2,16 @@ package routers
import (
"beeblog/controllers"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
)
func init() {
beego.Router("/", &controllers.IndexController{})
beego.Router("/404", &controllers.PageController{},"get:PageNotFound")
beego.Router("/500", &controllers.PageController{},"get:ServerError")
beego.Router("/404", &controllers.PageController{}, "get:PageNotFound")
beego.Router("/500", &controllers.PageController{}, "get:ServerError")
beego.Router("/map", &controllers.MapController{})
beego.Router("/us", &controllers.PageController{},"get:UsPage")
beego.Router("/iframe/user", &controllers.PageController{},"get:IframeUser")
beego.Router("/us", &controllers.PageController{}, "get:UsPage")
beego.Router("/iframe/user", &controllers.PageController{}, "get:IframeUser")
beego.Router("/file/upload", &controllers.FileController{}, "post:Upload")
beego.Router("/himg/upload", &controllers.FileController{}, "post:HeadImgUpload")
//beego.Include(&controllers.PageController{})

20
service/BlogService.go

@ -1,9 +1,9 @@
package service
import (
"github.com/astaxie/beego/orm"
"beeblog/models"
"beeblog/utils"
"github.com/beego/beego/v2/client/orm"
)
type BlogService struct {
@ -133,7 +133,6 @@ func (this *BlogService) FindBlogs(num int, size int, cat int64, flag int) (*uti
return page, nil
}
func (this *BlogService) AllBlogs() ([]*models.Blog, error) {
var blogs []*models.Blog
@ -147,13 +146,12 @@ func (this *BlogService) AllBlogs() ([]*models.Blog, error) {
return blogs, nil
}
func (this *BlogService) SaveBlog(blog *models.Blog, strs []string) error {
o := orm.NewOrm()
o.Begin()
tx, _ := o.Begin()
id, eror := o.Insert(blog)
if eror != nil {
o.Rollback()
tx.Rollback()
return eror
} else {
blog.Id = id
@ -163,21 +161,21 @@ func (this *BlogService) SaveBlog(blog *models.Blog, strs []string) error {
nlabels[i] = &models.NLabel{Title: strs[i], BlogId: id, UserId: blog.UserId}
}
if _, err := o.InsertMulti(len(nlabels), nlabels); err != nil {
o.Rollback()
tx.Rollback()
return err
}
}
o.Commit()
tx.Commit()
}
return nil
}
func (this *BlogService) EditBlog(blog *models.Blog, strs []string) error {
o := orm.NewOrm()
o.Begin()
tx, _ := o.Begin()
_, eror := o.Update(blog)
if eror != nil {
o.Rollback()
tx.Rollback()
return eror
} else {
o.QueryTable(models.NLabel{}).Filter("BlogId", blog.Id).Delete()
@ -187,11 +185,11 @@ func (this *BlogService) EditBlog(blog *models.Blog, strs []string) error {
nlabels[i] = &models.NLabel{Title: strs[i], BlogId: blog.Id, UserId: blog.UserId}
}
if _, err := o.InsertMulti(len(nlabels), nlabels); err != nil {
o.Rollback()
tx.Rollback()
return err
}
}
o.Commit()
tx.Commit()
}
return nil
}

2
service/CategoryService.go

@ -1,8 +1,8 @@
package service
import (
"github.com/astaxie/beego/orm"
"beeblog/models"
"github.com/beego/beego/v2/client/orm"
)
type CategoryService struct {

10
service/CommentService.go

@ -2,8 +2,8 @@ package service
import (
"beeblog/models"
"github.com/astaxie/beego/orm"
"fmt"
"github.com/beego/beego/v2/client/orm"
)
type CommentService struct {
@ -12,7 +12,7 @@ type CommentService struct {
func (this *CommentService) FindCommentByBlog(bid int64) ([]*models.Comment, error) {
var comms []*models.Comment
o := orm.NewOrm()
_, err := o.QueryTable(&models.Comment{}).Filter("Pid", 0).Filter("BlogId",bid).OrderBy("-Ctime").All(&comms)
_, err := o.QueryTable(&models.Comment{}).Filter("Pid", 0).Filter("BlogId", bid).OrderBy("-Ctime").All(&comms)
if err != nil {
return nil, err
}
@ -21,9 +21,9 @@ func (this *CommentService) FindCommentByBlog(bid int64) ([]*models.Comment, err
var childs []*models.Comment
_, childerrr := o.QueryTable(&models.Comment{}).Filter("Pid", comms[i].Id).OrderBy("-Ctime").All(&childs)
if childerrr == nil {
if len(childs) > 0{
if len(childs) > 0 {
comms[i].Childs = childs
for j:=0 ; j<len(childs);j++{
for j := 0; j < len(childs); j++ {
cuser := &models.User{Id: childs[j].CuserId}
o.Read(cuser)
childs[j].CUser = cuser
@ -49,7 +49,7 @@ func (this *CommentService) SaveComment(comment *models.Comment) error {
cuser := &models.User{Id: comment.CuserId}
o.Read(cuser)
comment.CUser = cuser
if comment.BuserId !=0 {
if comment.BuserId != 0 {
buser := &models.User{Id: comment.BuserId}
o.Read(buser)
comment.BUser = buser

4
service/LikeService.go

@ -2,9 +2,9 @@ package service
import (
"beeblog/models"
"github.com/astaxie/beego/orm"
"fmt"
"beeblog/utils"
"fmt"
"github.com/beego/beego/v2/client/orm"
)
type LikeService struct {

2
service/NoteService.go

@ -2,8 +2,8 @@ package service
import (
"beeblog/models"
"github.com/astaxie/beego/orm"
"errors"
"github.com/beego/beego/v2/client/orm"
)
type NoteService struct {

9
service/UserService.go

@ -1,8 +1,8 @@
package service
import (
"github.com/astaxie/beego/orm"
"beeblog/models"
"github.com/beego/beego/v2/client/orm"
)
type UserService struct {
@ -36,7 +36,6 @@ func (this *UserService) SaveUser(user *models.User) error {
return eror
} else {
user.Id = id
o.Commit()
}
return nil
}
@ -53,14 +52,14 @@ func (this *UserService) 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) //获取总条数
return
}
func (this *UserService) CountComments(uid int64,bid int64) {
func (this *UserService) CountComments(uid int64, bid int64) {
o := orm.NewOrm()
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 `blog` SET `comments` = (select count(id) num from comment where blog_id = ?) WHERE `id` = ? ", bid, bid).QueryRow(&browses) //获取总条数
return
}
func (this *UserService) CountLike(uid int64,bid int64) {
func (this *UserService) CountLike(uid int64, bid int64) {
o := orm.NewOrm()
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)
@ -73,5 +72,5 @@ func (this *UserService) EditUser(user *models.User) (int64, error) {
}
func (this *UserService) EditHeadImg(user *models.User) (int64, error) {
return orm.NewOrm().Update(user,"Headimg")
return orm.NewOrm().Update(user, "Headimg")
}

2
utils/EsUtil.go

@ -13,7 +13,7 @@ import (
)
var client *elastic.Client
var host = "http://47.98.109.5:8209/"
var host = "http://49.235.160.131:6002/"
const mapping = `
{

Loading…
Cancel
Save