Example #1
0
// 检查 mUserId 与 sUserId 的关系,
// return:
//      @isFollower: sUserId是否关注mUserId
//      @isFollowed: mUserId是否关注sUserId
//      @isFriend: 是否互相关注
func User_CheckRelationship(mUserId, sUserId int64) (isFollower, isFollowed, isFriend bool) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	rows, err := db.Query("select * from `user_follow` where `user_id`=? and `follow_id`=? limit 1",
		mUserId, sUserId)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return
	}
	defer rows.Close()
	if rows.Next() {
		isFollowed = true
	}

	rows1, err1 := db.Query("select * from `user_follow` where `user_id`=? and `follow_id`=? limit 1",
		sUserId, mUserId)
	if err1 != nil {
		goku.Logger().Errorln(err1.Error())
		return
	}
	defer rows1.Close()
	if rows1.Next() {
		isFollower = true
	}

	if isFollowed && isFollower {
		isFriend = true
	}

	return
}
Example #2
0
func thirdPartyUser_SearchOneBy(criteria string, values ...interface{}) (u *ThirdPartyUser) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	sql := "SELECT `user_id`, `third_party`, `third_party_user_id`, `third_party_email`, `access_token`, `refresh_token`, `token_expire_time`, `create_time`, `last_active_time`, `avatar_url`, `link` FROM `third_party_user` WHERE " + criteria + " limit 1"
	thirdPartyUserRow, err := db.Query(sql, values...)
	if err != nil {
		return
	}
	if thirdPartyUserRow == nil {
		return
	}

	if thirdPartyUserRow.Next() {
		u = &ThirdPartyUser{}
		err = thirdPartyUserRow.Scan(
			&u.UserId, &u.ThirdParty, &u.ThirdPartyUserId, &u.ThirdPartyEmail,
			&u.AccessToken, &u.RefreshToken, &u.TokenExpireTime, &u.CreateTime, &u.LastActiveTime, &u.AvatarUrl, &u.Link)
	}

	if err != nil {
		u = nil
	}

	return
}
/**
 * 删除tui_link_for_handle已经处理的数据
 */
func delete_tui_link_for_handle(handleTime time.Time, db *goku.MysqlDB) error {

	sql := "DELETE FROM tui_link_for_handle WHERE `insert_time`<=? "
	_, err := db.Query(sql, handleTime)

	return err
}
Example #4
0
func Del_link_for_topic_all(db *goku.MysqlDB) error {

	err := del_link_for_topic_later_top("tui_link_for_topic_top", "reddit_score DESC,link_id DESC", db)
	if err == nil {
		err = del_link_for_topic_later_top("tui_link_for_topic_later", "link_id DESC", db)
	}
	if err == nil {
		_, err = db.Query(`DELETE FROM tui_link_for_topic_hot WHERE (time_type=2 AND create_time<?) OR (time_type=3 AND create_time<?) OR 
							(time_type=4 AND create_time<?) OR (time_type=5 AND create_time<?) OR 
			(time_type=6 AND create_time<?)`, utils.ThisHour(), utils.ThisDate(), utils.ThisWeek(), utils.ThisMonth(), utils.ThisYear())
		if err == nil {
			err = del_link_for_topic_hot_vote("tui_link_for_topic_hot", "dispute_score DESC,link_id DESC", db)
		}
	}
	if err == nil {
		_, err = db.Query(`DELETE FROM tui_link_for_topic_vote WHERE (time_type=2 AND create_time<?) OR (time_type=3 AND create_time<?) OR 
							(time_type=4 AND create_time<?) OR (time_type=5 AND create_time<?) OR 
			(time_type=6 AND create_time<?)`, utils.ThisHour(), utils.ThisDate(), utils.ThisWeek(), utils.ThisMonth(), utils.ThisYear())
		if err == nil {
			err = del_link_for_topic_hot_vote("tui_link_for_topic_vote", "vote DESC,link_id DESC", db)
		}
	}

	return err
}
Example #5
0
/**
 * 链接推送给话题(热议) 2:这个小时;3:今天;4:这周;5:这个月;6:今年
 */
