|
@@ -1,7 +1,12 @@
|
|
|
package controllers
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"hongze/hongze_mfyx/models"
|
|
|
+ "hongze/hongze_mfyx/services"
|
|
|
+ "hongze/hongze_mfyx/utils"
|
|
|
+ "strconv"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
// 报告
|
|
@@ -50,3 +55,188 @@ func (this *ReportController) IsShow() {
|
|
|
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
|
|
|
+ }
|
|
|
+ resp := new(models.CygxIndustryFllowResp)
|
|
|
+ countUser, err := models.GetCountCygxIndustryFllowByUid(uid)
|
|
|
+ if countUser == 0 {
|
|
|
+ resp.GoFollow = true
|
|
|
+ }
|
|
|
+ item := new(models.CygxIndustryFllow)
|
|
|
+ item.IndustrialManagementId = industrialManagementId
|
|
|
+ item.UserId = uid
|
|
|
+ item.Email = user.Email
|
|
|
+ item.Mobile = user.Mobile
|
|
|
+ item.RealName = user.RealName
|
|
|
+ item.Source = utils.REGISTER_PLATFORM
|
|
|
+ item.CompanyId = user.CompanyId
|
|
|
+ item.CompanyName = user.CompanyName
|
|
|
+ if count == 0 {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ resp.Status = 1
|
|
|
+ } else {
|
|
|
+ item.Type = 2
|
|
|
+ err = models.RemoveCygxIndustryFllow(uid, industrialManagementId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "取消关注失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ go services.IndustryFllowWithTrack(industrialManagementId, count, uid) //处理是否关注全部赛道字段
|
|
|
+ go services.IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid) //处理用户标签
|
|
|
+ go services.AddCygxIndustryFllowLog(item) //添加操作日志记录
|
|
|
+ br.Msg = "操作成功"
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Data = resp
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 关注作者/取消关注作者
|
|
|
+// @Description 关注作者/取消关注作者 接口
|
|
|
+// @Param request body models.CygxArticleDepartmentId true "type json string"
|
|
|
+// @Success 200
|
|
|
+// @router /fllowDepartment [post]
|
|
|
+func (this *ReportController) FllowDepartment() {
|
|
|
+ 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.CygxArticleDepartmentId
|
|
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ departmentId := req.DepartmentId
|
|
|
+ var condition string
|
|
|
+ countDepartment, err := models.GetDepartmentCount(departmentId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取数据失败!"
|
|
|
+ br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if countDepartment == 0 {
|
|
|
+ br.Msg = "作者不存在!"
|
|
|
+ br.ErrMsg = "作者ID不存在:" + strconv.Itoa(departmentId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ countUser, err := models.GetArticleDepartmentFollowByUid(uid)
|
|
|
+ count, err := models.GetArticleDepartmentFollow(uid, departmentId, condition)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取数据失败!"
|
|
|
+ br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp := new(models.CygxArticleDepartmentFollowResp)
|
|
|
+ if countUser == 0 {
|
|
|
+ resp.GoFollow = true
|
|
|
+ }
|
|
|
+ if count == 0 {
|
|
|
+ item := new(models.CygxArticleDepartmentFollow)
|
|
|
+ item.DepartmentId = departmentId
|
|
|
+ item.UserId = uid
|
|
|
+ item.Email = user.Email
|
|
|
+ item.Mobile = user.Mobile
|
|
|
+ item.RealName = user.RealName
|
|
|
+ item.CompanyId = user.CompanyId
|
|
|
+ item.CompanyName = user.CompanyName
|
|
|
+ item.Type = 1
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ item.ModifyTime = time.Now()
|
|
|
+ _, err = models.AddArticleDepartmentFollow(item)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "操作失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.Status = 1
|
|
|
+ } else {
|
|
|
+ var doType int
|
|
|
+ condition = ` AND type = 1`
|
|
|
+ count, err = models.GetArticleDepartmentFollow(uid, departmentId, condition)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "操作失败!"
|
|
|
+ br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if count == 1 {
|
|
|
+ resp.Status = 2
|
|
|
+ doType = 2
|
|
|
+ } else {
|
|
|
+ resp.Status = 1
|
|
|
+ doType = 1
|
|
|
+ }
|
|
|
+ err = models.RemoveArticleDepartmentFollow(uid, departmentId, doType)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "取消关注失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ br.Msg = "操作成功"
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Data = resp
|
|
|
+}
|