yanxuan_special.go 6.5 KB

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