func link_for_topic_hop_time(timeType int, handleTime time.Time, db *goku.MysqlDB) error {

	var t time.Time
	switch {
	case timeType == 2:
		t = utils.ThisHour()
	case timeType == 3:
		t = utils.ThisDate()
	case timeType == 4:
		t = utils.ThisWeek()
	case timeType == 5:
		t = utils.ThisMonth()
	case timeType == 6:
		t = utils.ThisYear()
	}

	sql := `INSERT ignore INTO tui_link_for_topic_hot(topic_id,link_id,create_time,dispute_score,time_type) 
		( 
		SELECT TL.topic_id,H.link_id,H.create_time,L.dispute_score,? AS time_type FROM tui_link_for_handle H 
		INNER JOIN topic_link TL ON H.insert_time<=? AND H.create_time>=? AND H.link_id=TL.link_id
		INNER JOIN link L ON L.id=H.link_id
		);`
	_, err := db.Query(sql, timeType, handleTime, t)

	return err
}
Example #6
0
//更新邀请码
func UpdateIsRegister(invite *RegisterInvite) {
	if !golink.Invite_Enabled {
		return
	}
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	db.Query("UPDATE `register_invite` SET `is_register`=1 WHERE `Guid`=?", invite.Guid)

}
Example #7
0
//根据用户关注的话题给它推荐相关的用户
func User_RecommendFromTopic(userId int64) ([]User, error) {
	iRecommendCount := 10
	var db *goku.MysqlDB = GetDB()
	db.Debug = true
	defer db.Close()

	sql := "SELECT `topic_id` FROM `topic_follow` WHERE `user_id`=? ORDER BY `create_time` DESC limit ?"
	topicRows, topicErr := db.Query(sql, userId, iRecommendCount)
	if topicErr != nil {
		return nil, topicErr
	}
	topicIds := make([]int64, 0)
	var topicId int64
	for topicRows.Next() {
		topicErr = topicRows.Scan(&topicId)
		if topicErr == nil {
			topicIds = append(topicIds, topicId)
		}
	}

	hashUsers := map[int64]int64{}
	users := make([]User, 0)
	tLen := len(topicIds)
	var uCount int
	uCount = iRecommendCount / tLen
	strUserIds := fmt.Sprintf("%d", userId)
	hashUsers[userId] = userId
	if tLen > 0 {
		sql = "SELECT u.`id`,u.`name`,u.`email`,u.`description`,u.`user_pic`,u.`friend_count`,u.`topic_count`,u.`ftopic_count`,u.`status`," +
			"u.`follower_count`,u.`link_count`,u.`create_time` FROM `tui_link_for_topic_top` tl INNER JOIN `link` l ON " +
			"tl.`topic_id`=? AND tl.`link_id`=l.`id` AND l.`user_id` NOT IN(?) " +
			"AND NOT EXISTS(SELECT 1 FROM `user_follow` uf WHERE uf.`user_id`=? AND uf.`follow_id`=l.`user_id`) " +
			"INNER JOIN `user` u ON u.`id`=l.`user_id` " +
			"ORDER BY tl.`reddit_score` DESC limit ?"

		for _, tId := range topicIds {
			userRows, userErr := db.Query(sql, tId, strUserIds, userId, uCount)
			if userErr == nil {
				for userRows.Next() {
					user := User{}
					userErr = userRows.Scan(&user.Id, &user.Name, &user.Email, &user.Description, &user.UserPic, &user.FriendCount, &user.TopicCount, &user.FtopicCount, &user.Status, &user.FollowerCount, &user.LinkCount, &user.CreateTime)
					if userErr == nil && hashUsers[userId] <= 0 {
						users = append(users, user)
						strUserIds += fmt.Sprintf(",%d", user.Id)
						hashUsers[user.Id] = user.Id
					}

				}
			}
		}
	}
	//fmt.Print(users)
	return users, nil
}
Example #8
0
/**
 * 链接推送给话题(最新)
 */
func Link_for_topic_later(handleTime time.Time, db *goku.MysqlDB) error {

	sql := `INSERT ignore INTO tui_link_for_topic_later(topic_id,link_id,create_time) 
		( 
		SELECT TL.topic_id,H.link_id,H.create_time FROM tui_link_for_handle H 
		INNER JOIN topic_link TL ON H.data_type=1 AND H.insert_time<=? AND H.link_id=TL.link_id 
		);`
	_, err := db.Query(sql, handleTime)

	return err
}
Example #9
0
/**
 * 链接推送给网站首页(热门)
 */
