zwxi 1 年之前
父节点
当前提交
1b51661c7d
共有 4 个文件被更改,包括 21 次插入9 次删除
  1. 11 1
      controllers/company_user.go
  2. 3 1
      models/company/company_user.go
  3. 4 4
      models/company_user/request/follow.go
  4. 3 3
      models/wx_user.go

+ 11 - 1
controllers/company_user.go

@@ -5962,7 +5962,17 @@ func (this *CompanyUserController) Follow() {
 	}
 
 	// 查公司里有多少已关注,上限三个
-
+	count, err := models.GetCompanyFollowCount(req.CompanyId)
+	if err != nil {
+		br.Msg = "操作失败! "
+		br.ErrMsg = "操作失败,Err:" + err.Error()
+		return
+	}
+	if count == 3 && req.Type == 1 {
+		br.Msg = "操作失败! "
+		br.ErrMsg = "操作失败,公司已达到关注上限"
+		return
+	}
 
 	// 关注或取关
 	err = models.SetUserFollow(req.UserId, req.Type)

+ 3 - 1
models/company/company_user.go

@@ -61,6 +61,7 @@ type CompanyUser struct {
 	IsChartPermissionSetting int       `description:"是否设置过图表权限, 0-未设置,1-已设置,2-无需设置"`
 	YbProductViewTotal       int       `description:"研报分产品阅读统计"`
 	IsSubscribe              int       `description:"是否关注了微信公众号: 0-未关注; 1-已关注"`
+	IsFollow                 int       `description:"是否特别关注: 0-未关注; 1-已关注"`
 	IsSubscribeHzyj          int       `description:"是否关注了弘则研究微信公众号: 0-未关注; 1-已关注"`
 	IsSubscribeCygx          int       `description:"是否关注了查研观向微信公众号: 0-未关注; 1-已关注"`
 	FiccViewTotal            int       `description:"ficc报告的阅读次数" json:"-"`
@@ -138,7 +139,8 @@ func GetCompanyUserListV2(condition string, pars []interface{}, companyId, start
 	if condition != "" {
 		sql += condition
 	}
-	sql += ` group by a.user_id ORDER BY a.is_register desc,a.report_last_view_time desc,a.last_updated_time DESC LIMIT ?,? `
+	//sql += ` group by a.user_id ORDER BY a.is_register desc,a.report_last_view_time desc,a.last_updated_time DESC LIMIT ?,? `
+	sql += ` group by a.user_id ORDER BY is_follow DESC, CASE WHEN is_follow = 1 AND report_last_view_time < NOW()  - INTERVAL 7 DAY THEN 0 ELSE 1 END  LIMIT ?,? `
 	_, err = o.Raw(sql, companyId, pars, startSize, pageSize).QueryRows(&items)
 	return
 }

+ 4 - 4
models/company_user/request/follow.go

@@ -1,7 +1,7 @@
 package request
 
-
 type FollowReq struct {
-	UserId        int `description:"用户ID"`
-	Type         int `description:"类型 0取关 1关注"`
-}
+	UserId    int `description:"用户ID"`
+	CompanyId int `description:"公司ID"`
+	Type      int `description:"类型 0取关 1关注"`
+}

+ 3 - 3
models/wx_user.go

@@ -593,9 +593,9 @@ func SetUserFollow(userId, follow int) (err error) {
 	return
 }
 
-func GetCompanyFollowCount(companyId int) (err error) {
+func GetCompanyFollowCount(companyId int) (count int, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT COUNT(1) FROM wx_user WHERE user_id=? `
-	_, err = o.Raw(sql, companyId).Exec()
+	sql := ` SELECT COUNT(1) FROM wx_user WHERE company_id=? `
+	err = o.Raw(sql, companyId).QueryRow(&count)
 	return
 }