12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604 |
- package controllers
- import (
- "encoding/json"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_mfyx/models"
- "hongze/hongze_mfyx/services"
- "hongze/hongze_mfyx/utils"
- "strconv"
- "strings"
- "time"
- )
- type YanxuanSpecialController struct {
- BaseAuthController
- }
- type YanxuanSpecialNoLoginController struct {
- BaseAuthMobileController
- }
- // @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 *BaseAuthMobileController) 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.PageSize50
- }
- 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)
- yanxuanSpecialLike := services.GetYanxuanSpecialLikeMap(userId) //专栏本人是否点赞
- 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]
- //if sysUser.UserId == 0 {
- // v.Content = utils.InterceptHtmlLength(v.Content, 242) // 截取前80个字
- //}
- v.IsLikeCount = yanxuanSpecialLike[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 InviteShareCode query string false "销售账号邀请码"
- // @Param Id query int true "详情ID"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /detail [get]
- func (this *BaseAuthMobileController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录1,SysUser Is Empty"
- br.Ret = 408
- return
- }
- specialId, _ := this.GetInt("Id", 0)
- isSendWx, _ := this.GetInt("IsSendWx", 0)
- inviteShareCode := this.GetString("InviteShareCode")
- if specialId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- userId := user.UserId
- item, tmpErr := models.GetYanxuanSpecialById(specialId, userId)
- if tmpErr != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
- return
- }
- if item.MyCollectNum > 0 {
- item.IsCollect = 1
- }
- //是否点赞
- total, err := models.GetCygxYanxuanSpecialSpecialLikeCountByUidYid(user.UserId, specialId)
- if err != nil {
- br.Msg = "操作失败!"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- if total > 0 {
- item.IsLikeCount = true
- }
- item.Pv += item.HzPv // 添加弘则PV
- //记录分享来源
- if inviteShareCode != "" {
- go services.AddCygxUserAdminShareHistory(user, utils.CYGX_OBJ_YANXUANSPECIAL, item.Title, inviteShareCode, specialId)
- }
- if userId == 0 {
- item.Content = utils.InterceptHtmlLength(item.Content, 150)
- }
- 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
- }
- //如果在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
- }
- //校验研选专栏权限,以及无权限的时候的对应状态码
- 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 && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,GetUserDetailPermissionCode Err:" + err.Error()
- return
- }
- }
- resp.HasPermission = hasPermission
- //支付信息
- resp.IsShowWxPay = utils.IS_SHOW_WX_PAY //是否展示微信支付按钮
- resp.IsCompanyApply = services.GetUserApplyRecordCountByCompanyIdPay(user.CompanyId) //获取客户是否有过历史申请记录
- resp.IsNeedBusinessCard = services.GetCygxUserBusinessCardCount(user.UserId, user.CompanyId) //是否需要上传名片
- resp.GoodsList = services.GetUserGoodsCardList() //日卡月卡商品信息
- for _, v := range resp.GoodsList {
- resp.PopupPriceMsg += v.PopupPriceMsg //价格弹窗信息
- }
- 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.SendWxCategoryMsgSpecialFollow(req.Id) //研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
- go services.SendWxMsgSpecialAuthor(req.Id, 1) //研选专栏审核完成时,给提交人发送模板消息
- go services.SendWxCategoryMsgSpecialAuthor(req.Id, 1) //研选专栏审核完成时,给提交人发送类目模板消息
- go services.UdpateYanxuanSpecialauthorArticleNum(authorUserId) // 更新作者发布文章的数量
- } 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) // 更新作者发布文章的数量
- 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
- if user.CompanyId > 1 {
- 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
- }
- services.AddSpecialRecord(this.User, specialId, stopTime)
- 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
- if user.CompanyId > 1 {
- 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.MomentsImg = services.GetSpecialAuthorListMomentsImg() //获取作者列表朋友圈分享封面图
- 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
- }
- // @Title 获取专栏朋友圈封面详情
- // @Description 获取专栏朋友圈封面详情接口
- // @Param UserId query int false "用户ID,等于0列表详情,大于0作者详情"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /moments_img [get]
- func (this *YanxuanSpecialController) MomentsImg() {
- 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
- }
- type imgUrlResp struct {
- MomentsImg string // 分享图片
- }
- var imgUrl string
- userId, _ := this.GetInt("UserId", 0)
- if userId == 0 {
- imgUrl = services.GetYanxuanSpecialAuthoListMomentsImg()
- } else {
- imgUrl = services.GetYanxuanSpecialAuthoMomentsImg(userId)
- }
- resp := new(imgUrlResp)
- resp.MomentsImg = imgUrl
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 专栏文章点赞/取消点赞
- // @Description 专栏文章点赞/取消点赞接口
- // @Param request body models.TopCygxYanxuanSpecialMessageReq true "type json string"
- // @Success Ret=200 {object}
- // @router /like [post]
- func (this *YanxuanSpecialController) Like() {
- 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.LikeCygxYanxuanSpecialSpecialLikeReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- yanxuanSpecialId := req.YanxuanSpecialId
- doType := req.DoType
- userId := user.UserId
- // 研选专栏
- yanxuanSpecialBySpeciaDetail, err := models.GetYanxuanSpecialBySpecialId(yanxuanSpecialId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- total, err := models.GetCygxYanxuanSpecialSpecialLikeCountByUidYid(userId, yanxuanSpecialId)
- if err != nil {
- br.Msg = "操作失败!"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- var msgContent string
- if doType == 1 {
- if total == 0 {
- item := new(models.CygxYanxuanSpecialSpecialLike)
- item.UserId = userId
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.RealName = user.RealName
- item.YanxuanSpecialId = yanxuanSpecialId
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- item.RegisterPlatform = utils.REGISTER_PLATFORM
- err = models.AddCygxCygxYanxuanSpecialSpecialLike(item, yanxuanSpecialBySpeciaDetail.UserId)
- if err != nil {
- br.Msg = "点赞失败!"
- br.ErrMsg = "点赞失败,Err:" + err.Error()
- return
- }
- }
- msgContent = "已点赞"
- } else {
- if total > 0 {
- err = models.DeleteCygxYanxuanSpecialSpecialLike(userId, yanxuanSpecialId, yanxuanSpecialBySpeciaDetail.UserId)
- if err != nil {
- br.Msg = "点赞失败!"
- br.ErrMsg = "点赞失败,Err:" + err.Error()
- return
- }
- }
- msgContent = "已取消点赞"
- }
- br.Ret = 200
- br.Success = true
- br.Msg = msgContent
- }
- // @Title 作者粉丝列表
- // @Description 作者粉丝列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /author/fans_list [get]
- func (this *YanxuanSpecialController) FanList() {
- 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
- }
- 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)
- resp := new(models.CygxYanxuanSpecialFollowListResp)
- var condition string
- var pars []interface{}
- condition = " AND follow_user_id = ? "
- pars = append(pars, user.UserId)
- //作者粉丝数量
- total, err := models.GetCygxYanxuanSpecialFollowCount(condition, pars)
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取信息失败,GetCygxYanxuanSpecialFollowCountErr:" + err.Error()
- return
- }
- condition += " ORDER BY cygx_yanxuan_special_follow_id DESC "
- list, err := models.GetCygxYanxuanSpecialFollowList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取信息失败,GetCygxYanxuanSpecialFollowList:" + err.Error()
- return
- }
- if len(list) > 0 {
- var userIds []int
- for _, v := range list {
- userIds = append(userIds, v.UserId)
- }
- //用户头像
- listUser, err := models.GetWxUserListByUserIdsArr(userIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + err.Error()
- return
- }
- mapUserImg := make(map[int]string)
- for _, v := range listUser {
- if v.Headimgurl != "" {
- mapUserImg[v.UserId] = v.Headimgurl
- } else {
- mapUserImg[v.UserId] = utils.DefaultHeadimgurl
- }
- }
- for _, v := range list {
- item := new(models.CygxYanxuanSpecialFollowResp)
- if v.CompanyName != "" {
- item.CompanyName = v.CompanyName
- } else {
- item.CompanyName = "潜在客户"
- }
- if v.RealName != "" {
- item.RealName = v.RealName
- } else {
- item.RealName = "--"
- }
- item.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
- item.Headimgurl = mapUserImg[v.UserId]
- resp.List = append(resp.List, item)
- }
- } else {
- resp.List = make([]*models.CygxYanxuanSpecialFollowResp, 0)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
|