互动
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.7 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
  1. package client
  2. import (
  3. "fmt"
  4. "github.com/ouxuanserver/osmanthuswine/src/core"
  5. "hudongzhuanjia/controllers"
  6. "hudongzhuanjia/libs/filter"
  7. "hudongzhuanjia/models"
  8. ws_send_service "hudongzhuanjia/services/ws_send"
  9. "hudongzhuanjia/utils/code"
  10. "hudongzhuanjia/utils/define"
  11. "time"
  12. )
  13. //弹幕
  14. type BarrageCtl struct {
  15. controllers.AuthorCtl
  16. }
  17. //发送弹幕
  18. func (t *BarrageCtl) Send() {
  19. uid := t.MustGetUID()
  20. customerId := t.MustGetCustomerId()
  21. activityId := t.MustGetInt64("activity_id")
  22. content := t.MustGet("content")
  23. //检查内容是否包含敏感
  24. if ok, _ := filter.Validate(content); !ok {
  25. t.ERROR("内容包含敏感字", code.MSG_ERR)
  26. }
  27. //查询该活动的所属客户
  28. activity := new(models.Activity)
  29. exist, err := models.Get(activity, activityId)
  30. t.CheckErr(err)
  31. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  32. //查询当前的用户信息
  33. user := new(models.User)
  34. exist, err = models.Get(user, uid)
  35. t.CheckErr(err)
  36. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  37. //插入弹幕消息
  38. _, err = core.GetXormAuto().InsertOne(&models.BarrageHistory{
  39. ActivityId: activityId,
  40. UserId: uid,
  41. Content: content,
  42. CreateAt: time.Now(),
  43. UpdateAt: time.Now(),
  44. })
  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. }