func Link_for_home_top(handleTime time.Time, db *goku.MysqlDB) error {

	sql := `INSERT ignore INTO tui_link_for_home(link_id,create_time,data_type,score) 
		( 
		SELECT H.link_id,H.create_time,2,L.reddit_score FROM tui_link_for_handle H 
		INNER JOIN link L ON H.insert_time<=? AND L.id=H.link_id 
		); `

	_, err := db.Query(sql, handleTime)

	return err
}
Example #10
0
func Comment_DelById(id int64) error {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	_, err := db.Query("UPDATE `comment` SET status=2 WHERE id=?", id)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return err
	}

	return nil
}
Example #11
0
//更新发送的邀请email状态
func UpdateInviteEmailStatus(emails []*EmailInvite) {

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

	for _, email := range emails {
		if email.SendSuccess == true {
			db.Query("UPDATE register_invite SET is_send=1 WHERE guid=?", email.Guid)
		} else {
			db.Query("UPDATE register_invite SET fail_count=fail_count+1 WHERE guid=?", email.Guid)
		}
	}
}
Example #12
0
/** 删除`tui_link_for_home`
 * 热门, whereDataType:data_type=2    orderName:score DESC,link_id DESC
 * 热议, whereDataType:data_type IN(3,10,11,12,13,14)    orderName:score desc,link_id DESC
 * 投票, whereDataType:data_type IN(4,5,6,7,8,9)    orderName:score DESC,link_id DESC
 */
func del_link_for_home(whereDataType string, orderName string, db *goku.MysqlDB) error {

	sql := fmt.Sprintf(`SELECT data_type, tcount - %d AS del_count FROM 
		(SELECT link_id,data_type,COUNT(1) AS tcount FROM tui_link_for_home WHERE %s GROUP BY data_type) T
		WHERE T.tcount>%d;`, LinkMaxCount, whereDataType, LinkMaxCount)

	delSqlCreate := `INSERT ignore INTO tui_link_temporary_delete(id)
		( 
		SELECT link_id FROM tui_link_for_home WHERE data_type=%d ORDER BY ` + orderName + ` LIMIT %d,%d 
		); `
	delSqlDelete := `DELETE T FROM tui_link_temporary_delete D INNER JOIN tui_link_for_home T ON T.data_type=%d
		AND T.link_id=D.id; `

	var delCount int64
	var dataType int
	rows, err := db.Query(sql)
	if err == nil {
		for rows.Next() {
			rows.Scan(&dataType, &delCount)
			db.Query("DELETE FROM tui_link_temporary_delete;")
			db.Query(fmt.Sprintf(delSqlCreate, dataType, LinkMaxCount, delCount))
			db.Query(fmt.Sprintf(delSqlDelete, dataType))
		}
	}

	return err
}
Example #13
0
// 检查用户是否已经关注话题,
// @isFollowed: 是否已经关注话题
func Topic_CheckFollowByDb(db *goku.MysqlDB, userId, topicId int64) (isFollowed bool) {

	rows, err := db.Query("select * from `topic_follow` where `user_id`=? and `topic_id`=? limit 1",
		userId, topicId)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return
	}
	defer rows.Close()
	if rows.Next() {
		isFollowed = true
	}

	return
}
Example #14
0
/**
 * 链接推送给网站首页(更新现有数据 )
 */
