ManagerController.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "html/template"
  5. "regexp"
  6. "strings"
  7. "math"
  8. "path/filepath"
  9. "strconv"
  10. "github.com/astaxie/beego"
  11. "github.com/astaxie/beego/logs"
  12. "github.com/astaxie/beego/orm"
  13. "github.com/lifei6671/mindoc/conf"
  14. "github.com/lifei6671/mindoc/models"
  15. "github.com/lifei6671/mindoc/utils"
  16. "github.com/lifei6671/mindoc/utils/filetil"
  17. "github.com/lifei6671/mindoc/utils/pagination"
  18. "gopkg.in/russross/blackfriday.v2"
  19. )
  20. type ManagerController struct {
  21. BaseController
  22. }
  23. func (c *ManagerController) Prepare() {
  24. c.BaseController.Prepare()
  25. if !c.Member.IsAdministrator() {
  26. c.Abort("403")
  27. }
  28. }
  29. func (c *ManagerController) Index() {
  30. c.TplName = "manager/index.tpl"
  31. c.Data["Model"] = models.NewDashboard().Query()
  32. }
  33. // 用户列表.
  34. func (c *ManagerController) Users() {
  35. c.Prepare()
  36. c.TplName = "manager/users.tpl"
  37. pageIndex, _ := c.GetInt("page", 0)
  38. members, totalCount, err := models.NewMember().FindToPager(pageIndex, conf.PageSize)
  39. if err != nil {
  40. c.Data["ErrorMessage"] = err.Error()
  41. return
  42. }
  43. if totalCount > 0 {
  44. pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
  45. c.Data["PageHtml"] = pager.HtmlPages()
  46. for _,item := range members {
  47. item.Avatar = conf.URLForWithCdnImage(item.Avatar)
  48. }
  49. } else {
  50. c.Data["PageHtml"] = ""
  51. }
  52. b, err := json.Marshal(members)
  53. if err != nil {
  54. c.Data["Result"] = template.JS("[]")
  55. } else {
  56. c.Data["Result"] = template.JS(string(b))
  57. }
  58. }
  59. // 添加用户.
  60. func (c *ManagerController) CreateMember() {
  61. c.Prepare()
  62. account := strings.TrimSpace(c.GetString("account"))
  63. password1 := strings.TrimSpace(c.GetString("password1"))
  64. password2 := strings.TrimSpace(c.GetString("password2"))
  65. email := strings.TrimSpace(c.GetString("email"))
  66. phone := strings.TrimSpace(c.GetString("phone"))
  67. role, _ := c.GetInt("role", 1)
  68. status, _ := c.GetInt("status", 0)
  69. if ok, err := regexp.MatchString(conf.RegexpAccount, account); account == "" || !ok || err != nil {
  70. c.JsonResult(6001, "账号只能由英文字母数字组成,且在3-50个字符")
  71. }
  72. if l := strings.Count(password1, ""); password1 == "" || l > 50 || l < 6 {
  73. c.JsonResult(6002, "密码必须在6-50个字符之间")
  74. }
  75. if password1 != password2 {
  76. c.JsonResult(6003, "确认密码不正确")
  77. }
  78. if ok, err := regexp.MatchString(conf.RegexpEmail, email); !ok || err != nil || email == "" {
  79. c.JsonResult(6004, "邮箱格式不正确")
  80. }
  81. if role != 0 && role != 1 && role != 2 {
  82. role = 1
  83. }
  84. if status != 0 && status != 1 {
  85. status = 0
  86. }
  87. member := models.NewMember()
  88. if _, err := member.FindByAccount(account); err == nil && member.MemberId > 0 {
  89. c.JsonResult(6005, "账号已存在")
  90. }
  91. member.Account = account
  92. member.Password = password1
  93. member.Role = role
  94. member.Avatar = conf.GetDefaultAvatar()
  95. member.CreateAt = c.Member.MemberId
  96. member.Email = email
  97. member.RealName = strings.TrimSpace(c.GetString("real_name", ""))
  98. if phone != "" {
  99. member.Phone = phone
  100. }
  101. if err := member.Add(); err != nil {
  102. c.JsonResult(6006, err.Error())
  103. }
  104. c.JsonResult(0, "ok", member)
  105. }
  106. //更新用户状态.
  107. func (c *ManagerController) UpdateMemberStatus() {
  108. c.Prepare()
  109. member_id, _ := c.GetInt("member_id", 0)
  110. status, _ := c.GetInt("status", 0)
  111. if member_id <= 0 {
  112. c.JsonResult(6001, "参数错误")
  113. }
  114. if status != 0 && status != 1 {
  115. status = 0
  116. }
  117. member := models.NewMember()
  118. if _, err := member.Find(member_id); err != nil {
  119. c.JsonResult(6002, "用户不存在")
  120. }
  121. if member.MemberId == c.Member.MemberId {
  122. c.JsonResult(6004, "不能变更自己的状态")
  123. }
  124. if member.Role == conf.MemberSuperRole {
  125. c.JsonResult(6005, "不能变更超级管理员的状态")
  126. }
  127. member.Status = status
  128. if err := member.Update(); err != nil {
  129. logs.Error("", err)
  130. c.JsonResult(6003, "用户状态设置失败")
  131. }
  132. c.JsonResult(0, "ok", member)
  133. }
  134. //变更用户权限.
  135. func (c *ManagerController) ChangeMemberRole() {
  136. c.Prepare()
  137. member_id, _ := c.GetInt("member_id", 0)
  138. role, _ := c.GetInt("role", 0)
  139. if member_id <= 0 {
  140. c.JsonResult(6001, "参数错误")
  141. }
  142. if role != conf.MemberAdminRole && role != conf.MemberGeneralRole {
  143. c.JsonResult(6001, "用户权限不正确")
  144. }
  145. member := models.NewMember()
  146. if _, err := member.Find(member_id); err != nil {
  147. c.JsonResult(6002, "用户不存在")
  148. }
  149. if member.MemberId == c.Member.MemberId {
  150. c.JsonResult(6004, "不能变更自己的权限")
  151. }
  152. if member.Role == conf.MemberSuperRole {
  153. c.JsonResult(6005, "不能变更超级管理员的权限")
  154. }
  155. member.Role = role
  156. if err := member.Update(); err != nil {
  157. c.JsonResult(6003, "用户权限设置失败")
  158. }
  159. member.ResolveRoleName()
  160. c.JsonResult(0, "ok", member)
  161. }
  162. //编辑用户信息.
  163. func (c *ManagerController) EditMember() {
  164. c.Prepare()
  165. c.TplName = "manager/edit_users.tpl"
  166. member_id, _ := c.GetInt(":id", 0)
  167. if member_id <= 0 {
  168. c.Abort("404")
  169. }
  170. member, err := models.NewMember().Find(member_id)
  171. if err != nil {
  172. beego.Error(err)
  173. c.Abort("404")
  174. }
  175. if c.Ctx.Input.IsPost() {
  176. password1 := c.GetString("password1")
  177. password2 := c.GetString("password2")
  178. email := c.GetString("email")
  179. phone := c.GetString("phone")
  180. description := c.GetString("description")
  181. member.Email = email
  182. member.Phone = phone
  183. member.Description = description
  184. member.RealName = c.GetString("real_name")
  185. if password1 != "" && password2 != password1 {
  186. c.JsonResult(6001, "确认密码不正确")
  187. }
  188. if password1 != "" && member.AuthMethod != conf.AuthMethodLDAP {
  189. member.Password = password1
  190. }
  191. if err := member.Valid(password1 == ""); err != nil {
  192. c.JsonResult(6002, err.Error())
  193. }
  194. if password1 != "" {
  195. password, err := utils.PasswordHash(password1)
  196. if err != nil {
  197. beego.Error(err)
  198. c.JsonResult(6003, "对用户密码加密时出错")
  199. }
  200. member.Password = password
  201. }
  202. if err := member.Update(); err != nil {
  203. c.JsonResult(6004, err.Error())
  204. }
  205. c.JsonResult(0, "ok")
  206. }
  207. c.Data["Model"] = member
  208. }
  209. //删除一个用户,并将该用户的所有信息转移到超级管理员上.
  210. func (c *ManagerController) DeleteMember() {
  211. c.Prepare()
  212. member_id, _ := c.GetInt("id", 0)
  213. if member_id <= 0 {
  214. c.JsonResult(404, "参数错误")
  215. }
  216. member, err := models.NewMember().Find(member_id)
  217. if err != nil {
  218. beego.Error(err)
  219. c.JsonResult(500, "用户不存在")
  220. }
  221. if member.Role == conf.MemberSuperRole {
  222. c.JsonResult(500, "不能删除超级管理员")
  223. }
  224. superMember, err := models.NewMember().FindByFieldFirst("role", 0)
  225. if err != nil {
  226. beego.Error(err)
  227. c.JsonResult(5001, "未能找到超级管理员")
  228. }
  229. err = models.NewMember().Delete(member_id, superMember.MemberId)
  230. if err != nil {
  231. beego.Error(err)
  232. c.JsonResult(5002, "删除失败")
  233. }
  234. c.JsonResult(0, "ok")
  235. }
  236. //项目列表.
  237. func (c *ManagerController) Books() {
  238. c.Prepare()
  239. c.TplName = "manager/books.tpl"
  240. pageIndex, _ := c.GetInt("page", 1)
  241. books, totalCount, err := models.NewBookResult().FindToPager(pageIndex, conf.PageSize)
  242. if err != nil {
  243. c.Abort("500")
  244. }
  245. if totalCount > 0 {
  246. //html := utils.GetPagerHtml(c.Ctx.Request.RequestURI, pageIndex, 8, totalCount)
  247. pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
  248. c.Data["PageHtml"] = pager.HtmlPages()
  249. } else {
  250. c.Data["PageHtml"] = ""
  251. }
  252. for i, book := range books {
  253. books[i].Description = utils.StripTags(string(blackfriday.Run([]byte(book.Description))))
  254. books[i].ModifyTime = book.ModifyTime.Local()
  255. books[i].CreateTime = book.CreateTime.Local()
  256. }
  257. c.Data["Lists"] = books
  258. }
  259. //编辑项目.
  260. func (c *ManagerController) EditBook() {
  261. c.Prepare()
  262. c.TplName = "manager/edit_book.tpl"
  263. identify := c.GetString(":key")
  264. if identify == "" {
  265. c.Abort("404")
  266. }
  267. book, err := models.NewBook().FindByFieldFirst("identify", identify)
  268. if err != nil {
  269. c.Abort("500")
  270. }
  271. if c.Ctx.Input.IsPost() {
  272. bookName := strings.TrimSpace(c.GetString("book_name"))
  273. description := strings.TrimSpace(c.GetString("description", ""))
  274. commentStatus := c.GetString("comment_status")
  275. tag := strings.TrimSpace(c.GetString("label"))
  276. orderIndex, _ := c.GetInt("order_index", 0)
  277. isDownload := strings.TrimSpace(c.GetString("is_download")) == "on"
  278. enableShare := strings.TrimSpace(c.GetString("enable_share")) == "on"
  279. isUseFirstDocument := strings.TrimSpace(c.GetString("is_use_first_document")) == "on"
  280. autoRelease := strings.TrimSpace(c.GetString("auto_release")) == "on"
  281. publisher := strings.TrimSpace(c.GetString("publisher"))
  282. historyCount, _ := c.GetInt("history_count", 0)
  283. if strings.Count(description, "") > 500 {
  284. c.JsonResult(6004, "项目描述不能大于500字")
  285. }
  286. if commentStatus != "open" && commentStatus != "closed" && commentStatus != "group_only" && commentStatus != "registered_only" {
  287. commentStatus = "closed"
  288. }
  289. if tag != "" {
  290. tags := strings.Split(tag, ";")
  291. if len(tags) > 10 {
  292. c.JsonResult(6005, "最多允许添加10个标签")
  293. }
  294. }
  295. book.Publisher = publisher
  296. book.HistoryCount = historyCount
  297. book.BookName = bookName
  298. book.Description = description
  299. book.CommentStatus = commentStatus
  300. book.Label = tag
  301. book.OrderIndex = orderIndex
  302. if autoRelease {
  303. book.AutoRelease = 1
  304. } else {
  305. book.AutoRelease = 0
  306. }
  307. if isDownload {
  308. book.IsDownload = 0
  309. } else {
  310. book.IsDownload = 1
  311. }
  312. if enableShare {
  313. book.IsEnableShare = 0
  314. } else {
  315. book.IsEnableShare = 1
  316. }
  317. if isUseFirstDocument {
  318. book.IsUseFirstDocument = 1
  319. } else {
  320. book.IsUseFirstDocument = 0
  321. }
  322. if err := book.Update(); err != nil {
  323. c.JsonResult(6006, "保存失败")
  324. }
  325. c.JsonResult(0, "ok")
  326. }
  327. if book.PrivateToken != "" {
  328. book.PrivateToken = conf.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken)
  329. }
  330. bookResult := models.NewBookResult()
  331. bookResult.ToBookResult(*book)
  332. c.Data["Model"] = bookResult
  333. }
  334. // 删除项目.
  335. func (c *ManagerController) DeleteBook() {
  336. c.Prepare()
  337. bookId, _ := c.GetInt("book_id", 0)
  338. if bookId <= 0 {
  339. c.JsonResult(6001, "参数错误")
  340. }
  341. book := models.NewBook()
  342. err := book.ThoroughDeleteBook(bookId)
  343. if err == orm.ErrNoRows {
  344. c.JsonResult(6002, "项目不存在")
  345. }
  346. if err != nil {
  347. logs.Error("DeleteBook => ", err)
  348. c.JsonResult(6003, "删除失败")
  349. }
  350. c.JsonResult(0, "ok")
  351. }
  352. // CreateToken 创建访问来令牌.
  353. func (c *ManagerController) CreateToken() {
  354. c.Prepare()
  355. action := c.GetString("action")
  356. identify := c.GetString("identify")
  357. book, err := models.NewBook().FindByFieldFirst("identify", identify)
  358. if err != nil {
  359. c.JsonResult(6001, "项目不存在")
  360. }
  361. if action == "create" {
  362. if book.PrivatelyOwned == 0 {
  363. c.JsonResult(6001, "公开项目不能创建阅读令牌")
  364. }
  365. book.PrivateToken = string(utils.Krand(conf.GetTokenSize(), utils.KC_RAND_KIND_ALL))
  366. if err := book.Update(); err != nil {
  367. logs.Error("生成阅读令牌失败 => ", err)
  368. c.JsonResult(6003, "生成阅读令牌失败")
  369. }
  370. c.JsonResult(0, "ok", conf.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken))
  371. } else {
  372. book.PrivateToken = ""
  373. if err := book.Update(); err != nil {
  374. logs.Error("CreateToken => ", err)
  375. c.JsonResult(6004, "删除令牌失败")
  376. }
  377. c.JsonResult(0, "ok", "")
  378. }
  379. }
  380. //项目设置.
  381. func (c *ManagerController) Setting() {
  382. c.Prepare()
  383. c.TplName = "manager/setting.tpl"
  384. options, err := models.NewOption().All()
  385. if c.Ctx.Input.IsPost() {
  386. for _, item := range options {
  387. item.OptionValue = c.GetString(item.OptionName)
  388. item.InsertOrUpdate()
  389. }
  390. c.JsonResult(0, "ok")
  391. }
  392. if err != nil {
  393. c.Abort("500")
  394. }
  395. c.Data["SITE_TITLE"] = c.Option["SITE_NAME"]
  396. for _, item := range options {
  397. c.Data[item.OptionName] = item.OptionValue
  398. }
  399. }
  400. // Transfer 转让项目.
  401. func (c *ManagerController) Transfer() {
  402. c.Prepare()
  403. account := c.GetString("account")
  404. if account == "" {
  405. c.JsonResult(6004, "接受者账号不能为空")
  406. }
  407. member, err := models.NewMember().FindByAccount(account)
  408. if err != nil {
  409. logs.Error("FindByAccount => ", err)
  410. c.JsonResult(6005, "接受用户不存在")
  411. }
  412. if member.Status != 0 {
  413. c.JsonResult(6006, "接受用户已被禁用")
  414. }
  415. if !c.Member.IsAdministrator() {
  416. c.Abort("403")
  417. }
  418. identify := c.GetString("identify")
  419. book, err := models.NewBook().FindByFieldFirst("identify", identify)
  420. if err != nil {
  421. c.JsonResult(6001, err.Error())
  422. }
  423. rel, err := models.NewRelationship().FindFounder(book.BookId)
  424. if err != nil {
  425. beego.Error("FindFounder => ", err)
  426. c.JsonResult(6009, "查询项目创始人失败")
  427. }
  428. if member.MemberId == rel.MemberId {
  429. c.JsonResult(6007, "不能转让给自己")
  430. }
  431. err = models.NewRelationship().Transfer(book.BookId, rel.MemberId, member.MemberId)
  432. if err != nil {
  433. logs.Error("Transfer => ", err)
  434. c.JsonResult(6008, err.Error())
  435. }
  436. c.JsonResult(0, "ok")
  437. }
  438. func (c *ManagerController) Comments() {
  439. c.Prepare()
  440. c.TplName = "manager/comments.tpl"
  441. if !c.Member.IsAdministrator() {
  442. c.Abort("403")
  443. }
  444. }
  445. //DeleteComment 标记评论为已删除
  446. func (c *ManagerController) DeleteComment() {
  447. c.Prepare()
  448. comment_id, _ := c.GetInt("comment_id", 0)
  449. if comment_id <= 0 {
  450. c.JsonResult(6001, "参数错误")
  451. }
  452. comment := models.NewComment()
  453. if _, err := comment.Find(comment_id); err != nil {
  454. c.JsonResult(6002, "评论不存在")
  455. }
  456. comment.Approved = 3
  457. if err := comment.Update("approved"); err != nil {
  458. c.JsonResult(6003, "删除评论失败")
  459. }
  460. c.JsonResult(0, "ok", comment)
  461. }
  462. //设置项目私有状态.
  463. func (c *ManagerController) PrivatelyOwned() {
  464. c.Prepare()
  465. status := c.GetString("status")
  466. identify := c.GetString("identify")
  467. if status != "open" && status != "close" {
  468. c.JsonResult(6003, "参数错误")
  469. }
  470. state := 0
  471. if status == "open" {
  472. state = 0
  473. } else {
  474. state = 1
  475. }
  476. if !c.Member.IsAdministrator() {
  477. c.Abort("403")
  478. }
  479. book, err := models.NewBook().FindByFieldFirst("identify", identify)
  480. if err != nil {
  481. c.JsonResult(6001, err.Error())
  482. }
  483. book.PrivatelyOwned = state
  484. logs.Info("", state, status)
  485. err = book.Update()
  486. if err != nil {
  487. logs.Error("PrivatelyOwned => ", err)
  488. c.JsonResult(6004, "保存失败")
  489. }
  490. c.JsonResult(0, "ok")
  491. }
  492. //附件列表.
  493. func (c *ManagerController) AttachList() {
  494. c.Prepare()
  495. c.TplName = "manager/attach_list.tpl"
  496. pageIndex, _ := c.GetInt("page", 1)
  497. attachList, totalCount, err := models.NewAttachment().FindToPager(pageIndex, conf.PageSize)
  498. if err != nil {
  499. c.Abort("500")
  500. }
  501. if totalCount > 0 {
  502. pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
  503. c.Data["PageHtml"] = pager.HtmlPages()
  504. } else {
  505. c.Data["PageHtml"] = ""
  506. }
  507. for _, item := range attachList {
  508. p := filepath.Join(conf.WorkingDirectory, item.FilePath)
  509. item.IsExist = filetil.FileExists(p)
  510. }
  511. c.Data["Lists"] = attachList
  512. }
  513. //附件详情.
  514. func (c *ManagerController) AttachDetailed() {
  515. c.Prepare()
  516. c.TplName = "manager/attach_detailed.tpl"
  517. attach_id, _ := strconv.Atoi(c.Ctx.Input.Param(":id"))
  518. if attach_id <= 0 {
  519. c.Abort("404")
  520. }
  521. attach, err := models.NewAttachmentResult().Find(attach_id)
  522. if err != nil {
  523. beego.Error("AttachDetailed => ", err)
  524. if err == orm.ErrNoRows {
  525. c.Abort("404")
  526. } else {
  527. c.Abort("500")
  528. }
  529. }
  530. attach.FilePath = filepath.Join(conf.WorkingDirectory, attach.FilePath)
  531. attach.HttpPath = conf.URLForWithCdnImage(attach.HttpPath)
  532. attach.IsExist = filetil.FileExists(attach.FilePath)
  533. c.Data["Model"] = attach
  534. }
  535. //删除附件.
  536. func (c *ManagerController) AttachDelete() {
  537. c.Prepare()
  538. attachId, _ := c.GetInt("attach_id")
  539. if attachId <= 0 {
  540. c.Abort("404")
  541. }
  542. attach, err := models.NewAttachment().Find(attachId)
  543. if err != nil {
  544. beego.Error("AttachDelete => ", err)
  545. c.JsonResult(6001, err.Error())
  546. }
  547. attach.FilePath = filepath.Join(conf.WorkingDirectory,attach.FilePath)
  548. if err := attach.Delete(); err != nil {
  549. beego.Error("AttachDelete => ", err)
  550. c.JsonResult(6002, err.Error())
  551. }
  552. c.JsonResult(0, "ok")
  553. }
  554. //标签列表
  555. func (c *ManagerController) LabelList() {
  556. c.Prepare()
  557. c.TplName = "manager/label_list.tpl"
  558. pageIndex, _ := c.GetInt("page", 1)
  559. labels, totalCount, err := models.NewLabel().FindToPager(pageIndex, conf.PageSize)
  560. if err != nil {
  561. c.ShowErrorPage(50001, err.Error())
  562. }
  563. if totalCount > 0 {
  564. pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
  565. c.Data["PageHtml"] = pager.HtmlPages()
  566. } else {
  567. c.Data["PageHtml"] = ""
  568. }
  569. c.Data["TotalPages"] = int(math.Ceil(float64(totalCount) / float64(conf.PageSize)))
  570. c.Data["Lists"] = labels
  571. }
  572. //删除标签
  573. func (c *ManagerController) LabelDelete() {
  574. labelId, err := strconv.Atoi(c.Ctx.Input.Param(":id"))
  575. if err != nil {
  576. beego.Error("获取删除标签参数时出错:", err)
  577. c.JsonResult(50001, "参数错误")
  578. }
  579. if labelId <= 0 {
  580. c.JsonResult(50001, "参数错误")
  581. }
  582. label, err := models.NewLabel().FindFirst("label_id", labelId)
  583. if err != nil {
  584. beego.Error("查询标签时出错:", err)
  585. c.JsonResult(50001, "查询标签时出错:"+err.Error())
  586. }
  587. if err := label.Delete(); err != nil {
  588. c.JsonResult(50002, "删除失败:"+err.Error())
  589. } else {
  590. c.JsonResult(0, "ok")
  591. }
  592. }