蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

svc_emoticon.go 2.7 KiB

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