yanxuan_special.go 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/services"
  7. "hongze/hongze_clpt/utils"
  8. "path"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. type YanxuanSpecialController struct {
  14. BaseAuthController
  15. }
  16. type YanxuanSpecialNoLoginController struct {
  17. BaseAuthMobileController
  18. }
  19. // @Title 专栏列表
  20. // @Description 专栏列表
  21. // @Param SpecialColumnId query int true "作者专栏ID"
  22. // @Param PageSize query int true "每页数据条数"
  23. // @Param CurrentIndex query int true "当前页页码,从1开始"
  24. // @Success 200 {object} models.AddEnglishReportResp
  25. // @router /list [get]
  26. func (this *YanxuanSpecialNoLoginController) List() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. sysUser := this.User
  33. if sysUser == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,SysUser Is Empty"
  36. br.Ret = 408
  37. return
  38. }
  39. specialColumnId, _ := this.GetInt("SpecialColumnId", 0)
  40. pageSize, _ := this.GetInt("PageSize")
  41. currentIndex, _ := this.GetInt("CurrentIndex")
  42. var startSize int
  43. if pageSize <= 0 {
  44. pageSize = utils.PageSize20
  45. }
  46. if currentIndex <= 0 {
  47. currentIndex = 1
  48. }
  49. startSize = utils.StartIndex(currentIndex, pageSize)
  50. resp := new(models.SpecialListResp)
  51. var condition string
  52. var pars []interface{}
  53. if specialColumnId > 0 {
  54. authorItem, err := models.GetYanxuanSpecialAuthorById(specialColumnId)
  55. if err != nil {
  56. br.Msg = "查询栏目详情失败!"
  57. br.ErrMsg = "查询栏目详情失败,Err:" + err.Error()
  58. return
  59. }
  60. condition += ` AND a.user_id = ? `
  61. pars = append(pars, authorItem.UserId)
  62. }
  63. condition += ` AND a.status = 3 `
  64. total, err := models.GetCygxYanxuanSpecialCount(condition, pars)
  65. if err != nil {
  66. br.Msg = "获取失败"
  67. br.ErrMsg = "获取失败, Err:" + err.Error()
  68. return
  69. }
  70. list, err := models.GetYanxuanSpecialList(sysUser.UserId, condition, pars, startSize, pageSize)
  71. if err != nil {
  72. br.Msg = "获取失败"
  73. br.ErrMsg = "获取失败, Err:" + err.Error()
  74. return
  75. }
  76. for _, v := range list {
  77. hasImg, err := utils.ArticleHasImgUrl(v.Content)
  78. if err != nil {
  79. return
  80. }
  81. if hasImg {
  82. v.ContentHasImg = 1
  83. }
  84. v.ImgUrl = strings.TrimRight(v.ImgUrl, ",")
  85. //去除图片标签
  86. v.Content = utils.ArticleRemoveImgUrl(v.Content)
  87. //v.Content, err = utils.ExtractText(v.Content)
  88. if v.DocUrl != "" {
  89. var docs []models.Doc
  90. err := json.Unmarshal([]byte(v.DocUrl), &docs)
  91. if err != nil {
  92. br.Msg = "参数解析异常!"
  93. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  94. return
  95. }
  96. v.Docs = docs
  97. }
  98. if v.MyCollectNum > 0 {
  99. v.IsCollect = 1
  100. }
  101. if v.ImgUrl != "" {
  102. imgList := strings.Split(v.ImgUrl, ",")
  103. for _, s := range imgList {
  104. v.ImgUrlList = append(v.ImgUrlList, s)
  105. }
  106. } else {
  107. v.ImgUrlList = []string{}
  108. }
  109. if v.CompanyTags != "" {
  110. tagList := strings.Split(v.CompanyTags, ",")
  111. for _, s := range tagList {
  112. v.TagList = append(v.TagList, s)
  113. }
  114. }
  115. if v.IndustryTags != "" {
  116. tagList := strings.Split(v.IndustryTags, ",")
  117. for _, s := range tagList {
  118. v.TagList = append(v.TagList, s)
  119. }
  120. }
  121. if len(v.TagList) == 0 {
  122. v.TagList = []string{}
  123. }
  124. }
  125. specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
  126. resp.IsAuthor = specialAuthorCheck.IsAuthor
  127. resp.IsImproveInformation = specialAuthorCheck.IsImproveInformation
  128. resp.List = list
  129. page := paging.GetPaging(currentIndex, pageSize, total)
  130. resp.Paging = page
  131. br.Data = resp
  132. br.Ret = 200
  133. br.Success = true
  134. br.Msg = "获取成功"
  135. }
  136. // @Title 专栏详情
  137. // @Description 专栏详情
  138. // @Param request body help_doc.AddHelpDocReq true "type json string"
  139. // @Success 200 {object} models.AddEnglishReportResp
  140. // @router /detail [get]
  141. func (this *YanxuanSpecialController) Detail() {
  142. br := new(models.BaseResponse).Init()
  143. defer func() {
  144. this.Data["json"] = br
  145. this.ServeJSON()
  146. }()
  147. sysUser := this.User
  148. if sysUser == nil {
  149. br.Msg = "请登录"
  150. br.ErrMsg = "请登录,SysUser Is Empty"
  151. br.Ret = 408
  152. return
  153. }
  154. specialId, _ := this.GetInt("Id", 0)
  155. if specialId <= 0 {
  156. br.Msg = "参数错误"
  157. br.ErrMsg = "参数错误"
  158. return
  159. }
  160. item, tmpErr := models.GetYanxuanSpecialById(specialId, sysUser.UserId)
  161. if tmpErr != nil {
  162. br.Msg = "获取失败"
  163. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  164. return
  165. }
  166. if item.MyCollectNum > 0 {
  167. item.IsCollect = 1
  168. }
  169. var resp models.CygxYanxuanSpecialResp
  170. resp.HasPermission = 1
  171. resp.CygxYanxuanSpecialItem = *item
  172. if item.DocUrl != "" {
  173. var docs []models.Doc
  174. err := json.Unmarshal([]byte(item.DocUrl), &docs)
  175. if err != nil {
  176. br.Msg = "参数解析异常!"
  177. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  178. return
  179. }
  180. resp.Docs = docs
  181. }
  182. if item.ImgUrl != "" {
  183. imgList := strings.Split(item.ImgUrl, ",")
  184. for _, s := range imgList {
  185. resp.ImgUrlList = append(resp.ImgUrlList, s)
  186. }
  187. } else {
  188. resp.ImgUrlList = []string{}
  189. }
  190. if item.CompanyTags != "" {
  191. cTagList := strings.Split(item.CompanyTags, ",")
  192. for _, s := range cTagList {
  193. resp.CompanyTags = append(resp.CompanyTags, s)
  194. }
  195. } else {
  196. resp.CompanyTags = []string{}
  197. }
  198. if item.IndustryTags != "" {
  199. iTagList := strings.Split(item.IndustryTags, ",")
  200. for _, s := range iTagList {
  201. resp.IndustryTags = append(resp.IndustryTags, s)
  202. }
  203. } else {
  204. resp.IndustryTags = []string{}
  205. }
  206. var configCode string
  207. //如果是研选的就推送给汪洋跟王芳,否则就推送给王芳
  208. configCode = utils.TPL_MSG_WANG_FANG_WANG_YANG
  209. cnf, err := models.GetConfigByCode(configCode)
  210. if err != nil {
  211. br.Msg = "获取失败"
  212. br.ErrMsg = "获取失败, Err:" + err.Error()
  213. return
  214. }
  215. if item.UserId != sysUser.UserId && item.Status != 3 && !strings.Contains(cnf.ConfigValue, sysUser.Mobile) {
  216. resp.CygxYanxuanSpecialItem = *new(models.CygxYanxuanSpecialItem) // 如果内容不可见,就把内容置空
  217. resp.HasPermission = 2
  218. }
  219. //判断是否属于审核人员
  220. mobileSlice := strings.Split(cnf.ConfigValue, ",")
  221. for _, v := range mobileSlice {
  222. if v == sysUser.Mobile {
  223. resp.IsApprovalAdmin = true
  224. }
  225. }
  226. br.Data = resp
  227. br.Ret = 200
  228. br.Success = true
  229. br.Msg = "获取成功"
  230. }
  231. // @Title 新增保存专栏作者详情
  232. // @Description 新增保存专栏作者详情
  233. // @Param request body help_doc.AddHelpDocReq true "type json string"
  234. // @Success 200 {object} models.AddEnglishReportResp
  235. // @router /author/save [post]
  236. func (this *YanxuanSpecialController) AuthorSave() {
  237. br := new(models.BaseResponse).Init()
  238. defer func() {
  239. this.Data["json"] = br
  240. this.ServeJSON()
  241. }()
  242. sysUser := this.User
  243. if sysUser == nil {
  244. br.Msg = "请登录"
  245. br.ErrMsg = "请登录,SysUser Is Empty"
  246. br.Ret = 408
  247. return
  248. }
  249. var req models.SaveCygxYanxuanSpecialAuthorReq
  250. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  251. if err != nil {
  252. br.Msg = "参数解析异常!"
  253. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  254. return
  255. }
  256. if req.SpecialColumnId <= 0 {
  257. br.Msg = "栏目id有误"
  258. return
  259. }
  260. if req.SpecialName == "" {
  261. br.Msg = "请输入专栏名称"
  262. return
  263. }
  264. if req.NickName == "" {
  265. br.Msg = "请输入昵称"
  266. return
  267. }
  268. item := models.CygxYanxuanSpecialAuthor{
  269. Id: req.SpecialColumnId,
  270. UserId: sysUser.UserId,
  271. SpecialName: req.SpecialName,
  272. Introduction: req.Introduction,
  273. Label: req.Label,
  274. NickName: req.NickName,
  275. CreateTime: time.Now(),
  276. ModifyTime: time.Now(),
  277. BgImg: "",
  278. Status: 1,
  279. }
  280. //if req.Id == 0{
  281. // _, err = models.AddCygxYanxuanSpecialAuthor(&item)
  282. // if err != nil {
  283. // br.Msg = "新增失败"
  284. // br.ErrMsg = "新增失败,Err:" + err.Error()
  285. // return
  286. // }
  287. //} else {
  288. // err = models.UpdateYanxuanSpecialAuthor(&item)
  289. // if err != nil {
  290. // br.Msg = "保存失败"
  291. // br.ErrMsg = "保存失败,Err:" + err.Error()
  292. // return
  293. // }
  294. //}
  295. err = models.UpdateYanxuanSpecialAuthor(&item)
  296. if err != nil {
  297. br.Msg = "保存失败"
  298. br.ErrMsg = "保存失败,Err:" + err.Error()
  299. return
  300. }
  301. br.Ret = 200
  302. br.Success = true
  303. br.Msg = "保存成功"
  304. }
  305. // @Title 新增保存专栏
  306. // @Description 新增保存专栏
  307. // @Param request body help_doc.AddHelpDocReq true "type json string"
  308. // @Success 200 {object} models.AddEnglishReportResp
  309. // @router /save [post]
  310. func (this *YanxuanSpecialController) Save() {
  311. br := new(models.BaseResponse).Init()
  312. defer func() {
  313. this.Data["json"] = br
  314. this.ServeJSON()
  315. }()
  316. sysUser := this.User
  317. if sysUser == nil {
  318. br.Msg = "请登录"
  319. br.ErrMsg = "请登录,SysUser Is Empty"
  320. br.Ret = 408
  321. return
  322. }
  323. var req models.CygxYanxuanSpecialReq
  324. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  325. if err != nil {
  326. br.Msg = "参数解析异常!"
  327. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  328. return
  329. }
  330. if req.Content == "" && req.DoType == 2 {
  331. br.Msg = "请输入内容"
  332. return
  333. }
  334. if len(req.CompanyTags) == 0 && len(req.IndustryTags) == 0 && req.DoType == 2 {
  335. br.Msg = "请至少输入一个标签"
  336. return
  337. }
  338. if len(req.Docs) > 0 {
  339. for i, doc := range req.Docs {
  340. extMap := services.GetCloudDiskResourceFileTypeExtMap()
  341. ext := path.Ext(doc.DocName)
  342. req.Docs[i].DocIcon = extMap[ext]
  343. }
  344. }
  345. docUrl, err := json.Marshal(req.Docs)
  346. if err != nil {
  347. return
  348. }
  349. imgUrls := strings.Join(req.ImgUrl, ",")
  350. cTags := strings.Join(req.CompanyTags, ",")
  351. iTags := strings.Join(req.IndustryTags, ",")
  352. isApprovalPersonnel := req.IsApprovalPersonnel
  353. item := models.CygxYanxuanSpecial{
  354. Id: req.Id,
  355. UserId: sysUser.UserId,
  356. CreateTime: time.Now(),
  357. ModifyTime: time.Now(),
  358. PublishTime: time.Now(),
  359. Content: req.Content,
  360. CompanyTags: cTags,
  361. IndustryTags: iTags,
  362. ImgUrl: imgUrls,
  363. DocUrl: string(docUrl),
  364. Title: req.Title,
  365. Type: req.Type,
  366. }
  367. if req.DoType == 1 {
  368. item.Status = 1
  369. br.Msg = "保存成功"
  370. } else {
  371. item.Status = 2
  372. br.Msg = "已提交审核"
  373. }
  374. var authorUserId int
  375. // 如果是审批人员操作的那么就是修改内容,加审批通过
  376. if isApprovalPersonnel {
  377. item.Status = 3
  378. //校验是否属于审核人员
  379. if !services.CheckYxSpecialIsApprovalPersonnel(sysUser.Mobile) {
  380. br.Msg = "操作失败"
  381. br.ErrMsg = "操作失败,该账号不属于审核人员:" + sysUser.Mobile
  382. return
  383. }
  384. specialItem, err := models.GetYanxuanSpecialItemById(req.Id)
  385. if err != nil {
  386. br.Msg = "保存失败"
  387. br.ErrMsg = "保存失败,Err:" + err.Error()
  388. return
  389. }
  390. item.UserId = specialItem.UserId // 专栏userid还是原有userId
  391. authorUserId = specialItem.UserId
  392. item.AdminName = sysUser.RealName //审核人员姓名
  393. br.Msg = "审批成功"
  394. }
  395. specialId := 0
  396. if req.Id == 0 {
  397. id, err := models.AddCygxYanxuanSpecial(&item)
  398. if err != nil {
  399. br.Msg = "新增失败"
  400. br.ErrMsg = "新增失败,Err:" + err.Error()
  401. return
  402. }
  403. specialId = int(id)
  404. } else {
  405. detail, tmpErr := models.GetYanxuanSpecialById(req.Id, sysUser.UserId)
  406. if tmpErr != nil {
  407. br.Msg = "获取失败"
  408. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  409. return
  410. }
  411. if detail.Status == 2 && !isApprovalPersonnel {
  412. br.Msg = "请勿重复提交"
  413. br.ErrMsg = "保存失败,专栏内容正在审核"
  414. return
  415. }
  416. err = models.UpdateYanxuanSpecial(&item)
  417. if err != nil {
  418. br.Msg = "保存失败"
  419. br.ErrMsg = "保存失败,Err:" + err.Error()
  420. return
  421. }
  422. specialId = req.Id
  423. }
  424. if isApprovalPersonnel {
  425. go services.UpdateYanxuanSpecialResourceData(specialId) // 写入首页最新 cygx_resource_data 表
  426. go services.EsAddYanxuanSpecial(specialId) // 写入es 综合搜索
  427. go services.SendWxMsgSpecialFollow(req.Id) //研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
  428. go services.SendWxMsgSpecialAuthor(req.Id, 2) //研选专栏审核完成时,给提交人发送模板消息
  429. go services.UdpateYanxuanSpecialauthorArticleNum(authorUserId) // 更新作者发布文章的数量
  430. } else {
  431. if req.DoType == 2 {
  432. go services.SendReviewTemplateMsgAdmin(specialId)
  433. go services.UpdateYanxuanSpecialResourceData(specialId) // 写入首页最新 cygx_resource_data 表
  434. go services.EsAddYanxuanSpecial(specialId) // 写入es 综合搜索
  435. }
  436. }
  437. br.Ret = 200
  438. br.Success = true
  439. br.Data = specialId
  440. }
  441. // @Title 专栏作者详情
  442. // @Description 专栏作者详情
  443. // @Param request body help_doc.AddHelpDocReq true "type json string"
  444. // @Success 200 {object} models.AddEnglishReportResp
  445. // @router /author/detail [get]
  446. func (this *YanxuanSpecialNoLoginController) AuthorDetail() {
  447. br := new(models.BaseResponse).Init()
  448. defer func() {
  449. this.Data["json"] = br
  450. this.ServeJSON()
  451. }()
  452. sysUser := this.User
  453. if sysUser == nil {
  454. br.Msg = "请登录"
  455. br.ErrMsg = "请登录,SysUser Is Empty"
  456. br.Ret = 408
  457. return
  458. }
  459. specialColumnId, _ := this.GetInt("SpecialColumnId", 0)
  460. item, tmpErr := models.GetYanxuanSpecialAuthorBySpecialColumnId(specialColumnId, sysUser.UserId)
  461. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  462. br.Msg = "获取失败"
  463. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  464. return
  465. }
  466. br.Data = item
  467. br.Ret = 200
  468. br.Success = true
  469. br.Msg = "获取成功"
  470. }
  471. // @Title 审批研选专栏
  472. // @Description 审批研选专栏
  473. // @Param request body help_doc.AddHelpDocReq true "type json string"
  474. // @Success 200 {object} models.AddEnglishReportResp
  475. // @router /enable [post]
  476. func (this *YanxuanSpecialController) Enable() {
  477. br := new(models.BaseResponse).Init()
  478. defer func() {
  479. this.Data["json"] = br
  480. this.ServeJSON()
  481. }()
  482. user := this.User
  483. if user == nil {
  484. br.Msg = "请登录"
  485. br.ErrMsg = "请登录,SysUser Is Empty"
  486. br.Ret = 408
  487. return
  488. }
  489. var req models.EnableCygxYanxuanSpecialReq
  490. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  491. if err != nil {
  492. br.Msg = "参数解析异常!"
  493. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  494. return
  495. }
  496. if req.Id <= 0 {
  497. br.Msg = "文章id错误"
  498. return
  499. }
  500. if req.Status <= 0 {
  501. br.Msg = "参数错误"
  502. return
  503. }
  504. status := 0
  505. if req.Status == 1 {
  506. status = 3
  507. } else {
  508. status = 4
  509. }
  510. detail, err := models.GetYanxuanSpecialItemById(req.Id)
  511. if err != nil {
  512. br.Msg = "审批失败"
  513. br.ErrMsg = "审批失败, Err:" + err.Error()
  514. return
  515. }
  516. if tmpErr := models.EnableYanxuanSpecial(req.Id, status, req.Reason, user.RealName); tmpErr != nil {
  517. br.Msg = "审批失败"
  518. br.ErrMsg = "审批失败, Err:" + tmpErr.Error()
  519. return
  520. }
  521. if req.Status == 1 {
  522. go services.SendWxMsgSpecialFollow(req.Id)
  523. }
  524. go services.SendWxMsgSpecialAuthor(req.Id, req.Status)
  525. go services.UpdateYanxuanSpecialResourceData(req.Id) // 写入首页最新 cygx_resource_data 表
  526. go services.EsAddYanxuanSpecial(req.Id) // 写入es 综合搜索
  527. go services.AddAddCygxYanxuanSpecialApprovalLog(user, req.Id, req.Status, req.Reason) // 写入es 综合搜索
  528. go services.UdpateYanxuanSpecialauthorArticleNum(detail.UserId) // 更新作者发布文章的数量
  529. br.Msg = "审批成功"
  530. br.Ret = 200
  531. br.Success = true
  532. }
  533. // @Title 研选专栏收藏
  534. // @Description 研选专栏收藏
  535. // @Param request body help_doc.AddHelpDocReq true "type json string"
  536. // @Success 200 {object} models.AddEnglishReportResp
  537. // @router /collect [post]
  538. func (this *YanxuanSpecialController) Collect() {
  539. br := new(models.BaseResponse).Init()
  540. defer func() {
  541. this.Data["json"] = br
  542. this.ServeJSON()
  543. }()
  544. user := this.User
  545. if user == nil {
  546. br.Msg = "请登录"
  547. br.ErrMsg = "请登录,SysUser Is Empty"
  548. br.Ret = 408
  549. return
  550. }
  551. var req models.CollectCygxYanxuanSpecialReq
  552. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  553. if err != nil {
  554. br.Msg = "参数解析异常!"
  555. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  556. return
  557. }
  558. if req.Id <= 0 {
  559. br.Msg = "文章id错误"
  560. return
  561. }
  562. if req.Status <= 0 {
  563. br.Msg = "参数错误"
  564. return
  565. }
  566. var sellerName string
  567. if req.Status == 1 {
  568. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  569. if err != nil {
  570. br.Msg = "报名失败!"
  571. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  572. return
  573. }
  574. item := models.CygxYanxuanSpecialCollect{
  575. UserId: user.UserId,
  576. Mobile: user.Mobile,
  577. Email: user.Email,
  578. CompanyId: user.CompanyId,
  579. CompanyName: user.CompanyName,
  580. RealName: user.RealName,
  581. SellerName: sellerName,
  582. CreateTime: time.Now(),
  583. ModifyTime: time.Now(),
  584. RegisterPlatform: utils.REGISTER_PLATFORM,
  585. YanxuanSpecialId: req.Id,
  586. }
  587. _, err = models.AddCygxYanxuanSpecialCollect(&item)
  588. if err != nil {
  589. br.Msg = "新增失败"
  590. br.ErrMsg = "新增失败,Err:" + err.Error()
  591. return
  592. }
  593. br.Msg = "收藏成功"
  594. } else {
  595. err = models.DelCygxYanxuanSpecialCollect(user.UserId, req.Id)
  596. if err != nil {
  597. br.Msg = "删除失败"
  598. br.ErrMsg = "删除失败,Err:" + err.Error()
  599. return
  600. }
  601. br.Msg = "取消收藏成功"
  602. }
  603. go services.UdpateYanxuanSpecialCollect(user, req.Id, req.Status)
  604. br.Ret = 200
  605. br.Success = true
  606. }
  607. // @Title 专栏内容中心
  608. // @Description 专栏内容中心
  609. // @Param request body help_doc.AddHelpDocReq true "type json string"
  610. // @Success 200 {object} models.AddEnglishReportResp
  611. // @router /center [get]
  612. func (this *YanxuanSpecialController) Center() {
  613. br := new(models.BaseResponse).Init()
  614. defer func() {
  615. this.Data["json"] = br
  616. this.ServeJSON()
  617. }()
  618. sysUser := this.User
  619. if sysUser == nil {
  620. br.Msg = "请登录"
  621. br.ErrMsg = "请登录,SysUser Is Empty"
  622. br.Ret = 408
  623. return
  624. }
  625. // 1:未发布,2:审核中 3:已发布 4:驳回
  626. status, _ := this.GetInt("Status", 0)
  627. if status <= 0 {
  628. br.Msg = "参数错误"
  629. br.ErrMsg = "参数错误"
  630. return
  631. }
  632. var condition string
  633. var pars []interface{}
  634. condition += ` AND a.user_id = ? `
  635. pars = append(pars, sysUser.UserId)
  636. condition += ` AND a.status = ? `
  637. pars = append(pars, status)
  638. list, tmpErr := models.GetYanxuanSpecialList(sysUser.UserId, condition, pars, 0, 0)
  639. if tmpErr != nil {
  640. br.Msg = "获取失败"
  641. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  642. return
  643. }
  644. br.Data = list
  645. br.Ret = 200
  646. br.Success = true
  647. br.Msg = "获取成功"
  648. }
  649. // @Title 专栏点击记录
  650. // @Description 专栏点击记录
  651. // @Param request body models.AddCygxReportSelectionSubjectHistoryReq true "type json string"
  652. // @router /record [post]
  653. func (this *YanxuanSpecialController) Record() {
  654. br := new(models.BaseResponse).Init()
  655. defer func() {
  656. this.Data["json"] = br
  657. this.ServeJSON()
  658. }()
  659. user := this.User
  660. if user == nil {
  661. br.Msg = "请重新登录"
  662. br.Ret = 408
  663. return
  664. }
  665. var req models.AddCygxYanxuanSpecialRecordReq
  666. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  667. if err != nil {
  668. br.Msg = "参数解析异常!"
  669. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  670. return
  671. }
  672. if req.SpecialId <= 0 {
  673. br.Msg = "文章不存在"
  674. br.ErrMsg = "文章不存在,文章ID错误"
  675. return
  676. }
  677. specialId := req.SpecialId
  678. stopTime := req.StopTime
  679. if req.SpecialId <= 0 {
  680. br.Msg = "文章不存在"
  681. br.ErrMsg = "文章不存在,文章ID错误"
  682. return
  683. }
  684. err = services.AddSpecialRecord(this.User, specialId, stopTime)
  685. if err != nil {
  686. br.Msg = "记录失败"
  687. br.ErrMsg = "记录失败,Err:" + err.Error()
  688. return
  689. }
  690. br.Ret = 200
  691. br.Success = true
  692. br.Msg = "记录成功"
  693. }
  694. // @Title 研选专栏关注
  695. // @Description 研选专栏关注
  696. // @Param request body help_doc.AddHelpDocReq true "type json string"
  697. // @Success 200 {object} models.AddEnglishReportResp
  698. // @router /follow [post]
  699. func (this *YanxuanSpecialController) Follow() {
  700. br := new(models.BaseResponse).Init()
  701. defer func() {
  702. this.Data["json"] = br
  703. this.ServeJSON()
  704. }()
  705. user := this.User
  706. if user == nil {
  707. br.Msg = "请登录"
  708. br.ErrMsg = "请登录,SysUser Is Empty"
  709. br.Ret = 408
  710. return
  711. }
  712. var req models.FollowCygxYanxuanSpecialReq
  713. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  714. if err != nil {
  715. br.Msg = "参数解析异常!"
  716. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  717. return
  718. }
  719. if req.FollowSpecialColumnId <= 0 {
  720. br.Msg = "被关注的专栏栏目id错误"
  721. return
  722. }
  723. if req.Status <= 0 {
  724. br.Msg = "参数错误"
  725. return
  726. }
  727. var sellerName string
  728. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  729. if err != nil {
  730. br.Msg = "查询栏目详情失败!"
  731. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  732. return
  733. }
  734. sellerName = sellerItemQy.RealName
  735. authorItem, err := models.GetYanxuanSpecialAuthorById(req.FollowSpecialColumnId)
  736. if err != nil {
  737. br.Msg = "查询栏目详情失败!"
  738. br.ErrMsg = "查询栏目详情失败,Err:" + err.Error()
  739. return
  740. }
  741. if req.Status == 1 {
  742. item := models.CygxYanxuanSpecialFollow{
  743. UserId: user.UserId,
  744. FollowUserId: authorItem.UserId,
  745. Mobile: user.Mobile,
  746. Email: user.Email,
  747. CompanyId: user.CompanyId,
  748. CompanyName: user.CompanyName,
  749. RealName: user.RealName,
  750. SellerName: sellerName,
  751. CreateTime: time.Now(),
  752. ModifyTime: time.Now(),
  753. RegisterPlatform: utils.REGISTER_PLATFORM,
  754. YanxuanSpecialId: req.SpecialId,
  755. }
  756. err = models.AddCygxYanxuanSpecialFollow(&item)
  757. if err != nil {
  758. br.Msg = "新增失败"
  759. br.ErrMsg = "新增失败,Err:" + err.Error()
  760. return
  761. }
  762. br.Msg = "关注成功"
  763. } else {
  764. err = models.DelCygxYanxuanSpecialFollow(user.UserId, authorItem.UserId)
  765. if err != nil {
  766. br.Msg = "删除失败"
  767. br.ErrMsg = "删除失败,Err:" + err.Error()
  768. return
  769. }
  770. br.Msg = "取消关注成功"
  771. }
  772. go services.UdpateYanxuanSpecialFansNum(user, authorItem.Id, req.Status)
  773. br.Ret = 200
  774. br.Success = true
  775. }
  776. // @Title 行业标签搜索
  777. // @Description 行业标签搜索
  778. // @Param request body help_doc.AddHelpDocReq true "type json string"
  779. // @Success 200 {object} models.AddEnglishReportResp
  780. // @router /industrySearch [get]
  781. func (this *YanxuanSpecialController) IndustrySearch() {
  782. br := new(models.BaseResponse).Init()
  783. defer func() {
  784. this.Data["json"] = br
  785. this.ServeJSON()
  786. }()
  787. sysUser := this.User
  788. if sysUser == nil {
  789. br.Msg = "请登录"
  790. br.ErrMsg = "请登录,SysUser Is Empty"
  791. br.Ret = 408
  792. return
  793. }
  794. keyword := this.GetString("Keyword")
  795. list, tmpErr := models.GetYanxuanSpecialIndustry(keyword)
  796. if tmpErr != nil {
  797. br.Msg = "获取失败"
  798. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  799. return
  800. }
  801. br.Data = list
  802. br.Ret = 200
  803. br.Success = true
  804. br.Msg = "获取成功"
  805. }
  806. // @Title 公司标签搜索
  807. // @Description 公司标签搜索
  808. // @Param request body help_doc.AddHelpDocReq true "type json string"
  809. // @Success 200 {object} models.AddEnglishReportResp
  810. // @router /companySearch [get]
  811. func (this *YanxuanSpecialController) CompanySearch() {
  812. br := new(models.BaseResponse).Init()
  813. defer func() {
  814. this.Data["json"] = br
  815. this.ServeJSON()
  816. }()
  817. sysUser := this.User
  818. if sysUser == nil {
  819. br.Msg = "请登录"
  820. br.ErrMsg = "请登录,SysUser Is Empty"
  821. br.Ret = 408
  822. return
  823. }
  824. keyword := this.GetString("Keyword")
  825. if keyword == "" {
  826. br.Ret = 200
  827. return
  828. }
  829. list, tmpErr := models.GetYanxuanSpecialCompany(keyword)
  830. if tmpErr != nil {
  831. br.Msg = "获取失败"
  832. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  833. return
  834. }
  835. br.Data = list
  836. br.Ret = 200
  837. br.Success = true
  838. br.Msg = "获取成功"
  839. }
  840. // @Title 专栏取消发布
  841. // @Description 专栏取消发布
  842. // @Param request body help_doc.AddHelpDocReq true "type json string"
  843. // @Success 200 {object} models.AddEnglishReportResp
  844. // @router /cancel [post]
  845. func (this *YanxuanSpecialController) Cancel() {
  846. br := new(models.BaseResponse).Init()
  847. defer func() {
  848. this.Data["json"] = br
  849. this.ServeJSON()
  850. }()
  851. sysUser := this.User
  852. if sysUser == nil {
  853. br.Msg = "请登录"
  854. br.ErrMsg = "请登录,SysUser Is Empty"
  855. br.Ret = 408
  856. return
  857. }
  858. var req models.CancelPublishCygxYanxuanSpecialReq
  859. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  860. if err != nil {
  861. br.Msg = "参数解析异常!"
  862. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  863. return
  864. }
  865. if req.Id <= 0 {
  866. br.Msg = "文章id错误"
  867. return
  868. }
  869. specialItem, err := models.GetYanxuanSpecialItemById(req.Id)
  870. if err != nil {
  871. br.Msg = "专栏取消发布失败"
  872. br.ErrMsg = "专栏取消发布失败,Err:" + err.Error()
  873. return
  874. }
  875. if tmpErr := models.CancelPublishYanxuanSpecial(req.Id); tmpErr != nil {
  876. br.Msg = "取消发布失败"
  877. br.ErrMsg = "取消发布失败, Err:" + tmpErr.Error()
  878. return
  879. }
  880. go services.UpdateYanxuanSpecialResourceData(req.Id) // 写入首页最新 cygx_resource_data 表
  881. go services.EsAddYanxuanSpecial(req.Id) // 写入es 综合搜索
  882. go services.UdpateYanxuanSpecialauthorArticleNum(specialItem.UserId) // 更新作者发布文章的数量
  883. br.Msg = "取消发布成功"
  884. br.Ret = 200
  885. br.Success = true
  886. }
  887. // @Title 作者列表
  888. // @Description 作者列表
  889. // @Param PageSize query int true "每页数据条数"
  890. // @Param CurrentIndex query int true "当前页页码,从1开始"
  891. // @Success 200 {object} models.AddEnglishReportResp
  892. // @router /author/list [get]
  893. func (this *YanxuanSpecialNoLoginController) AuthorList() {
  894. br := new(models.BaseResponse).Init()
  895. defer func() {
  896. this.Data["json"] = br
  897. this.ServeJSON()
  898. }()
  899. sysUser := this.User
  900. if sysUser == nil {
  901. br.Msg = "请登录"
  902. br.ErrMsg = "请登录,SysUser Is Empty"
  903. br.Ret = 408
  904. return
  905. }
  906. pageSize, _ := this.GetInt("PageSize")
  907. currentIndex, _ := this.GetInt("CurrentIndex")
  908. var startSize int
  909. if pageSize <= 0 {
  910. pageSize = utils.PageSize20
  911. }
  912. if currentIndex <= 0 {
  913. currentIndex = 1
  914. }
  915. startSize = utils.StartIndex(currentIndex, pageSize)
  916. resp := new(models.SpecialAuthorListResp)
  917. specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
  918. resp.IsAuthor = specialAuthorCheck.IsAuthor
  919. resp.IsImproveInformation = specialAuthorCheck.IsImproveInformation
  920. resp.SpecialColumnId = specialAuthorCheck.SpecialColumnId
  921. resp.HeadImg = specialAuthorCheck.HeadImg
  922. var condition string
  923. var conditionUserSort string
  924. var pars []interface{}
  925. condition += ` AND a.nick_name <> '' `
  926. conditionUserSort += ` ( IF ( a.user_id = ` + strconv.Itoa(sysUser.UserId) + `, 1 = 1, user_id = 1 ) ) AS user_sort , ` // 用户本人如果开通了专栏,就放在最前面
  927. total, err := models.GetCygxYanxuanSpecialAuthorCount(condition, pars)
  928. if err != nil {
  929. br.Msg = "获取失败"
  930. br.ErrMsg = "获取失败,Err:" + err.Error()
  931. return
  932. }
  933. condition += ` ORDER BY user_sort DESC, latest_publish_time DESC`
  934. list, tmpErr := models.GetYanxuanSpecialAuthorList(conditionUserSort, condition, pars, startSize, pageSize)
  935. if tmpErr != nil {
  936. br.Msg = "获取失败"
  937. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  938. return
  939. }
  940. //var userIds []int
  941. for _, v := range list {
  942. v.LatestPublishDate = v.LatestPublishTime.Format(utils.FormatDate) + "更新"
  943. //userIds = append(userIds, v.UserId)
  944. }
  945. page := paging.GetPaging(currentIndex, pageSize, total)
  946. resp.List = list
  947. resp.Paging = page
  948. br.Data = resp
  949. br.Ret = 200
  950. br.Success = true
  951. br.Msg = "获取成功"
  952. }
  953. // @Title 更新作者头像
  954. // @Description 更新作者头像
  955. // @Param request body help_doc.AddHelpDocReq true "type json string"
  956. // @Success 200 {object} models.AddEnglishReportResp
  957. // @router /author/head_img [post]
  958. func (this *YanxuanSpecialController) AuthorHeadImg() {
  959. br := new(models.BaseResponse).Init()
  960. defer func() {
  961. this.Data["json"] = br
  962. this.ServeJSON()
  963. }()
  964. sysUser := this.User
  965. if sysUser == nil {
  966. br.Msg = "请登录"
  967. br.ErrMsg = "请登录,SysUser Is Empty"
  968. br.Ret = 408
  969. return
  970. }
  971. var req models.SaveCygxYanxuanSpecialAuthoHeadImgrReq
  972. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  973. if err != nil {
  974. br.Msg = "参数解析异常!"
  975. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  976. return
  977. }
  978. if req.SpecialColumnId <= 0 {
  979. br.Msg = "专栏栏目id错误"
  980. return
  981. }
  982. if req.HeadImg == "" {
  983. br.Msg = "头像图片错误"
  984. return
  985. }
  986. item := models.CygxYanxuanSpecialAuthor{
  987. Id: req.SpecialColumnId,
  988. HeadImg: req.HeadImg,
  989. }
  990. err = models.UpdateYanxuanSpecialAuthorHeadImg(&item)
  991. if err != nil {
  992. br.Msg = "保存失败"
  993. br.ErrMsg = "保存失败,Err:" + err.Error()
  994. return
  995. }
  996. br.Ret = 200
  997. br.Success = true
  998. br.Msg = "保存成功"
  999. }
  1000. // @Title 删除专栏
  1001. // @Description 删除专栏
  1002. // @Param request body help_doc.AddHelpDocReq true "type json string"
  1003. // @Success 200 {object} models.AddEnglishReportResp
  1004. // @router /del [post]
  1005. func (this *YanxuanSpecialController) Delete() {
  1006. br := new(models.BaseResponse).Init()
  1007. defer func() {
  1008. this.Data["json"] = br
  1009. this.ServeJSON()
  1010. }()
  1011. sysUser := this.User
  1012. if sysUser == nil {
  1013. br.Msg = "请登录"
  1014. br.ErrMsg = "请登录,SysUser Is Empty"
  1015. br.Ret = 408
  1016. return
  1017. }
  1018. var req models.DelCygxYanxuanSpecialReq
  1019. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1020. if err != nil {
  1021. br.Msg = "参数解析异常!"
  1022. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1023. return
  1024. }
  1025. if req.Id <= 0 {
  1026. br.Msg = "文章id错误"
  1027. return
  1028. }
  1029. if tmpErr := models.DelYanxuanSpecial(req.Id); tmpErr != nil {
  1030. br.Msg = "删除失败"
  1031. br.ErrMsg = "删除失败, Err:" + tmpErr.Error()
  1032. return
  1033. }
  1034. br.Msg = "删除成功"
  1035. br.Ret = 200
  1036. br.Success = true
  1037. }
  1038. // @Title 专栏文章敏感词检测
  1039. // @Description 专栏文章敏感词检测
  1040. // @Param request body help_doc.AddHelpDocReq true "type json string"
  1041. // @Success 200 {object} models.AddEnglishReportResp
  1042. // @router /check [post]
  1043. func (this *YanxuanSpecialController) Check() {
  1044. br := new(models.BaseResponse).Init()
  1045. defer func() {
  1046. this.Data["json"] = br
  1047. this.ServeJSON()
  1048. }()
  1049. sysUser := this.User
  1050. if sysUser == nil {
  1051. br.Msg = "请登录"
  1052. br.ErrMsg = "请登录,SysUser Is Empty"
  1053. br.Ret = 408
  1054. return
  1055. }
  1056. var req models.CygxYanxuanSpecialCheckReq
  1057. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1058. if err != nil {
  1059. br.Msg = "参数解析异常!"
  1060. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1061. return
  1062. }
  1063. if req.Content == "" {
  1064. br.Ret = 200
  1065. br.Success = true
  1066. br.Msg = "校验成功"
  1067. }
  1068. itemToken, err := services.WxGetToken()
  1069. if err != nil {
  1070. br.Msg = "GetWxAccessToken Err:" + err.Error()
  1071. return
  1072. }
  1073. if itemToken.AccessToken == "" {
  1074. br.Msg = "accessToken is empty"
  1075. return
  1076. }
  1077. suggest := models.WxCheckContent(itemToken.AccessToken, sysUser.OpenId, req.Content)
  1078. if suggest == "risky" {
  1079. br.Msg = "文章内容含有违法违规内容"
  1080. br.ErrMsg = "文章内容含有违法违规内容"
  1081. return
  1082. }
  1083. if len(req.ImgUrl) > 0 {
  1084. //for _, imgUrl := range req.ImgUrl {
  1085. // imgBody, err := http.Get(imgUrl)
  1086. // if err != nil {
  1087. // br.Msg = "图片链接有误"
  1088. // br.ErrMsg = "图片链接有误"
  1089. // return
  1090. // }
  1091. // rnStr := utils.GetRandStringNoSpecialChar(5)
  1092. // savePath := time.Now().Format(utils.FormatDateTimeUnSpace) + rnStr + ".jpg"
  1093. // err = file.SaveFile(imgBody, savePath)
  1094. // if err != nil {
  1095. // br.Msg = "保存图片错误"
  1096. // br.ErrMsg = "保存图片错误"
  1097. // return
  1098. // }
  1099. // res, err := weapp.IMGSecCheck(itemToken.AccessToken, savePath)
  1100. // if err != nil {
  1101. // // 处理一般错误信息
  1102. // br.Msg = "图片内容含有违法违规内容"
  1103. // br.ErrMsg = "图片内容含有违法违规内容"
  1104. // return
  1105. // }
  1106. // if err := res.GetResponseError(); err != nil {
  1107. // // 处理微信返回错误信息
  1108. // br.Msg = "GetResponseError Err:" + err.Error()
  1109. // return
  1110. // }
  1111. // err = os.RemoveAll(savePath)
  1112. // if err != nil {
  1113. // br.Msg = "RemoveAll Err:" + err.Error()
  1114. // return
  1115. // }
  1116. //}
  1117. }
  1118. br.Ret = 200
  1119. br.Success = true
  1120. br.Msg = "校验成功"
  1121. }