码农笔录博客源码
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

78 lignes
2.1 KiB

package service
import (
"github.com/astaxie/beego/orm"
"beeblog/models"
)
type UserService struct {
}
il y a 6 ans
func GetUser(id int64) (*models.User, error) {
il y a 6 ans
o := orm.NewOrm()
il y a 6 ans
user := &models.User{Id: id}
il y a 6 ans
err := o.Read(user)
il y a 6 ans
return user, err
il y a 6 ans
}
func FindByUserName(username string) (*models.User, error) {
o := orm.NewOrm()
qs := o.QueryTable(&models.User{})
var users []*models.User
_, err := qs.Filter("UserName", username).All(&users)
if err != nil {
return nil, err
}
if len(users) != 0 {
return users[0], nil
}
return nil, nil
}
func SaveUser(user *models.User) error {
o := orm.NewOrm()
id, eror := o.Insert(user)
if eror != nil {
return eror
} else {
user.Id = id
o.Commit()
}
return nil
}
func CountBlog(uid int64) {
o := orm.NewOrm()
il y a 6 ans
browses := 0
il y a 6 ans
o.Raw("UPDATE `auth_user` SET `blog_count` = (SELECT count(id) num FROM blog where delflag = 0 and user_id =? ) WHERE `id` = ? ", uid, uid).QueryRow(&browses)
return
}
il y a 6 ans
func CountBrows(uid int64) {
o := orm.NewOrm()
browses := 0
il y a 6 ans
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 CountComments(uid int64,bid int64) {
il y a 6 ans
o := orm.NewOrm()
browses := 0
il y a 6 ans
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) //获取总条数
il y a 6 ans
return
}
func CountLike(uid int64,bid int64) {
il y a 6 ans
o := orm.NewOrm()
browses := 0
il y a 6 ans
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)
il y a 6 ans
return
}
il y a 6 ans
il y a 6 ans
func EditUser(user *models.User) (int64, error) {
il y a 6 ans
return orm.NewOrm().Update(user)
}
il y a 6 ans
func EditHeadImg(user *models.User) (int64, error) {
return orm.NewOrm().Update(user,"Headimg")
}