Browse Source

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

xingzai 1 year ago
parent
commit
1fc6f7bdde

+ 12 - 8
controllers/report.go

@@ -830,6 +830,7 @@ func (this *MobileReportController) SearchReport() {
 	keyWord := this.GetString("KeyWord")
 	keyWord := this.GetString("KeyWord")
 	isAll, _ := this.GetBool("IsAll")
 	isAll, _ := this.GetBool("IsAll")
 	var condition string
 	var condition string
+	var conditionYxSpecial string
 	var pars []interface{}
 	var pars []interface{}
 	//var conditionSql string
 	//var conditionSql string
 	var total int
 	var total int
@@ -940,13 +941,16 @@ func (this *MobileReportController) SearchReport() {
 		}
 		}
 	} else {
 	} else {
 
 
-		//condition = `AND ( a.title LIKE '%` + keyWord + `%' OR  a.body LIKE '%` + keyWord + `%' OR  a.annotation LIKE '%` + keyWord + `%' OR  a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1 `
-		if articleType == 1 {
-			condition = `  AND ( a.title LIKE '%` + keyWord + `%' OR  a.body LIKE '%` + keyWord + `%' OR  a.annotation LIKE '%` + keyWord + `%' OR  a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1  AND a.article_type_id NOT IN (` + articleTypeIds + `)  `
-			total, err = models.GetReoprtSearchCountHz(condition)
-		} else {
-			condition = `  AND ( a.title LIKE '%` + keyWord + `%' OR  a.body LIKE '%` + keyWord + `%' OR  a.annotation LIKE '%` + keyWord + `%' OR  a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1  AND a.article_type_id  IN (` + articleTypeIds + `)  `
-			total, err = models.GetReoprtSearchCountYx(condition)
+		if keyWord != "" {
+			if articleType == 1 {
+				condition = `  AND ( a.title LIKE '%` + keyWord + `%' OR  a.body LIKE '%` + keyWord + `%' OR  a.annotation LIKE '%` + keyWord + `%' OR  a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1  AND a.article_type_id NOT IN (` + articleTypeIds + `)  `
+				total, err = models.GetReoprtSearchCountHz(condition)
+			} else {
+				condition = `  AND ( a.title LIKE '%` + keyWord + `%' OR  a.body LIKE '%` + keyWord + `%' OR  a.annotation LIKE '%` + keyWord + `%' OR  a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1  AND a.article_type_id  IN (` + articleTypeIds + `)  `
+				total, err = models.GetReoprtSearchCountYx(condition)
+			}
+
+			conditionYxSpecial = `   AND ( a.title LIKE '%` + keyWord + `%' OR  a.content LIKE '%` + keyWord + `%')  `
 		}
 		}
 		if err != nil {
 		if err != nil {
 			br.Msg = "获取信息失败"
 			br.Msg = "获取信息失败"
@@ -958,7 +962,7 @@ func (this *MobileReportController) SearchReport() {
 		if articleType == 1 {
 		if articleType == 1 {
 			list, err = models.GetArticleResearchListHz(condition, pars, startSize, pageSize, user.UserId)
 			list, err = models.GetArticleResearchListHz(condition, pars, startSize, pageSize, user.UserId)
 		} else {
 		} else {
-			list, err = models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId, true)
+			total, list, err = models.GetArticleResearchAndYxSpecialList(condition, conditionYxSpecial, pars, startSize, pageSize, user.UserId, true)
 		}
 		}
 		if err != nil {
 		if err != nil {
 			br.Msg = "获取信息失败"
 			br.Msg = "获取信息失败"

+ 28 - 24
controllers/yanxuan_special.go

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

+ 21 - 3
models/cygx_yanxuan_special.go

@@ -111,11 +111,11 @@ type EnableCygxYanxuanSpecialReq struct {
 	Reason string //理由
 	Reason string //理由
 }
 }
 
 
-func EnableYanxuanSpecial(id, status int, reason string) (err error) {
+func EnableYanxuanSpecial(id, status int, reason, adminName string) (err error) {
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	sql := ``
 	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
 	return
 }
 }
 
 
@@ -283,3 +283,21 @@ func UpdateYanxuanSpecialUv(id int) (err error) {
 	_, err = o.Raw(sql, id).Exec()
 	_, err = o.Raw(sql, id).Exec()
 	return
 	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()
 	_, err = o.Raw(sql, userId).Exec()
 	return
 	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
+}

+ 69 - 0
models/report.go

@@ -935,6 +935,75 @@ func GetArticleResearchList(condition string, pars []interface{}, startSize, pag
 	return
 	return
 }
 }
 
 
+func GetArticleResearchAndYxSpecialList(condition, conditionYxSpecial string, pars []interface{}, startSize, pageSize, userId int, needYanxuanSpecial bool) (total int, items []*ArticleListResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			a.article_id,
+			a.title,
+			a.body,
+			a.annotation,
+			a.abstract,
+			a.publish_date,
+			a.article_type_id,
+			d.nick_name,
+			d.department_id,
+			( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
+			( SELECT count( 1 ) FROM cygx_article_collect AS ac    WHERE ac.article_id = a.article_id  ) AS collect_num, 
+			( SELECT count( 1 ) FROM cygx_article_collect AS ac   WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time )  ) AS collect_num_order, 
+			( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id  AND user_id = ? ) AS my_collect_num,
+			0 AS is_special,
+			0 AS special_type,
+			0 AS special_column_id,
+			'' AS company_tags, 
+			'' AS industry_tags
+		FROM
+			cygx_article AS a
+			LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
+			LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
+			INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id 
+		WHERE
+			1 = 1  AND a.publish_status = 1  `
+	if condition != "" {
+		sql += condition
+	}
+	if needYanxuanSpecial {
+		sql += `UNION ALL
+	SELECT
+		a.id AS article_id,
+		a.title AS title,
+		'' AS body,
+		a.content AS annotation,
+		'' AS abstract,
+		a.publish_time AS publish_date,
+		-1 AS article_type_id,
+		b.nick_name AS nick_name,
+		0 AS department_id,
+		( SELECT count( 1 ) FROM cygx_yanxuan_special_record AS h WHERE h.yanxuan_special_id = a.id ) AS pv,
+		( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac   WHERE ac.yanxuan_special_id = a.id  ) AS collect_num,
+		0 AS collect_num_order,
+		( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id  AND user_id = ? ) AS my_collect_num,
+		1 AS is_special,
+		a.type AS special_type,
+		b.id AS special_column_id,
+		a.company_tags AS company_tags, 
+		a.industry_tags AS industry_tags 
+	FROM
+	cygx_yanxuan_special AS a
+	JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
+	WHERE
+	1 = 1  AND a.status = 3 ` + conditionYxSpecial
+
+		totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
+		err = o.Raw(totalSql, userId, userId, pars).QueryRow(&total)
+		sql += ` GROUP BY article_id ORDER  BY publish_date DESC  LIMIT ?,? `
+		_, err = o.Raw(sql, userId, userId, pars, startSize, pageSize).QueryRows(&items)
+	} else {
+		sql += ` GROUP BY a.article_id ORDER  BY a.publish_date DESC  LIMIT ?,? `
+		_, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
+	}
+	return
+}
+
 func GetArticleResearchListHz(condition string, pars []interface{}, startSize, pageSize, userId int) (items []*ArticleListResp, err error) {
 func GetArticleResearchListHz(condition string, pars []interface{}, startSize, pageSize, userId int) (items []*ArticleListResp, err error) {
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	sql := `SELECT
 	sql := `SELECT

+ 81 - 0
services/cygx_yanxuan_special.go

@@ -389,3 +389,84 @@ func AddAddCygxYanxuanSpecialApprovalLog(user *models.WxUserItem, specialId, sta
 	}
 	}
 	return
 	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
+}