package controllers import ( "encoding/json" "hongze/hongze_web_mfyx/models" "hongze/hongze_web_mfyx/models/order" "hongze/hongze_web_mfyx/services" "hongze/hongze_web_mfyx/utils" "strconv" "strings" "time" ) type ArticleController struct { BaseAuthController } type ArticleCommonController struct { BaseCommonController } type ArticleNoLoginController struct { BaseAuthMobileController } // @Title 获取报告详情 // @Description 获取报告详情接口 // @Param ArticleId query int true "报告ID" // @Param InviteShareCode query string false "销售账号邀请码" // @Success 200 {object} models.ArticleDetailResp // @router /detail [get] func (this *ArticleNoLoginController) Detail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } resp := new(models.ArticleDetailResp) uid := user.UserId articleId, err := this.GetInt("ArticleId") if articleId <= 0 { br.Msg = "文章不存在" br.ErrMsg = "文章不存在,文章ID错误" return } inviteShareCode := this.GetString("InviteShareCode") detail := new(models.ArticleDetail) hasPermission := 0 //resp := new(models.ArticleDetailResp) detail, err = models.GetArticleDetailById(articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,Err:" + err.Error() return } //记录分享来源 if inviteShareCode != "" { go services.AddCygxUserAdminShareHistory(user, utils.CYGX_OBJ_ARTICLE, detail.Title, inviteShareCode, articleId) } resp.IsResearch = true havePower, err := services.GetArticleDetailUserPower(user) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "校验用户权限失败,Err:" + err.Error() return } // 判断是否属于研选类型的报告 if strings.Contains(detail.CategoryName, utils.CHART_PERMISSION_NAME_YANXUAN) { resp.IsResearch = true } if havePower { detail.Body = services.GetReportContentTextArticleBody(detail.Body) hasPermission = 1 go services.ArticleHistory(articleId, user) //30分钟之内阅读同一篇文章不错二次推送 key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) if !utils.Rc.IsExist(key) { go services.ArticleUserRemind(user, detail, 1) utils.Rc.Put(key, 1, 30*time.Second) } articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取关注信息失败,Err:" + err.Error() return } detail.FollowNum = articleFollowdetail.DNum detail.CollectionNum = articleFollowdetail.AcNum if articleFollowdetail.MdNum > 0 { detail.IsFollow = true } resp.GoodsList = make([]*order.CygxGoodsResp, 0) } else { hasPermission, err = services.GetUserDetailPermissionCode(user.UserId, user.CompanyId) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,GetUserDetailPermissionCode Err:" + err.Error() return } //权益客户对权益销售信息进行展示 if hasPermission == 2 || hasPermission == 3 { sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "获取销售信息失败,Err:" + err.Error() return } if sellerItemQy != nil { detail.Seller.SellerMobile = sellerItemQy.Mobile detail.Seller.SellerName = sellerItemQy.RealName } } detail.Body = "" resp.IsShowWxPay = utils.IS_SHOW_WX_PAY //是否展示微信支付按钮 resp.IsCompanyApply = services.GetUserApplyRecordCountByCompanyIdPay(user.CompanyId) //获取客户是否有过历史申请记录 resp.IsNeedBusinessCard = services.GetCygxUserBusinessCardCount(user.UserId, user.CompanyId) //是否需要上传名片 resp.GoodsList = services.GetUserGoodsCardList() //日卡月卡商品信息 for _, v := range resp.GoodsList { resp.PopupPriceMsg += v.PopupPriceMsg //价格弹窗信息 } } if detail.ArticleTypeId == 14 { detail.IsApplyAppointmentExpert = true //判断文章类型是否属于专家访谈 查研观向11.0 } detail.Disclaimers = utils.DISCLAIMERS detail.ShareImg = services.GetArticleShareImg(articleId) //作者头像 if detail.DepartmentId > 0 { departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId) if err == nil { detail.ShareImg = departmentDetail.ImgUrl } } if user.UserId == 0 { hasPermission = 1 } resp.HasPermission = hasPermission resp.IsSpecialArticle = detail.IsSpecialArticle resp.Detail = detail br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 收藏\取消收藏 // @Description 收藏\取消收藏 // @Param request body models.ArticleCollectReq true "type json string" // @Success 200 {object} models.ArticleCollectResp // @router /collect [post] func (this *ArticleController) ArticleCollect() { 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.ArticleCollectReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } articleId := req.ArticleId detail, err := models.GetArticleDetailById(articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,Err:" + err.Error() return } count, err := models.GetArticleCollectCount(uid, articleId) if err != nil { br.Msg = "获取数据失败!" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } resp := new(models.ArticleCollectResp) if count <= 0 { item := new(models.CygxArticleCollect) item.ArticleId = req.ArticleId item.UserId = uid item.CreateTime = time.Now() item.Mobile = user.Mobile item.Email = user.Email item.CompanyId = user.CompanyId item.CompanyName = user.CompanyName item.RealName = user.RealName _, err = models.AddCygxArticleCollect(item) if err != nil { br.Msg = "收藏失败" br.ErrMsg = "收藏失败,Err:" + err.Error() return } br.Msg = "收藏成功" resp.Status = 1 // 文章收藏消息发送 go services.ArticleUserRemind(user, detail, 1) // 互动提醒 go services.SendWxCategoryMsgInteractive(user, "收藏报告", articleId, detail.Title) } else { err = models.RemoveArticleCollect(uid, articleId) if err != nil { br.Msg = "取消收藏失败" br.ErrMsg = "取消收藏失败,Err:" + err.Error() return } br.Msg = "已取消收藏" resp.Status = 2 } collectTotal, err := models.GetArticleCollectUsersCount(articleId) if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } resp.CollectCount = collectTotal br.Ret = 200 br.Success = true br.Data = resp } // @Title 访谈申请\取消访谈申请 // @Description 访谈申请\取消访谈申请 // @Param request body models.ArticleInterviewApplyReq true "type json string" // @Success 200 {object} models.FontsCollectResp // @router /interview/apply [post] func (this *ArticleController) InterviewApply() { 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.ArticleInterviewApplyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } article, err := models.GetArticleDetailById(req.ArticleId) if err != nil { br.Msg = "获取纪要失败!" br.ErrMsg = "获取纪要失败,Err:" + err.Error() return } count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId) if err != nil { br.Msg = "获取数据失败!" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } resp := new(models.ArticleInterviewApplyResp) if count <= 0 { item := new(models.CygxInterviewApply) item.ArticleId = req.ArticleId item.UserId = uid item.CompanyId = user.CompanyId item.Status = "待邀请" item.Sort = 1 item.ArticleTitle = article.Title item.CreateTime = time.Now() item.ModifyTime = time.Now() item.ArticleIdMd5 = article.ArticleIdMd5 _, err = models.AddCygxInterviewApply(item) if err != nil { br.Msg = "申请失败" br.ErrMsg = "申请失败,Err:" + err.Error() return } br.Msg = "申请成功" resp.Status = 1 //发送模板消息 if user.CompanyId > 1 { mobile := user.Mobile if mobile == "" { mobile = user.Email } sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId) if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" { openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile) if openIpItem != nil && openIpItem.OpenId != "" { go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem) } } } } else { err = models.RemoveArticleInterviewApply(uid, req.ArticleId) if err != nil { br.Msg = "取消申请失败" br.ErrMsg = "取消申请失败,Err:" + err.Error() return } br.Msg = "已取消申请" resp.Status = 2 if user.CompanyId > 1 { mobile := user.Mobile if mobile == "" { mobile = user.Email } sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId) if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" { openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile) if openIpItem != nil && openIpItem.OpenId != "" { go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem) } } } } br.Ret = 200 br.Success = true br.Data = resp } // @Title 文章带问 // @Description 新增文章带问接口 // @Param request body models.AddArticleAskRep true "type json string" // @Success Ret=200 新增成功 // @router /askAdd [post] func (this *ArticleController) AskAdd() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req models.AddArticleAskRep err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.Content == "" { br.Msg = "建议内容不可为空" return } content := req.Content //accessToken, err := models.GetWxAccessTokenByXzs() //itemToken, err := services.WxGetToken() //if err != nil { // br.Msg = "GetWxAccessToken Err:" + err.Error() // return //} //if accessToken == "" { // br.Msg = "accessToken is empty" // return //} //commerr, err := weapp.MSGSecCheck(accessToken, content) //if err != nil { // br.Msg = "内容校验失败!" // br.ErrMsg = "内容校验失败,Err:" + err.Error() // // return //} //fmt.Println(commerr) //if commerr.ErrCode != 0 { // br.Msg = "内容违规,请重新提交!" // br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG // return //} articleId := req.ArticleId count, _ := models.GetArticleCountById(articleId) if count == 0 { br.Msg = "操作失败" br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId) 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 := new(models.CygxArticleAsk) item.UserId = user.UserId item.ArticleId = req.ArticleId item.CompanyId = user.CompanyId item.CompanyName = companyDetail.CompanyName item.CreateTime = time.Now() item.Mobile = user.Mobile item.Email = user.Email item.Content = content _, err = models.AddArticleAsk(item) if err != nil { br.Msg = "提交失败" br.ErrMsg = "提交失败,Err:" + err.Error() return } companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error() return } var mobile string if utils.RunMode == "release" { mobile = utils.WxMsgTemplateIdAskMsgMobileAll + "," + companyItem.Mobile } else { mobile = utils.WxMsgTemplateIdAskMsgMobile + "," + companyItem.Mobile } openIdList, err := models.GetWxOpenIdByMobileList(mobile) if err != nil { br.Msg = "提交失败" br.ErrMsg = "提交失败,Err:" + err.Error() return } detail, err := models.GetArticleDetailById(articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,Err:" + err.Error() return } companyName := user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")" go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId) br.Ret = 200 br.Success = true br.Msg = "提交成功" } // @Title 文章相关热门收藏 // @Description 文章相关热门收藏接口 // @Param ArticleId query int true "文章ID" // @Success 200 {object} models.ArticleCollectionLIstResp // @router /hotList [get] func (this *ArticleController) ArticleHotList() { 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 } articleId, _ := this.GetInt("ArticleId") if articleId < 1 { br.Msg = "请输入分类ID" return } var condition string condition = ` AND a.article_id IN (SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id IN (SELECT industrial_management_id FROM cygx_industrial_article_group_management WHERE article_id = ` + strconv.Itoa(articleId) + ` ) ) AND a.article_id != ` + strconv.Itoa(articleId) + ` AND a.category_name LIKE '%研选%' AND publish_status = 1 GROUP BY a.article_id ORDER BY collect_num DESC, publish_date DESC LIMIT 3 ` list, err := models.GetArticleCollectionList(condition, user.UserId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取品种信息失败,Err:" + err.Error() return } resp := new(models.ArticleCollectionLIstResp) if len(list) == 0 { list = make([]*models.ArticleCollectionResp, 0) } resp.List = list br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 上传文章阅读时间 // @Description 上传文章阅读时间接口 // @Param request body models.AddStopTimeRep true "type json string" // @Success 200 {object} models.ArticleDetailResp // @router /addStopTime [post] func (this *ArticleController) AddStopTime() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } var req models.AddStopTimeRep err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } //uid := user.UserId articleId := req.ArticleId stopTime := req.StopTime outType := req.OutType //source := req.Source if articleId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误" return } if stopTime == 0 { stopTime = 1 } if outType != 2 { outType = 1 } //source = "WEB" //detail := new(models.ArticleDetail) hasPermission := 0 hasFree := 0 // //detail, err = models.GetArticleDetailById(articleId) //if err != nil { // br.Msg = "获取信息失败" // br.ErrMsg = "获取信息失败,Err:" + err.Error() // return //} havePower, err := services.GetArticleDetailUserPower(user) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "校验用户权限失败,Err:" + err.Error() return } if havePower { hasPermission = 1 go services.ArticleHistoryStopTime(articleId, stopTime, outType, user) } else { hasPermission, err = services.GetUserDetailPermissionCode(user.UserId, user.CompanyId) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,GetUserDetailPermissionCode Err:" + err.Error() return } } // //判断是否已经申请过 // applyCount, err := models.GetApplyRecordCount(uid) // if err != nil && err.Error() != utils.ErrNoRow() { // br.Msg = "获取信息失败" // br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error() // return // } // mfyxUserPermissionTotal := services.GetMfyxUserPermissionTotal(uid) // //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"` // if user.CompanyId > 1 || mfyxUserPermissionTotal == 1 { // companyPermission, err := models.GetCompanyPermission(user.CompanyId) // if err != nil { // br.Msg = "获取信息失败" // br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) // return // } // detail, err = models.GetArticleDetailById(articleId) // if err != nil { // br.Msg = "获取信息失败" // br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) // return // } // if mfyxUserPermissionTotal == 1 { // companyPermission = utils.CHART_PERMISSION_NAME_MF_YANXUAN // } // if companyPermission == "" { // if applyCount > 0 { // hasPermission = 5 // } else { // hasPermission = 2 // } // hasFree = 2 // goto Loop // } else { // hasFree = 1 // var articlePermissionPermissionName string // if detail.CategoryId > 0 { // articlePermission, err := models.GetArticlePermission(detail.CategoryId) // if err != nil { // br.Msg = "获取信息失败" // br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) // return // } // if articlePermission == nil { // br.Msg = "获取信息失败" // br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) // return // } // articlePermissionPermissionName = articlePermission.PermissionName // } else { // articlePermissionPermissionName = detail.CategoryName // } // var hasPersion bool // slice := strings.Split(articlePermissionPermissionName, ",") // //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称 // // if mfyxUserPermissionTotal == 1 { // companyPermission += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN // companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME // } // //如果有研选订阅的权限,那么就拼接一个 买方研选的权限做校验 // if strings.Contains(companyPermission, utils.CHART_PERMISSION_NAME_MF_YANXUAN) { // companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME // } // for _, v := range slice { // if strings.Contains(companyPermission, v) { // hasPersion = true // } // } // if hasPersion { // go services.ArticleHistoryStopTime(articleId, stopTime, outType, user) // } else { //无该行业权限 // hasPermission = 3 // } // } // } else { //潜在客户 // if applyCount > 0 { // hasPermission = 5 // } else { // hasPermission = 4 // } // } //Loop: resp := new(models.ArticleDetailAddStopTimeRep) resp.HasPermission = hasPermission resp.HasFree = hasFree br.Ret = 200 br.Success = true br.Msg = "操作成功" br.Data = resp } // @Title 约访专家 // @Description 约访专家接口 // @Param request body models.CygxArticleIdReq true "type json string" // @Success 200 {object} // @router /applyAppointmentExpert [post] func (this *ArticleController) ApplyAppointmentExpert() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } var req models.CygxArticleIdReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } articleId := req.ArticleId var condition string var pars []interface{} condition += ` AND article_id =? AND user_id = ? ` pars = append(pars, articleId, user.UserId) total, err := models.GetCygxArticleApplyAppointmentExpertCount(condition, pars) if err != nil { br.Msg = "约访专家失败" br.ErrMsg = "约访专家失败,Err:" + err.Error() return } if total > 0 { br.Msg = "您已提交申请,请勿重复提交。" return } err = services.AddArticleApplyAppointmentExpert(user, articleId) if err != nil { br.Msg = "约访专家失败" br.ErrMsg = "约访专家失败,Err:" + err.Error() return } services.SendArticleApplyAppointmentExpertTemplateMsg(user, articleId) br.Ret = 200 br.Success = true br.Msg = "操作成功" }