From 2c19188db3ecc01bd4eecacf10ced90c04be8e7a Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Wed, 8 Apr 2020 13:20:04 +0800 Subject: [PATCH] live --- controllers/client/live.go | 31 +++++++++++++++++++ controllers/client/sign.go | 16 +++++++++- models/init_models.go | 1 + models/live_config.go | 65 +++++++++++++++++++++------------------- models/module_service_history.go | 4 +++ 5 files changed, 86 insertions(+), 31 deletions(-) diff --git a/controllers/client/live.go b/controllers/client/live.go index 6bf53da..aaaaeb8 100644 --- a/controllers/client/live.go +++ b/controllers/client/live.go @@ -8,11 +8,13 @@ import ( type LiveCtl struct { controllers.AuthorCtl + //controllers.BaseCtl } // 详情 func (t *LiveCtl) Detail() { activityId := t.MustGetInt64("activity_id") + //var userId int64 = 0 userId := t.MustGetUID() err := new(models.LiveViewer).Record(userId, activityId) @@ -26,3 +28,32 @@ func (t *LiveCtl) Detail() { live.AdminLiveUrl = "" t.JSON(live) } + +func (t *LiveCtl) Like() { + activityId := t.MustGetInt64("activity_id") + //userId := t.MustGetUID() + + _, err := new(models.LiveConfig).Like(activityId) + t.CheckErr(err) + + live := new(models.LiveConfig) + exist, err := live.GetByActivityId(activityId) + t.CheckErr(err) + t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "直播活动不存在") + t.JSON(map[string]interface{}{ + "like": live.LikeNum, + "watch": live.WatchNum, + }) +} + +func (t *LiveCtl) LoopQuery() { + activityId := t.MustGetInt64("activity_id") + live := new(models.LiveConfig) + exist, err := live.GetByActivityId(activityId) + t.CheckErr(err) + t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "直播活动不存在") + t.JSON(map[string]interface{}{ + "like": live.LikeNum, + "watch": live.WatchNum, + }) +} diff --git a/controllers/client/sign.go b/controllers/client/sign.go index f811f8b..0bb9b3e 100644 --- a/controllers/client/sign.go +++ b/controllers/client/sign.go @@ -22,8 +22,22 @@ func (t *SignCtl) CheckSign() { activityId := t.MustGetInt64("activity_id") uid := t.MustGetUID() + live := new(models.LiveConfig) + exist, err := live.GetByActivityId(activityId) + t.CheckErr(err) + t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "直播活动不存在") + if live.AdaptationFunc != nil { + exist, err = new(models.ModuleServiceHistory).ExistSignModule(live.AdaptationFunc) + t.CheckErr(err) + if !exist { + t.JSON(!exist) + } + } else { + t.JSON(true) + } + activity := 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, "主活动不存在") diff --git a/models/init_models.go b/models/init_models.go index ccc0cde..8c19b1d 100644 --- a/models/init_models.go +++ b/models/init_models.go @@ -85,6 +85,7 @@ func init() { new(RealSignList), new(RealSignHistory), new(LiveViewer), + new(LiveConfig), ) fmt.Printf("error=======>%v\n\n", err) } diff --git a/models/live_config.go b/models/live_config.go index 12dd2ca..3d96af8 100644 --- a/models/live_config.go +++ b/models/live_config.go @@ -8,40 +8,45 @@ import ( const LiveConfigTN = TableNamePrefix + "live_config" type LiveConfig struct { - Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"` - IsDelete bool `json:"-" xorm:"not null default 0 comment('是否删除') TINYINT(1)"` - CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"` - UpdatedAt time.Time `json:"updated_at" xorm:"not null updated default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"` - LiveSwitch int `json:"live_switch" xorm:"not null default 0 comment('直播开关0关1开') INT(11)"` - ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"` - LiveRoomId string `json:"live_room_id" xorm:"not null default '' comment('直播间id') VARCHAR(128)"` - AdaptationFunc string `json:"adaptation_func" xorm:"not null default '' comment('选中的适配功能及互动已买的服务id,json格式') VARCHAR(255)"` - StartTime time.Time `json:"start_time" xorm:"not null default '1970-01-01 08:00:00' comment('开播时间') DATETIME"` - EndTime time.Time `json:"end_time" xorm:"not null default '1970-01-01 08:00:00' comment('直播结束时间') DATETIME"` - LiveH5Url string `json:"live_h5_url" xorm:"not null default '' comment('h5直播地址') VARCHAR(255)"` - AdminLiveUrl string `json:"admin_live_url" xorm:"not null default '' comment('管理员直播地址,即直播页面中管理员登录页面') VARCHAR(255)"` - LiveH5Qrcode string `json:"live_h5_qrcode" xorm:"not null default '' comment('h5直播地址二维码') VARCHAR(255)"` - UnpayOrderTime string `json:"unpay_order_time" xorm:"not null default '' comment('待支付订单直播结束延长的时间戳') VARCHAR(128)"` - LiveType int `json:"live_type" xorm:"not null default 1 comment('直播方式1推流方式2app直播') INT(1)"` - VideoPushUrl string `json:"video_push_url" xorm:"not null default '' comment('视频推流地址') VARCHAR(255)"` - VideoPullUrlRtmp string `json:"video_pull_url_rtmp" xorm:"not null default '' comment('视频拉流地址即播放地址') VARCHAR(255)"` - VideoPullUrlFlv string `json:"video_pull_url_flv" xorm:"not null default '' comment('视频拉流地址即播放地址') VARCHAR(255)"` - VideoPullUrlM3u8 string `json:"video_pull_url_m3u8" xorm:"not null default '' comment('视频拉流地址即播放地址') VARCHAR(255)"` - LiveStartPage string `json:"live_start_page" xorm:"not null default '' comment('直播启动页图片') VARCHAR(255)"` - BeforeStartPage string `json:"before_start_page" xorm:"not null default '' comment('开播前图片') VARCHAR(255)"` - ActivityDesc string `json:"activity_desc" xorm:"not null default '' comment('活动介绍页图片') VARCHAR(255)"` - SharePosterImg string `json:"share_poster_img" xorm:"not null default '' comment('分享的海报图片') VARCHAR(255)"` - Status int `json:"status" xorm:"not null default 1 comment('直播的状态1未开始2进行中3已结束') VARCHAR(255)"` - Announcement string `json:"announcement" xorm:"not null default '' comment('公告内容') VARCHAR(255)"` - WatchNum int `json:"watch_num" xorm:"not null default 0 comment('观看人数') BIGINT(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)"` + Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"` + IsDelete bool `json:"-" xorm:"not null default 0 comment('是否删除') TINYINT(1)"` + CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"` + UpdatedAt time.Time `json:"updated_at" xorm:"not null updated default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"` + LiveSwitch int `json:"live_switch" xorm:"not null default 0 comment('直播开关0关1开') INT(11)"` + ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"` + LiveRoomId string `json:"live_room_id" xorm:"not null default '' comment('直播间id') VARCHAR(128)"` + AdaptationFunc []interface{} `json:"adaptation_func" xorm:"json default '' comment('选中的适配功能及互动已买的服务id,json格式') VARCHAR(255)"` + StartTime time.Time `json:"start_time" xorm:"not null default '1970-01-01 08:00:00' comment('开播时间') DATETIME"` + EndTime time.Time `json:"end_time" xorm:"not null default '1970-01-01 08:00:00' comment('直播结束时间') DATETIME"` + LiveH5Url string `json:"live_h5_url" xorm:"not null default '' comment('h5直播地址') VARCHAR(255)"` + AdminLiveUrl string `json:"admin_live_url" xorm:"not null default '' comment('管理员直播地址,即直播页面中管理员登录页面') VARCHAR(255)"` + LiveH5Qrcode string `json:"live_h5_qrcode" xorm:"not null default '' comment('h5直播地址二维码') VARCHAR(255)"` + UnpayOrderTime string `json:"unpay_order_time" xorm:"not null default '' comment('待支付订单直播结束延长的时间戳') VARCHAR(128)"` + LiveType int `json:"live_type" xorm:"not null default 1 comment('直播方式1推流方式2app直播') INT(1)"` + VideoPushUrl string `json:"video_push_url" xorm:"not null default '' comment('视频推流地址') VARCHAR(255)"` + VideoPullUrlRtmp string `json:"video_pull_url_rtmp" xorm:"not null default '' comment('视频拉流地址即播放地址') VARCHAR(255)"` + VideoPullUrlFlv string `json:"video_pull_url_flv" xorm:"not null default '' comment('视频拉流地址即播放地址') VARCHAR(255)"` + VideoPullUrlM3u8 string `json:"video_pull_url_m3u8" xorm:"not null default '' comment('视频拉流地址即播放地址') VARCHAR(255)"` + LiveStartPage string `json:"live_start_page" xorm:"not null default '' comment('直播启动页图片') VARCHAR(255)"` + BeforeStartPage string `json:"before_start_page" xorm:"not null default '' comment('开播前图片') VARCHAR(255)"` + ActivityDesc string `json:"activity_desc" xorm:"not null default '' comment('活动介绍页图片') VARCHAR(255)"` + SharePosterImg string `json:"share_poster_img" xorm:"not null default '' comment('分享的海报图片') VARCHAR(255)"` + Status int `json:"status" xorm:"not null default 1 comment('直播的状态1未开始2进行中3已结束') VARCHAR(255)"` + Announcement string `json:"announcement" xorm:"not null default '' comment('公告内容') VARCHAR(255)"` + WatchNum int `json:"watch_num" xorm:"not null default 0 comment('观看人数') BIGINT(11)"` + LikeNum int `json:"like_num" xorm:"not null default 0 comment('点赞数') BIGINT(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)"` } func (t *LiveConfig) TableName() string { return LiveConfigTN } -func (t *LiveConfig) GetByActivityId(id interface{}) (bool, error) { - return core.GetXormAuto().Where("is_delete=0 and activity_id=?", id).Get(t) +func (t *LiveConfig) GetByActivityId(aid interface{}) (bool, error) { + return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).Get(t) +} + +func (t *LiveConfig) Like(aid interface{}) (int64, error) { + return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).Incr("like_num").Update(t) } diff --git a/models/module_service_history.go b/models/module_service_history.go index f896962..8e80821 100644 --- a/models/module_service_history.go +++ b/models/module_service_history.go @@ -32,3 +32,7 @@ func (t *ModuleServiceHistory) Alias(name string) string { func (t *ModuleServiceHistory) GetByModuleIdAndName(id int64, name string) (bool, error) { return core.GetXormAuto().Where("is_delete=0 and service_module_id=? and name=?", id, name).Get(t) } + +func (t *ModuleServiceHistory) ExistSignModule(ids []interface{}) (bool, error) { + return core.GetXormAuto().Where("is_delete=0 and name=?", "签到").In("id", ids...).Exist(t) +}