xingzai 1 éve
szülő
commit
802f0f5d72

+ 24 - 6
controllers/yanxuan_special.go

@@ -400,6 +400,7 @@ func (this *YanxuanSpecialController) Save() {
 		item.Status = 2
 		br.Msg = "已提交审核"
 	}
+	var authorUserId int
 	// 如果是审批人员操作的那么就是修改内容,加审批通过
 	if isApprovalPersonnel {
 		item.Status = 3
@@ -417,6 +418,7 @@ func (this *YanxuanSpecialController) Save() {
 			return
 		}
 		item.UserId = specialItem.UserId // 专栏userid还是原有userId
+		authorUserId = specialItem.UserId
 		br.Msg = "保存成功"
 	}
 
@@ -440,10 +442,11 @@ func (this *YanxuanSpecialController) Save() {
 	}
 
 	if isApprovalPersonnel {
-		go services.UpdateYanxuanSpecialResourceData(specialId) //  写入首页最新  cygx_resource_data 表
-		go services.EsAddYanxuanSpecial(specialId)              //  写入es 综合搜索
-		go services.SendWxMsgSpecialFollow(req.Id)              //研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
-		go services.SendWxMsgSpecialAuthor(req.Id, 2)           //研选专栏审核完成时,给提交人发送模板消息
+		go services.UpdateYanxuanSpecialResourceData(specialId)        //  写入首页最新  cygx_resource_data 表
+		go services.EsAddYanxuanSpecial(specialId)                     //  写入es 综合搜索
+		go services.SendWxMsgSpecialFollow(req.Id)                     //研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
+		go services.SendWxMsgSpecialAuthor(req.Id, 2)                  //研选专栏审核完成时,给提交人发送模板消息
+		go services.UdpateYanxuanSpecialauthorArticleNum(authorUserId) //  更新作者发布文章的数量
 	} else {
 		if req.DoType == 2 {
 			go services.SendReviewTemplateMsgAdmin(specialId)
@@ -530,6 +533,12 @@ func (this *YanxuanSpecialController) Enable() {
 	} else {
 		status = 4
 	}
+	detail, err := models.GetYanxuanSpecialItemById(req.Id)
+	if err != nil {
+		br.Msg = "审批失败"
+		br.ErrMsg = "审批失败, Err:" + err.Error()
+		return
+	}
 	if tmpErr := models.EnableYanxuanSpecial(req.Id, status, req.Reason, user.RealName); tmpErr != nil {
 		br.Msg = "审批失败"
 		br.ErrMsg = "审批失败, Err:" + tmpErr.Error()
@@ -542,6 +551,7 @@ func (this *YanxuanSpecialController) Enable() {
 	go services.UpdateYanxuanSpecialResourceData(req.Id)                                  //  写入首页最新  cygx_resource_data 表
 	go services.EsAddYanxuanSpecial(req.Id)                                               //  写入es 综合搜索
 	go services.AddAddCygxYanxuanSpecialApprovalLog(user, req.Id, req.Status, req.Reason) //  写入es 综合搜索
+	go services.UdpateYanxuanSpecialauthorArticleNum(detail.UserId)                       //  更新作者发布文章的数量
 	br.Msg = "审批成功"
 	br.Ret = 200
 	br.Success = true
@@ -911,13 +921,21 @@ func (this *YanxuanSpecialController) Cancel() {
 		return
 	}
 
+	specialItem, err := models.GetYanxuanSpecialItemById(req.Id)
+	if err != nil {
+		br.Msg = "专栏取消发布失败"
+		br.ErrMsg = "专栏取消发布失败,Err:" + err.Error()
+		return
+	}
+
 	if tmpErr := models.CancelPublishYanxuanSpecial(req.Id); tmpErr != nil {
 		br.Msg = "取消发布失败"
 		br.ErrMsg = "取消发布失败, Err:" + tmpErr.Error()
 		return
 	}
-	go services.UpdateYanxuanSpecialResourceData(req.Id) //  写入首页最新  cygx_resource_data 表
-	go services.EsAddYanxuanSpecial(req.Id)              //  写入es 综合搜索
+	go services.UpdateYanxuanSpecialResourceData(req.Id)                 //  写入首页最新  cygx_resource_data 表
+	go services.EsAddYanxuanSpecial(req.Id)                              //  写入es 综合搜索
+	go services.UdpateYanxuanSpecialauthorArticleNum(specialItem.UserId) //  更新作者发布文章的数量
 	br.Msg = "取消发布成功"
 	br.Ret = 200
 	br.Success = true

+ 9 - 0
models/cygx_yanxuan_special_user.go

@@ -254,3 +254,12 @@ func UpdateYanxuanSpecialAuthorFansNumReduce(userId int) (err error) {
 	_, err = o.Raw(sql, userId).Exec()
 	return
 }
+
+// 更新作者发布文章的数量
+func UdpateYanxuanSpecialauthorArticleNum(articleNum, userId int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special_author SET article_num = ? WHERE user_id = ? `
+	_, err = o.Raw(sql, articleNum, userId).Exec()
+	return
+}

+ 29 - 3
services/cygx_yanxuan_special.go

@@ -422,21 +422,21 @@ func UdpateYanxuanSpecialCollect(user *models.WxUserItem, specialId, status int)
 		//更新作者文章被收藏数量
 		e = models.UpdateYanxuanSpecialAuthorArticleCollectNumIncrease(specialAuthor.Id)
 		if e != nil {
-			err = errors.New("UpdateYanxuanSpecialarticleCollectNumIncrease, Err: " + e.Error())
+			err = errors.New("UpdateYanxuanSpecialAuthorArticleCollectNumIncrease, Err: " + e.Error())
 			return
 		}
 	} else {
 		//更新文章被收藏数量
 		e = models.UpdateYanxuanSpecialarticleCollectNumReduce(specialId)
 		if e != nil {
-			err = errors.New("UpdateYanxuanSpecialarticleCollectNumIncrease, Err: " + e.Error())
+			err = errors.New("UpdateYanxuanSpecialarticleCollectNumReduce, Err: " + e.Error())
 			return
 		}
 
 		//更新作者文章被收藏数量
 		e = models.UpdateYanxuanSpecialAuthorArticleCollectNumReduce(specialAuthor.Id)
 		if e != nil {
-			err = errors.New("UpdateYanxuanSpecialarticleCollectNumIncrease, Err: " + e.Error())
+			err = errors.New("UpdateYanxuanSpecialAuthorArticleCollectNumReduce, Err: " + e.Error())
 			return
 		}
 	}
@@ -470,3 +470,29 @@ func UdpateYanxuanSpecialFansNum(user *models.WxUserItem, specialAuthorId, statu
 	}
 	return
 }
+
+// UdpateYanxuanSpecialauthorArticleNum 更新作者发布文章的数量
+func UdpateYanxuanSpecialauthorArticleNum(authoruserId int) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("更新作者发布文章的数量失败,UdpateYanxuanSpecialauthorArticleNum Err ", err, "userId", authoruserId), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	condition = ` AND status = 3  AND  user_id = ?  `
+	pars = append(pars, authoruserId)
+	total, e := models.GetCygxYanxuanSpecialCount(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxYanxuanSpecialCount, Err: " + e.Error())
+		return
+	}
+	e = models.UdpateYanxuanSpecialauthorArticleNum(total, authoruserId)
+	if e != nil {
+		err = errors.New("UdpateYanxuanSpecialauthorArticleNum, Err: " + e.Error())
+		return
+	}
+	return
+}