Prechádzať zdrojové kódy

Merge branch 'yb/9.3' into debug

hsun 2 rokov pred
rodič
commit
1f143c6ba4
1 zmenil súbory, kde vykonal 45 pridanie a 14 odobranie
  1. 45 14
      services/collection/collection.go

+ 45 - 14
services/collection/collection.go

@@ -23,10 +23,51 @@ const (
 
 
 // AddCollection 加入收藏
 // AddCollection 加入收藏
 func AddCollection(userId, collectionType, primaryId, extendId, sourceAgent int) (collectionId int, err error) {
 func AddCollection(userId, collectionType, primaryId, extendId, sourceAgent int) (collectionId int, err error) {
+	if userId <= 0 || collectionType <= 0 || primaryId <= 0 {
+		return
+	}
+
 	title := ""
 	title := ""
 	nowTime := time.Now().Local()
 	nowTime := time.Now().Local()
 	publishTime := nowTime
 	publishTime := nowTime
 
 
+	// 判断是否曾收藏过
+	var cond string
+	var pars []interface{}
+	cond += `user_id = ?`
+	pars = append(pars, userId)
+	cond += ` AND collection_type = ?`
+	pars = append(pars, collectionType)
+	cond += ` AND primary_id = ?`
+	pars = append(pars, primaryId)
+	if extendId > 0 {
+		cond += ` AND extend_id = ?`
+		pars = append(pars, extendId)
+	}
+	exist, e := yb_user_collection.GetItemByCondition(cond, pars)
+	if e != nil && e != utils.ErrNoRow {
+		err = errors.New("获取用户收藏失败, Err: " + e.Error())
+		return
+	}
+	if exist != nil && exist.CollectionID > 0 {
+		// 可能手快重复收藏
+		collectionId = exist.CollectionID
+		if exist.State == 1 {
+			return
+		}
+		// 重新收藏
+		exist.State = 1
+		exist.CreateTime = nowTime
+		exist.ModifyTime = nowTime
+		updateCols := []string{"State", "CreateTime", "ModifyTime"}
+		if e = exist.Update(updateCols); e != nil {
+			collectionId = 0
+			err = errors.New("重新收藏失败, Err: " + e.Error())
+			return
+		}
+		return
+	}
+
 	// 收藏类型:1-研报; 2-视频社区; 3-微路演视频
 	// 收藏类型:1-研报; 2-视频社区; 3-微路演视频
 	switch collectionType {
 	switch collectionType {
 	case CollectionTypeReport:
 	case CollectionTypeReport:
@@ -69,17 +110,7 @@ func AddCollection(userId, collectionType, primaryId, extendId, sourceAgent int)
 		return
 		return
 	}
 	}
 
 
-	// 是否已收藏
-	isCollect, e := GetUserCollectByItem(userId, collectionType, primaryId, extendId)
-	if e != nil {
-		err = e
-		return
-	}
-	if isCollect > 0 {
-		collectionId = isCollect
-		return
-	}
-
+	// 新增收藏
 	item := &yb_user_collection.YbUserCollection{
 	item := &yb_user_collection.YbUserCollection{
 		CollectionType: collectionType,
 		CollectionType: collectionType,
 		UserID:         userId,
 		UserID:         userId,
@@ -139,7 +170,7 @@ func GetCollectionList(userId, fromType, currPage, pageSize int, keywords string
 	// 查询收藏列表
 	// 查询收藏列表
 	var cond string
 	var cond string
 	var pars []interface{}
 	var pars []interface{}
-	cond += `user_id = ?`
+	cond += `state = 1 AND user_id = ?`
 	pars = append(pars, userId)
 	pars = append(pars, userId)
 	if fromType > 0 {
 	if fromType > 0 {
 		cond += ` AND collection_type = ?`
 		cond += ` AND collection_type = ?`
@@ -340,7 +371,7 @@ func GetUserCollectByItem(userId, collectionType, primaryId, extendId int) (coll
 
 
 	var cond string
 	var cond string
 	var pars []interface{}
 	var pars []interface{}
-	cond += `user_id = ?`
+	cond += `state = 1 AND user_id = ?`
 	pars = append(pars, userId)
 	pars = append(pars, userId)
 	cond += ` AND collection_type = ?`
 	cond += ` AND collection_type = ?`
 	pars = append(pars, collectionType)
 	pars = append(pars, collectionType)
@@ -371,7 +402,7 @@ func GetUserCollectByList(userId, collectionType int, primaryIds []int) (collect
 
 
 	var cond string
 	var cond string
 	var pars []interface{}
 	var pars []interface{}
-	cond += `user_id = ?`
+	cond += `state = 1 AND user_id = ?`
 	pars = append(pars, userId)
 	pars = append(pars, userId)
 	cond += ` AND collection_type = ?`
 	cond += ` AND collection_type = ?`
 	pars = append(pars, collectionType)
 	pars = append(pars, collectionType)