yanxuan_special.go 32 KB

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