1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384 |
- package controllers
- import (
- "encoding/json"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/services"
- "hongze/hongze_cygx/utils"
- "strconv"
- "strings"
- "time"
- )
- type YanxuanSpecialController struct {
- BaseAuthController
- }
- // @Title 专栏列表
- // @Description 专栏列表
- // @Param UserId query int true "用户ID"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Status query int false "研选专栏装态"
- // @Success 200 {object} models.SpecialListResp
- // @router /list [get]
- func (this *YanxuanSpecialController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.User
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- userId, _ := this.GetInt("UserId", 0)
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- status, _ := this.GetInt("Status")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- resp := new(models.SpecialListResp)
- var condition string
- var pars []interface{}
- if userId > 0 {
- condition += ` AND a.user_id = ? `
- pars = append(pars, userId)
- }
- if status == 2 {
- condition += ` AND a.status = 2 `
- } else {
- condition += ` AND a.status = 3 `
- }
- total, err := models.GetCygxYanxuanSpecialCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + err.Error()
- return
- }
- list, err := models.GetYanxuanSpecialList(sysUser.UserId, condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + err.Error()
- return
- }
- var yanxuanSpecialIds []int
- for _, v := range list {
- yanxuanSpecialIds = append(yanxuanSpecialIds, v.Id)
- }
- yanxuanSpecialPv := services.GetYanxuanSpecialRecordByYanxuanSpecialId(yanxuanSpecialIds)
- for _, v := range list {
- hasImg, err := utils.ArticleHasImgUrl(v.Content)
- if err != nil {
- return
- }
- if hasImg {
- v.ContentHasImg = 1
- }
- v.Content = utils.ArticleRemoveImgUrl(v.Content)
- //v.Content, err = utils.ExtractText(v.Content)
- //if err != nil {
- // return
- //}
- //v.Content, _ = services.GetReportContentTextSubNew(v.Content)
- v.Content = services.AnnotationHtml(v.Content)
- v.Content = strings.Replace(v.Content, " <br> <br>", "", -1)
- if v.DocUrl != "" {
- var docs []models.Doc
- err := json.Unmarshal([]byte(v.DocUrl), &docs)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- v.Docs = docs
- }
- if v.MyCollectNum > 0 {
- v.IsCollect = 1
- }
- if v.CompanyTags != "" {
- v.Tags += v.CompanyTags
- }
- if v.IndustryTags != "" {
- if v.Tags != "" {
- v.Tags += ","
- }
- v.Tags += v.IndustryTags
- }
- v.Pv = yanxuanSpecialPv[v.Id]
- }
- isAuthor, isImproveInformation := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
- resp.IsAuthor = isAuthor
- resp.IsImproveInformation = isImproveInformation
- resp.List = list
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 专栏详情
- // @Description 专栏详情
- // @Param IsSendWx query int false "是否是通过微信模版进来的 1是,其它否"
- // @Param Id query int true "详情ID"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /detail [get]
- func (this *YanxuanSpecialController) Detail() {
- 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
- }
- specialId, _ := this.GetInt("Id", 0)
- isSendWx, _ := this.GetInt("IsSendWx", 0)
- if specialId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- item, tmpErr := models.GetYanxuanSpecialById(specialId, user.UserId)
- if tmpErr != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
- return
- }
- if item.MyCollectNum > 0 {
- item.IsCollect = 1
- }
- item.Pv += item.HzPv // 添加弘则PV
- var resp models.CygxYanxuanSpecialResp
- resp.HasPermission = 1
- resp.CygxYanxuanSpecialItem = *item
- if item.DocUrl != "" {
- var docs []models.Doc
- err := json.Unmarshal([]byte(item.DocUrl), &docs)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- resp.Docs = docs
- }
- if item.CompanyTags != "" {
- resp.Tags += item.CompanyTags
- resp.CompanyTags = append(resp.CompanyTags, item.CompanyTags)
- }
- if item.IndustryTags != "" {
- if resp.Tags != "" {
- resp.Tags += ","
- }
- resp.Tags += item.IndustryTags
- resp.IndustryTags = strings.Split(item.IndustryTags, ",")
- }
- //如果状态未审核通过,而且查看的不是本人,不是审核人员,就无法查看详情
- var configCode string
- configCode = utils.TPL_MSG_YAN_XUAN_SPECIAL_APPROVAL
- cnf, err := models.GetConfigByCode(configCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + err.Error()
- return
- }
- if isSendWx == 1 && strings.Contains(cnf.ConfigValue, user.Mobile) {
- resp.IsShowExamine = true
- resp.ExamineStatus = item.Status
- }
- resp.ExamineStatus = item.Status
- if item.UserId != user.UserId && item.Status != 3 && !strings.Contains(cnf.ConfigValue, user.Mobile) {
- resp.CygxYanxuanSpecialItem = *new(models.CygxYanxuanSpecialItem) // 如果内容不可见,就把内容置空
- //resp.HasPermission = 2
- }
- //如果是用户本人写的专栏,那么就不做校验
- //if item.UserId == sysUser.UserId || sysUser.UserId == 0 {
- // resp.HasPermission = 1
- //} else {
- // hasPermission, err := services.GetUserRaiPermissionYanXuanInfo(sysUser)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败, Err:" + err.Error()
- // return
- // }
- // resp.HasPermission = hasPermission
- //}
- //如果在web端有样式或者上传了文件,小程序就禁止编辑修改内容
- hasStyle, err := utils.ArticleHasStyle(item.Content)
- if err != nil {
- return
- }
- hasImg, err := utils.ArticleHasImgUrl(item.Content)
- if err != nil {
- return
- }
- if hasStyle || strings.Contains(item.DocUrl, "http") || hasImg {
- resp.ContentHasStyle = true
- }
- if resp.HasPermission != 1 || user.UserId == 0 {
- resp.Content = services.AnnotationHtml(resp.Content)
- }
- if user.UserId > 0 {
- followCount, err := models.GetCygxYanxuanSpecialFollowCountByUser(user.UserId, item.UserId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + err.Error()
- return
- }
- if followCount > 0 {
- resp.IsFollowAuthor = true
- }
- } else {
- item.Content = utils.InterceptHtmlLength(item.Content, 150)
- }
- //校验研选专栏权限,以及无权限的时候的对应状态码
- havePower, err := services.GetYanxuanSpecialDetailUserPower(user)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "校验用户权限失败,Err:" + err.Error()
- return
- }
- //看自己的文章时不设权限限制,不需要判断是否有研选订阅权限,都可以看。
- if user.UserId == item.UserId {
- havePower = true
- }
- var hasPermission int
- if havePower {
- hasPermission = 1
- } else {
- hasPermission, err = services.GetUserDetailPermissionCode(user.UserId, user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取用户权限状态失败,Err:" + err.Error()
- return
- }
- }
- resp.HasPermission = hasPermission
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 新增保存专栏作者详情
- // @Description 新增保存专栏作者详情
- // @Param request body help_doc.AddHelpDocReq true "type json string"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /author/save [post]
- func (this *YanxuanSpecialController) AuthorSave() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.User
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.SaveCygxYanxuanSpecialAuthorReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.UserId <= 0 {
- br.Msg = "用户id有误"
- return
- }
- if req.SpecialName == "" {
- br.Msg = "请输入专栏名称"
- return
- }
- if req.NickName == "" {
- br.Msg = "请输入昵称"
- return
- }
- item := models.CygxYanxuanSpecialAuthor{
- UserId: req.UserId,
- SpecialName: req.SpecialName,
- Introduction: req.Introduction,
- Label: req.Label,
- NickName: req.NickName,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- BgImg: "",
- Status: 1,
- }
- //if req.Id == 0{
- // _, err = models.AddCygxYanxuanSpecialAuthor(&item)
- // if err != nil {
- // br.Msg = "新增失败"
- // br.ErrMsg = "新增失败,Err:" + err.Error()
- // return
- // }
- //} else {
- // err = models.UpdateYanxuanSpecialAuthor(&item)
- // if err != nil {
- // br.Msg = "保存失败"
- // br.ErrMsg = "保存失败,Err:" + err.Error()
- // return
- // }
- //}
- err = models.UpdateYanxuanSpecialAuthor(&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 help_doc.AddHelpDocReq true "type json string"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /save [post]
- func (this *YanxuanSpecialController) Save() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.User
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.CygxYanxuanSpecialReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Content == "" && req.DoType == 2 {
- br.Msg = "请输入内容"
- return
- }
- if req.CompanyTags == "" && req.IndustryTags == "" && req.DoType == 2 {
- br.Msg = "请至少输入一个标签"
- return
- }
- isApprovalPersonnel := req.IsApprovalPersonnel
- item := models.CygxYanxuanSpecial{
- Id: req.Id,
- UserId: sysUser.UserId,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- PublishTime: time.Now(),
- Content: req.Content,
- ImgUrl: req.ImgUrl,
- DocUrl: req.DocUrl,
- Title: req.Title,
- Type: req.Type,
- CompanyTags: req.CompanyTags,
- IndustryTags: req.IndustryTags,
- }
- if req.DoType == 1 {
- item.Status = 1
- } else {
- item.Status = 2
- }
- var authorUserId int
- // 如果是审批人员操作的那么就是修改内容,加审批通过
- if isApprovalPersonnel {
- item.Status = 3
- //校验是否属于审核人员
- if !services.CheckYxSpecialIsApprovalPersonnel(sysUser.Mobile) {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,该账号不属于审核人员:" + sysUser.Mobile
- return
- }
- specialItem, err := models.GetYanxuanSpecialItemById(req.Id)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- item.UserId = specialItem.UserId // 专栏userid还是原有userId
- authorUserId = specialItem.UserId
- item.AdminName = sysUser.RealName //审核人员姓名
- }
- specialId := 0
- if req.Id == 0 {
- id, err := models.AddCygxYanxuanSpecial(&item)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- specialId = int(id)
- } else {
- err = models.UpdateYanxuanSpecial(&item)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- specialId = req.Id
- }
- if isApprovalPersonnel {
- go services.UpdateYanxuanSpecialResourceData(specialId) // 写入首页最新 cygx_resource_data 表
- go services.EsAddYanxuanSpecial(specialId) // 写入es 综合搜索
- go services.SendWxMsgSpecialFollow(req.Id) //研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
- go services.SendWxMsgSpecialAuthor(req.Id, 1) //研选专栏审核完成时,给提交人发送模板消息
- go services.UdpateYanxuanSpecialauthorArticleNum(authorUserId) // 更新作者发布文章的数量
- go services.MakeYanxuanSpecialMomentsImg(specialId) // 生成研选专栏分享到朋友圈的图片
- go services.SendWxCategoryMsgSpecialAuthor(req.Id, 1) //研选专栏审核完成时,给提交人发送类目模板消息
- go services.SendWxCategoryMsgSpecialFollow(req.Id) // 研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
- } else {
- if req.DoType == 2 {
- go services.SendReviewTemplateMsgAdmin(specialId)
- go services.SendReviewCategoryTemplateMsgAdmin(specialId) //买方研选类目消息
- go services.UpdateYanxuanSpecialResourceData(specialId) // 写入首页最新 cygx_resource_data 表
- go services.EsAddYanxuanSpecial(specialId) // 写入es 综合搜索
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
- // @Title 专栏作者详情
- // @Description 专栏作者详情
- // @Param request body help_doc.AddHelpDocReq true "type json string"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /author/detail [get]
- func (this *YanxuanSpecialController) AuthorDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.User
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- userId, _ := this.GetInt("UserId", 0)
- if userId == 0 {
- userId = sysUser.UserId
- }
- item, tmpErr := models.GetYanxuanSpecialAuthor(userId, sysUser.UserId, "")
- if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
- return
- }
- if item.IsFollow > 0 {
- item.IsFollow = 1
- }
- br.Data = item
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 审批研选专栏
- // @Description 审批研选专栏
- // @Param request body help_doc.AddHelpDocReq true "type json string"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /enable [post]
- func (this *YanxuanSpecialController) Enable() {
- 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.EnableCygxYanxuanSpecialReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Id <= 0 {
- br.Msg = "文章id错误"
- return
- }
- if req.Status <= 0 {
- br.Msg = "参数错误"
- return
- }
- status := 0
- if req.Status == 1 {
- status = 3
- } else {
- status = 4
- }
- detail, err := models.GetYanxuanSpecialItemById(req.Id)
- if err != nil {
- br.Msg = "审批失败"
- br.ErrMsg = "审批失败, Err:" + err.Error()
- return
- }
- if tmpErr := models.EnableYanxuanSpecial(req.Id, status, req.Reason, user.RealName); tmpErr != nil {
- br.Msg = "审批失败"
- br.ErrMsg = "审批失败, Err:" + tmpErr.Error()
- return
- }
- if req.Status == 1 {
- go services.SendWxMsgSpecialFollow(req.Id)
- go services.SendWxCategoryMsgSpecialFollow(req.Id) // 研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
- }
- go services.SendWxMsgSpecialAuthor(req.Id, req.Status)
- go services.SendWxCategoryMsgSpecialAuthor(req.Id, req.Status)
- go services.UpdateYanxuanSpecialResourceData(req.Id) // 写入首页最新 cygx_resource_data 表
- go services.EsAddYanxuanSpecial(req.Id) // 写入es 综合搜索
- go services.AddAddCygxYanxuanSpecialApprovalLog(user, req.Id, req.Status, req.Reason) // 添加审核记录日志
- go services.UdpateYanxuanSpecialauthorArticleNum(detail.UserId) // 更新作者发布文章的数量
- go services.MakeYanxuanSpecialMomentsImg(req.Id) // 生成研选专栏分享到朋友圈的图片
- br.Msg = "审批成功"
- br.Ret = 200
- br.Success = true
- }
- // @Title 研选专栏收藏
- // @Description 研选专栏收藏
- // @Param request body help_doc.AddHelpDocReq true "type json string"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /collect [post]
- func (this *YanxuanSpecialController) Collect() {
- 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.CollectCygxYanxuanSpecialReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Id <= 0 {
- br.Msg = "文章id错误"
- return
- }
- if req.Status <= 0 {
- br.Msg = "参数错误"
- return
- }
- var sellerName string
- 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 {
- sellerName = sellerItemQy.RealName
- }
- if req.Status == 1 {
- item := models.CygxYanxuanSpecialCollect{
- UserId: user.UserId,
- Mobile: user.Mobile,
- Email: user.Email,
- CompanyId: user.CompanyId,
- CompanyName: user.CompanyName,
- RealName: user.RealName,
- SellerName: sellerName,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- RegisterPlatform: utils.REGISTER_PLATFORM,
- YanxuanSpecialId: req.Id,
- }
- _, err = models.AddCygxYanxuanSpecialCollect(&item)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- br.Msg = "收藏成功"
- } else {
- err = models.DelCygxYanxuanSpecialCollect(user.UserId, req.Id)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Msg = "取消收藏成功"
- }
- go services.UdpateYanxuanSpecialCollect(req.Id)
- br.Ret = 200
- br.Success = true
- }
- // @Title 专栏内容中心
- // @Description 专栏内容中心
- // @Param request body help_doc.AddHelpDocReq true "type json string"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /center [get]
- func (this *YanxuanSpecialController) Center() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.User
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- // 1:未发布,2:审核中 3:已发布 4:驳回
- status, _ := this.GetInt("Status", 0)
- if status <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- var condition string
- var pars []interface{}
- condition += ` AND a.user_id = ? `
- pars = append(pars, sysUser.UserId)
- condition += ` AND a.status = ? `
- pars = append(pars, status)
- list, tmpErr := models.GetYanxuanSpecialList(sysUser.UserId, condition, pars, 0, 0)
- if tmpErr != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
- return
- }
- for _, v := range list {
- //如果在web端有样式或者上传了文件,小程序就禁止编辑修改内容
- hasStyle, err := utils.ArticleHasStyle(v.Content)
- if err != nil {
- return
- }
- hasImg, err := utils.ArticleHasImgUrl(v.Content)
- if err != nil {
- return
- }
- if hasStyle || strings.Contains(v.DocUrl, "http") || hasImg {
- v.ContentHasStyle = true
- }
- }
- br.Data = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 专栏点击记录
- // @Description 专栏点击记录
- // @Param request body models.AddCygxYanxuanSpecialRecordReq true "type json string"
- // @router /record [post]
- func (this *YanxuanSpecialController) Record() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请重新登录"
- br.Ret = 408
- return
- }
- var req models.AddCygxYanxuanSpecialRecordReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- specialId := req.SpecialId
- stopTime := req.StopTime
- if req.SpecialId <= 0 {
- br.Msg = "文章不存在"
- br.ErrMsg = "文章不存在,文章ID错误"
- return
- }
- err = services.AddSpecialRecord(this.User, specialId, stopTime)
- if err != nil {
- br.Msg = "记录失败"
- br.ErrMsg = "记录失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "记录成功"
- }
- // @Title 研选专栏关注
- // @Description 研选专栏关注
- // @Param request body help_doc.AddHelpDocReq true "type json string"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /follow [post]
- func (this *YanxuanSpecialController) Follow() {
- 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.FollowCygxYanxuanSpecialReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.FollowUserId <= 0 {
- br.Msg = "被关注的用户id"
- return
- }
- if req.Status <= 0 {
- br.Msg = "参数错误"
- return
- }
- var sellerName string
- 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 {
- sellerName = sellerItemQy.RealName
- }
- if req.Status == 1 {
- followCount, err := models.GetCygxYanxuanSpecialFollowCountByUser(user.UserId, req.FollowUserId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + err.Error()
- return
- }
- if followCount == 0 && user.UserId > 0 {
- item := models.CygxYanxuanSpecialFollow{
- UserId: user.UserId,
- FollowUserId: req.FollowUserId,
- Mobile: user.Mobile,
- Email: user.Email,
- CompanyId: user.CompanyId,
- CompanyName: user.CompanyName,
- RealName: user.RealName,
- SellerName: sellerName,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- RegisterPlatform: utils.REGISTER_PLATFORM,
- YanxuanSpecialId: req.SpecialId,
- }
- err = models.AddCygxYanxuanSpecialFollow(&item)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- }
- br.Msg = "关注成功"
- } else {
- err = models.DelCygxYanxuanSpecialFollow(user.UserId, req.FollowUserId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Msg = "取消关注成功"
- }
- go services.UdpateYanxuanSpecialFansNum(req.FollowUserId)
- br.Ret = 200
- br.Success = true
- }
- // @Title 行业标签搜索
- // @Description 行业标签搜索
- // @Param request body help_doc.AddHelpDocReq true "type json string"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /industrySearch [get]
- func (this *YanxuanSpecialController) IndustrySearch() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.User
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- keyword := this.GetString("Keyword")
- list, tmpErr := models.GetYanxuanSpecialIndustry(keyword)
- if tmpErr != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
- return
- }
- br.Data = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 公司标签搜索
- // @Description 公司标签搜索
- // @Param request body help_doc.AddHelpDocReq true "type json string"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /companySearch [get]
- func (this *YanxuanSpecialController) CompanySearch() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.User
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- keyword := this.GetString("Keyword")
- if keyword == "" {
- br.Ret = 200
- return
- }
- list, tmpErr := models.GetYanxuanSpecialCompany(keyword)
- if tmpErr != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
- return
- }
- br.Data = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 专栏取消发布
- // @Description 专栏取消发布
- // @Param request body help_doc.AddHelpDocReq true "type json string"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /cancel [post]
- func (this *YanxuanSpecialController) Cancel() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.User
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.CancelPublishCygxYanxuanSpecialReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Id <= 0 {
- br.Msg = "文章id错误"
- return
- }
- specialItem, err := models.GetYanxuanSpecialItemById(req.Id)
- if err != nil {
- br.Msg = "专栏取消发布失败"
- br.ErrMsg = "专栏取消发布失败,Err:" + err.Error()
- return
- }
- if tmpErr := models.CancelPublishYanxuanSpecial(req.Id); tmpErr != nil {
- br.Msg = "取消发布失败"
- br.ErrMsg = "取消发布失败, Err:" + tmpErr.Error()
- return
- }
- go services.UpdateYanxuanSpecialResourceData(req.Id) // 写入首页最新 cygx_resource_data 表
- go services.EsAddYanxuanSpecial(req.Id) // 写入es 综合搜索
- go services.UdpateYanxuanSpecialauthorArticleNum(specialItem.UserId) // 更新作者发布文章的数量
- br.Msg = "取消发布成功"
- br.Ret = 200
- br.Success = true
- }
- // @Title 作者列表
- // @Description 作者列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /author/list [get]
- func (this *YanxuanSpecialController) AuthorList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.User
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- condition += ` AND a.nick_name <> '' `
- total, err := models.GetCygxYanxuanSpecialAuthorCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- condition += ` ORDER BY latest_publish_time DESC`
- list, tmpErr := models.GetYanxuanSpecialAuthorList(condition, pars, startSize, pageSize)
- if tmpErr != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
- return
- }
- var userIds []int
- for _, v := range list {
- v.LatestPublishDate = v.LatestPublishTime.Format(utils.FormatDate) + "更新"
- userIds = append(userIds, v.UserId)
- }
- bestNew := services.GetBestNewYanxuanSpecialByUserId(userIds)
- for _, v := range list {
- v.YanxuanSpecialCenter = bestNew[v.UserId]
- }
- resp := new(models.SpecialAuthorListResp)
- isAuthor, _ := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
- resp.IsAuthor = isAuthor
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.List = list
- resp.Paging = page
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 更新作者头像
- // @Description 更新作者头像
- // @Param request body help_doc.AddHelpDocReq true "type json string"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /author/head_img [post]
- func (this *YanxuanSpecialController) AuthorHeadImg() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.User
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.SaveCygxYanxuanSpecialAuthoHeadImgrReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.UserId <= 0 {
- br.Msg = "用户id有误"
- return
- }
- if req.HeadImg == "" {
- br.Msg = "头像图片错误"
- return
- }
- item := models.CygxYanxuanSpecialAuthor{
- UserId: req.UserId,
- HeadImg: req.HeadImg,
- }
- err = models.UpdateYanxuanSpecialAuthorHeadImg(&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 help_doc.AddHelpDocReq true "type json string"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /del [post]
- func (this *YanxuanSpecialController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.User
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.EnableCygxYanxuanSpecialReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Id <= 0 {
- br.Msg = "文章id错误"
- return
- }
- if tmpErr := models.DelYanxuanSpecial(req.Id); tmpErr != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败, Err:" + tmpErr.Error()
- return
- }
- br.Msg = "删除成功"
- br.Ret = 200
- br.Success = true
- }
- // @Title 专栏文章敏感词检测
- // @Description 专栏文章敏感词检测
- // @Param request body help_doc.AddHelpDocReq true "type json string"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /check [post]
- func (this *YanxuanSpecialController) Check() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.User
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.CygxYanxuanSpecialCheckReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Content == "" {
- br.Ret = 200
- br.Success = true
- br.Msg = "校验成功"
- }
- itemToken, err := services.WxGetToken()
- if err != nil {
- br.Msg = "GetWxAccessToken Err:" + err.Error()
- return
- }
- if itemToken.AccessToken == "" {
- br.Msg = "accessToken is empty"
- return
- }
- suggest := models.WxCheckContent(itemToken.AccessToken, sysUser.OpenId, req.Content)
- if suggest == "risky" {
- br.Msg = "文章内容含有违法违规内容"
- br.ErrMsg = "文章内容含有违法违规内容"
- return
- }
- if len(req.ImgUrl) > 0 {
- //for _, imgUrl := range req.ImgUrl {
- // imgBody, err := http.Get(imgUrl)
- // if err != nil {
- // br.Msg = "图片链接有误"
- // br.ErrMsg = "图片链接有误"
- // return
- // }
- // rnStr := utils.GetRandStringNoSpecialChar(5)
- // savePath := time.Now().Format(utils.FormatDateTimeUnSpace) + rnStr + ".jpg"
- // err = file.SaveFile(imgBody, savePath)
- // if err != nil {
- // br.Msg = "保存图片错误"
- // br.ErrMsg = "保存图片错误"
- // return
- // }
- // res, err := weapp.IMGSecCheck(itemToken.AccessToken, savePath)
- // if err != nil {
- // // 处理一般错误信息
- // br.Msg = "图片内容含有违法违规内容"
- // br.ErrMsg = "图片内容含有违法违规内容"
- // return
- // }
- // if err := res.GetResponseError(); err != nil {
- // // 处理微信返回错误信息
- // return
- // }
- // err = os.RemoveAll(savePath)
- // if err != nil {
- // return
- // }
- //}
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "校验成功"
- }
- // @Title 上传文章阅读时间
- // @Description 上传文章阅读时间接口
- // @Param request body models.AddStopTimeRep true "type json string"
- // @Success 200 {object} models.ArticleDetailResp
- // @router /addStopTimedel [post]
- func (this *YanxuanSpecialController) 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 {
- 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
- }
|