admin_user.go 934 字节
package models

import (
	"context"
	"time"

	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"

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

type AdminUser struct {
	tableName struct{} `pg:"admin_user"`
	//id
	Id int64 `pg:",pk"`
	//用户账号
	Account string `pg:",unique"`
	//用户名称
	AdminName string
	//账号密码
	Password string
	//是否是默认账号
	IsDefault bool `pg:",use_zero"`
	//账号是否可用
	IsUsable bool `pg:",use_zero"`
	//用户的权限
	Permission []domain.AdminPermissionBase

	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
}