func Link_for_home_update(handleTime time.Time, db *goku.MysqlDB) error {

	sql := `UPDATE tui_link_for_handle H 
		INNER JOIN tui_link_for_home T ON H.insert_time<=? AND H.data_type=2 AND T.link_id=H.link_id 
		INNER JOIN link L ON L.id=H.link_id 
		SET T.score=CASE WHEN T.data_type=2 THEN L.reddit_score -- 热门 
		WHEN T.data_type=3 THEN L.dispute_score -- 热议
		WHEN T.data_type BETWEEN 10 AND 14 THEN L.dispute_score -- 热议
		ELSE L.vote_up-L.vote_down -- 投票 
		END;`

	_, err := db.Query(sql, handleTime)

	return err
}
Example #15
0
// 检查email地址是否存在。
// 任何出错都认为email地址存在,防止注册
func User_IsEmailExist(email string) bool {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	rows, err := db.Query("select id from `user` where `email_lower`=? limit 1", strings.ToLower(email))
	if err != nil {
		goku.Logger().Errorln(err.Error())
		// 出错直接认为email存在
		return true
	}
	defer rows.Close()
	if rows.Next() {
		return true
	}
	return false
}
Example #16
0
// 保存link到数据库,如果成功,则返回link的id
func Link_SaveMap(m map[string]interface{}) int64 {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()
	m["create_time"] = time.Now()
	//新增link默认投票1次,显示的时候默认减一
	m["vote_up"] = 0 //1
	m["reddit_score"] = utils.LinkSortAlgorithm(m["create_time"].(time.Time), int64(0), int64(0))
	m["context_md5"] = utils.MD5_16(strings.ToLower(m["context"].(string)))

	r, err := db.Insert("link", m)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return 0
	}
	var id int64
	id, err = r.LastInsertId()
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return 0
	}

	if id > 0 {
		uid := m["user_id"].(int64)
		// 更新用户的链接计数
		IncCountById(db, "user", uid, "link_count", 1)
		// 直接推送给自己,自己必须看到
		LinkForUser_Add(uid, id, LinkForUser_ByUser)

		// 存入`tui_link_for_handle` 链接处理队列表
		db.Query("INSERT ignore INTO tui_link_for_handle(link_id,create_time,user_id,insert_time,data_type) VALUES (?, ?, ?, NOW(), ?)",
			id, m["create_time"].(time.Time), uid, 1)

		redisClient := GetRedis()
		defer redisClient.Quit()
		// 加入推送队列
		// 格式: pushtype,userid,linkid,timestamp
		qv := fmt.Sprintf("%v,%v,%v,%v", LinkForUser_ByUser, uid, id, time.Now().Unix())
		_, err = redisClient.Lpush(golink.KEY_LIST_PUSH_TO_USER, qv)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			// return 0
		}

	}

	return id
}
Example #17
0
/**
 * 链接推送给网站首页(更新现有数据 )
 */
func Link_for_home_update(handleTime time.Time, db *goku.MysqlDB) error {

	sql := `UPDATE tui_link_for_handle H 
		INNER JOIN tui_link_for_home T ON H.insert_time<=? AND H.data_type=2 AND T.link_id=H.link_id 
		INNER JOIN link L ON L.id=H.link_id 
		SET T.score=CASE T.data_type WHEN 2 THEN L.reddit_score -- 热门 
		WHEN 3 THEN ABS(L.vote_up-L.vote_down) -- 热议 
		ELSE L.vote_up-L.vote_down -- 投票 
		END, 
		T.vote_add_score=CASE T.data_type WHEN 3 THEN (L.vote_up+L.vote_down) -- 热议 
		ELSE 0 
		END;`

	_, err := db.Query(sql, handleTime)

	return err
}
Example #18
0
//获取需要发送的邀请email
func GetEmailForSend() ([]*EmailInvite, error) {

	var db *goku.MysqlDB = GetDB()
	defer db.Close()
	emails := make([]*EmailInvite, 0)

	strSQL := "SELECT RI.guid,RI.to_email,U.name FROM `register_invite` RI INNER JOIN `user` U ON RI.user_id=U.id AND RI.is_register=0 AND RI.is_send=0 AND RI.fail_count<? LIMIT 0,100"
	rows, err := db.Query(strSQL, golink.Register_Invite_Fail_Count_Max)
	if err == nil {
		for rows.Next() {
			email := &EmailInvite{}
			rows.Scan(&email.Guid, &email.ToEmail, &email.UserName)
			email.SendSuccess = false
			emails = append(emails, email)
		}
	}

	return emails, err
}
Example #19
0
/**
 * 链接推送给话题(热门)
 */
