xingzai 11 mesiacov pred
rodič
commit
fea133bea7

+ 28 - 17
controllers/yanxuan_special.go

@@ -501,6 +501,9 @@ func (this *YanxuanSpecialController) AuthorDetail() {
 		br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
 		return
 	}
+	if item.IsFollow > 0 {
+		item.IsFollow = 1
+	}
 
 	br.Data = item
 	br.Ret = 200
@@ -804,26 +807,34 @@ func (this *YanxuanSpecialController) Follow() {
 		}
 	}
 	if req.Status == 1 {
-		item := models.CygxYanxuanSpecialFollow{
-			UserId:           user.UserId,
-			FollowUserId:     req.FollowUserId,
-			Mobile:           user.Mobile,
-			Email:            user.Email,
-			CompanyId:        user.CompanyId,
-			CompanyName:      user.CompanyName,
-			RealName:         user.RealName,
-			SellerName:       sellerName,
-			CreateTime:       time.Now(),
-			ModifyTime:       time.Now(),
-			RegisterPlatform: utils.REGISTER_PLATFORM,
-			YanxuanSpecialId: req.SpecialId,
-		}
-		err = models.AddCygxYanxuanSpecialFollow(&item)
+		followCount, err := models.GetCygxYanxuanSpecialFollowCountByUser(user.UserId, req.FollowUserId)
 		if err != nil {
-			br.Msg = "新增失败"
-			br.ErrMsg = "新增失败,Err:" + err.Error()
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败, Err:" + err.Error()
 			return
 		}
+		if followCount == 0 && user.UserId > 0 {
+			item := models.CygxYanxuanSpecialFollow{
+				UserId:           user.UserId,
+				FollowUserId:     req.FollowUserId,
+				Mobile:           user.Mobile,
+				Email:            user.Email,
+				CompanyId:        user.CompanyId,
+				CompanyName:      user.CompanyName,
+				RealName:         user.RealName,
+				SellerName:       sellerName,
+				CreateTime:       time.Now(),
+				ModifyTime:       time.Now(),
+				RegisterPlatform: utils.REGISTER_PLATFORM,
+				YanxuanSpecialId: req.SpecialId,
+			}
+			err = models.AddCygxYanxuanSpecialFollow(&item)
+			if err != nil {
+				br.Msg = "新增失败"
+				br.ErrMsg = "新增失败,Err:" + err.Error()
+				return
+			}
+		}
 		br.Msg = "关注成功"
 	} else {
 		err = models.DelCygxYanxuanSpecialFollow(user.UserId, req.FollowUserId)

+ 8 - 0
models/cygx_yanxuan_special_follow.go

@@ -66,3 +66,11 @@ func GetCygxYanxuanSpecialFollowCount(condition string, pars []interface{}) (cou
 	err = o.Raw(sqlCount, pars).QueryRow(&count)
 	return
 }
+
+// 获取数量判断用户是否关注专栏
+func GetCygxYanxuanSpecialFollowCountByUser(userId, followUserId int) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_follow as a WHERE user_id=? AND follow_user_id=? `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, userId, followUserId).QueryRow(&count)
+	return
+}