yanxuan_special.go 32 KB

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