old_cp.go 1.11 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
package cp_m

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
	"gorm.io/gorm"
	"hilo-user/myerr"
)

type StatusCp = mysql.Type

const (
	Connect    StatusCp = 1
	Disconnect StatusCp = 2
)

type OldCp struct {
	mysql.Entity
	//必须保证userId1 > userId2
	UserId1     mysql.ID
	UserId2     mysql.ID
	Score       mysql.Num
	DayScore    mysql.Num
	PeriodDay   mysql.Str
	WeekScore   mysql.Num
	PeriodWeek  mysql.Str
	MonthScore  mysql.Num
	PeriodMonth mysql.Str
	Status      StatusCp
	//中断时长
	DisconnectSecond int64
}

func (OldCp) TableName() string {
	return "cp"
}

hujiebin's avatar
hujiebin committed
38 39
// 获取旧的绑定中的cp
func GetOldConnectCp(model *domain.Model, tmpUserId1 mysql.ID, tmpUserId2 mysql.ID) (*OldCp, error) {
hujiebin's avatar
hujiebin committed
40 41 42 43 44 45
	userId1 := tmpUserId1
	userId2 := tmpUserId2
	if tmpUserId1 < tmpUserId2 {
		userId1 = tmpUserId2
		userId2 = tmpUserId1
	}
hujiebin's avatar
hujiebin committed
46 47
	cp := OldCp{}
	if err := model.Db.Where(&OldCp{
hujiebin's avatar
hujiebin committed
48 49
		UserId1: userId1,
		UserId2: userId2,
hujiebin's avatar
hujiebin committed
50
		Status:  Connect,
hujiebin's avatar
hujiebin committed
51 52 53 54 55 56 57 58 59
	}).First(&cp).Error; err != nil {
		if err == gorm.ErrRecordNotFound {
			return nil, nil
		} else {
			return nil, myerr.WrapErr(err)
		}
	}
	return &cp, nil
}