func Link_for_topic_top(handleTime time.Time, db *goku.MysqlDB) error {

	sql := `UPDATE tui_link_for_handle H 
		INNER JOIN tui_link_for_topic_top T ON H.data_type=2 AND H.insert_time<=? AND T.link_id=H.link_id 
		INNER JOIN link L ON L.id=H.link_id 
		SET T.reddit_score=L.reddit_score;`
	_, err := db.Query(sql, handleTime)

	if err == nil {
		sql = `INSERT ignore INTO tui_link_for_topic_top(topic_id,link_id,create_time,reddit_score) 
			( 
			SELECT TL.topic_id,H.link_id,H.create_time,L.reddit_score FROM tui_link_for_handle H 
			INNER JOIN topic_link TL ON H.insert_time<=? AND H.link_id=TL.link_id 
			INNER JOIN link L ON L.id=H.link_id 
			);`
		_, err = db.Query(sql, handleTime)
	}

	return err
}
Example #20
0
//剩余的邀请码数量
func RegisterInviteRemainCount(userId int64) int {
	iCount := 0
	if userId <= int64(0) {
		return iCount
	}

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

	sql := "SELECT COUNT(1) AS FCount FROM register_invite WHERE user_id=?"
	rows, err := db.Query(sql, userId)
	if err == nil && rows.Next() {
		rows.Scan(&iCount)
		iCount = golink.Register_Invite_Count_Max - iCount
		if iCount < 0 {
			iCount = 0
		}
	}

	return iCount
}
Example #21
0
func Del_link_for_home_all(db *goku.MysqlDB) error {

	err := del_link_for_home("data_type=2", "score DESC,link_id DESC", db)
	if err == nil {
		_, err = db.Query(`DELETE FROM tui_link_for_home WHERE ((data_type=10 OR data_type=5) AND create_time<?) OR 
							((data_type=11 OR data_type=6) AND create_time<?) OR 
							((data_type=12 OR data_type=7) AND create_time<?) OR 
							((data_type=13 OR data_type=8) AND create_time<?) OR 
			((data_type=14 OR data_type=9) AND create_time<?)`, utils.ThisHour(), utils.ThisDate(), utils.ThisWeek(), utils.ThisMonth(), utils.ThisYear())
	}
	if err == nil {
		if err == nil {
			err = del_link_for_home("data_type IN(3,10,11,12,13,14)", "score DESC,link_id DESC", db)
		}
	}
	if err == nil {

		err = del_link_for_home("data_type IN(4,5,6,7,8,9)", "score DESC,link_id DESC", db)
	}

	return err
}
func main() {
	//ls := utils.LinkSearch{}
	//ls.SearchLink("名次", 1, 30)
	//return

	var db *goku.MysqlDB = models.GetDB()
	defer db.Close()
	rows, _ := db.Query("SELECT l.id,l.title,l.context,l.topics,u.Name,l.context_type FROM `link` l INNER JOIN `user` u ON l.user_id=u.id")
	var linkId int64
	var title string
	var context string
	var topics string
	var userName string
	var contextType int
	for rows.Next() {
		rows.Scan(&linkId, &title, &context, &topics, &userName, &contextType)
		addLinkForSearch(contextType, linkId, title, context, topics, userName)
	}

	fmt.Println("执行完成")

}
Example #23
0
// 检查账号密码是否正确
// 如果正确,则返回用户id
func User_CheckPwd(email, pwd string) int {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	pwd = utils.PasswordHash(pwd)
	rows, err := db.Query("select id from `user` where `email_lower`=? and pwd=? limit 1", strings.ToLower(email), pwd)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return 0
	}
	defer rows.Close()
	if rows.Next() {
		var id int
		err = rows.Scan(&id)
		if err != nil {
			goku.Logger().Errorln(err.Error())
		} else {
			return id
		}
	}
	return 0
}
Example #24
0
//创建关联系统的用户
func Exists_Reference_System_User(accesstoken string, uid string, reference_system int) (int64, string, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	rows, err := db.Query("select id,email_lower from `user` where `reference_system`=? and `reference_id`=? limit 1", reference_system, uid)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return 0, "", err
	}

	if rows.Next() {
		var userId int64
		var email_lower string
		rows.Scan(&userId, email_lower)
		db.Query("UPDATE `user` SET reference_token=? where `id`=? limit 1", accesstoken, userId)

		return userId, email_lower, nil
	} else {
		return 0, "", nil
	}

	return 0, "", nil
}
Example #25
0
/**
 * 链接推送给网站首页(投票)[投票时间范围: 4:全部时间;5:这个小时;6:今天;7:这周;8:这个月;9:今年]
 */
