예제 #1
0
파일: topic.go 프로젝트: yonglehou/ohlala
// 保持topic到数据库,同时建立topic与link的关系表
// 如果topic已经存在,则直接建立与link的关联
// 全部成功则返回true
func Topic_SaveTopics(topics string, linkId int64) bool {
	if topics == "" {
		return true
	}
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	success := true
	topicList := strings.Split(topics, ",")
	for _, topic := range topicList {
		topicLower := strings.ToLower(topic)
		t := new(Topic)
		err := db.GetStruct(t, "`name_lower`=?", topic)
		if err != nil {
			goku.Logger().Logln(topic)
			goku.Logger().Errorln(err.Error())
			success = false
			continue
		}
		if t.Id < 1 {
			t.Name = topic
			t.NameLower = topicLower
			_, err = db.InsertStruct(t)
			if err != nil {
				goku.Logger().Errorln(err.Error())
				success = false
				continue
			}
		}
		if t.Id > 0 && linkId > 0 {
			_, err = db.Insert("topic_link", map[string]interface{}{"topic_id": t.Id, "link_id": linkId})
			if err != nil {
				goku.Logger().Errorln(err.Error())
				success = false
			} else {
				// 成功,更新话题的链接数量统计
				Topic_IncCount(db, t.Id, "link_count", 1)

				redisClient := GetRedis()
				defer redisClient.Quit()
				// 加入推送队列
				// 格式: pushtype,topicid,linkid,timestamp
				qv := fmt.Sprintf("%v,%v,%v,%v", LinkForUser_ByTopic, t.Id, linkId, time.Now().Unix())
				_, err = redisClient.Lpush(golink.KEY_LIST_PUSH_TO_USER, qv)
				if err != nil {
					goku.Logger().Errorln(err.Error())
				}
			}
		}
	}
	return success
}
예제 #2
0
파일: invite.go 프로젝트: cloudcache/ohlala
//保存一个邀请
func saveRegisterInvite(userId int64, toEmail string, db *goku.MysqlDB) (string, error) {
	if userId <= int64(0) || toEmail == "" {
		return "", errors.New("用户id不合法")
	}

	invite := new(RegisterInvite)
	invite.Guid = utils.GeneticKey()
	invite.UserId = userId
	invite.ToEmail = toEmail
	invite.IsRegister = false
	invite.ExpiredDate = time.Now().AddDate(0, 0, golink.Register_Invite_Expired_Day)
	invite.IsSend = false
	invite.FailCount = 0
	_, err := db.InsertStruct(invite)

	return invite.Guid, err
}
예제 #3
0
파일: invite.go 프로젝트: cloudcache/ohlala
//获取一个邀请码(非邮件邀请方式,可能是通过qq和微薄发送)
func CreateRegisterInviteWithoutEmail(userId int64) (string, error) {
	if userId <= int64(0) {
		return "", errors.New("用户id不合法")
	}

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

	invite := new(RegisterInvite)
	invite.Guid = utils.GeneticKey()
	invite.UserId = userId
	invite.ToEmail = ""
	invite.IsRegister = false
	invite.ExpiredDate = time.Now().AddDate(0, 0, golink.Register_Invite_Expired_Day)
	invite.IsSend = true
	invite.FailCount = 0
	_, err := db.InsertStruct(invite)

	return invite.Guid, err
}