本文整理匯總了Golang中Model.NewUserActive函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewUserActive函數的具體用法?Golang NewUserActive怎麽用?Golang NewUserActive使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewUserActive函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CreateUser
func CreateUser(form url.Values) (errMsg string, err error) {
// 存用戶基本信息,產生自增長UID
user := model.NewUser()
err = util.ConvertAssign(user, form)
if err != nil {
logger.Errorln("user ConvertAssign error", err)
errMsg = err.Error()
return
}
uid, err := user.Insert()
if err != nil {
errMsg = "內部服務器錯誤"
logger.Errorln(errMsg, ":", err)
return
}
// 存用戶登錄信息
userLogin := model.NewUserLogin()
err = util.ConvertAssign(userLogin, form)
if err != nil {
errMsg = err.Error()
logger.Errorln("CreateUser error:", err)
return
}
userLogin.Uid = uid
_, err = userLogin.Insert()
if err != nil {
errMsg = "內部服務器錯誤"
logger.Errorln(errMsg, ":", err)
return
}
// 存用戶角色信息
userRole := model.NewUserRole()
// 默認為初級會員
roleId := model.AllRoleId[len(model.AllRoleId)-1]
if form.Get("roleid") != "" {
tmpId, err := strconv.Atoi(form.Get("roleid"))
if err == nil {
roleId = tmpId
}
}
userRole.Roleid = roleId
userRole.Uid = uid
if _, err = userRole.Insert(); err != nil {
logger.Errorln("userRole insert Error:", err)
}
// 存用戶活躍信息,初始活躍+2
userActive := model.NewUserActive()
userActive.Uid = uid
userActive.Username = user.Username
userActive.Email = user.Email
userActive.Weight = 2
if _, err = userActive.Insert(); err != nil {
logger.Errorln("UserActive insert Error:", err)
}
return
}
示例2: FindActiveUsers
// 獲得活躍用戶
func FindActiveUsers(start, num int) []*model.UserActive {
activeUsers, err := model.NewUserActive().Order("weight DESC").Limit(strconv.Itoa(start) + "," + strconv.Itoa(num)).FindAll()
if err != nil {
logger.Errorln("user service FindActiveUsers error:", err)
return nil
}
return activeUsers
}
示例3: ChangeAvatar
// 更換頭像
func ChangeAvatar(uid int, avatar string) (err error) {
err = model.NewUser().Set("avatar=?", avatar).Where("uid=?", uid).Update()
if err == nil {
err = model.NewUserActive().Set("avatar=?", avatar).Where("uid=?", uid).Update()
}
return
}
示例4: DecrUserWeight
func DecrUserWeight(where string, divide int) {
if divide <= 0 {
return
}
strSql := "UPDATE user_active SET weight=weight/" + strconv.Itoa(divide) + " WHERE " + where
if result, err := model.NewUserActive().Exec(strSql); err != nil {
logger.Errorln("UserActive update Error:", err)
} else {
n, _ := result.RowsAffected()
logger.Debugln(strSql, "affected num:", n)
}
}
示例5: GetUserMentions
// 獲取 @ 的 suggest 列表
func GetUserMentions(term string, limit int) []map[string]string {
term = "%" + term + "%"
userActives, err := model.NewUserActive().Where("username like ?", term).Limit(strconv.Itoa(limit)).Order("mtime DESC").FindAll("email", "username", "avatar")
if err != nil {
logger.Errorln("user service GetUserMentions Error:", err)
return nil
}
users := make([]map[string]string, len(userActives))
for i, userActive := range userActives {
user := make(map[string]string, 2)
user["username"] = userActive.Username
user["avatar"] = util.Gravatar(userActive.Avatar, userActive.Email, 20)
users[i] = user
}
return users
}
示例6: IncUserWeight
// 增加或減少用戶活躍度
func IncUserWeight(where string, weight int) {
if err := model.NewUserActive().Where(where).Increment("weight", weight); err != nil {
logger.Errorln("UserActive update Error:", err)
}
}
示例7: CreateUser
func CreateUser(form url.Values) (errMsg string, err error) {
if EmailExists(form.Get("email")) {
err = errors.New("該郵箱已注冊過")
return
}
if UsernameExists(form.Get("username")) {
err = errors.New("用戶名已存在")
return
}
// 存用戶基本信息,產生自增長UID
user := model.NewUser()
err = util.ConvertAssign(user, form)
if err != nil {
logger.Errorln("user ConvertAssign error", err)
errMsg = err.Error()
return
}
user.Ctime = util.TimeNow()
// 隨機給一個默認頭像
user.Avatar = DefaultAvatars[rand.Intn(len(DefaultAvatars))]
uid, err := user.Insert()
if err != nil {
errMsg = "內部服務器錯誤"
logger.Errorln(errMsg, ":", err)
return
}
// 存用戶登錄信息
userLogin := model.NewUserLogin()
err = util.ConvertAssign(userLogin, form)
if err != nil {
errMsg = err.Error()
logger.Errorln("CreateUser error:", err)
return
}
userLogin.Uid = uid
_, err = userLogin.Insert()
if err != nil {
errMsg = "內部服務器錯誤"
logger.Errorln(errMsg, ":", err)
return
}
// 存用戶角色信息
userRole := model.NewUserRole()
// 默認為初級會員
userRole.Roleid = Roles[len(Roles)-1].Roleid
userRole.Uid = uid
if _, err = userRole.Insert(); err != nil {
logger.Errorln("userRole insert Error:", err)
}
// 存用戶活躍信息,初始活躍+2
userActive := model.NewUserActive()
userActive.Uid = uid
userActive.Username = user.Username
userActive.Avatar = user.Avatar
userActive.Email = user.Email
userActive.Weight = 2
if _, err = userActive.Insert(); err != nil {
logger.Errorln("UserActive insert Error:", err)
}
return
}