yanxuan_special.go 30 KB

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