Forráskód Böngészése

Merge branch 'cygx_12.8' of http://8.136.199.33:3000/cxzhang/hongze_clpt into debug

xingzai 1 éve
szülő
commit
7b9e8a43f1

+ 2 - 2
controllers/yanxuan_special.go

@@ -642,7 +642,7 @@ func (this *YanxuanSpecialController) Collect() {
 		br.Msg = "取消收藏成功"
 	}
 
-	go services.UdpateYanxuanSpecialCollect(user, req.Id, req.Status)
+	go services.UdpateYanxuanSpecialCollect(req.Id)
 	br.Ret = 200
 	br.Success = true
 }
@@ -824,7 +824,7 @@ func (this *YanxuanSpecialController) Follow() {
 		}
 		br.Msg = "取消关注成功"
 	}
-	go services.UdpateYanxuanSpecialFansNum(user, authorItem.Id, req.Status)
+	go services.UdpateYanxuanSpecialFansNum(authorItem.UserId)
 	br.Ret = 200
 	br.Success = true
 }

+ 9 - 0
models/cygx_yanxuan_special.go

@@ -302,3 +302,12 @@ func UpdateYanxuanSpecialarticleCollectNumReduce(id int) (err error) {
 	_, err = o.Raw(sql, id).Exec()
 	return
 }
