Browse Source

live

master
黄梓健 5 years ago
parent
commit
2c19188db3
  1. 31
      controllers/client/live.go
  2. 16
      controllers/client/sign.go
  3. 1
      models/init_models.go
  4. 11
      models/live_config.go
  5. 4
      models/module_service_history.go

31
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,
})
}

16
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, "主活动不存在")

1
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)
}

11
models/live_config.go

@ -15,7 +15,7 @@ type LiveConfig struct {
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)"`
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)"`
@ -34,6 +34,7 @@ type LiveConfig struct {
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)"`
}
@ -42,6 +43,10 @@ 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)
}

4
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)
}
Loading…
Cancel
Save