func link_for_home_vote(dataType int, handleTime time.Time, db *goku.MysqlDB) error {

	var t time.Time
	switch {
	case dataType == 5:
		t = utils.ThisHour()
	case dataType == 6:
		t = utils.ThisDate()
	case dataType == 7:
		t = utils.ThisWeek()
	case dataType == 8:
		t = utils.ThisMonth()
	case dataType == 9:
		t = utils.ThisYear()
	}

	var err error
	if dataType == 4 { //4:全部时间
		sql := `INSERT ignore INTO tui_link_for_home(link_id,create_time,data_type,score) 
			( 
			SELECT H.link_id,H.create_time,?,L.vote_up-L.vote_down FROM tui_link_for_handle H 
			INNER JOIN link L ON H.insert_time<=? AND L.id=H.link_id 
			);`

		_, err = db.Query(sql, dataType, handleTime)
	} else {
		sql := `INSERT ignore INTO tui_link_for_home(link_id,create_time,data_type,score) 
			( 
			SELECT H.link_id,H.create_time,?,L.vote_up-L.vote_down FROM tui_link_for_handle H 
			INNER JOIN link L ON H.insert_time<=? AND L.create_time>=? AND L.id=H.link_id  
			); `

		_, err = db.Query(sql, dataType, handleTime, t)
	}

	return err
}
Example #26
0
/**
 * 链接推送给网站首页(热议)[3:全部时间;10:这个小时;11:今天;12:这周;13:这个月;14:今年]
 */
func link_for_home_hot(dataType int, handleTime time.Time, db *goku.MysqlDB) error {

	var t time.Time
	switch {
	case dataType == 10:
		t = utils.ThisHour()
	case dataType == 11:
		t = utils.ThisDate()
	case dataType == 12:
		t = utils.ThisWeek()
	case dataType == 13:
		t = utils.ThisMonth()
	case dataType == 14:
		t = utils.ThisYear()
	}

	var err error
	if dataType == 3 { //3:全部时间
		sql := `INSERT ignore INTO tui_link_for_home(link_id,create_time,data_type,score) 
			( 
			SELECT H.link_id,H.create_time,?,L.dispute_score FROM tui_link_for_handle H 
			INNER JOIN link L ON H.insert_time<=? AND L.id=H.link_id 
			); `

		_, err = db.Query(sql, dataType, handleTime)
	} else {
		sql := `INSERT ignore INTO tui_link_for_home(link_id,create_time,data_type,score) 
		( 
		SELECT H.link_id,H.create_time,?,L.dispute_score FROM tui_link_for_handle H 
		INNER JOIN link L ON H.insert_time<=? AND H.create_time>=? AND L.id=H.link_id 
		); `

		_, err = db.Query(sql, dataType, handleTime, t)
	}

	return err
}
Example #27
0
/**
 * 链接推送给域名(热议)全部时间:1
 */
func Link_for_host_hot_all(handleTime time.Time, db *goku.MysqlDB) error {

	sql := `UPDATE tui_link_for_handle H 
		INNER JOIN tui_link_for_host_hot TH ON H.data_type=2 AND H.insert_time<=? AND TH.link_id=H.link_id 
		INNER JOIN link L ON L.id=H.link_id 
		SET TH.vote_abs_score=ABS(L.vote_up-L.vote_down),TH.vote_add_score=(L.vote_up+L.vote_down);`
	_, err := db.Query(sql, handleTime)

	if err == nil {
		sql = `INSERT ignore INTO tui_link_for_host_hot(host_id,link_id,create_time,vote_abs_score,vote_add_score,time_type) 
			( 
			SELECT TL.host_id,H.link_id,H.create_time,ABS(L.vote_up-L.vote_down) AS vote_abs_score, 
			L.vote_up+L.vote_down AS vote_add_score,1 FROM tui_link_for_handle H 
			INNER JOIN host_link TL ON H.insert_time<=? AND H.link_id=TL.link_id 
			INNER JOIN link L ON L.id=H.link_id 
			);`
		_, err = db.Query(sql, handleTime)
	}

	if err == nil {
		err = link_for_host_hop_time(2, handleTime, db)
	}
	if err == nil {
		err = link_for_host_hop_time(3, handleTime, db)
	}
	if err == nil {
		err = link_for_host_hop_time(4, handleTime, db)
	}
	if err == nil {
		err = link_for_host_hop_time(5, handleTime, db)
	}
	if err == nil {
		err = link_for_host_hop_time(6, handleTime, db)
	}

	return err
}
Example #28
0
/**
 * 链接推送给话题(投票)全部时间:1
 */
