emoji.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package service
  2. import (
  3. "context"
  4. "strings"
  5. "go-common/app/admin/main/reply/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. // EmojiList EmojiList
  10. func (s *Service) EmojiList(c context.Context, pid int64) (emojis []*model.Emoji, err error) {
  11. if pid != 0 {
  12. emojis, err = s.dao.EmojiListByPid(c, pid)
  13. } else {
  14. emojis, err = s.dao.EmojiList(c)
  15. }
  16. if err != nil {
  17. log.Error("service.EmojiList error (%v)", err)
  18. }
  19. return
  20. }
  21. // CreateEmoji CreateEmoji
  22. func (s *Service) CreateEmoji(c context.Context, pid int64, name string, url string, sort int32, state int32, remark string) (id int64, err error) {
  23. if !strings.HasPrefix(name, "[") {
  24. name = "[" + name
  25. }
  26. if !strings.HasSuffix(name, "]") {
  27. name = name + "]"
  28. }
  29. id, err = s.dao.CreateEmoji(c, pid, name, url, sort, state, remark)
  30. if err != nil {
  31. log.Error("service.CreateEmoji error (%v)", err)
  32. }
  33. return
  34. }
  35. // UpEmojiSort UpEmojiSort
  36. func (s *Service) UpEmojiSort(c context.Context, ids string) (err error) {
  37. tx, err := s.dao.BeginTran(c)
  38. if err != nil {
  39. return
  40. }
  41. err = s.dao.UpEmojiSort(tx, ids)
  42. if err != nil {
  43. tx.Rollback()
  44. log.Error("service.UpEmojiSort error (%v)", err)
  45. return
  46. }
  47. return tx.Commit()
  48. }
  49. // UpEmojiState UpEmojiState
  50. func (s *Service) UpEmojiState(c context.Context, state int32, id int64) (idx int64, err error) {
  51. if state == 2 { // delete emoji
  52. idx, err = s.dao.DelEmojiByID(c, id)
  53. } else {
  54. idx, err = s.dao.UpEmojiStateByID(c, state, id)
  55. }
  56. if err != nil {
  57. log.Error("service.UpEmojiState error (%v)", err)
  58. }
  59. return
  60. }
  61. // UpEmoji UpEmoji
  62. func (s *Service) UpEmoji(c context.Context, name string, remark string, url string, id int64) (idx int64, err error) {
  63. idx, err = s.dao.UpEmoji(c, name, remark, url, id)
  64. if err != nil {
  65. log.Error("service.UpEmojiState error (%v)", err)
  66. }
  67. return
  68. }
  69. // EmojiByName EmojiByName
  70. func (s *Service) EmojiByName(c context.Context, name string) (err error) {
  71. emojis, e := s.dao.EmojiByName(c, name)
  72. if e != nil {
  73. log.Error("service.CreateEmoji EmojiByName err (%v)", e)
  74. err = e
  75. return
  76. }
  77. if len(emojis) > 0 {
  78. err = ecode.ReplyEmojiExits
  79. return
  80. }
  81. return
  82. }