admin_user.go 828 字节
package models

import (
	"context"
	"time"

	"github.com/go-pg/pg/v10"
)

type AdminUser struct {
	tableName struct{} `pg:"admin_user"`
	//id
	Id int64 `pg:",pk"`
	//用户账号
	AdminAccount string `pg:",unique"`
	//用户名称
	AdminName string
	//账号密码
	Password string
	//是否是默认账号
	IsDefault bool `pg:",use_zero"`
	//账号是否可用
	IsUsable bool `json:"is_userable"`

	CreateAt time.Time
	UpdateAt time.Time
}

var _ pg.BeforeUpdateHook = (*AdminUser)(nil)

func (user *AdminUser) BeforeUpdate(ctx context.Context) (context.Context, error) {
	user.UpdateAt = time.Now()
	return ctx, nil
}

var _ pg.BeforeInsertHook = (*AdminUser)(nil)

func (user *AdminUser) BeforeInsert(ctx context.Context) (context.Context, error) {
	user.CreateAt = time.Now()
	user.UpdateAt = time.Now()
	return ctx, nil
}