Browse Source

watch num

master
黄梓健 5 years ago
parent
commit
bac418af7e
  1. 6
      controllers/client/live.go
  2. 6
      log/hdzj.log
  3. 1
      models/init_models.go
  4. 6
      models/live_config.go
  5. 50
      models/live_viewer.go

6
controllers/client/live.go

@ -7,12 +7,18 @@ import (
)
type LiveCtl struct {
//controllers.AuthorCtl
controllers.BaseCtl
}
// 详情
func (t *LiveCtl) Detail() {
activityId := t.MustGetInt64("activity_id")
//userId := t.MustGetUID()
var userId int64 = 0
err := new(models.LiveViewer).Record(userId, activityId)
t.CheckErr(err)
live := new(models.LiveConfig)
exist, err := live.GetByActivityId(activityId)

6
log/hdzj.log

@ -9,3 +9,9 @@
2020-04-01 18:28:54.848 ERROR logger/logger.go:92 check err {"error": "errcode: 40029, errmsg: invalid code, hints: [ req_id: NIaBpZFFE-LTy2HA ]"}
2020-04-01 18:31:58.104 ERROR logger/logger.go:92 check err {"error": "needs a pointer to a value"}
2020-04-01 18:35:07.725 ERROR logger/logger.go:92 check err {"error": "errcode: 40029, errmsg: invalid code, hints: [ req_id: rIaBI6yFe-2LduEa ]"}
2020-04-07 14:27:48.989 ERROR logger/logger.go:92 check err {"error": "Error 1146: Table 'hudongzhuanjia.ox_live_viewer' doesn't exist"}
2020-04-07 14:31:04.148 ERROR logger/logger.go:92 check err {"error": "Error 1146: Table 'hudongzhuanjia.ox_live_viewer' doesn't exist"}
2020-04-07 14:31:16.099 ERROR logger/logger.go:92 check err {"error": "Error 1146: Table 'hudongzhuanjia.ox_live_viewer' doesn't exist"}
2020-04-07 14:31:17.846 ERROR logger/logger.go:92 check err {"error": "Error 1146: Table 'hudongzhuanjia.ox_live_viewer' doesn't exist"}
2020-04-07 14:33:15.037 ERROR logger/logger.go:92 check err {"error": "Error 1292: Incorrect datetime value: '' for column 'created_at' at row 1"}
2020-04-07 14:33:46.303 ERROR logger/logger.go:92 check err {"error": "Error 1292: Incorrect datetime value: '' for column 'created_at' at row 1"}

1
models/init_models.go

@ -84,6 +84,7 @@ func init() {
new(UserRedPack),
new(RealSignList),
new(RealSignHistory),
new(LiveViewer),
)
fmt.Printf("error=======>%v\n\n", err)
}

6
models/live_config.go

@ -9,9 +9,9 @@ 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 '' comment('是否删除')"`
CreatedAt time.Time `json:"created_at" xorm:"not null comment('创建时间') DATETIME"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"`
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)"`

50
models/live_viewer.go

@ -0,0 +1,50 @@
package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
)
const LiveViewerTN = TableNamePrefix + "live_viewer"
type LiveViewer 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"`
UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户id') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('活动id') INT(11)"`
}
func (t *LiveViewer) TableName() string {
return LiveViewerTN
}
func (t *LiveViewer) Record(uid, aid int64) error {
session := core.GetXormAuto().NewSession()
defer session.Close()
session.Begin()
exist, err := session.Where("is_delete=0 and user_id=? and activity_id=?", uid, aid).Exist(t)
if err != nil {
session.Rollback()
return err
}
if exist {
session.Commit()
return nil
}
t.UserId = uid
t.ActivityId = aid
_, err = session.InsertOne(t)
if err != nil {
session.Rollback()
return err
}
_, err = session.Where("is_delete=0 and activity_id=?", aid).Incr("watch_num").Update(&LiveConfig{})
if err != nil {
session.Rollback()
return err
}
session.Commit()
return nil
}
Loading…
Cancel
Save