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

69 lines
1.6 KiB

5 years ago
  1. package client
  2. import (
  3. "fmt"
  4. "github.com/ouxuanserver/osmanthuswine/src/core"
  5. "hudongzhuanjia/controllers"
  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.MustGetActivityId()
  21. content := t.MustGet("content")
  22. //检查内容是否包含敏感
  23. if models.IsSensitive(content) {
  24. t.ERROR("内容包含敏感字", code.MSG_ERR)
  25. }
  26. //查询该活动的所属客户
  27. activity := new(models.Activity)
  28. exist, err := models.GetById(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.GetById(user, uid)
  34. t.CheckErr(err)
  35. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  36. //插入弹幕消息
  37. _, err = core.GetXormAuto().InsertOne(&models.BarrageHistory{
  38. ActivityId: activityId,
  39. UserId: uid,
  40. Content: content,
  41. CreateAt: time.Now(),
  42. UpdateAt: time.Now(),
  43. })
  44. t.CheckErr(err)
  45. customer := new(models.Customer)
  46. exist, err = models.GetById(customer, customerId)
  47. t.CheckErr(err)
  48. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
  49. go ws_send_service.SendBarrage(fmt.Sprintf("%d", activity.Id),
  50. define.TYPE_CUSTOMER, 0, map[string]interface{}{
  51. "type": "barrage",
  52. "customer_id": 0,
  53. "data": map[string]interface{}{
  54. "avatar": user.Avatar,
  55. "content": content,
  56. },
  57. })
  58. t.SUCCESS("发送成功")
  59. }