Browse Source

no message

xingzai 1 year ago
parent
commit
6cf7be0a09

+ 28 - 24
controllers/yanxuan_special.go

@@ -417,6 +417,7 @@ func (this *YanxuanSpecialController) Save() {
 			return
 		}
 		item.UserId = specialItem.UserId // 专栏userid还是原有userId
+		br.Msg = "保存成功"
 	}
 
 	specialId := 0
@@ -529,7 +530,7 @@ func (this *YanxuanSpecialController) Enable() {
 	} else {
 		status = 4
 	}
-	if tmpErr := models.EnableYanxuanSpecial(req.Id, status, req.Reason); tmpErr != nil {
+	if tmpErr := models.EnableYanxuanSpecial(req.Id, status, req.Reason, user.RealName); tmpErr != nil {
 		br.Msg = "审批失败"
 		br.ErrMsg = "审批失败, Err:" + tmpErr.Error()
 		return
@@ -557,8 +558,8 @@ func (this *YanxuanSpecialController) Collect() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	sysUser := this.User
-	if sysUser == nil {
+	user := this.User
+	if user == nil {
 		br.Msg = "请登录"
 		br.ErrMsg = "请登录,SysUser Is Empty"
 		br.Ret = 408
@@ -583,19 +584,19 @@ func (this *YanxuanSpecialController) Collect() {
 	var sellerName string
 
 	if req.Status == 1 {
-		sellerName, err = models.GetCompanySellerName(sysUser.CompanyId)
+		sellerName, err = models.GetCompanySellerName(user.CompanyId)
 		if err != nil {
 			br.Msg = "报名失败!"
 			br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
 			return
 		}
 		item := models.CygxYanxuanSpecialCollect{
-			UserId:           sysUser.UserId,
-			Mobile:           sysUser.Mobile,
-			Email:            sysUser.Email,
-			CompanyId:        sysUser.CompanyId,
-			CompanyName:      sysUser.CompanyName,
-			RealName:         sysUser.RealName,
+			UserId:           user.UserId,
+			Mobile:           user.Mobile,
+			Email:            user.Email,
+			CompanyId:        user.CompanyId,
+			CompanyName:      user.CompanyName,
+			RealName:         user.RealName,
 			SellerName:       sellerName,
 			CreateTime:       time.Now(),
 			ModifyTime:       time.Now(),
@@ -610,7 +611,7 @@ func (this *YanxuanSpecialController) Collect() {
 		}
 		br.Msg = "收藏成功"
 	} else {
-		err = models.DelCygxYanxuanSpecialCollect(sysUser.UserId, req.Id)
+		err = models.DelCygxYanxuanSpecialCollect(user.UserId, req.Id)
 		if err != nil {
 			br.Msg = "删除失败"
 			br.ErrMsg = "删除失败,Err:" + err.Error()
@@ -619,6 +620,7 @@ func (this *YanxuanSpecialController) Collect() {
 		br.Msg = "取消收藏成功"
 	}
 
+	go services.UdpateYanxuanSpecialCollect(user, req.Id, req.Status)
 	br.Ret = 200
 	br.Success = true
 }
@@ -730,8 +732,8 @@ func (this *YanxuanSpecialController) Follow() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	sysUser := this.User
-	if sysUser == nil {
+	user := this.User
+	if user == nil {
 		br.Msg = "请登录"
 		br.ErrMsg = "请登录,SysUser Is Empty"
 		br.Ret = 408
@@ -754,12 +756,14 @@ func (this *YanxuanSpecialController) Follow() {
 		return
 	}
 	var sellerName string
-	sellerName, err = models.GetCompanySellerName(sysUser.CompanyId)
+
+	sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
 	if err != nil {
-		br.Msg = "报名失败!"
-		br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
+		br.Msg = "查询栏目详情失败!"
+		br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
 		return
 	}
+	sellerName = sellerItemQy.RealName
 	authorItem, err := models.GetYanxuanSpecialAuthorById(req.FollowSpecialColumnId)
 	if err != nil {
 		br.Msg = "查询栏目详情失败!"
@@ -769,13 +773,13 @@ func (this *YanxuanSpecialController) Follow() {
 
 	if req.Status == 1 {
 		item := models.CygxYanxuanSpecialFollow{
-			UserId:           sysUser.UserId,
+			UserId:           user.UserId,
 			FollowUserId:     authorItem.UserId,
-			Mobile:           sysUser.Mobile,
-			Email:            sysUser.Email,
-			CompanyId:        sysUser.CompanyId,
-			CompanyName:      sysUser.CompanyName,
-			RealName:         sysUser.RealName,
+			Mobile:           user.Mobile,
+			Email:            user.Email,
+			CompanyId:        user.CompanyId,
+			CompanyName:      user.CompanyName,
+			RealName:         user.RealName,
 			SellerName:       sellerName,
 			CreateTime:       time.Now(),
 			ModifyTime:       time.Now(),
@@ -790,7 +794,7 @@ func (this *YanxuanSpecialController) Follow() {
 		}
 		br.Msg = "关注成功"
 	} else {
-		err = models.DelCygxYanxuanSpecialFollow(sysUser.UserId, authorItem.UserId)
+		err = models.DelCygxYanxuanSpecialFollow(user.UserId, authorItem.UserId)
 		if err != nil {
 			br.Msg = "删除失败"
 			br.ErrMsg = "删除失败,Err:" + err.Error()
@@ -798,7 +802,7 @@ func (this *YanxuanSpecialController) Follow() {
 		}
 		br.Msg = "取消关注成功"
 	}
-
+	go services.UdpateYanxuanSpecialFansNum(user, authorItem.Id, req.Status)
 	br.Ret = 200
 	br.Success = true
 }

+ 21 - 3
models/cygx_yanxuan_special.go

@@ -111,11 +111,11 @@ type EnableCygxYanxuanSpecialReq struct {
 	Reason string //理由
 }
 
-func EnableYanxuanSpecial(id, status int, reason string) (err error) {
+func EnableYanxuanSpecial(id, status int, reason, adminName string) (err error) {
 	o := orm.NewOrm()
 	sql := ``
-	sql = `UPDATE cygx_yanxuan_special SET status=?,reason=?,publish_time=NOW() WHERE id = ? `
-	_, err = o.Raw(sql, status, reason, id).Exec()
+	sql = `UPDATE cygx_yanxuan_special SET status=?,reason=?,admin_name = ? , publish_time=NOW() WHERE id = ? `
+	_, err = o.Raw(sql, status, reason, adminName, id).Exec()
 	return
 }
 
@@ -283,3 +283,21 @@ func UpdateYanxuanSpecialUv(id int) (err error) {
 	_, err = o.Raw(sql, id).Exec()
 	return
 }
+
+// 增加收藏数量
+func UpdateYanxuanSpecialarticleCollectNumIncrease(id int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special SET article_collect_num = article_collect_num +1  WHERE id = ? `
+	_, err = o.Raw(sql, id).Exec()
+	return
+}
+
+// 减少收藏数量
+func UpdateYanxuanSpecialarticleCollectNumReduce(id int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special SET article_collect_num = article_collect_num  - 1  WHERE id = ? `
+	_, err = o.Raw(sql, id).Exec()
+	return
+}

+ 36 - 0
models/cygx_yanxuan_special_user.go

@@ -218,3 +218,39 @@ func UpdateCygxYanxuanSpecialAuthorUv(userId int) (err error) {
 	_, err = o.Raw(sql, userId).Exec()
 	return
 }
+
+// 增加收藏数量
+func UpdateYanxuanSpecialAuthorArticleCollectNumIncrease(userId int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special_author SET article_collect_num = article_collect_num +1  WHERE id = ? `
+	_, err = o.Raw(sql, userId).Exec()
+	return
+}
+
+// 减少收藏数量
+func UpdateYanxuanSpecialAuthorArticleCollectNumReduce(userId int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special_author SET article_collect_num = article_collect_num  - 1  WHERE id = ? `
+	_, err = o.Raw(sql, userId).Exec()
+	return
+}
+
+// 增加粉丝数量
+func UpdateYanxuanSpecialAuthorFansNumIncrease(userId int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special_author SET fans_num = fans_num +1  WHERE id = ? `
+	_, err = o.Raw(sql, userId).Exec()
+	return
+}
+
+// 减少粉丝数量
+func UpdateYanxuanSpecialAuthorFansNumReduce(userId int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special_author SET fans_num = fans_num  - 1  WHERE id = ? `
+	_, err = o.Raw(sql, userId).Exec()
+	return
+}

+ 81 - 0
services/cygx_yanxuan_special.go

@@ -389,3 +389,84 @@ func AddAddCygxYanxuanSpecialApprovalLog(user *models.WxUserItem, specialId, sta
 	}
 	return
 }
+
+// 更新文章收藏数量
+func UdpateYanxuanSpecialCollect(user *models.WxUserItem, specialId, status int) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("更新文章收藏数量失败,UdpateYanxuanSpecialCollect Err ", err, "userId", user.UserId), 2)
+		}
+	}()
+	detail, e := models.GetYanxuanSpecialBySpecialId(specialId)
+	if e != nil {
+		err = errors.New("GetYanxuanSpecialBySpecialId, Err: " + e.Error())
+		return
+	}
+
+	specialAuthor, e := models.GetCygxYanxuanSpecialAuthorByUserId(detail.UserId)
+	if e != nil {
+		err = errors.New("GetCygxYanxuanSpecialAuthorByUserId, Err: " + e.Error())
+		return
+	}
+
+	if status == 1 {
+		//更新文章被收藏数量
+		e = models.UpdateYanxuanSpecialarticleCollectNumIncrease(specialId)
+		if e != nil {
+			err = errors.New("UpdateYanxuanSpecialarticleCollectNumIncrease, Err: " + e.Error())
+			return
+		}
+
+		//更新作者文章被收藏数量
+		e = models.UpdateYanxuanSpecialAuthorArticleCollectNumIncrease(specialAuthor.Id)
+		if e != nil {
+			err = errors.New("UpdateYanxuanSpecialarticleCollectNumIncrease, Err: " + e.Error())
+			return
+		}
+	} else {
+		//更新文章被收藏数量
+		e = models.UpdateYanxuanSpecialarticleCollectNumReduce(specialId)
+		if e != nil {
+			err = errors.New("UpdateYanxuanSpecialarticleCollectNumIncrease, Err: " + e.Error())
+			return
+		}
+
+		//更新作者文章被收藏数量
+		e = models.UpdateYanxuanSpecialAuthorArticleCollectNumReduce(specialAuthor.Id)
+		if e != nil {
+			err = errors.New("UpdateYanxuanSpecialarticleCollectNumIncrease, Err: " + e.Error())
+			return
+		}
+	}
+	return
+}
+
+// 更新作者粉丝数量
+func UdpateYanxuanSpecialFansNum(user *models.WxUserItem, specialAuthorId, status int) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("更新作者粉丝数量失败,UdpateYanxuanSpecialFansNum Err ", err, "userId", user.UserId), 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
+		}
+	}
+	return
+}