package controllers import ( "encoding/json" "github.com/medivhzhan/weapp/v2" "hongze/hongze_mfyx/models" "hongze/hongze_mfyx/services" "hongze/hongze_mfyx/utils" "strconv" "time" ) // 报告 type ReportController struct { BaseAuthController } type ReportCommonController struct { BaseCommonController } // @Title 相关按钮是否展示接口 // @Description 相关按钮是否展示接口 // @Param request body models.IsShow true "type json string" // @Success 200 // @router /isShow [get] func (this *ReportController) IsShow() { 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 } var resp models.IsShow var condition string var pars []interface{} condition += ` AND a.user_id = ? AND a.status = 1 ` pars = append(pars, user.UserId) total, err := models.GetCygxYanxuanSpecialAuthorCount(condition, pars) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } if total > 0 { resp.IsYanxuanSpecialAuthor = true } //resp.IsShowMobileAndEmailButton = true resp.IsShowWxPay = utils.IS_SHOW_WX_PAY // 是否调取微信支付 resp.IsShow = true br.Ret = 200 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 } // @Title 文章留言接口 // @Description 文章留言接口 // @Param request body models.AddCygxActivityHelpAsk true "type json string" // @Success 200 {object} models.TacticsListResp // @router /commentAdd [post] func (this *ReportController) CommentAdd() { 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 } var req models.AddCygxArticleCommentReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ArticleId <= 0 { br.Msg = "文章不存在" br.ErrMsg = "文章不存在,文章ID错误" return } if req.Content == "" { br.Msg = "建议内容不可为空" return } content := req.Content itemToken, err := services.WxGetToken() if err != nil { br.Msg = "GetWxAccessToken Err:" + err.Error() return } if itemToken.AccessToken == "" { br.Msg = "accessToken is empty" return } commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content) if err != nil { br.Msg = "内容校验失败!" br.ErrMsg = "内容校验失败,Err:" + err.Error() return } if commerr.ErrCode != 0 { br.Msg = "内容违规,请重新提交!" br.ErrMsg = "内容违规,Err:" + commerr.ErrMSG return } articleId := req.ArticleId articleInfo, errInfo := models.GetArticleDetailById(articleId) if articleInfo == nil { br.Msg = "操作失败" br.ErrMsg = "文章ID错误,不存在articleId:" + strconv.Itoa(articleId) return } if errInfo != nil { br.Msg = "操作失败" br.ErrMsg = "操作失败,Err:" + errInfo.Error() return } companyDetail, err := models.GetCompanyDetailById(user.CompanyId) if err != nil { br.Msg = "提交失败!" br.ErrMsg = "获取客户详情失败,Err:" + err.Error() return } if companyDetail == nil { br.Msg = "提交失败!" br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) return } item := models.CygxArticleComment{ UserId: user.UserId, ArticleId: req.ArticleId, CreateTime: time.Now(), Mobile: user.Mobile, Email: user.Email, CompanyId: user.CompanyId, CompanyName: companyDetail.CompanyName, Content: content, Title: articleInfo.Title, } msgId, err := models.AddArticleComment(&item) if err != nil { br.Msg = "提交失败" br.ErrMsg = "提交留言失败,Err:" + err.Error() return } services.SendCommentWxTemplateMsg(req, user, articleInfo, int(msgId)) go services.SendCommentWxCategoryTemplateMsg(req, user, articleInfo, int(msgId)) br.Ret = 200 br.Success = true br.Msg = "提交成功" }