yanxuan_special.go 6.4 KB

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