You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB
Go

3 years ago
package model
import (
"context"
3 years ago
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
"gorm.io/gorm"
)
3 years ago
var _ UserPlatformModel = (*customUserPlatformModel)(nil)
type (
// UserPlatformModel is an interface to be customized, add more methods here,
// and implement the added methods in customUserPlatformModel.
UserPlatformModel interface {
userPlatformModel
3 years ago
// FindOneByPlatformAndPUid 查询平台用户
FindOneByPlatformAndPUid(ctx context.Context, platform, pUid string) (*UserPlatform, error)
FindUpdatableList(ctx context.Context, duration int64, num int64) ([]UserPlatform, error)
3 years ago
}
customUserPlatformModel struct {
*defaultUserPlatformModel
}
)
// NewUserPlatformModel returns a model for the database table.
3 years ago
func NewUserPlatformModel(conn *gorm.DB) UserPlatformModel {
3 years ago
return &customUserPlatformModel{
defaultUserPlatformModel: newUserPlatformModel(conn),
}
}
3 years ago
func (m *customUserPlatformModel) FindOneByPlatformAndPUid(ctx context.Context, platform, pUid string) (*UserPlatform, error) {
var resp UserPlatform
3 years ago
err := m.conn.WithContext(ctx).Model(&UserPlatform{}).Where("`platform` = ? AND `p_uid` = ?", platform, pUid).Take(&resp).Error
switch err {
case nil:
return &resp, nil
3 years ago
case gormc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *customUserPlatformModel) FindUpdatableList(ctx context.Context, duration int64, num int64) ([]UserPlatform, error) {
var resp []UserPlatform
err := m.conn.WithContext(ctx).
Where("`p_info = ? AND `update_time` < (NOW() - INTERVAL ? HOUR LIMIT ?", "{}", duration, num).
Find(&resp).Error
switch err {
case nil:
return resp, nil
case gormc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}