Exemple #1
0
// 减少DB操作
// @t: 推送类型, 1:关注的用户, 2:关注的话题
func linkForUser_AddWithDb(db *goku.MysqlDB, userId, linkId int64, t int) error {
	m := map[string]interface{}{
		"user_id":     userId,
		"link_id":     linkId,
		"create_time": time.Now(),
	}
	if t == 1 {
		m["user_count"] = 1
	} else {
		m["topic_count"] = 1
	}

	_, err := db.Insert(LinkForUser_TableName(userId), m)
	if err != nil {
		if strings.Index(err.Error(), "Duplicate entry") > -1 {
			m := map[string]interface{}{}
			if t == 1 {
				m["user_count"] = 1
			} else {
				m["topic_count"] = 1
			}
			_, err = db.Update(LinkForUser_TableName(userId), m, "user_id=? and link_id=?", userId, linkId)
			if err != nil {
				goku.Logger().Errorln(err.Error())
			}
		} else {
			goku.Logger().Errorln(err.Error())
		}
	}
	return err
}
Exemple #2
0
func (ur *UserRecovery) Update() (sql.Result, error) {
	m := make(map[string]interface{})
	m["active"] = ur.Active
	m["recovery_time"] = ur.RecoveryTime

	var db *goku.MysqlDB = GetDB()
	defer db.Close()
	r, err := db.Update("user_recovery", m, "`user_id`=? AND `token`=?", ur.UserId, ur.Token)
	return r, err
}
Exemple #3
0
// 更新话题的图片地址(只存相对路径)
func Topic_UpdatePic(id int64, pic string) (sql.Result, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	m := map[string]interface{}{"pic": pic}
	r, err := db.Update("topic", m, "id=?", id)
	if err != nil {
		goku.Logger().Errorln(err.Error())
	}
	return r, err
}
func (u *ThirdPartyUser) Update() (sql.Result, error) {
	m := make(map[string]interface{})
	m["third_party_email"] = u.ThirdPartyEmail
	m["access_token"] = u.AccessToken
	m["refresh_token"] = u.RefreshToken
	m["token_expire_time"] = u.TokenExpireTime
	m["create_time"] = u.CreateTime
	m["last_active_time"] = u.LastActiveTime
	m["avatar_url"] = u.AvatarUrl
	m["link"] = u.Link

	var db *goku.MysqlDB = GetDB()
	defer db.Close()
	r, err := db.Update("third_party_user", m, "`user_id`=? AND `third_party`=?", u.UserId, u.ThirdParty)
	return r, err
}
Exemple #5
0
// 更新用户已读的关注好友的最新链接的最大的链接id
func NewestLinkUnread_UpdateForUser(userId, lastReadLinkId int64) error {
	if userId < 1 || lastReadLinkId < 1 {
		return nil
	}

	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	m := map[string]interface{}{
		"last_read_friend_link_id": lastReadLinkId,
	}
	_, err := db.Update(Table_User, m, "id=?", userId)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return err
	}
	return nil
}
Exemple #6
0
// 更改话题的名称。
// 只能改变大写小,不能修改名称。
func Topic_UpdateName(id int64, name string) (r sql.Result, err error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	topic, err := Topic_GetByName(name)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return
	}
	if topic == nil || topic.Id != id {
		err = errors.New("不能改变话题的名称,只能更改大小写。")
		return
	}

	m := map[string]interface{}{"name": name}
	r, err = db.Update("topic", m, "id=?", id)
	if err != nil {
		goku.Logger().Errorln(err.Error())
	}
	return r, err
}
Exemple #7
0
func User_Update(id int64, m map[string]interface{}) (sql.Result, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()
	r, err := db.Update("user", m, "id=?", id)
	return r, err
}