bullet_chat.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package yb
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/yb"
  7. "hongze/hz_crm_api/models/yb/response"
  8. "hongze/hz_crm_api/utils"
  9. "time"
  10. )
  11. // GetBulletChatList 获取弹幕列表
  12. func GetBulletChatList(condition string, pars []interface{}, startSize, pageSize int) (total int, resp []*response.BulletChatItem, err error) {
  13. resp = make([]*response.BulletChatItem, 0)
  14. t, list, e := yb.GetBulletChatPageList(condition, pars, "", startSize, pageSize)
  15. if e != nil {
  16. err = errors.New("获取弹幕列表失败 Err:" + e.Error())
  17. return
  18. }
  19. if len(list) == 0 {
  20. return
  21. }
  22. total = t
  23. // 用户名称
  24. userIdArr := make([]int, 0)
  25. for i := range list {
  26. userIdArr = append(userIdArr, list[i].UserId)
  27. }
  28. userIds := utils.IntArr2joinString(userIdArr, ",")
  29. userMap := make(map[int]string, 0)
  30. if userIds != "" {
  31. userList, e := models.GetWxUserListByUserIds(userIds)
  32. if e != nil {
  33. err = errors.New("获取弹幕用户信息失败, Err: " + e.Error())
  34. return
  35. }
  36. for i := range userList {
  37. userMap[int(userList[i].UserId)] = userList[i].RealName
  38. }
  39. }
  40. for _, v := range list {
  41. sa := 1
  42. if v.SourceAgent == 2 || v.SourceAgent == 4 {
  43. sa = 2
  44. }
  45. item := &response.BulletChatItem{
  46. Id: v.Id,
  47. Title: v.Title,
  48. Content: v.Content,
  49. Source: v.Source,
  50. Seconds: fmt.Sprint(v.Seconds),
  51. UserName: userMap[v.UserId],
  52. SourceAgent: sa,
  53. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  54. }
  55. resp = append(resp, item)
  56. }
  57. return
  58. }
  59. // SoftDeleteBulletChat 删除弹幕
  60. func SoftDeleteBulletChat(adminId, id int) (err error) {
  61. item, e := yb.GetBulletChatById(id)
  62. if e != nil {
  63. err = errors.New("获取弹幕信息失败, Err:" + e.Error())
  64. return
  65. }
  66. if item.IsDeleted != 0 {
  67. err = errors.New("弹幕状态有误")
  68. return
  69. }
  70. nowTime := time.Now().Local()
  71. updateCols := []string{"ModifyTime", "OpAdminId", "IsDeleted", "DeleteTime"}
  72. item.ModifyTime = nowTime
  73. item.OpAdminId = adminId
  74. item.IsDeleted = 1
  75. item.DeleteTime = nowTime
  76. if e = item.Update(updateCols); e != nil {
  77. err = errors.New("删除弹幕失败, Err: " + e.Error())
  78. return
  79. }
  80. return
  81. }