yanxuan_special.go 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  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. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  569. if err != nil {
  570. br.Msg = "报名失败!"
  571. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  572. return
  573. }
  574. sellerName = sellerItem.RealName
  575. item := models.CygxYanxuanSpecialCollect{
  576. UserId: user.UserId,
  577. Mobile: user.Mobile,
  578. Email: user.Email,
  579. CompanyId: user.CompanyId,
  580. CompanyName: user.CompanyName,
  581. RealName: user.RealName,
  582. SellerName: sellerName,
  583. CreateTime: time.Now(),
  584. ModifyTime: time.Now(),
  585. RegisterPlatform: utils.REGISTER_PLATFORM,
  586. YanxuanSpecialId: req.Id,
  587. }
  588. _, err = models.AddCygxYanxuanSpecialCollect(&item)
  589. if err != nil {
  590. br.Msg = "新增失败"
  591. br.ErrMsg = "新增失败,Err:" + err.Error()
  592. return
  593. }
  594. br.Msg = "收藏成功"
  595. } else {
  596. err = models.DelCygxYanxuanSpecialCollect(user.UserId, req.Id)
  597. if err != nil {
  598. br.Msg = "删除失败"
  599. br.ErrMsg = "删除失败,Err:" + err.Error()
  600. return
  601. }
  602. br.Msg = "取消收藏成功"
  603. }
  604. go services.UdpateYanxuanSpecialCollect(req.Id)
  605. br.Ret = 200
  606. br.Success = true
  607. }
  608. // @Title 专栏内容中心
  609. // @Description 专栏内容中心
  610. // @Param request body help_doc.AddHelpDocReq true "type json string"
  611. // @Success 200 {object} models.AddEnglishReportResp
  612. // @router /center [get]
  613. func (this *YanxuanSpecialController) Center() {
  614. br := new(models.BaseResponse).Init()
  615. defer func() {
  616. this.Data["json"] = br
  617. this.ServeJSON()
  618. }()
  619. sysUser := this.User
  620. if sysUser == nil {
  621. br.Msg = "请登录"
  622. br.ErrMsg = "请登录,SysUser Is Empty"
  623. br.Ret = 408
  624. return
  625. }
  626. // 1:未发布,2:审核中 3:已发布 4:驳回
  627. status, _ := this.GetInt("Status", 0)
  628. if status <= 0 {
  629. br.Msg = "参数错误"
  630. br.ErrMsg = "参数错误"
  631. return
  632. }
  633. var condition string
  634. var pars []interface{}
  635. condition += ` AND a.user_id = ? `
  636. pars = append(pars, sysUser.UserId)
  637. condition += ` AND a.status = ? `
  638. pars = append(pars, status)
  639. list, tmpErr := models.GetYanxuanSpecialList(sysUser.UserId, condition, pars, 0, 0)
  640. if tmpErr != nil {
  641. br.Msg = "获取失败"
  642. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  643. return
  644. }
  645. br.Data = list
  646. br.Ret = 200
  647. br.Success = true
  648. br.Msg = "获取成功"
  649. }
  650. // @Title 专栏点击记录
  651. // @Description 专栏点击记录
  652. // @Param request body models.AddCygxReportSelectionSubjectHistoryReq true "type json string"
  653. // @router /record [post]
  654. func (this *YanxuanSpecialController) Record() {
  655. br := new(models.BaseResponse).Init()
  656. defer func() {
  657. this.Data["json"] = br
  658. this.ServeJSON()
  659. }()
  660. user := this.User
  661. if user == nil {
  662. br.Msg = "请重新登录"
  663. br.Ret = 408
  664. return
  665. }
  666. var req models.AddCygxYanxuanSpecialRecordReq
  667. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  668. if err != nil {
  669. br.Msg = "参数解析异常!"
  670. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  671. return
  672. }
  673. if req.SpecialId <= 0 {
  674. br.Msg = "文章不存在"
  675. br.ErrMsg = "文章不存在,文章ID错误"
  676. return
  677. }
  678. specialId := req.SpecialId
  679. stopTime := req.StopTime
  680. if req.SpecialId <= 0 {
  681. br.Msg = "文章不存在"
  682. br.ErrMsg = "文章不存在,文章ID错误"
  683. return
  684. }
  685. err = services.AddSpecialRecord(this.User, specialId, stopTime)
  686. if err != nil {
  687. br.Msg = "记录失败"
  688. br.ErrMsg = "记录失败,Err:" + err.Error()
  689. return
  690. }
  691. br.Ret = 200
  692. br.Success = true
  693. br.Msg = "记录成功"
  694. }
  695. // @Title 研选专栏关注
  696. // @Description 研选专栏关注
  697. // @Param request body help_doc.AddHelpDocReq true "type json string"
  698. // @Success 200 {object} models.AddEnglishReportResp
  699. // @router /follow [post]
  700. func (this *YanxuanSpecialController) Follow() {
  701. br := new(models.BaseResponse).Init()
  702. defer func() {
  703. this.Data["json"] = br
  704. this.ServeJSON()
  705. }()
  706. user := this.User
  707. if user == nil {
  708. br.Msg = "请登录"
  709. br.ErrMsg = "请登录,SysUser Is Empty"
  710. br.Ret = 408
  711. return
  712. }
  713. var req models.FollowCygxYanxuanSpecialReq
  714. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  715. if err != nil {
  716. br.Msg = "参数解析异常!"
  717. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  718. return
  719. }
  720. if req.FollowSpecialColumnId <= 0 {
  721. br.Msg = "被关注的专栏栏目id错误"
  722. return
  723. }
  724. if req.Status <= 0 {
  725. br.Msg = "参数错误"
  726. return
  727. }
  728. var sellerName string
  729. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  730. if err != nil {
  731. br.Msg = "查询栏目详情失败!"
  732. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  733. return
  734. }
  735. sellerName = sellerItemQy.RealName
  736. authorItem, err := models.GetYanxuanSpecialAuthorById(req.FollowSpecialColumnId)
  737. if err != nil {
  738. br.Msg = "查询栏目详情失败!"
  739. br.ErrMsg = "查询栏目详情失败,Err:" + err.Error()
  740. return
  741. }
  742. if req.Status == 1 {
  743. item := models.CygxYanxuanSpecialFollow{
  744. UserId: user.UserId,
  745. FollowUserId: authorItem.UserId,
  746. Mobile: user.Mobile,
  747. Email: user.Email,
  748. CompanyId: user.CompanyId,
  749. CompanyName: user.CompanyName,
  750. RealName: user.RealName,
  751. SellerName: sellerName,
  752. CreateTime: time.Now(),
  753. ModifyTime: time.Now(),
  754. RegisterPlatform: utils.REGISTER_PLATFORM,
  755. YanxuanSpecialId: req.SpecialId,
  756. }
  757. err = models.AddCygxYanxuanSpecialFollow(&item)
  758. if err != nil {
  759. br.Msg = "新增失败"
  760. br.ErrMsg = "新增失败,Err:" + err.Error()
  761. return
  762. }
  763. br.Msg = "关注成功"
  764. } else {
  765. err = models.DelCygxYanxuanSpecialFollow(user.UserId, authorItem.UserId)
  766. if err != nil {
  767. br.Msg = "删除失败"
  768. br.ErrMsg = "删除失败,Err:" + err.Error()
  769. return
  770. }
  771. br.Msg = "取消关注成功"
  772. }
  773. go services.UdpateYanxuanSpecialFansNum(authorItem.UserId)
  774. br.Ret = 200
  775. br.Success = true
  776. }
  777. // @Title 行业标签搜索
  778. // @Description 行业标签搜索
  779. // @Param request body help_doc.AddHelpDocReq true "type json string"
  780. // @Success 200 {object} models.AddEnglishReportResp
  781. // @router /industrySearch [get]
  782. func (this *YanxuanSpecialController) IndustrySearch() {
  783. br := new(models.BaseResponse).Init()
  784. defer func() {
  785. this.Data["json"] = br
  786. this.ServeJSON()
  787. }()
  788. sysUser := this.User
  789. if sysUser == nil {
  790. br.Msg = "请登录"
  791. br.ErrMsg = "请登录,SysUser Is Empty"
  792. br.Ret = 408
  793. return
  794. }
  795. keyword := this.GetString("Keyword")
  796. list, tmpErr := models.GetYanxuanSpecialIndustry(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 /companySearch [get]
  812. func (this *YanxuanSpecialController) CompanySearch() {
  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. keyword := this.GetString("Keyword")
  826. if keyword == "" {
  827. br.Ret = 200
  828. return
  829. }
  830. list, tmpErr := models.GetYanxuanSpecialCompany(keyword)
  831. if tmpErr != nil {
  832. br.Msg = "获取失败"
  833. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  834. return
  835. }
  836. br.Data = list
  837. br.Ret = 200
  838. br.Success = true
  839. br.Msg = "获取成功"
  840. }
  841. // @Title 专栏取消发布
  842. // @Description 专栏取消发布
  843. // @Param request body help_doc.AddHelpDocReq true "type json string"
  844. // @Success 200 {object} models.AddEnglishReportResp
  845. // @router /cancel [post]
  846. func (this *YanxuanSpecialController) Cancel() {
  847. br := new(models.BaseResponse).Init()
  848. defer func() {
  849. this.Data["json"] = br
  850. this.ServeJSON()
  851. }()
  852. sysUser := this.User
  853. if sysUser == nil {
  854. br.Msg = "请登录"
  855. br.ErrMsg = "请登录,SysUser Is Empty"
  856. br.Ret = 408
  857. return
  858. }
  859. var req models.CancelPublishCygxYanxuanSpecialReq
  860. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  861. if err != nil {
  862. br.Msg = "参数解析异常!"
  863. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  864. return
  865. }
  866. if req.Id <= 0 {
  867. br.Msg = "文章id错误"
  868. return
  869. }
  870. specialItem, err := models.GetYanxuanSpecialItemById(req.Id)
  871. if err != nil {
  872. br.Msg = "专栏取消发布失败"
  873. br.ErrMsg = "专栏取消发布失败,Err:" + err.Error()
  874. return
  875. }
  876. if tmpErr := models.CancelPublishYanxuanSpecial(req.Id); tmpErr != nil {
  877. br.Msg = "取消发布失败"
  878. br.ErrMsg = "取消发布失败, Err:" + tmpErr.Error()
  879. return
  880. }
  881. go services.UpdateYanxuanSpecialResourceData(req.Id) // 写入首页最新 cygx_resource_data 表
  882. go services.EsAddYanxuanSpecial(req.Id) // 写入es 综合搜索
  883. go services.UdpateYanxuanSpecialauthorArticleNum(specialItem.UserId) // 更新作者发布文章的数量
  884. br.Msg = "取消发布成功"
  885. br.Ret = 200
  886. br.Success = true
  887. }
  888. // @Title 作者列表
  889. // @Description 作者列表
  890. // @Param PageSize query int true "每页数据条数"
  891. // @Param CurrentIndex query int true "当前页页码,从1开始"
  892. // @Success 200 {object} models.AddEnglishReportResp
  893. // @router /author/list [get]
  894. func (this *YanxuanSpecialNoLoginController) AuthorList() {
  895. br := new(models.BaseResponse).Init()
  896. defer func() {
  897. this.Data["json"] = br
  898. this.ServeJSON()
  899. }()
  900. sysUser := this.User
  901. if sysUser == nil {
  902. br.Msg = "请登录"
  903. br.ErrMsg = "请登录,SysUser Is Empty"
  904. br.Ret = 408
  905. return
  906. }
  907. pageSize, _ := this.GetInt("PageSize")
  908. currentIndex, _ := this.GetInt("CurrentIndex")
  909. var startSize int
  910. if pageSize <= 0 {
  911. pageSize = utils.PageSize20
  912. }
  913. if currentIndex <= 0 {
  914. currentIndex = 1
  915. }
  916. startSize = utils.StartIndex(currentIndex, pageSize)
  917. resp := new(models.SpecialAuthorListResp)
  918. specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
  919. resp.IsAuthor = specialAuthorCheck.IsAuthor
  920. resp.IsImproveInformation = specialAuthorCheck.IsImproveInformation
  921. resp.SpecialColumnId = specialAuthorCheck.SpecialColumnId
  922. resp.HeadImg = specialAuthorCheck.HeadImg
  923. var condition string
  924. var conditionUserSort string
  925. var pars []interface{}
  926. condition += ` AND a.nick_name <> '' `
  927. conditionUserSort += ` ( IF ( a.user_id = ` + strconv.Itoa(sysUser.UserId) + `, 1 = 1, user_id = 1 ) ) AS user_sort , ` // 用户本人如果开通了专栏,就放在最前面
  928. total, err := models.GetCygxYanxuanSpecialAuthorCount(condition, pars)
  929. if err != nil {
  930. br.Msg = "获取失败"
  931. br.ErrMsg = "获取失败,Err:" + err.Error()
  932. return
  933. }
  934. condition += ` ORDER BY user_sort DESC, latest_publish_time DESC`
  935. list, tmpErr := models.GetYanxuanSpecialAuthorList(conditionUserSort, condition, pars, startSize, pageSize)
  936. if tmpErr != nil {
  937. br.Msg = "获取失败"
  938. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  939. return
  940. }
  941. //var userIds []int
  942. for _, v := range list {
  943. v.LatestPublishDate = v.LatestPublishTime.Format(utils.FormatDate) + "更新"
  944. //userIds = append(userIds, v.UserId)
  945. }
  946. page := paging.GetPaging(currentIndex, pageSize, total)
  947. resp.List = list
  948. resp.Paging = page
  949. br.Data = resp
  950. br.Ret = 200
  951. br.Success = true
  952. br.Msg = "获取成功"
  953. }
  954. // @Title 更新作者头像
  955. // @Description 更新作者头像
  956. // @Param request body help_doc.AddHelpDocReq true "type json string"
  957. // @Success 200 {object} models.AddEnglishReportResp
  958. // @router /author/head_img [post]
  959. func (this *YanxuanSpecialController) AuthorHeadImg() {
  960. br := new(models.BaseResponse).Init()
  961. defer func() {
  962. this.Data["json"] = br
  963. this.ServeJSON()
  964. }()
  965. sysUser := this.User
  966. if sysUser == nil {
  967. br.Msg = "请登录"
  968. br.ErrMsg = "请登录,SysUser Is Empty"
  969. br.Ret = 408
  970. return
  971. }
  972. var req models.SaveCygxYanxuanSpecialAuthoHeadImgrReq
  973. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  974. if err != nil {
  975. br.Msg = "参数解析异常!"
  976. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  977. return
  978. }
  979. if req.SpecialColumnId <= 0 {
  980. br.Msg = "专栏栏目id错误"
  981. return
  982. }
  983. if req.HeadImg == "" {
  984. br.Msg = "头像图片错误"
  985. return
  986. }
  987. item := models.CygxYanxuanSpecialAuthor{
  988. Id: req.SpecialColumnId,
  989. HeadImg: req.HeadImg,
  990. }
  991. err = models.UpdateYanxuanSpecialAuthorHeadImg(&item)
  992. if err != nil {
  993. br.Msg = "保存失败"
  994. br.ErrMsg = "保存失败,Err:" + err.Error()
  995. return
  996. }
  997. br.Ret = 200
  998. br.Success = true
  999. br.Msg = "保存成功"
  1000. }
  1001. // @Title 删除专栏
  1002. // @Description 删除专栏
  1003. // @Param request body help_doc.AddHelpDocReq true "type json string"
  1004. // @Success 200 {object} models.AddEnglishReportResp
  1005. // @router /del [post]
  1006. func (this *YanxuanSpecialController) Delete() {
  1007. br := new(models.BaseResponse).Init()
  1008. defer func() {
  1009. this.Data["json"] = br
  1010. this.ServeJSON()
  1011. }()
  1012. sysUser := this.User
  1013. if sysUser == nil {
  1014. br.Msg = "请登录"
  1015. br.ErrMsg = "请登录,SysUser Is Empty"
  1016. br.Ret = 408
  1017. return
  1018. }
  1019. var req models.DelCygxYanxuanSpecialReq
  1020. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1021. if err != nil {
  1022. br.Msg = "参数解析异常!"
  1023. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1024. return
  1025. }
  1026. if req.Id <= 0 {
  1027. br.Msg = "文章id错误"
  1028. return
  1029. }
  1030. if tmpErr := models.DelYanxuanSpecial(req.Id); tmpErr != nil {
  1031. br.Msg = "删除失败"
  1032. br.ErrMsg = "删除失败, Err:" + tmpErr.Error()
  1033. return
  1034. }
  1035. br.Msg = "删除成功"
  1036. br.Ret = 200
  1037. br.Success = true
  1038. }
  1039. // @Title 专栏文章敏感词检测
  1040. // @Description 专栏文章敏感词检测
  1041. // @Param request body help_doc.AddHelpDocReq true "type json string"
  1042. // @Success 200 {object} models.AddEnglishReportResp
  1043. // @router /check [post]
  1044. func (this *YanxuanSpecialController) Check() {
  1045. br := new(models.BaseResponse).Init()
  1046. defer func() {
  1047. this.Data["json"] = br
  1048. this.ServeJSON()
  1049. }()
  1050. sysUser := this.User
  1051. if sysUser == nil {
  1052. br.Msg = "请登录"
  1053. br.ErrMsg = "请登录,SysUser Is Empty"
  1054. br.Ret = 408
  1055. return
  1056. }
  1057. var req models.CygxYanxuanSpecialCheckReq
  1058. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1059. if err != nil {
  1060. br.Msg = "参数解析异常!"
  1061. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1062. return
  1063. }
  1064. if req.Content == "" {
  1065. br.Ret = 200
  1066. br.Success = true
  1067. br.Msg = "校验成功"
  1068. }
  1069. itemToken, err := services.WxGetToken()
  1070. if err != nil {
  1071. br.Msg = "GetWxAccessToken Err:" + err.Error()
  1072. return
  1073. }
  1074. if itemToken.AccessToken == "" {
  1075. br.Msg = "accessToken is empty"
  1076. return
  1077. }
  1078. suggest := models.WxCheckContent(itemToken.AccessToken, sysUser.OpenId, req.Content)
  1079. if suggest == "risky" {
  1080. br.Msg = "文章内容含有违法违规内容"
  1081. br.ErrMsg = "文章内容含有违法违规内容"
  1082. return
  1083. }
  1084. if len(req.ImgUrl) > 0 {
  1085. //for _, imgUrl := range req.ImgUrl {
  1086. // imgBody, err := http.Get(imgUrl)
  1087. // if err != nil {
  1088. // br.Msg = "图片链接有误"
  1089. // br.ErrMsg = "图片链接有误"
  1090. // return
  1091. // }
  1092. // rnStr := utils.GetRandStringNoSpecialChar(5)
  1093. // savePath := time.Now().Format(utils.FormatDateTimeUnSpace) + rnStr + ".jpg"
  1094. // err = file.SaveFile(imgBody, savePath)
  1095. // if err != nil {
  1096. // br.Msg = "保存图片错误"
  1097. // br.ErrMsg = "保存图片错误"
  1098. // return
  1099. // }
  1100. // res, err := weapp.IMGSecCheck(itemToken.AccessToken, savePath)
  1101. // if err != nil {
  1102. // // 处理一般错误信息
  1103. // br.Msg = "图片内容含有违法违规内容"
  1104. // br.ErrMsg = "图片内容含有违法违规内容"
  1105. // return
  1106. // }
  1107. // if err := res.GetResponseError(); err != nil {
  1108. // // 处理微信返回错误信息
  1109. // br.Msg = "GetResponseError Err:" + err.Error()
  1110. // return
  1111. // }
  1112. // err = os.RemoveAll(savePath)
  1113. // if err != nil {
  1114. // br.Msg = "RemoveAll Err:" + err.Error()
  1115. // return
  1116. // }
  1117. //}
  1118. }
  1119. br.Ret = 200
  1120. br.Success = true
  1121. br.Msg = "校验成功"
  1122. }