diff --git a/controllers/author.go b/controllers/author.go index 6850c94..40e8894 100644 --- a/controllers/author.go +++ b/controllers/author.go @@ -48,10 +48,6 @@ func (t *AuthorCtl) MustGetCustomerId() int64 { return t.claims.CustomerId } -func (t *AuthorCtl) MustGetCustomerPid() int64 { - return t.claims.CustomerPid -} - func (t *AuthorCtl) MustGetAreaId() int64 { return t.claims.AreaId } diff --git a/controllers/client/barrage.go b/controllers/client/barrage.go index 251f98f..611d634 100644 --- a/controllers/client/barrage.go +++ b/controllers/client/barrage.go @@ -25,10 +25,9 @@ func (t *BarrageCtl) Send() { content := t.MustGet("content") //检查内容是否包含敏感 - //if models.IsSensitive(content) { - // t.ERROR("内容包含敏感字", code.MSG_ERR) - //} - content = filter.Replace(content) + if ok, _ := filter.Validate(content); !ok { + t.ERROR("内容包含敏感字", code.MSG_ERR) + } //查询该活动的所属客户 activity := new(models.Activity) diff --git a/controllers/client/bully_screen.go b/controllers/client/bully_screen.go index 7afb321..dd04b26 100644 --- a/controllers/client/bully_screen.go +++ b/controllers/client/bully_screen.go @@ -34,10 +34,9 @@ func (t *BullyScreenCtl) PaScreen() { t.CheckRunning(activity.Status) //检查内容是否包含敏感 - //if models.IsSensitive(content) { - // t.ERROR("内容包含敏感字", code.MSG_ERR) - //} - content = filter.Replace(content) + if ok, _ := filter.Validate(content); !ok { + t.ERROR("内容包含敏感字", code.MSG_ERR) + } //查询该活动的的霸屏服务id bullyScreenServer := new(models.BullyScreenServer) diff --git a/controllers/client/reward.go b/controllers/client/reward.go index b82c434..47f6385 100644 --- a/controllers/client/reward.go +++ b/controllers/client/reward.go @@ -18,20 +18,19 @@ type RewardCtl struct { controllers.AuthorCtl } -// todo: 支付接口 func (t *RewardCtl) Reward() { activityId := t.MustGetInt64("activity_id") content := t.MustGet("content") amount := t.MustGetDouble("amount") uid := t.MustGetUID() + if amount <= 0 { t.ERROR("打赏金额不能小于0", code.MSG_ERR_Param) } //检查内容是否包含敏感 - //if models.IsSensitive(content) { - // t.ERROR("内容包含敏感字", code.MSG_ERR) - //} - content = filter.Replace(content) + if ok, _ := filter.Validate(content); !ok { + t.ERROR("内容包含敏感字", code.MSG_ERR) + } activity := new(models.Activity) exist, err := models.GetById(activity, activityId) diff --git a/controllers/pc/lottery_draw.go b/controllers/pc/lottery_draw.go index 7027d93..cd8797e 100644 --- a/controllers/pc/lottery_draw.go +++ b/controllers/pc/lottery_draw.go @@ -81,9 +81,15 @@ type LotteryLadderResult struct { //获取所有抽奖活动列表 func (t *LotteryDrawCtl) List() { activityId := t.MustGetInt64("activity_id") + customerId := t.MustGetUID() + + customer := new(models.Customer) + exist, err := models.GetById(customer, customerId) + t.CheckErr(err) + t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") activity := new(models.Activity) - exist, err := models.GetById(activity, activityId) + exist, err = models.GetById(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") @@ -97,7 +103,7 @@ func (t *LotteryDrawCtl) List() { // 多地区的一个坑:分配给主会场的area_id不是主账号的area_id area := new(models.AreaStore) - if t.MustGetCustomerPid() == 0 { + if customer.Pid == 0 { exist, err = area.GetMainAreaById(activityId) } else { exist, err = area.GetAreaStoreById(t.MustGetAreaId()) @@ -178,14 +184,20 @@ type LotteryUsersResult struct { func (t *LotteryDrawCtl) Users() { activityId := t.MustGetInt64("activity_id") ruleId := t.MustGetInt64("lottery_draw_rule_id") + customerId := t.MustGetUID() + + customer := new(models.Customer) + exist, err := models.GetById(customer, customerId) + t.CheckErr(err) + t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") activity := new(models.Activity) - exist, err := models.GetById(activity, activityId) + exist, err = models.GetById(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") area := new(models.AreaStore) - if t.MustGetCustomerPid() == 0 { + if customer.Pid == 0 { exist, err = area.GetMainAreaById(activityId) } else { exist, err = area.GetAreaStoreById(t.MustGetAreaId()) @@ -227,16 +239,22 @@ func (t *LotteryDrawCtl) Lottery() { ruleId := t.MustGetInt64("lottery_draw_rule_id") ladderId := t.MustGetInt64("lottery_draw_ladder_id") number := t.MustGetInt("number") // 奖品数量 + customerId := t.MustGetUID() + + customer := new(models.Customer) + exist, err := models.GetById(customer, customerId) + t.CheckErr(err) + t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") activity := new(models.Activity) - exist, err := models.GetById(activity, activityId) + exist, err = models.GetById(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") t.CheckRunning(activity.Status) // 多地区设置 area := new(models.AreaStore) - if t.MustGetCustomerPid() == 0 { + if customer.Pid == 0 { exist, err = area.GetMainAreaById(activity.Id) } else { exist, err = area.GetAreaStoreById(t.MustGetAreaId()) diff --git a/controllers/pc/order_draw.go b/controllers/pc/order_draw.go index 721d602..2e4e24a 100644 --- a/controllers/pc/order_draw.go +++ b/controllers/pc/order_draw.go @@ -111,9 +111,15 @@ type OrderLadderResult struct { //获取所有订单奖品 func (t *OrderDrawCtl) List() { activityId := t.MustGetInt64("activity_id") + customerId := t.MustGetUID() + + customer := new(models.Customer) + exist, err := models.GetById(customer, customerId) + t.CheckErr(err) + t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") activity := new(models.Activity) - exist, err := models.GetById(activity, activityId) + exist, err = models.GetById(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") @@ -132,7 +138,7 @@ func (t *OrderDrawCtl) List() { // 多地区的一个坑:分配给主会场的area_id不是主账号的area_id area := new(models.AreaStore) - if t.MustGetCustomerPid() == 0 { + if customer.Pid == 0 { exist, err = area.GetMainAreaById(activityId) } else { exist, err = area.GetAreaStoreById(t.MustGetAreaId()) @@ -253,15 +259,21 @@ func (t *OrderDrawCtl) Draw() { ruleId := t.MustGetInt64("order_draw_rule_id") ladderId := t.MustGetInt64("order_draw_rule_ladder_id") number := t.MustGetInt("number") + customerId := t.MustGetUID() + + customer := new(models.Customer) + exist, err := models.GetById(customer, customerId) + t.CheckErr(err) + t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") activity := new(models.Activity) - exist, err := models.GetById(activity, activityId) + exist, err = models.GetById(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") t.CheckRunning(activity.Status) area := new(models.AreaStore) - if t.MustGetCustomerPid() == 0 { + if customer.Pid == 0 { exist, err = area.GetMainAreaById(activity.Id) } else { exist, err = area.GetAreaStoreById(t.MustGetAreaId()) diff --git a/controllers/pc/shake_red_envelope.go b/controllers/pc/shake_red_envelope.go index 22d9d0c..eea9e96 100644 --- a/controllers/pc/shake_red_envelope.go +++ b/controllers/pc/shake_red_envelope.go @@ -91,9 +91,15 @@ func (t *ShakeRedEnvelopeCtl) Stop() { func (t *ShakeRedEnvelopeCtl) List() { activityId := t.MustGetInt64("activity_id") + customerId := t.MustGetUID() + + customer := new(models.Customer) + exist, err := models.GetById(customer, customerId) + t.CheckErr(err) + t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") activity := new(models.Activity) - exist, err := models.GetById(activity, activityId) + exist, err = models.GetById(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") t.CheckRunning(activity.Status) @@ -106,7 +112,7 @@ func (t *ShakeRedEnvelopeCtl) List() { aIds = append(aIds, v.Id) } area := new(models.AreaStore) - if t.MustGetCustomerPid() == 0 { + if customer.Pid == 0 { exist, err = area.GetMainAreaById(activityId) } else { exist, err = area.GetAreaStoreById(t.MustGetAreaId()) diff --git a/libs/filter/filter.go b/libs/filter/filter.go index 902548e..9352577 100644 --- a/libs/filter/filter.go +++ b/libs/filter/filter.go @@ -24,3 +24,10 @@ func Replace(content string) string { } return filter.Replace(content, '*') } + +func Validate(content string) (bool, string) { + if filter == nil { + initFilter() + } + return filter.Validate(content) +}