蛋蛋星球 后台端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

svc_emoticon.go 2.6 KiB

před 3 týdny
před 3 týdny
před 3 týdny
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/im/model"
  5. md "applet/app/md/im"
  6. "errors"
  7. "time"
  8. )
  9. func PageEmoticon(req md.PageEmoticonReq) (err error, resp md.PageEmoticonResp) {
  10. sess := db.DbIm.Where("1=1")
  11. if req.Memo != "" {
  12. sess.And("memo LIKE ?", "%"+req.Memo+"%")
  13. }
  14. if req.State != 0 {
  15. sess.And("memo = ?", req.State)
  16. }
  17. var mm []*model.Emoticon
  18. resp.Total, err = sess.Limit(req.PageSize, (req.Page-1)*req.PageSize).Desc("id").FindAndCount(&mm)
  19. if err != nil {
  20. return
  21. }
  22. resp.Page = req.Page
  23. resp.PageSize = req.PageSize
  24. for _, v := range mm {
  25. resp.List = append(resp.List, struct {
  26. Id int64 `json:"id"` //记录id
  27. Name string `json:"name" example:"名称"`
  28. ImgUrl string `json:"img_url" example:"图片地址"`
  29. Sort int `json:"Sort"` // 权重
  30. State int `json:"state"` // 状态0关闭,1开启
  31. Memo string `json:"memo" example:"备注"` // 备注
  32. CreateAt string `json:"create_at" example:"创建时间"` // 创建时间
  33. UpdateAt string `json:"update_at" example:"更新时间"` // 更新时间
  34. }{Id: v.Id, Name: v.Name, ImgUrl: v.ImgUrl, Sort: v.Sort, State: v.State, Memo: v.Memo, CreateAt: v.CreateAt, UpdateAt: v.UpdateAt})
  35. }
  36. return
  37. }
  38. func AddEmoticon(req md.AddEmoticonReq) (err error) {
  39. cfg := model.Emoticon{
  40. Name: req.Name,
  41. ImgUrl: req.ImgUrl,
  42. Memo: req.Memo,
  43. Sort: req.Sort,
  44. State: 1,
  45. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  46. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  47. }
  48. _, err = db.DbIm.InsertOne(&cfg)
  49. if err != nil {
  50. return
  51. }
  52. return
  53. }
  54. func SetEmoticonState(req md.SetEmoticonStateReq) (err error) {
  55. var customerService model.Emoticon
  56. has, err := db.DbIm.ID(req.Id).Get(&customerService)
  57. if err != nil {
  58. return
  59. }
  60. if has {
  61. return errors.New("未查询到对应记录!")
  62. }
  63. customerService.State = req.State
  64. _, err = db.DbIm.ID(req.Id).Cols("state").Update(&customerService)
  65. if err != nil {
  66. return
  67. }
  68. return
  69. }
  70. func UpdateEmoticon(req md.UpdateEmoticonReq) (err error) {
  71. var customerService model.Emoticon
  72. has, err := db.DbIm.ID(req.Id).Get(&customerService)
  73. if err != nil {
  74. return
  75. }
  76. if has {
  77. return errors.New("未查询到对应记录!")
  78. }
  79. customerService.Name = req.Name
  80. customerService.ImgUrl = req.ImgUrl
  81. customerService.Sort = req.Sort
  82. customerService.Memo = req.Memo
  83. _, err = db.DbIm.ID(req.Id).Update(&customerService)
  84. if err != nil {
  85. return
  86. }
  87. return
  88. }
  89. func DeleteEmoticon(req md.DeleteEmoticonReq) (err error) {
  90. _, err = db.DbIm.Where("id = ?", req.Id).Delete(&model.Emoticon{})
  91. return
  92. }