yanxuan_special.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "hongze/hz_crm_api/controllers"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/cygx"
  7. cygxService "hongze/hz_crm_api/services/cygx"
  8. "hongze/hz_crm_api/services/elastic"
  9. "hongze/hz_crm_api/utils"
  10. "strconv"
  11. "time"
  12. )
  13. // YanxuanSpecialController 研选专栏
  14. type YanxuanSpecialController struct {
  15. controllers.BaseAuthController
  16. }
  17. // @Title 新增研选专栏作者
  18. // @Description 新增研选专栏作者
  19. // @Param request body help_doc.AddHelpDocReq true "type json string"
  20. // @Success 200 {object} models.AddEnglishReportResp
  21. // @router /yanxuan_special/author/add [post]
  22. func (this *YanxuanSpecialController) Add() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. sysUser := this.SysUser
  29. if sysUser == nil {
  30. br.Msg = "请登录"
  31. br.ErrMsg = "请登录,SysUser Is Empty"
  32. br.Ret = 408
  33. return
  34. }
  35. var req cygx.AddCygxYanxuanSpecialAuthorReq
  36. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  37. if err != nil {
  38. br.Msg = "参数解析异常!"
  39. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  40. return
  41. }
  42. if req.UserId <= 0 {
  43. br.Msg = "请输入用户信息"
  44. return
  45. }
  46. if req.RealName == "" {
  47. br.Msg = "请输入真实姓名"
  48. return
  49. }
  50. if req.Mobile == "" {
  51. br.Msg = "请输入手机号"
  52. return
  53. }
  54. rnd := utils.GetRandInt(1, 5)
  55. item := cygx.CygxYanxuanSpecialAuthor{
  56. UserId: req.UserId,
  57. RealName: req.RealName,
  58. Mobile: req.Mobile,
  59. CreateTime: time.Now(),
  60. ModifyTime: time.Now(),
  61. HeadImg: utils.CYGX_YANXUAN_SPECIAL_HEAD_IMG_URL + strconv.Itoa(rnd) + ".png",
  62. BgImg: utils.CYGX_YANXUAN_SPECIAL_BG_IMG_URL + strconv.Itoa(rnd) + "a.png",
  63. BgImgDown: utils.CYGX_YANXUAN_SPECIAL_BG_IMG_URL + strconv.Itoa(rnd) + "b.png",
  64. BgImgPc: utils.CYGX_YANXUAN_SPECIAL_BG_IMG_URL_PC + strconv.Itoa(rnd) + ".png",
  65. Status: 1,
  66. }
  67. _, err = cygx.AddCygxYanxuanSpecialAuthor(&item)
  68. if err != nil {
  69. br.Msg = "新增失败"
  70. br.ErrMsg = "新增失败,Err:" + err.Error()
  71. return
  72. }
  73. br.Ret = 200
  74. br.Success = true
  75. br.Msg = "新增成功"
  76. }
  77. // @Title 禁用/启用研选专栏作者
  78. // @Description 禁用/启用研选专栏作者
  79. // @Param request body help_doc.AddHelpDocReq true "type json string"
  80. // @Success 200 {object} models.AddEnglishReportResp
  81. // @router /yanxuan_special/author/enable [post]
  82. func (this *YanxuanSpecialController) AuthorEnable() {
  83. br := new(models.BaseResponse).Init()
  84. defer func() {
  85. this.Data["json"] = br
  86. this.ServeJSON()
  87. }()
  88. sysUser := this.SysUser
  89. if sysUser == nil {
  90. br.Msg = "请登录"
  91. br.ErrMsg = "请登录,SysUser Is Empty"
  92. br.Ret = 408
  93. return
  94. }
  95. var req cygx.EnableCygxYanxuanSpecialAuthorReq
  96. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  97. if err != nil {
  98. br.Msg = "参数解析异常!"
  99. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  100. return
  101. }
  102. if req.UserId <= 0 {
  103. br.Msg = "用户id错误"
  104. return
  105. }
  106. if req.Status <= 0 {
  107. br.Msg = "参数错误"
  108. return
  109. }
  110. if tmpErr := cygx.EnableYanxuanSpecialAuthor(req.UserId, req.Status); tmpErr != nil {
  111. br.Msg = "启用/禁用作者失败"
  112. br.ErrMsg = "启用/禁用作者失败, Err:" + tmpErr.Error()
  113. return
  114. }
  115. if req.Status == 1 {
  116. br.Msg = "启用成功"
  117. } else {
  118. br.Msg = "禁用成功"
  119. }
  120. br.Ret = 200
  121. br.Success = true
  122. }
  123. // @Title 作者列表
  124. // @Description 作者列表
  125. // @Param request body help_doc.AddHelpDocReq true "type json string"
  126. // @Success 200 {object} models.AddEnglishReportResp
  127. // @router /yanxuan_special/author/list [get]
  128. func (this *YanxuanSpecialController) AuthorList() {
  129. br := new(models.BaseResponse).Init()
  130. defer func() {
  131. this.Data["json"] = br
  132. this.ServeJSON()
  133. }()
  134. sysUser := this.SysUser
  135. if sysUser == nil {
  136. br.Msg = "请登录"
  137. br.ErrMsg = "请登录,SysUser Is Empty"
  138. br.Ret = 408
  139. return
  140. }
  141. list, tmpErr := cygx.GetYanxuanSpecialAuthorList()
  142. if tmpErr != nil {
  143. br.Msg = "获取失败"
  144. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  145. return
  146. }
  147. br.Data = list
  148. br.Ret = 200
  149. br.Success = true
  150. br.Msg = "获取成功"
  151. }
  152. // @Title 审核列表
  153. // @Description 审核列表
  154. // @Param request body help_doc.AddHelpDocReq true "type json string"
  155. // @Success 200 {object} models.AddEnglishReportResp
  156. // @router /yanxuan_special/list [get]
  157. func (this *YanxuanSpecialController) List() {
  158. br := new(models.BaseResponse).Init()
  159. defer func() {
  160. this.Data["json"] = br
  161. this.ServeJSON()
  162. }()
  163. sysUser := this.SysUser
  164. if sysUser == nil {
  165. br.Msg = "请登录"
  166. br.ErrMsg = "请登录,SysUser Is Empty"
  167. br.Ret = 408
  168. return
  169. }
  170. userId, _ := this.GetInt("UserId", 0)
  171. var condition string
  172. var pars []interface{}
  173. if userId > 0 {
  174. condition += ` AND a.user_id = ? `
  175. pars = append(pars, userId)
  176. }
  177. condition += ` AND a.status = 2 `
  178. list, tmpErr := cygx.GetYanxuanSpecialList(condition, pars)
  179. if tmpErr != nil {
  180. br.Msg = "获取失败"
  181. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  182. return
  183. }
  184. for _, v := range list {
  185. hasImg, err := utils.ArticleHasImgUrl(v.Content)
  186. if err != nil {
  187. return
  188. }
  189. if hasImg {
  190. v.ContentHasImg = 1
  191. }
  192. if v.DocUrl != "" {
  193. var docs []cygx.Doc
  194. err := json.Unmarshal([]byte(v.DocUrl), &docs)
  195. if err != nil {
  196. br.Msg = "参数解析异常!"
  197. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  198. return
  199. }
  200. v.Docs = docs
  201. }
  202. if v.Type == 1 {
  203. v.Title = "【笔记】" + v.Title
  204. } else if v.Type == 2 {
  205. v.Title = "【观点】" + v.Title
  206. }
  207. if v.CompanyTags != "" {
  208. v.Tags += v.CompanyTags
  209. }
  210. if v.IndustryTags != "" {
  211. if v.Tags != "" {
  212. v.Tags += ","
  213. }
  214. v.Tags += v.IndustryTags
  215. }
  216. }
  217. br.Data = list
  218. br.Ret = 200
  219. br.Success = true
  220. br.Msg = "获取成功"
  221. }
  222. // @Title 审批研选专栏
  223. // @Description 审批研选专栏
  224. // @Param request body help_doc.AddHelpDocReq true "type json string"
  225. // @Success 200 {object} models.AddEnglishReportResp
  226. // @router /yanxuan_special/enable [post]
  227. func (this *YanxuanSpecialController) Enable() {
  228. br := new(models.BaseResponse).Init()
  229. defer func() {
  230. this.Data["json"] = br
  231. this.ServeJSON()
  232. }()
  233. sysUser := this.SysUser
  234. if sysUser == nil {
  235. br.Msg = "请登录"
  236. br.ErrMsg = "请登录,SysUser Is Empty"
  237. br.Ret = 408
  238. return
  239. }
  240. var req cygx.EnableCygxYanxuanSpecialReq
  241. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  242. if err != nil {
  243. br.Msg = "参数解析异常!"
  244. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  245. return
  246. }
  247. if req.Id <= 0 {
  248. br.Msg = "文章id错误"
  249. return
  250. }
  251. if req.Status <= 0 {
  252. br.Msg = "参数错误"
  253. return
  254. }
  255. status := 0
  256. if req.Status == 1 {
  257. status = 3
  258. } else {
  259. status = 4
  260. }
  261. if tmpErr := cygx.EnableYanxuanSpecial(req.Id, status, req.Reason); tmpErr != nil {
  262. br.Msg = "审批失败"
  263. br.ErrMsg = "审批失败, Err:" + tmpErr.Error()
  264. return
  265. }
  266. if req.Status == 1 {
  267. go cygxService.SendWxMsgSpecialFollow(req.Id)
  268. }
  269. go cygxService.SendWxMsgSpecialAuthor(req.Id, req.Status) // 研选专栏审核完成时,给提交人发送模板消息
  270. go cygxService.UpdateYanxuanSpecialResourceData(req.Id) // 写入首页最新 cygx_resource_data 表
  271. go elastic.EsAddYanxuanSpecial(req.Id) // 写入es 综合搜索
  272. br.Msg = "审批成功"
  273. br.Ret = 200
  274. br.Success = true
  275. }