123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755 |
- package controllers
- import (
- "bufio"
- "github.com/pdfcpu/pdfcpu/pkg/api"
- "github.com/pdfcpu/pdfcpu/pkg/pdfcpu"
- "io"
- //"bufio"
- "encoding/json"
- "fmt"
- "github.com/medivhzhan/weapp/v2"
- "os"
- //"github.com/pdfcpu/pdfcpu/pkg/api"
- //"github.com/pdfcpu/pdfcpu/pkg/pdfcpu"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/services"
- "hongze/hongze_cygx/utils"
- "html"
- nhttp "net/http"
- "strconv"
- "strings"
- "time"
- )
- type ArticleController struct {
- BaseAuthController
- }
- type ArticleCommonController struct {
- BaseCommonController
- }
- type ArticleControllerMobile struct {
- BaseAuthMobileController
- }
- // @Title 获取报告详情
- // @Description 获取报告详情接口
- // @Param ArticleId query int true "报告ID"
- // @Param IsSendWx query int false "是否是通过微信模版进来的 1是,其它否"
- // @Success 200 {object} models.ArticleDetailResp
- // @router /detail [get]
- func (this *ArticleController) 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
- }
- uid := user.UserId
- articleId, err := this.GetInt("ArticleId")
- isSendWx, _ := this.GetInt("IsSendWx")
- if articleId <= 0 {
- br.Msg = "文章不存在"
- br.ErrMsg = "文章不存在,文章ID错误"
- return
- }
- detail := new(models.ArticleDetail)
- //detailInit := new(models.ArticleDetail) // 初始化的文章信息,用来处理body 内容回显
- hasPermission := 0
- var haveResearch bool
- //判断是否已经申请过
- applyCount, err := models.GetApplyRecordCount(uid)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
- resp := new(models.ArticleDetailResp)
- detail, err = models.GetArticleDetailById(articleId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- detail.PublishDate = utils.TimeRemoveHms2(detail.PublishDate)
- detail.Body = html.UnescapeString(detail.Body)
- detail.Body = strings.Replace(detail.Body, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sans-serif;\">Powered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
- detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
- detail.Abstract = html.UnescapeString(detail.Abstract)
- //detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
- //作者头像
- if detail.DepartmentId > 0 {
- departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId)
- if err == nil {
- detail.DepartmentImgUrl = departmentDetail.ImgUrl
- }
- }
- lyjhTypeMap, _ := services.GetLyjhTypeMap()
- if _, ok := lyjhTypeMap[detail.CategoryId]; ok {
- detail.IsRoadShow = true
- }
- // 判断是否属于研选类型的报告
- if strings.Contains(detail.CategoryName, utils.CHART_PERMISSION_NAME_YANXUAN) {
- detail.IsResearch = true
- }
- // 高毅资产的联系人,有权限的行业也不能查看报告详情页。提示无权限页面
- if detail.ArticleTypeId == 0 && user.CompanyId == utils.GAO_YI_ZI_CHAN_COMPANY_ID {
- _, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
- resp.PopupMsg = popupMsg
- resp.HasPermission = 3
- resp.SellerName = sellerName
- resp.SellerMobile = sellerMobile
- detail.Body = ""
- detail.Abstract = ""
- detail.BodyText = ""
- detail.SellerName = sellerName
- detail.SellerMobile = sellerMobile
- resp.Detail = detail
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)
- detail.IsCollect = articleCollectMap[detail.ArticleId]
- //detailInit = detail
- if isSendWx == 1 {
- var condition string
- var pars []interface{}
- pars = make([]interface{}, 0)
- condition = ` AND article_id = ? `
- reportMappingMap, _ := services.GetReportMappingMap()
- if reportMappingMap[detail.CategoryId] {
- chooseCategoryMap, _ := services.GetChooseCategoryMap(user)
- detail.IsShowFollowButton = true
- detail.IsFollowButton = chooseCategoryMap[detail.CategoryId]
- } else {
- pars = append(pars, articleId)
- industrialList, err := models.GetIndustrialArticleGroupManagementList(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if len(industrialList) > 0 {
- industryUserFollowMap, err := services.GetIndustryUserFollowMap(user)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "GetActivitySignupResp,Err:" + err.Error()
- return
- }
- for _, v := range industrialList {
- if industryUserFollowMap[v.IndustrialManagementId] {
- detail.IsFollowButton = true
- }
- }
- detail.IsShowFollowButton = true
- }
- }
- }
- //是否属于专项调研报告
- if detail.SubCategoryName == "专项调研" {
- detail.IsSpecialArticle = true
- havePower, err := services.GetSpecialArticleDetailUserPower(user, detail)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
- resp.IsSpecialArticle = true
- if !havePower {
- hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
- resp.PopupMsg = popupMsg
- resp.HasPermission = hasPermission
- resp.SellerName = sellerName
- resp.SellerMobile = sellerMobile
- detail.Body = ""
- detail.Abstract = ""
- detail.BodyText = ""
- detail.SellerName = sellerName
- detail.SellerMobile = sellerMobile
- resp.Detail = detail
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- }
- //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
- if user.CompanyId > 1 {
- companyPermission, err := models.GetCompanyPermission(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
- return
- }
- //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称
- mfyxUserPermissionTotal := services.GetMfyxUserPermissionTotal(uid)
- 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
- }
- if companyPermission == "" {
- if applyCount > 0 {
- hasPermission = 5
- } else {
- hasPermission = 2
- }
- goto Loop
- } else {
- var articlePermissionName string
- var matchTypeName 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
- }
- articlePermissionName = articlePermission.PermissionName
- matchTypeName = articlePermission.MatchTypeName
- } else {
- articlePermissionName = detail.CategoryName
- }
- var hasPersion bool
- slice := strings.Split(articlePermissionName, ",")
- for _, v := range slice {
- if strings.Contains(companyPermission, v) {
- hasPersion = true
- }
- }
- if articleId == 11223 { // 这是一篇非常特殊的文章,要单独处理 需求池 976
- if strings.Contains(companyPermission, utils.YI_YAO_NAME) || strings.Contains(companyPermission, utils.XIAO_FEI_NAME) || strings.Contains(companyPermission, utils.KE_JI_NAME) || strings.Contains(companyPermission, utils.ZHI_ZAO_NAME) || strings.Contains(companyPermission, utils.CE_LUE_NAME) || strings.Contains(companyPermission, utils.GU_SHOU_NAME) || strings.Contains(companyPermission, utils.ZHOU_QI_NAME) {
- hasPersion = true
- }
- }
- if strings.Contains(detail.CategoryName, "研选") {
- detail.IsResearch = true
- }
- userType, _, err := services.GetUserType(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
- return
- }
- //永续客户,无法查看研选权限,但是下面的联系人,单独开通研选后,也可以查看研选内容
- if userType == 1 && strings.Contains(detail.CategoryName, "研选") && mfyxUserPermissionTotal == 0 {
- hasPersion = false
- }
- //if detail.IsReport == 1 {
- //detailCategory, err := models.GetdetailByCategoryIdSando(detail.CategoryId)
- //if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "获取信息失败"
- // br.ErrMsg = "获取信息失败,Err:" + err.Error() + "categoryID 不存在:" + strconv.Itoa(detail.CategoryId)
- // return
- //}
- //permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
- //if err != nil {
- // br.Msg = "获取信息失败"
- // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- // return
- //}
- //if detailCategory != nil {
- // if detailCategory.PermissionType == 1 {
- // if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(主观)") {
- // hasPersion = false
- // }
- // } else if detailCategory.PermissionType == 2 {
- // if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(客观)") {
- // hasPersion = false
- // }
- // }
- //}
- //}
- //大行业通过权限校验,再校验主客观权限。只有医药、消费、科技、智造,才会校验主客观权限,热点问答这个匹配类型下的所有报告,也不做主客观校验
- if hasPersion && utils.InArrayByStr([]string{utils.YI_YAO_NAME, utils.XIAO_FEI_NAME, utils.KE_JI_NAME, utils.ZHI_ZAO_NAME}, articlePermissionName) && matchTypeName != "热点问答" {
- hasPersion = services.CheckArticlePermissionType(articleId, user)
- }
- if hasPersion {
- 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)
- }
- } else { //无该行业权限
- companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
- if err == nil && companyDetail.ProductId == 1 {
- hasPermission = 2
- } else {
- hasPermission = 3
- }
- }
- }
- interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
- return
- }
- if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
- detail.IsInterviewApply = true
- detail.InterviewApplyStatus = interviewApplyItem.Status
- }
- //获取销售手机号
- sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取销售数据失败2,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
- return
- }
- if sellerItem != nil {
- detail.SellerMobile = sellerItem.Mobile
- detail.SellerName = sellerItem.RealName
- }
- sellerList, err := models.GetSellerList(articleId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
- return
- }
- if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
- strnum := strings.Index(detail.SellerAndMobile, "-")
- detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
- if strnum > 0 {
- nickName := detail.SellerAndMobile[0:strnum]
- sellerAndMobile := &models.SellerRep{
- SellerMobile: "",
- SellerName: nickName,
- }
- sellerList = append(sellerList, sellerAndMobile)
- }
- }
- detail.SellerList = sellerList
- } else { //潜在客户
- if applyCount > 0 {
- hasPermission = 5
- } else {
- hasPermission = 4
- }
- }
- Loop:
- if hasPermission != 1 && user.UserId > 0 {
- detail.Body = ""
- detail.BodyText = ""
- } else {
- 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
- }
- if detail.IsSummary == 1 {
- detail.IsBelongSummary = true
- }
- if detail.IsReport == 1 {
- detail.IsBelongReport = true
- }
- haveResearch = true
- }
- if hasPermission == 5 {
- companyPermissionNoStatus, err := models.GetCompanyPermissionByUserNoStatus(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
- return
- }
- if companyPermissionNoStatus != "" {
- 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 {
- hasPermission = 3
- detail.SellerMobile = sellerItemQy.Mobile
- detail.SellerName = sellerItemQy.RealName
- }
- }
- }
- if hasPermission == 2 || hasPermission == 4 {
- //获取销售手机号
- 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 {
- hasPermission = 3
- detail.SellerMobile = sellerItemQy.Mobile
- detail.SellerName = sellerItemQy.RealName
- }
- }
- if detail.ArticleId < utils.SummaryArticleId {
- if user.Mobile != "" {
- chartUserTokenByMobile, _ := services.GetUserTokenByMobile(user.Mobile)
- detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile
- } else {
- detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId)
- }
- detail.IsNeedJump = true
- }
- // 处理研选下面的路演精华 的报告链接是否跳转
- if hasPermission == 1 && detail.ArticleId > utils.SummaryArticleId && detail.ArticleTypeId > 0 {
- //detail.PublishDate = utils.TimeRemoveHms2(detail.PublishDate)
- if detail.ReportLink != "" {
- chartUserTokenByMobile, _ := services.GetUserTokenByMobile(user.Mobile)
- detail.ReportLink += "?token=" + chartUserTokenByMobile
- }
- }
- if articleId < utils.SummaryArticleId {
- detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
- }
- if detail.ArticleTypeId == 14 {
- detail.IsApplyAppointmentExpert = true //判断文章类型是否属于专家访谈 查研观向11.0
- }
- resp.HasPermission = hasPermission
- resp.HaveResearch = haveResearch
- if user.UserId == 0 {
- resp.HasPermission = 1
- if detail.UpdateFrequency == "daily" {
- detail.Frequency = "日度"
- } else if detail.UpdateFrequency == "weekly" {
- detail.Frequency = "周度"
- } else if detail.UpdateFrequency == "monthly" {
- detail.Frequency = "月度"
- } else if detail.UpdateFrequency == "quarterly" {
- detail.Frequency = "季度"
- } else if detail.UpdateFrequency == "yearly" {
- detail.Frequency = "年度"
- }
- }
- resp.Detail = detail
- if user.Mobile != "" {
- resp.Mobile = user.Mobile
- } else {
- resp.Mobile = user.Email
- }
- 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.FontsCollectResp
- // @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, 2)
- go services.ArticleHistoryUserLabelLogAdd(articleId, user.UserId)
- } 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 ArticleIdMd5 query int true "报告ID"
- // @Success 200 {object} models.ArticleDetailResp
- // @router /look/detail [get]
- func (this *ArticleControllerMobile) DetailMd5() {
- 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
- }
- uid := user.UserId
- articleIdMd5 := this.GetString("ArticleIdMd5")
- if articleIdMd5 == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- resp := new(models.ArticleDetailResp)
- detail, err := models.GetArticleDetailByIdMd5(articleIdMd5)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- articleId := detail.ArticleId
- detail.Body = html.UnescapeString(detail.Body)
- hasPermission := 2
- //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
- if user.CompanyId > 1 {
- companyPermission, err := models.GetCompanyPermission(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取公司权限失败,Err:" + err.Error()
- return
- }
- detail.Body = html.UnescapeString(detail.Body)
- detail.Body = strings.Replace(detail.Body, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sans-serif;\">Powered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
- detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
- detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
- if companyPermission == "" {
- hasPermission = 2
- } else {
- var articlePermissionPermissionName string
- if detail.CategoryId > 0 {
- articlePermission, err := models.GetArticlePermission(detail.CategoryId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + articleIdMd5
- return
- }
- if articlePermission == nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "报告权限不存在,Err:" + articleIdMd5
- return
- }
- articlePermissionPermissionName = articlePermission.PermissionName
- } else {
- articlePermissionPermissionName = detail.CategoryName
- }
- var hasPersion bool
- slice := strings.Split(articlePermissionPermissionName, ",")
- for _, v := range slice {
- if strings.Contains(companyPermission, v) {
- hasPersion = true
- }
- }
- userType, _, err := services.GetUserType(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
- return
- }
- if userType == 1 && strings.Contains(detail.CategoryName, "研选") {
- hasPersion = false
- }
- if detail.IsReport == 1 {
- detailCategory, err := models.GetdetailByCategoryIdSando(detail.CategoryId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error() + "categoryID 不存在:" + strconv.Itoa(detail.CategoryId)
- return
- }
- permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- if detailCategory != nil {
- if detailCategory.PermissionType == 1 {
- if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(主观)") {
- hasPersion = false
- }
- } else if detailCategory.PermissionType == 2 {
- if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(客观)") {
- hasPersion = false
- }
- }
- }
- }
- if hasPersion {
- hasPermission = 1
- record := new(models.CygxArticleHistoryRecordNewpv)
- record.UserId = uid
- record.ArticleId = articleId
- record.CreateTime = time.Now()
- record.ModifyTime = time.Now()
- record.Mobile = user.Mobile
- record.Email = user.Email
- record.CompanyId = user.CompanyId
- record.CompanyName = user.CompanyName
- //新增浏览记录
- go models.AddCygxArticleViewRecordNewpv(record)
- //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)
- }
- }
- if hasPermission == 1 {
- key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
- if !utils.Rc.IsExist(key) {
- //新增浏览记录
- record := new(models.CygxArticleViewRecord)
- record.UserId = uid
- record.ArticleId = articleId
- record.CreateTime = time.Now()
- record.Mobile = user.Mobile
- record.Email = user.Email
- record.CompanyId = user.CompanyId
- record.CompanyName = user.CompanyName
- go models.AddCygxArticleViewRecord(record)
- utils.Rc.Put(key, 1, 5*time.Second)
- models.ModifyReportLastViewTime(uid)
- }
- }
- }
- //作者头像
- if detail.DepartmentId > 0 {
- departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId)
- if err == nil {
- detail.DepartmentImgUrl = departmentDetail.ImgUrl
- detail.NickName = departmentDetail.NickName
- }
- }
- }
- detail.SellerAndMobile = "" //业务需要强制处理为空
- resp.HasPermission = hasPermission
- if hasPermission == 1 {
- detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
- resp.Detail = detail
- } else {
- if user.Mobile != "" {
- resp.Mobile = user.Mobile
- } else {
- resp.Mobile = user.Email
- }
- }
- 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
- }
- if source != "PC" {
- source = "MOBILE"
- }
- detail := new(models.ArticleDetail)
- hasPermission := 0
- hasFree := 0
- //判断是否已经申请过
- applyCount, err := models.GetApplyRecordCount(uid)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
- //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
- if user.CompanyId > 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 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, ",")
- //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称
- mfyxUserPermissionTotal := services.GetMfyxUserPermissionTotal(uid)
- 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.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
- 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
- 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
- mobile = utils.WxMsgTemplateIdAskMsgMobileAll
- } else {
- mobile = utils.WxMsgTemplateIdAskMsgMobile
- }
- 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 下载PDF打水印
- // @Description 下载PDF打水印接口
- // @Param ArticleId query int true "报告ID"
- // @Success 200 {object} models.ArticleDetailFileLink
- // @router /pdfwatermark [get]
- func (this *ArticleController) Pdfwatermark() {
- 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
- }
- uid := user.UserId
- articleId, err := this.GetInt("ArticleId")
- if articleId <= 0 {
- br.Msg = "文章不存在"
- br.ErrMsg = "文章不存在,文章ID错误"
- return
- }
- //缓存校验
- cacheKey := fmt.Sprint("xygx:apply_record:add:", uid, "ArticleId_", articleId)
- ttlTime := utils.Rc.GetRedisTTL(cacheKey)
- if ttlTime > 0 && user.CompanyId != 16 {
- br.Msg = "下载失败,下载过于频繁"
- br.ErrMsg = "下载失败,下载过于频繁:mobile" + user.Mobile
- return
- }
- resp := new(models.ArticleDetailFileLink)
- detail := new(models.ArticleDetail)
- detail, err = models.GetArticleDetailById(articleId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- fileLink := detail.FileLink
- if fileLink == "" {
- br.Msg = "下载失败"
- br.ErrMsg = "下载失败,报告链接不存在"
- return
- }
- mobile := user.Mobile
- if mobile == "" {
- mobile = user.Email
- }
- sliceLink := strings.Split(fileLink, "/")
- uploadDir := "static/pdf/"
- //判断文件夹是否存在,不存在则创建
- if !utils.FileIsExist(uploadDir) {
- err = os.MkdirAll(uploadDir, 0755)
- if err != nil {
- br.Msg = "下载失败"
- br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
- return
- }
- }
- var oldFile string
- var newFile string
- //获取PDF源文件名称
- pdfName := sliceLink[len(sliceLink)-1]
- pdfName = utils.MD5(pdfName) + ".pdf"
- oldFile = uploadDir + pdfName
- //判断PDF本地是否存在,不存在则保存到本地
- if !utils.FileIsExist(oldFile) {
- res, err := nhttp.Get(fileLink)
- if err != nil {
- br.Msg = "下载失败"
- br.ErrMsg = "获取源文件失败,Err:" + err.Error()
- return
- }
- defer res.Body.Close()
- // 获得get请求响应的reader对象
- reader := bufio.NewReaderSize(res.Body, 32*1024)
- file, err := os.Create(oldFile)
- if err != nil {
- br.Msg = "下载失败"
- br.ErrMsg = "保存源文件到本地失败,Err:" + err.Error()
- return
- }
- defer file.Close()
- //获得文件的writer对象
- writer := bufio.NewWriter(file)
- written, _ := io.Copy(writer, reader)
- fmt.Printf("Total length: %d", written)
- }
- newFile = uploadDir + "new_" + pdfName
- onTop := true
- wm, err := pdfcpu.ParseTextWatermarkDetails(mobile, " op:.4, pos:c ,points:16 ", onTop, 1)
- if err != nil {
- br.Msg = "下载失败"
- br.ErrMsg = "生成水印文件失败,Err:" + err.Error()
- return
- }
- err = api.AddWatermarksFile(oldFile, newFile, nil, wm, nil)
- if err != nil {
- //br.Msg = "下载失败"
- //br.ErrMsg = "生成水印PDF失败,Err:" + err.Error()
- resp.FileLink = fileLink
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- randStr := utils.GetRandStringNoSpecialChar(28)
- fileName := randStr + ".pdf"
- savePath := uploadDir + time.Now().Format("200601/20060102/")
- savePath += fileName
- //上传到阿里云
- err = services.UploadFileToAliyun(fileName, newFile, savePath)
- if err != nil {
- br.Msg = "下载失败"
- br.ErrMsg = "文件上传失败,Err:" + err.Error()
- return
- }
- fileHost := "https://hzstatic.hzinsights.com/"
- resourceUrl := fileHost + savePath
- defer func() {
- os.Remove(newFile)
- }()
- utils.Rc.SetNX(cacheKey, user.Mobile, time.Minute*5)
- resp.FileLink = resourceUrl
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 获取报告详情(无需token)
- // @Description 获取报告详情接口
- // @Param ArticleId query int true "报告ID"
- // @Param CompanyCode query string false "机构编号"
- // @Param CompanyName query string false "机构名称"
- // @Param Email query string false "邮箱"
- // @Param Sign query string false "加密签名"
- // @Success 200 {object} models.ArticleDetailHtgjResp
- // @router /detailPublic [get]
- func (this *ArticleCommonController) DetailPublic() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- articleId, _ := this.GetInt("ArticleId")
- companyCode := this.GetString("CompanyCode")
- companyNameHt := this.GetString("CompanyName")
- email := this.GetString("Email")
- sign := this.GetString("Sign")
- resp := new(models.ArticleDetailHtgjResp)
- if companyCode == "" || email == "" {
- resp.HasPermission = 2
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- if articleId <= 0 {
- br.Msg = "文章不存在"
- br.ErrMsg = "文章不存在,文章ID错误"
- return
- }
- errMsg, err, wxUser, companyName := services.CheckHtgj(companyCode, companyNameHt, email, sign)
- if errMsg != "" {
- br.Msg = errMsg
- return
- }
- companyPermission, err := models.GetCompanyPermission(wxUser.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取用户权限失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(articleId)
- return
- }
- hasPermission := 0
- uid := wxUser.UserId
- detail, err := models.GetArticleDetailById(articleId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- detail.Body = html.UnescapeString(detail.Body)
- detail.Body = strings.Replace(detail.Body, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sans-serif;\">Powered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
- detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
- detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
- 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(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
- return
- }
- if articlePermission == nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
- return
- }
- articlePermissionPermissionName = articlePermission.PermissionName
- } else {
- articlePermissionPermissionName = detail.CategoryName
- }
- var hasPersion bool
- slice := strings.Split(articlePermissionPermissionName, ",")
- for _, v := range slice {
- if strings.Contains(companyPermission, v) {
- hasPersion = true
- }
- }
- if hasPersion {
- hasPermission = 1
- }
- if strings.Contains(detail.CategoryName, "研选") {
- detail.IsResearch = true
- }
- resp.HasPermission = hasPermission
- if hasPermission == 1 {
- //获取销售手机号
- sellerItem, err := models.GetSellerByCompanyId(wxUser.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取销售数据失败2,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
- return
- }
- if sellerItem != nil {
- detail.SellerMobile = sellerItem.Mobile
- detail.SellerName = sellerItem.RealName
- }
- sellerList, err := models.GetSellerList(articleId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
- return
- }
- if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
- strnum := strings.Index(detail.SellerAndMobile, "-")
- detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
- if strnum > 0 {
- nickName := detail.SellerAndMobile[0:strnum]
- sellerAndMobile := &models.SellerRep{
- SellerMobile: "",
- SellerName: nickName,
- }
- sellerList = append(sellerList, sellerAndMobile)
- }
- }
- detail.SellerList = sellerList
- resp.Detail = detail
- historyRecord := new(models.CygxArticleHistoryRecord)
- historyRecord.UserId = wxUser.UserId
- historyRecord.ArticleId = articleId
- historyRecord.CreateTime = time.Now()
- historyRecord.Mobile = wxUser.Mobile
- historyRecord.Email = wxUser.Email
- historyRecord.CompanyId = wxUser.CompanyId
- historyRecord.CompanyName = companyName
- recordCount, _ := models.GetNoAddStoptimeArticleCount(wxUser.UserId, articleId)
- if recordCount == 0 {
- go models.AddCygxArticleHistoryRecord(historyRecord)
- } else {
- detailNew, err := models.GetNewArticleHistoryRecord(wxUser.UserId, articleId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if detailNew.StopTime > 0 {
- go models.AddCygxArticleHistoryRecord(historyRecord)
- }
- }
- key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(wxUser.UserId)
- if !utils.Rc.IsExist(key) {
- //新增浏览记录
- record := new(models.CygxArticleViewRecord)
- record.UserId = wxUser.UserId
- record.ArticleId = articleId
- record.CreateTime = time.Now()
- record.Mobile = wxUser.Mobile
- record.Email = wxUser.Email
- record.CompanyId = wxUser.CompanyId
- record.CompanyName = companyName
- go models.AddCygxArticleViewRecord(record)
- utils.Rc.Put(key, 1, 5*time.Second)
- models.ModifyReportLastViewTime(wxUser.UserId)
- }
- if detail.ArticleId < utils.SummaryArticleId {
- chartUserTokenByMobile, _ := services.GetUserTokenByMobile(utils.HtgjPublicMobile)
- detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile
- detail.IsNeedJump = true
- }
- if detail.ArticleId < utils.SummaryArticleId {
- chartUserTokenByMobile, _ := services.GetUserTokenByMobile(utils.HtgjPublicMobile)
- detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile
- detail.IsNeedJump = true
- }
- collectCount, err := models.GetArticleCollectCount(uid, articleId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
- return
- }
- if collectCount > 0 {
- detail.IsCollect = true
- }
- interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
- return
- }
- if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
- detail.IsInterviewApply = true
- detail.InterviewApplyStatus = interviewApplyItem.Status
- }
- 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
- resp.Detail = detail
- }
- resp.CompanyName = companyName
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 上传文章阅读时间(无需token)
- // @Description 上传文章阅读时间接口(无需token)
- // @Param request body models.AddStopTimeHtgjRep true "type json string"
- // @Success 200 {object} models.ArticleDetailResp
- // @router /addStopTimePublic [post]
- func (this *ArticleCommonController) AddStopTimePublic() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.AddStopTimeHtgjRep
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- articleId := req.ArticleId
- stopTime := req.StopTime
- outType := req.OutType
- source := req.Source
- companyCode := req.CompanyCode
- companyName := req.CompanyName
- wxuUserName := req.Email
- sign := req.Sign
- if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
- br.Msg = "上传失败"
- br.ErrMsg = "必填参数不能为空"
- return
- }
- companyNameHt := companyCode + "_" + companyName
- errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
- if errMsg != "" {
- br.Msg = errMsg
- return
- }
- companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
- return
- }
- uid := user.UserId
- if articleId <= 0 {
- br.Msg = "文章ID不存在"
- br.ErrMsg = "参数错误"
- return
- }
- if stopTime == 0 {
- stopTime = 1
- }
- if outType != 2 {
- outType = 1
- }
- if source != "PC" {
- source = "MOBILE"
- }
- detail := new(models.ArticleDetail)
- hasPermission := 0
- hasFree := 0
- //判断是否已经申请过
- applyCount, err := models.GetApplyRecordCount(uid)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
- //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
- if user.CompanyId > 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 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, ",")
- for _, v := range slice {
- if strings.Contains(companyPermission, v) {
- hasPersion = true
- }
- }
- if hasPersion {
- detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
- if err == nil {
- hasPermission = 1
- historyRecord := new(models.AddStopTimeNewRep)
- historyRecord.StopTime = detailNew.StopTime + stopTime
- historyRecord.Id = detailNew.Id
- historyRecord.OutType = outType
- go models.UpdateArticleStopTime(historyRecord)
- }
- //不统计本公司的阅读记录、正常退出的不做时间差统计
- if user.CompanyId != 16 && stopTime > 3 {
- key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
- record := new(models.CygxArticleHistoryRecordNewpv)
- record.UserId = uid
- record.ArticleId = articleId
- record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
- record.ModifyTime = time.Now()
- record.Mobile = user.Mobile
- record.Email = user.Email
- record.CompanyId = user.CompanyId
- record.CompanyName = companyInfo.CompanyName
- record.StopTime = stopTime
- record.OutType = outType
- record.Source = source
- if !utils.Rc.IsExist(key) || outType != 2 {
- //新增浏览记录
- go models.AddCygxArticleViewRecordNewpv(record)
- recordRedis := new(services.ReportViewRecord)
- recordRedis.UserId = user.UserId
- recordRedis.ReportId = articleId
- recordRedis.Mobile = user.Mobile
- recordRedis.Email = user.Email
- recordRedis.RealName = user.RealName
- recordRedis.CompanyName = companyName
- //recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
- go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
- } else {
- go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
- }
- utils.Rc.Put(key, 1, 10*time.Minute)
- }
- models.ModifyReportLastViewTime(uid)
- } 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 页面访问统计(无需token)
- // @Description 上传页面访问统计(无需token)
- // @Param request body models.CygxPageHistoryRecordHtgjRep true "type json string"
- // @Success Ret=200 新增成功
- // @router /pageHistoryPublic [post]
- func (this *ArticleCommonController) PageHistoryPublic() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.CygxPageHistoryRecordHtgjRep
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- companyCode := req.CompanyCode
- companyName := req.CompanyName
- wxuUserName := req.Email
- sign := req.Sign
- if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
- br.Msg = "上传失败"
- br.ErrMsg = "必填参数不能为空"
- return
- }
- companyNameHt := companyCode + "_" + companyName
- errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
- if errMsg != "" {
- br.Msg = errMsg
- return
- }
- companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
- return
- }
- item := new(models.CygxPageHistoryRecord)
- item.UserId = user.UserId
- item.CreateTime = time.Now()
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = companyName
- item.DetailId = req.DetailId
- item.ChartPermissionId = req.ChartPermissionId
- item.IndustrialManagementId = req.IndustrialManagementId
- item.PageType = "ArticleCopy"
- _, err = models.AddCygxPageHistoryRecord(item)
- if err != nil {
- br.Msg = "记录信息失败"
- br.ErrMsg = "新增访问记录失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- }
- // @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 = "操作成功"
- }
|