emoji_package.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/reply/model"
  5. "go-common/library/log"
  6. )
  7. // EmojiPackageList return all emojipackages and emojis
  8. func (s *Service) EmojiPackageList(c context.Context) (resp []*model.EmojiPackage, err error) {
  9. packs, err := s.dao.EmojiPackageList(c)
  10. if err != nil {
  11. log.Error("service.EmojiPackageList err (%v)", err)
  12. return
  13. }
  14. for _, pack := range packs {
  15. eList, err := s.dao.EmojiListByPid(c, pack.ID)
  16. if err != nil {
  17. return nil, err
  18. }
  19. pack.Emojis = eList
  20. resp = append(resp, pack)
  21. }
  22. return
  23. }
  24. // CreateEmojiPackage CreateEmojiPackage
  25. func (s *Service) CreateEmojiPackage(c context.Context, name string, url string, sort int32, remark string, state int32) (id int64, err error) {
  26. id, err = s.dao.CreateEmojiPackage(c, name, url, sort, remark, state)
  27. if err != nil {
  28. log.Error("service.CreateEmojiPackage err (%v)", err)
  29. }
  30. return
  31. }
  32. // UpEmojiPackageSort UpEmojiPackageSort
  33. func (s *Service) UpEmojiPackageSort(c context.Context, ids string) (err error) {
  34. tx, err := s.dao.BeginTran(c)
  35. if err != nil {
  36. return
  37. }
  38. err = s.dao.UpEmojiPackageSort(tx, ids)
  39. if err != nil {
  40. tx.Rollback()
  41. log.Error("service.UpEmojiPackageSort err (%v)", err)
  42. return
  43. }
  44. return tx.Commit()
  45. }
  46. // UpEmojiPackage UpEmojiPackage
  47. func (s *Service) UpEmojiPackage(c context.Context, name string, url string, remark string, state int32, id int64) (idx int64, err error) {
  48. if state == 2 { // delete package
  49. _, err = s.dao.DelEmojiPackage(c, id)
  50. if err != nil {
  51. log.Error("service.DelEmojiPackage err (%v)", err)
  52. return 0, err
  53. }
  54. idx, err = s.dao.DelEmojiByPid(c, id)
  55. } else {
  56. idx, err = s.dao.UpEmojiPackage(c, name, url, remark, state, id)
  57. }
  58. if err != nil {
  59. log.Error("service.UpEmojiPackage err (%v)", err)
  60. }
  61. return
  62. }