|
|
@ -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 |
|
|
|
} |