+
+// 更新收藏数量
+func UpdateYanxuanSpecialarticleCollectNum(collectNum, id int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special SET article_collect_num = ?  WHERE id = ? `
+	_, err = o.Raw(sql, collectNum, id).Exec()
+	return
+}

+ 24 - 13
models/cygx_yanxuan_special_collect.go

@@ -7,17 +7,17 @@ import (
 
 type CygxYanxuanSpecialCollect struct {
 	CygxYanxuanSpecialCollectId int       `orm:"column(cygx_yanxuan_special_collect_id);pk"`
-	UserId                      int        // 用户ID
-	Mobile                      string     // 手机号
-	Email                       string     // 邮箱
-	CompanyId                   int        // 公司ID
-	CompanyName                 string     // 公司名称
-	RealName                    string     // 用户实际名称
-	SellerName                  string     // 所属销售
-	CreateTime                  time.Time  // 创建时间
-	ModifyTime                  time.Time  // 修改时间
-	RegisterPlatform            int        // 来源 1小程序,2:网页
-	YanxuanSpecialId            int        // cygx_yanxuan_special 表主键ID
+	UserId                      int       // 用户ID
+	Mobile                      string    // 手机号
+	Email                       string    // 邮箱
+	CompanyId                   int       // 公司ID
+	CompanyName                 string    // 公司名称
+	RealName                    string    // 用户实际名称
+	SellerName                  string    // 所属销售
+	CreateTime                  time.Time // 创建时间
+	ModifyTime                  time.Time // 修改时间
+	RegisterPlatform            int       // 来源 1小程序,2:网页
+	YanxuanSpecialId            int       // cygx_yanxuan_special 表主键ID
 }
 
 func AddCygxYanxuanSpecialCollect(item *CygxYanxuanSpecialCollect) (lastId int64, err error) {
@@ -27,8 +27,8 @@ func AddCygxYanxuanSpecialCollect(item *CygxYanxuanSpecialCollect) (lastId int64
 }
 
 type CollectCygxYanxuanSpecialReq struct {
-	Id     int    // 文章id
-	Status int    // 1收藏2取消收藏
+	Id     int // 文章id
+	Status int // 1收藏2取消收藏
 }
 
 func DelCygxYanxuanSpecialCollect(userId, articleId int) (err error) {
@@ -37,3 +37,14 @@ func DelCygxYanxuanSpecialCollect(userId, articleId int) (err error) {
 	_, err = o.Raw(sql, userId, articleId).Exec()
 	return
 }
+
+// 获取数量
+func GetCygxYanxuanSpecialCollectCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_collect as a  WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}

+ 11 - 0
models/cygx_yanxuan_special_follow.go

@@ -55,3 +55,14 @@ WHERE
 	_, err = o.Raw(sql, followUserId).QueryRows(&items)
 	return
 }
+
+// 获取数量
+func GetCygxYanxuanSpecialFollowCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_follow as a  WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}

+ 18 - 0
models/cygx_yanxuan_special_user.go

@@ -255,6 +255,24 @@ func UpdateYanxuanSpecialAuthorFansNumReduce(userId int) (err error) {
 	return
 }
 
+// 更新收藏数量
+func UpdateYanxuanSpecialAuthorArticleCollectNum(collectNum, userId int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special_author SET article_collect_num = ?  WHERE user_id = ? `
+	_, err = o.Raw(sql, collectNum, userId).Exec()
+	return
+}
+
+// 更新粉丝数量
+func UpdateYanxuanSpecialAuthorFansNum(fansNum, userId int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special_author SET fans_num = ?  WHERE user_id = ? `
+	_, err = o.Raw(sql, fansNum, userId).Exec()
+	return
+}
+
 // 更新作者发布文章的数量
 func UdpateYanxuanSpecialauthorArticleNum(articleNum, userId int) (err error) {
 	o := orm.NewOrm()

+ 49 - 44
services/cygx_yanxuan_special.go

@@ -391,12 +391,12 @@ func AddAddCygxYanxuanSpecialApprovalLog(user *models.WxUserItem, specialId, sta
 }
 
 // 更新文章收藏数量
-func UdpateYanxuanSpecialCollect(user *models.WxUserItem, specialId, status int) {
+func UdpateYanxuanSpecialCollect(specialId int) {
 	var err error
 	defer func() {
 		if err != nil {
 			fmt.Println(err)
-			go utils.SendAlarmMsg(fmt.Sprint("更新文章收藏数量失败,UdpateYanxuanSpecialCollect Err ", err, "userId", user.UserId), 2)
+			go utils.SendAlarmMsg(fmt.Sprint("更新文章收藏数量失败,UdpateYanxuanSpecialCollect Err ", err, "specialId:", specialId), 2)
 		}
 	}()
 	detail, e := models.GetYanxuanSpecialBySpecialId(specialId)
@@ -411,62 +411,67 @@ func UdpateYanxuanSpecialCollect(user *models.WxUserItem, specialId, status int)
 		return
 	}
 
-	if status == 1 {
-		//更新文章被收藏数量
-		e = models.UpdateYanxuanSpecialarticleCollectNumIncrease(specialId)
-		if e != nil {
-			err = errors.New("UpdateYanxuanSpecialarticleCollectNumIncrease, Err: " + e.Error())
-			return
-		}
+	var condition string
+	var pars []interface{}
+	condition = "  AND yanxuan_special_id = ? "
+	pars = append(pars, specialId)
+	//专栏被收藏的数量
+	totalSpecial, e := models.GetCygxYanxuanSpecialCollectCount(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxYanxuanSpecialCollectCount, Err: " + e.Error())
+		return
+	}
 
-		//更新作者文章被收藏数量
-		e = models.UpdateYanxuanSpecialAuthorArticleCollectNumIncrease(specialAuthor.Id)
-		if e != nil {
-			err = errors.New("UpdateYanxuanSpecialAuthorArticleCollectNumIncrease, Err: " + e.Error())
-			return
-		}
-	} else {
-		//更新文章被收藏数量
-		e = models.UpdateYanxuanSpecialarticleCollectNumReduce(specialId)
-		if e != nil {
-			err = errors.New("UpdateYanxuanSpecialarticleCollectNumReduce, Err: " + e.Error())
-			return
-		}
+	pars = make([]interface{}, 0)
+	condition = "  AND yanxuan_special_id  IN (SELECT id FROM cygx_yanxuan_special AS a WHERE user_id = ?)  "
+	pars = append(pars, specialAuthor.UserId)
+	//作者被收藏的数量
+	totalAuthor, e := models.GetCygxYanxuanSpecialCollectCount(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxYanxuanSpecialCollectCount, Err: " + e.Error())
+		return
+	}
 
-		//更新作者文章被收藏数量
-		e = models.UpdateYanxuanSpecialAuthorArticleCollectNumReduce(specialAuthor.Id)
-		if e != nil {
-			err = errors.New("UpdateYanxuanSpecialAuthorArticleCollectNumReduce, Err: " + e.Error())
-			return
-		}
+	//更新文章被收藏数量
+	e = models.UpdateYanxuanSpecialarticleCollectNum(totalSpecial, specialId)
+	if e != nil {
+		err = errors.New("UpdateYanxuanSpecialarticleCollectNum, Err: " + e.Error())
+		return
+	}
+
+	//更新作者文章被收藏数量
+	e = models.UpdateYanxuanSpecialAuthorArticleCollectNum(totalAuthor, specialAuthor.UserId)
+	if e != nil {
+		err = errors.New("UpdateYanxuanSpecialAuthorArticleCollectNum, Err: " + e.Error())
+		return
 	}
 	return
 }
 
 // 更新作者粉丝数量
-func UdpateYanxuanSpecialFansNum(user *models.WxUserItem, specialAuthorId, status int) {
+func UdpateYanxuanSpecialFansNum(specialUserIdId int) {
 	var err error
 	defer func() {
 		if err != nil {
 			fmt.Println(err)
-			go utils.SendAlarmMsg(fmt.Sprint("更新作者粉丝数量失败,UdpateYanxuanSpecialFansNum Err ", err, "userId", user.UserId), 2)
+			go utils.SendAlarmMsg(fmt.Sprint("更新作者粉丝数量失败,UdpateYanxuanSpecialFansNum Err ", err, "specialUserIdId", specialUserIdId), 2)
 		}
 	}()
 
-	if status == 1 {
-		//更新作者粉丝数量
-		e := models.UpdateYanxuanSpecialAuthorFansNumIncrease(specialAuthorId)
-		if e != nil {
-			err = errors.New("UpdateYanxuanSpecialAuthorFansNumIncrease, Err: " + e.Error())
-			return
-		}
-	} else {
-		//更新作者粉丝数量
-		e := models.UpdateYanxuanSpecialAuthorFansNumReduce(specialAuthorId)
-		if e != nil {
-			err = errors.New("UpdateYanxuanSpecialAuthorFansNumReduce, Err: " + e.Error())
-			return
-		}
+	var condition string
+	var pars []interface{}
+	condition = "  AND follow_user_id = ? "
+	pars = append(pars, specialUserIdId)
+	//作者粉丝数量
+	total, e := models.GetCygxYanxuanSpecialFollowCount(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxYanxuanSpecialFollowCount, Err: " + e.Error())
+		return
+	}
+	e = models.UpdateYanxuanSpecialAuthorFansNum(total, specialUserIdId)
+	if e != nil {
+		err = errors.New("UpdateYanxuanSpecialAuthorFansNum, Err: " + e.Error())
+		return
 	}
 	return
 }