mgr.go 999 Bytes
Newer Older
kzkzzzz's avatar
kzkzzzz 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 38 39 40 41 42 43 44 45 46 47 48
package dao

import (
	"gorm.io/gorm"
	"hilo/app/service/mgr/internal/model"
)

func (d *Dao) CheckMgrImeiExist(imei string) (bool, error) {
	var id int
	err := d.DB.Model(&model.MgrImei{}).Where("imei = ?", imei).Take(&id).Error
	if err != nil && err != gorm.ErrRecordNotFound {
		return false, err
	}

	if id > 0 {
		return true, nil
	}
	return false, nil
}

func (d *Dao) CheckMgrIpExist(ip string) (bool, error) {
	var id int
	err := d.DB.Model(&model.MgrIp{}).Where("ip = ?", ip).Take(&id).Error
	if err != nil && err != gorm.ErrRecordNotFound {
		return false, err
	}
	if id > 0 {
		return true, nil
	}
	return false, nil
}

func (d *Dao) GetMgrUserStatus(userId int64) (res *model.MgrUserStatus, err error) {
	res = &model.MgrUserStatus{}
	err = d.DB.Model(&model.MgrUserStatus{}).Where(&model.MgrUserStatus{
		UserId: userId,
	}).Take(res).Error

	// 正常状态
	if err == gorm.ErrRecordNotFound {
		res.Status = model.NormalStatus
		res.UserId = userId
		err = nil
		return
	}

	return
}