1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660 |
- 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"
- // @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")
- if articleId <= 0 {
- br.Msg = "文章不存在"
- br.ErrMsg = "文章不存在,文章ID错误"
- return
- }
- detail := new(models.ArticleDetail)
- 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
- }
- //是否属于专项调研报告
- 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
- }
- 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 companyPermission == "" {
- if applyCount > 0 {
- hasPermission = 5
- } else {
- hasPermission = 2
- }
- goto Loop
- } else {
- 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 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, "研选") {
- 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
- historyRecord := new(models.CygxArticleHistoryRecord)
- historyRecord.UserId = uid
- historyRecord.ArticleId = articleId
- historyRecord.CreateTime = time.Now()
- historyRecord.Mobile = user.Mobile
- historyRecord.Email = user.Email
- historyRecord.CompanyId = user.CompanyId
- historyRecord.CompanyName = user.CompanyName
- recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
- if recordCount == 0 {
- go models.AddCygxArticleHistoryRecord(historyRecord)
- } else {
- detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if detailNew.StopTime > 0 {
- go models.AddCygxArticleHistoryRecord(historyRecord)
- }
- }
- //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
- }
- }
- 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)
- }
- }
- }
- 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
- }
- //获取销售手机号
- 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
- //作者头像
- if detail.DepartmentId > 0 {
- departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId)
- if err == nil {
- detail.DepartmentImgUrl = departmentDetail.ImgUrl
- }
- }
- } else { //潜在客户
- if applyCount > 0 {
- hasPermission = 5
- } else {
- hasPermission = 4
- }
- }
- Loop:
- if hasPermission != 1 {
- 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
- }
- }
- resp.HasPermission = hasPermission
- resp.HaveResearch = haveResearch
- 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)
- } 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, ",")
- 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 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 = user.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 = user.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 文章带问
- // @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 = "新增成功"
- }
|