互动
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.

70 lines
1.6 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package client
  2. import (
  3. "fmt"
  4. "hudongzhuanjia/controllers"
  5. "hudongzhuanjia/libs/filter"
  6. "hudongzhuanjia/models"
  7. ws_send_service "hudongzhuanjia/services/ws_send"
  8. "hudongzhuanjia/utils/code"
  9. "hudongzhuanjia/utils/define"
  10. "time"
  11. )
  12. //弹幕
  13. type BarrageCtl struct {
  14. controllers.AuthorCtl
  15. }
  16. //发送弹幕
  17. func (t *BarrageCtl) Send() {
  18. uid := t.MustGetUID()
  19. customerId := t.MustGetCustomerId()
  20. activityId := t.MustGetInt64("activity_id")
  21. content := t.MustGet("content")
  22. //检查内容是否包含敏感
  23. if ok, _ := filter.Validate(content); !ok {
  24. t.ERROR("内容包含敏感字", code.MSG_ERR)
  25. }
  26. //查询该活动的所属客户
  27. activity := new(models.Activity)
  28. exist, err := models.Get(activity, activityId)
  29. t.CheckErr(err)
  30. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  31. //查询当前的用户信息
  32. user := new(models.User)
  33. exist, err = models.Get(user, uid)
  34. t.CheckErr(err)
  35. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  36. //插入弹幕消息
  37. history := models.BarrageHistory{
  38. ActivityId: activityId,
  39. UserId: uid,
  40. Content: content,
  41. CreateAt: time.Now(),
  42. UpdateAt: time.Now(),
  43. }
  44. _, err = models.Add(&history)
  45. t.CheckErr(err)
  46. customer := new(models.Customer)
  47. exist, err = models.Get(customer, customerId)
  48. t.CheckErr(err)
  49. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
  50. go ws_send_service.SendBarrage(fmt.Sprintf("%d", activity.Id),
  51. define.TYPE_CUSTOMER, 0, map[string]interface{}{
  52. "type": "barrage",
  53. "customer_id": 0,
  54. "data": map[string]interface{}{
  55. "avatar": user.Avatar,
  56. "content": content,
  57. },
  58. })
  59. t.SUCCESS("发送成功")
  60. }