yanxuan_special.go 28 KB

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