|
|
package client
import ( "fmt" "hudongzhuanjia/controllers" "hudongzhuanjia/libs/filter" "hudongzhuanjia/models" ws_send_service "hudongzhuanjia/services/ws_send" "hudongzhuanjia/utils/code" "hudongzhuanjia/utils/define" "time" )
//弹幕
type BarrageCtl struct { controllers.AuthorCtl }
//发送弹幕
func (t *BarrageCtl) Send() { uid := t.MustGetUID() customerId := t.MustGetCustomerId() activityId := t.MustGetInt64("activity_id") content := t.MustGet("content")
//检查内容是否包含敏感
if ok, _ := filter.Validate(content); !ok { t.ERROR("内容包含敏感字", code.MSG_ERR) }
//查询该活动的所属客户
activity := new(models.Activity) exist, err := models.Get(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
//查询当前的用户信息
user := new(models.User) exist, err = models.Get(user, uid) t.CheckErr(err) t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
//插入弹幕消息
history := models.BarrageHistory{ ActivityId: activityId, UserId: uid, Content: content, CreateAt: time.Now(), UpdateAt: time.Now(), } _, err = models.Add(&history) t.CheckErr(err)
customer := new(models.Customer) exist, err = models.Get(customer, customerId) t.CheckErr(err) t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
go ws_send_service.SendBarrage(fmt.Sprintf("%d", activity.Id), define.TYPE_CUSTOMER, 0, map[string]interface{}{ "type": "barrage", "customer_id": 0, "data": map[string]interface{}{ "avatar": user.Avatar, "content": content, }, })
t.SUCCESS("发送成功") }
|