123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- 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 = "提交成功"
- }
|