From cdcaa7c6cc4aba87994d52013ac71aa2cf1eb623 Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Fri, 12 Jun 2020 15:44:00 +0800 Subject: [PATCH] fix:bug --- controllers/client/sign.go | 10 +++++++++- go.mod | 4 ++-- go.sum | 4 ++++ models/live_config.go | 1 + models/live_viewer.go | 4 ++++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/controllers/client/sign.go b/controllers/client/sign.go index 0d7b87b..4cb0fdb 100644 --- a/controllers/client/sign.go +++ b/controllers/client/sign.go @@ -27,7 +27,15 @@ func (t *SignCtl) CheckSign() { t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "直播活动不存在") if live.LiveMode == 2 { - if live.WatchNum+1 >= live.Limit { + var num = 0 + if live.LimitType == 1 { + count, err := models.CountLiveViewerByLiveConfigId(live.Id) + t.CheckErr(err) + num = int(count) + } else if live.LimitType == 2 { + num = live.WatchNum + 1 + } + if num >= live.Limit { t.ERROR("直播人数已满", code.MSG_LIVE_LIMIT_ENOUGH) return } diff --git a/go.mod b/go.mod index 88a4f6d..d173ef6 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.12 require ( github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.1 github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect - github.com/aws/aws-sdk-go v1.31.12 // indirect + github.com/aws/aws-sdk-go v1.32.0 // indirect github.com/chanxuehong/wechat v0.0.0-20200409104612-0a1fd76d7a3a github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect @@ -38,7 +38,7 @@ require ( go.uber.org/atomic v1.6.0 go.uber.org/zap v1.15.0 golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a // indirect - golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 // indirect + golang.org/x/sys v0.0.0-20200610111108-226ff32320da // indirect google.golang.org/appengine v1.6.5 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 gopkg.in/yaml.v2 v2.3.0 // indirect diff --git a/go.sum b/go.sum index b8464e6..4528f8b 100644 --- a/go.sum +++ b/go.sum @@ -45,6 +45,8 @@ github.com/aws/aws-sdk-go v1.30.7 h1:IaXfqtioP6p9SFAnNfsqdNczbR5UNbYqvcZUSsCAdTY github.com/aws/aws-sdk-go v1.30.7/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= github.com/aws/aws-sdk-go v1.31.12 h1:SxRRGyhlCagI0DYkhOg+FgdXGXzRTE3vEX/gsgFaiKQ= github.com/aws/aws-sdk-go v1.31.12/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= +github.com/aws/aws-sdk-go v1.32.0 h1:P38SNbJIasEcA9gAlz/AG309VvhNv2CfNIJXQ61Oh6I= +github.com/aws/aws-sdk-go v1.32.0/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/bndr/gotabulate v1.1.2 h1:yC9izuZEphojb9r+KYL4W9IJKO/ceIO8HDwxMA24U4c= github.com/bndr/gotabulate v1.1.2/go.mod h1:0+8yUgaPTtLRTjf49E8oju7ojpU11YmXyvq1LbPAb3U= @@ -459,6 +461,8 @@ golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 h1:opSr2sbRXk5X5/givKrrKj9HX golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 h1:OjiUf46hAmXblsZdnoSXsEUSKU8r1UEzcL5RVZ4gO9Y= golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200610111108-226ff32320da h1:bGb80FudwxpeucJUjPYJXuJ8Hk91vNtfvrymzwiei38= +golang.org/x/sys v0.0.0-20200610111108-226ff32320da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= diff --git a/models/live_config.go b/models/live_config.go index 01e5fb8..27becd5 100644 --- a/models/live_config.go +++ b/models/live_config.go @@ -40,6 +40,7 @@ type LiveConfig struct { Announcement string `json:"announcement" xorm:"not null default '' comment('公告内容') VARCHAR(255)"` WatchNum int `json:"watch_num" xorm:"not null default 0 comment('观看人数') INT(11)"` LikeNum int `json:"like_num" xorm:"not null default 0 comment('点赞数') INT(11)"` + LimitType int `json:"limit_type" xorm:"not null default 0 comment('限制方式1累计人数2峰值在线人数') TINYINT(11)"` Limit int `json:"limit" xorm:"not null default 0 comment('限制人数') INT(11)"` ImGroupId string `json:"im_group_id" xorm:"not null default '' comment('腾讯im聊天群id') VARCHAR(255)"` ImGroupName string `json:"im_group_name" xorm:"not null default '' comment('聊天群名称') VARCHAR(255)"` diff --git a/models/live_viewer.go b/models/live_viewer.go index 2ee3f6a..eebaff7 100644 --- a/models/live_viewer.go +++ b/models/live_viewer.go @@ -56,3 +56,7 @@ func GetLiveViewerByLiveConfigIds(ids interface{}) ([]*LiveViewer, error) { err := core.GetXormAuto().Where("is_delete=0").In("live_config_id", ids).Find(&viewers) return viewers, err } + +func CountLiveViewerByLiveConfigId(lid interface{}) (int64, error) { + return core.GetXormAuto().Where("is_delete=0 and live_config_id=?", lid).Count(&LiveViewer{}) +}