123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533 |
- package controllers
- import (
- "encoding/json"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_web_mfyx/models"
- "hongze/hongze_web_mfyx/services"
- "hongze/hongze_web_mfyx/utils"
- "path"
- "strconv"
- "strings"
- "time"
- )
- type YanxuanSpecialController struct {
- BaseAuthController
- }
- type YanxuanSpecialNoLoginController struct {
- BaseAuthMobileController
- }
- // @Title 专栏列表
- // @Description 专栏列表
- // @Param SpecialColumnId query int true "作者专栏ID"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /list [get]
- func (this *YanxuanSpecialNoLoginController) 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
- }
- specialColumnId, _ := this.GetInt("SpecialColumnId", 0)
- 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)
- userId := sysUser.UserId
- resp := new(models.SpecialListResp)
- var condition string
- var pars []interface{}
- if specialColumnId > 0 {
- authorItem, err := models.GetYanxuanSpecialAuthorById(specialColumnId)
- if err != nil {
- br.Msg = "查询栏目详情失败!"
- br.ErrMsg = "查询栏目详情失败,Err:" + err.Error()
- return
- }
- condition += ` AND a.user_id = ? `
- pars = append(pars, authorItem.UserId)
- }
- 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.ImgUrl = strings.TrimRight(v.ImgUrl, ",")
- //去除图片标签
- v.Content = utils.ArticleRemoveImgUrl(v.Content)
- //v.Content, err = utils.ExtractText(v.Content)
- 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.ImgUrl != "" {
- imgList := strings.Split(v.ImgUrl, ",")
- for _, s := range imgList {
- v.ImgUrlList = append(v.ImgUrlList, s)
- }
- } else {
- v.ImgUrlList = []string{}
- }
- if v.CompanyTags != "" {
- tagList := strings.Split(v.CompanyTags, ",")
- for _, s := range tagList {
- v.TagList = append(v.TagList, s)
- }
- }
- if v.IndustryTags != "" {
- tagList := strings.Split(v.IndustryTags, ",")
- for _, s := range tagList {
- v.TagList = append(v.TagList, s)
- }
- }
- if len(v.TagList) == 0 {
- v.TagList = []string{}
- }
- v.Pv = yanxuanSpecialPv[v.Id]
- v.IsLikeCount = yanxuanSpecialLike[v.Id]
- }
- specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
- resp.IsAuthor = specialAuthorCheck.IsAuthor
- resp.IsImproveInformation = specialAuthorCheck.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 request body help_doc.AddHelpDocReq true "type json string"
- // @Param InviteShareCode query string false "销售账号邀请码"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /detail [get]
- func (this *YanxuanSpecialNoLoginController) 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)
- inviteShareCode := this.GetString("InviteShareCode")
- 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.ImgUrl != "" {
- imgList := strings.Split(item.ImgUrl, ",")
- for _, s := range imgList {
- item.ImgUrlList = append(item.ImgUrlList, s)
- }
- } else {
- item.ImgUrlList = []string{}
- }
- //记录分享来源
- if inviteShareCode != "" {
- go services.AddCygxUserAdminShareHistory(user, utils.CYGX_OBJ_YANXUANSPECIAL, item.Title, inviteShareCode, specialId)
- }
- if item.MyCollectNum > 0 {
- item.IsCollect = 1
- }
- var resp models.CygxYanxuanSpecialDetailResp
- yanxuanDetail := new(models.CygxYanxuanSpecialResp)
- yanxuanDetail.HasPermission = 1
- yanxuanDetail.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
- }
- yanxuanDetail.Docs = docs
- }
- if item.ImgUrl != "" {
- imgList := strings.Split(item.ImgUrl, ",")
- for _, s := range imgList {
- yanxuanDetail.ImgUrlList = append(yanxuanDetail.ImgUrlList, s)
- }
- } else {
- yanxuanDetail.ImgUrlList = []string{}
- }
- if item.CompanyTags != "" {
- cTagList := strings.Split(item.CompanyTags, ",")
- for _, s := range cTagList {
- yanxuanDetail.CompanyTags = append(yanxuanDetail.CompanyTags, s)
- }
- } else {
- yanxuanDetail.CompanyTags = []string{}
- }
- if item.IndustryTags != "" {
- iTagList := strings.Split(item.IndustryTags, ",")
- for _, s := range iTagList {
- yanxuanDetail.IndustryTags = append(yanxuanDetail.IndustryTags, s)
- }
- } else {
- yanxuanDetail.IndustryTags = []string{}
- }
- 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 item.UserId != user.UserId && item.Status != 3 && !strings.Contains(cnf.ConfigValue, user.Mobile) {
- yanxuanDetail.CygxYanxuanSpecialItem = *new(models.CygxYanxuanSpecialItem) // 如果内容不可见,就把内容置空
- yanxuanDetail.CygxYanxuanSpecialItem.Status = item.Status
- //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
- //}
- //判断是否属于审核人员
- mobileSlice := strings.Split(cnf.ConfigValue, ",")
- for _, v := range mobileSlice {
- if v == user.Mobile {
- yanxuanDetail.IsApprovalAdmin = true
- }
- }
- fllowNum, err := models.GetCygxYanxuanSpecialFollowCountByUser(user.UserId, item.UserId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取是否关注作者失败, Err:" + err.Error()
- return
- }
- if fllowNum == 1 {
- yanxuanDetail.IsFollowAuthor = 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
- }
- }
- //是否点赞
- total, err := models.GetCygxYanxuanSpecialSpecialLikeCountByUidYid(user.UserId, specialId)
- if err != nil {
- br.Msg = "操作失败!"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- if total > 0 {
- item.IsLikeCount = true
- }
- yanxuanDetail.HasPermission = hasPermission
- resp.HasPermission = hasPermission
- item.Pv += item.HzPv // 添加弘则PV
- //字段兼容
- resp.CygxYanxuanSpecialItem = *item
- resp.Docs = yanxuanDetail.Docs
- resp.CompanyTags = yanxuanDetail.CompanyTags
- resp.IndustryTags = yanxuanDetail.IndustryTags
- resp.IsApprovalAdmin = yanxuanDetail.IsApprovalAdmin
- resp.ShareImg = yanxuanDetail.ShareImg
- resp.IsFollowAuthor = yanxuanDetail.IsFollowAuthor
- //if resp.HasPermission != 1 || sysUser.UserId == 0 {
- // resp.Content = utils.InterceptHtmlLength(resp.Content, 240)
- //}
- //resp.ShareImg = utils.YANXUAN_SPECIAL_SHARE_IMG
- yanxuanDetail.ShareImg = yanxuanDetail.HeadImg
- resp.ShareImg = yanxuanDetail.HeadImg
- 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 //价格弹窗信息
- }
- resp.Detail = yanxuanDetail
- 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.SpecialColumnId <= 0 {
- br.Msg = "栏目id有误"
- return
- }
- if req.SpecialName == "" {
- br.Msg = "请输入专栏名称"
- return
- }
- if req.NickName == "" {
- br.Msg = "请输入昵称"
- return
- }
- item := models.CygxYanxuanSpecialAuthor{
- Id: req.SpecialColumnId,
- UserId: sysUser.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 len(req.CompanyTags) == 0 && len(req.IndustryTags) == 0 && req.DoType == 2 {
- br.Msg = "请至少输入一个标签"
- return
- }
- if len(req.Docs) > 0 {
- for i, doc := range req.Docs {
- extMap := services.GetCloudDiskResourceFileTypeExtMap()
- ext := path.Ext(doc.DocName)
- req.Docs[i].DocIcon = extMap[ext]
- }
- }
- docUrl, err := json.Marshal(req.Docs)
- if err != nil {
- return
- }
- imgUrls := strings.Join(req.ImgUrl, ",")
- cTags := strings.Join(req.CompanyTags, ",")
- iTags := strings.Join(req.IndustryTags, ",")
- isApprovalPersonnel := req.IsApprovalPersonnel
- item := models.CygxYanxuanSpecial{
- Id: req.Id,
- UserId: sysUser.UserId,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- PublishTime: time.Now(),
- Content: req.Content,
- CompanyTags: cTags,
- IndustryTags: iTags,
- ImgUrl: imgUrls,
- DocUrl: string(docUrl),
- Title: req.Title,
- Type: req.Type,
- }
- if req.DoType == 1 {
- item.Status = 1
- br.Msg = "保存成功"
- } else {
- item.Status = 2
- br.Msg = "已提交审核"
- }
- 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 //审核人员姓名
- br.Msg = "审批成功"
- }
- 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 {
- detail, tmpErr := models.GetYanxuanSpecialById(req.Id, sysUser.UserId)
- if tmpErr != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
- return
- }
- if detail.Status == 2 && !isApprovalPersonnel {
- br.Msg = "请勿重复提交"
- br.ErrMsg = "保存失败,专栏内容正在审核"
- return
- }
- 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.SendWxCategoryMsgSpecialAuthor(req.Id, 1) //研选专栏审核完成时,给提交人发送类目模板消息
- go services.SendWxCategoryMsgSpecialFollow(req.Id) // 研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
- go services.MakeYanxuanSpecialMomentsImg(specialId) // 生成研选专栏分享到朋友圈的图片
- } 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.Data = specialId
- }
- // @Title 专栏作者详情
- // @Description 专栏作者详情
- // @Param request body help_doc.AddHelpDocReq true "type json string"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /author/detail [get]
- func (this *YanxuanSpecialNoLoginController) 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
- }
- specialColumnId, _ := this.GetInt("SpecialColumnId", 0)
- item, tmpErr := models.GetYanxuanSpecialAuthorBySpecialColumnId(specialColumnId, 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.SendWxCategoryMsgSpecialAuthor(req.Id, 1) //研选专栏审核完成时,给提交人发送类目模板消息
- go services.SendWxCategoryMsgSpecialFollow(req.Id) // 研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
- } else {
- go services.SendWxCategoryMsgSpecialAuthor(req.Id, 2)
- }
- go services.SendWxMsgSpecialAuthor(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) // 写入es 综合搜索
- 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
- if req.Status == 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
- }
- 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
- }
- br.Data = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 专栏点击记录
- // @Description 专栏点击记录
- // @Param request body models.AddCygxReportSelectionSubjectHistoryReq 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
- }
- if req.SpecialId <= 0 {
- br.Msg = "文章不存在"
- br.ErrMsg = "文章不存在,文章ID错误"
- 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.FollowSpecialColumnId <= 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
- }
- authorItem, err := models.GetYanxuanSpecialAuthorById(req.FollowSpecialColumnId)
- if err != nil {
- br.Msg = "查询栏目详情失败!"
- br.ErrMsg = "查询栏目详情失败,Err:" + err.Error()
- return
- }
- if req.Status == 1 {
- followCount, err := models.GetCygxYanxuanSpecialFollowCountByUser(user.UserId, authorItem.UserId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败, Err:" + err.Error()
- return
- }
- if followCount == 0 {
- item := models.CygxYanxuanSpecialFollow{
- UserId: user.UserId,
- FollowUserId: authorItem.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.SpecialId,
- }
- err = models.AddCygxYanxuanSpecialFollow(&item)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- }
- br.Msg = "关注成功"
- } else {
- err = models.DelCygxYanxuanSpecialFollow(user.UserId, authorItem.UserId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Msg = "取消关注成功"
- }
- go services.UdpateYanxuanSpecialFansNum(authorItem.UserId)
- 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 *YanxuanSpecialNoLoginController) 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)
- resp := new(models.SpecialAuthorListResp)
- specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
- resp.IsAuthor = specialAuthorCheck.IsAuthor
- resp.IsImproveInformation = specialAuthorCheck.IsImproveInformation
- resp.SpecialColumnId = specialAuthorCheck.SpecialColumnId
- resp.HeadImg = specialAuthorCheck.HeadImg
- var condition string
- var conditionUserSort string
- var pars []interface{}
- condition += ` AND a.nick_name <> '' `
- conditionUserSort += ` ( IF ( a.user_id = ` + strconv.Itoa(sysUser.UserId) + `, 1 = 1, user_id = 1 ) ) AS user_sort , ` // 用户本人如果开通了专栏,就放在最前面
- total, err := models.GetCygxYanxuanSpecialAuthorCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- condition += ` ORDER BY user_sort DESC, latest_publish_time DESC`
- list, tmpErr := models.GetYanxuanSpecialAuthorList(conditionUserSort, 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)
- }
- 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.SpecialColumnId <= 0 {
- br.Msg = "专栏栏目id错误"
- return
- }
- if req.HeadImg == "" {
- br.Msg = "头像图片错误"
- return
- }
- item := models.CygxYanxuanSpecialAuthor{
- Id: req.SpecialColumnId,
- 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.DelCygxYanxuanSpecialReq
- 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 {
- // // 处理微信返回错误信息
- // br.Msg = "GetResponseError Err:" + err.Error()
- // return
- // }
- // err = os.RemoveAll(savePath)
- // if err != nil {
- // br.Msg = "RemoveAll Err:" + err.Error()
- // return
- // }
- //}
- }
- 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 = "获取成功"
- }
- //留言
- //点赞
- //列表
- //查询列表
- //公开
- //置顶
- //删除
- //精选
|