yanxuan_special.go 5.7 KB

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