func Link_for_topic_vote_all(handleTime time.Time, db *goku.MysqlDB) error {

	sql := `UPDATE tui_link_for_handle H 
		INNER JOIN tui_link_for_topic_vote V ON H.data_type=2 AND H.insert_time<=? AND V.link_id=H.link_id 
		INNER JOIN link L ON L.id=H.link_id 
		SET V.vote=(L.vote_up-L.vote_down);`
	_, err := db.Query(sql, handleTime)

	if err == nil {
		sql = `INSERT ignore INTO tui_link_for_topic_vote(topic_id,link_id,create_time,time_type,vote) 
			( 
			SELECT TL.topic_id,H.link_id,H.create_time,1 AS time_type, 
			L.vote_up-L.vote_down AS vote FROM tui_link_for_handle H 
			INNER JOIN topic_link TL ON H.insert_time<=? AND H.link_id=TL.link_id 
			INNER JOIN link L ON L.id=H.link_id 
			);`
		_, err = db.Query(sql, handleTime)
	}

	if err == nil {
		err = link_for_topic_vote_time(2, handleTime, db)
	}
	if err == nil {
		err = link_for_topic_vote_time(3, handleTime, db)
	}
	if err == nil {
		err = link_for_topic_vote_time(4, handleTime, db)
	}
	if err == nil {
		err = link_for_topic_vote_time(5, handleTime, db)
	}
	if err == nil {
		err = link_for_topic_vote_time(6, handleTime, db)
	}

	return err
}
Example #29
0
func userRecovery_GetActive(userId int64) (ur *UserRecovery, err error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	sql := "SELECT `user_id`, `token`, `active`, `create_time`, `recovery_time` FROM `user_recovery` WHERE `user_id`=? AND `active`=1 ORDER BY `create_time` DESC limit 1"
	userRecoveryRow, err := db.Query(sql, userId)
	if err != nil {
		return
	}
	if userRecoveryRow == nil {
		return
	}

	if userRecoveryRow.Next() {
		ur = &UserRecovery{}
		err = userRecoveryRow.Scan(&ur.UserId, &ur.Token, &ur.Active, &ur.CreateTime, &ur.RecoveryTime)
	}

	if err != nil {
		ur = nil
	}

	return
}
Example #30
0
/**
 * 链接推送给话题(热议)全部时间:1
 */
func Link_for_topic_hot_all(handleTime time.Time, db *goku.MysqlDB) error {

	sql := `UPDATE tui_link_for_handle H 
		INNER JOIN tui_link_for_topic_hot TH ON H.data_type=2 AND H.insert_time<=? AND TH.link_id=H.link_id 
		INNER JOIN link L ON L.id=H.link_id 
		SET TH.dispute_score=L.dispute_score;`
	_, err := db.Query(sql, handleTime)

	if err == nil {
		sql = `INSERT ignore INTO tui_link_for_topic_hot(topic_id,link_id,create_time,dispute_score,time_type) 
			( 
			SELECT TL.topic_id,H.link_id,H.create_time,L.dispute_score,1 FROM tui_link_for_handle H 
			INNER JOIN topic_link TL ON H.insert_time<=? AND H.link_id=TL.link_id 
			INNER JOIN link L ON L.id=H.link_id 
			);`
		_, err = db.Query(sql, handleTime)
	}

	if err == nil {
		err = link_for_topic_hop_time(2, handleTime, db)
	}
	if err == nil {
		err = link_for_topic_hop_time(3, handleTime, db)
	}
	if err == nil {
		err = link_for_topic_hop_time(4, handleTime, db)
	}
	if err == nil {
		err = link_for_topic_hop_time(5, handleTime, db)
	}
	if err == nil {
		err = link_for_topic_hop_time(6, handleTime, db)
	}

	return err
}