Browse Source

产业关注

xingzai 3 years ago
parent
commit
c5e81c6f32
6 changed files with 209 additions and 11 deletions
  1. 47 3
      controllers/chart_permission.go
  2. 106 3
      controllers/report.go
  3. 3 2
      models/chart_permission.go
  4. 1 0
      models/db.go
  5. 49 0
      models/industry_fllow.go
  6. 3 3
      models/report.go

+ 47 - 3
controllers/chart_permission.go

@@ -2,6 +2,7 @@ package controllers
 
 import (
 	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
 )
 
@@ -42,20 +43,63 @@ func (this *ChartPermissionController) Detail() {
 // @Description 获取报告所有品种接口
 // @Success 200 {object} models.ChartPermissionResp
 // @router /reportall [get]
-func (this *ChartPermissionController) ReportDetail() {
+func (this *ChartPermissionAuthController) ReportDetail() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	list, err := models.GetChartPermissionReportAll()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	var condition string
+	var userType int
+	if user.CompanyId > 1 {
+		total, err := models.GetCountCompanyDetailByIdGroup(user.CompanyId)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		if total == 0 {
+			userType = 0
+		} else {
+			companyDetail, err := models.GetCompanyDetailByIdGroup(user.CompanyId)
+			if err != nil {
+				br.Msg = "获取信息失败!"
+				br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
+				return
+			}
+			if companyDetail.Status == "永续" {
+				userType = 1
+			}
+		}
+	}
+	if userType == 1 {
+		condition += ` AND permission_name  != '研选'`
+	}
+	list, err := models.GetChartPermissionReportAll(condition)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
 		return
 	}
 	resp := new(models.ChartPermissionResp)
-	resp.List = list
+	for k, v := range list {
+		if userType == 1 {
+			if v.PermissionName != "研选" {
+				resp.List = append(resp.List, v)
+			}
+		} else {
+			resp.List = append(resp.List, v)
+		}
+		if services.GetShowSustainable() && v.PermissionName == "研选" {
+			resp.List[k].IsShowSustainable = true
+		}
+	}
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 106 - 3
controllers/report.go

@@ -93,7 +93,6 @@ func (this *ReportController) IndustryList() {
 		return
 	}
 	uid := user.UserId
-
 	ChartPermissionId, _ := this.GetInt("ChartPermissionId")
 	orderColumn := this.GetString("OrderColumn")
 	isNewLabel := this.GetString("IsNewLabel")
@@ -223,13 +222,12 @@ func (this *ReportController) IndustryList() {
 	//	list = append(listTop, listNoTop...)
 	//}
 
-	listNoTop, err := models.GetIndustrialManagementAll(uid, condition, orderSrt, startSize, pageSize)
+	list, err := models.GetIndustrialManagementAll(uid, condition, orderSrt, startSize, pageSize)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
 		return
 	}
-	list = listNoTop
 	for k, v := range list {
 		//var analystStr string
 		//analystList, err := models.GetIndustrialAnalystAll(v.IndustrialManagementId)
@@ -496,3 +494,108 @@ func (this *ReportController) ArticleCollect() {
 	br.Success = true
 	br.Data = resp
 }
+
+// @Title 关注/取消关注
+// @Description 关注/取消关注 接口
+// @Param	request	body models.CygxIndustryFllowRep true "type json string"
+// @Success 200
+// @router /fllow [post]
+func (this *ReportController) Fllow() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	uid := user.UserId
+	var req models.CygxIndustryFllowRep
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	industrialManagementId := req.IndustrialManagementId
+	var condition string
+	countIndustrial, err := models.GetIndustrialManagementCount(industrialManagementId)
+	if err != nil {
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	if countIndustrial == 0 {
+		br.Msg = "产业不存在!"
+		br.ErrMsg = "产业ID不存在:" + strconv.Itoa(industrialManagementId)
+		return
+	}
+	count, err := models.GetCountCygxIndustryFllow(uid, industrialManagementId, condition)
+	if err != nil {
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	//
+	//
+	//IndustrialManagementId int       `description:"产业D"`
+	//UserId                 int       `description:"用户ID"`
+	//CreateTime             time.Time `description:"创建时间"`
+	//Mobile                 string    `description:"手机号"`
+	//Email                  string    `description:"邮箱"`
+	//CompanyId              int       `description:"公司id"`
+	//CompanyName            string    `description:"公司名称"`
+	//Type                   int       `description:"操作方式,1报名,2取消报名"`
+	//ModifyTime             time.Time `description:"更新时间"`
+	resp := new(models.ArticleCollectResp)
+	if count == 0 {
+		item := new(models.CygxIndustryFllow)
+		item.IndustrialManagementId = industrialManagementId
+		item.UserId = uid
+		item.Email = user.Email
+		item.Mobile = user.Mobile
+		item.CompanyId = user.CompanyId
+		item.CompanyName = user.CompanyName
+		item.Type = 1
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		_, err = models.AddCygxIndustryFllow(item)
+		if err != nil {
+			br.Msg = "置顶失败"
+			br.ErrMsg = "置顶失败,Err:" + err.Error()
+			return
+		}
+		br.Msg = "置顶成功"
+		resp.Status = 1
+	} else {
+		var doType int
+		condition = ` AND type = 1`
+		count, err = models.GetCountCygxIndustryFllow(uid, industrialManagementId, condition)
+		if err != nil {
+			br.Msg = "获取数据失败!"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		if count == 1 {
+			br.Msg = "已取消关注"
+			resp.Status = 2
+			doType = 2
+		} else {
+			br.Msg = "已关注"
+			resp.Status = 1
+			doType = 1
+		}
+		err = models.RemoveCygxIndustryFllow(uid, industrialManagementId, doType)
+		if err != nil {
+			br.Msg = "取消关注失败"
+			br.ErrMsg = "取消置顶失败,Err:" + err.Error()
+			return
+		}
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}

+ 3 - 2
models/chart_permission.go

@@ -5,6 +5,7 @@ import "rdluck_tools/orm"
 type ChartPermission struct {
 	ChartPermissionId int    `description:"权限id"`
 	PermissionName    string `description:"权限名称"`
+	IsShowSustainable bool   `description:"是否展示限免标签"`
 }
 
 type ActivityChartPermission struct {
@@ -34,9 +35,9 @@ func GetCategoryId(chartPermissionId int) (category_id string, err error) {
 	return
 }
 
-func GetChartPermissionReportAll() (items []*ChartPermission, err error) {
+func GetChartPermissionReportAll(condition string) (items []*ChartPermission, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM chart_permission WHERE product_id=2 AND is_report=1 ORDER BY sort ASC `
+	sql := `SELECT * FROM chart_permission WHERE product_id=2 AND is_report=1 ` + condition + ` ORDER BY sort ASC `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }

+ 1 - 0
models/db.go

@@ -57,5 +57,6 @@ func init() {
 		new(CygxMySchedule),
 		new(WxUserWhite),
 		new(CygxActivityHelpAsk),
+		new(CygxIndustryFllow),
 	)
 }

+ 49 - 0
models/industry_fllow.go

@@ -0,0 +1,49 @@
+package models
+
+import (
+	"rdluck_tools/orm"
+	"time"
+)
+
+type CygxIndustryFllow struct {
+	Id                     int       `orm:"column(id);pk"`
+	IndustrialManagementId int       `description:"产业D"`
+	UserId                 int       `description:"用户ID"`
+	Mobile                 string    `description:"手机号"`
+	Email                  string    `description:"邮箱"`
+	CompanyId              int       `description:"公司id"`
+	CompanyName            string    `description:"公司名称"`
+	Type                   int       `description:"操作方式,1报名,2取消报名"`
+	CreateTime             time.Time `description:"创建时间"`
+	ModifyTime             time.Time `description:"更新时间"`
+}
+
+type CygxIndustryFllowRep struct {
+	IndustrialManagementId int `description:"产业D"`
+}
+
+//添加
+func AddCygxIndustryFllow(item *CygxIndustryFllow) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+type CygxIndustryFllowResp struct {
+	Status  int  `description:"1:关注,2:取消关注"`
+	GoFllow bool `description:"是否去关注"`
+}
+
+func RemoveCygxIndustryFllow(userId, industrialManagementId, doType int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_industry_fllow SET type = ? ,modify_time=? WHERE user_id=? AND industrial_management_id=? `
+	_, err = o.Raw(sql, doType, time.Now(), userId, industrialManagementId).Exec()
+	return
+}
+
+//获取数量
+func GetCountCygxIndustryFllow(userId, industrialManagementId int, condition string) (count int, err error) {
+	sql := `SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE user_id=? AND industrial_management_id=? ` + condition
+	err = orm.NewOrm().Raw(sql, userId, industrialManagementId).QueryRow(&count)
+	return
+}

+ 3 - 3
models/report.go

@@ -21,11 +21,11 @@ type IndustrialManagement struct {
 	UpdateTime             string               `description:"更新时间"`
 	IsRed                  bool                 `description:"是否标记红点"`
 	IsTop                  bool                 `description:"是否置顶"`
-	AnalystList            []*IndustrialAnalyst `description:"分析师列表"`
-	Analyst                string               `description:"分析师"`
-	IndustrialSubjectList  []*IndustrialSubject `description:"标的列表"`
 	IsHot                  bool                 `description:"是否是热门"`
 	IsFollow               int                  `description:"是否关注"`
+	Analyst                string               `description:"分析师"`
+	AnalystList            []*IndustrialAnalyst `description:"分析师列表"`
+	IndustrialSubjectList  []*IndustrialSubject `description:"标的列表"`
 }
 
 type IndustrialAnalyst struct {