code.go 542 Bytes
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
package res_m

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
	"hilo-group/myerr"
)

type ResCode struct {
	mysql.Entity
	*domain.Model `gorm:"-"`
	Code          string
}

/**
 * true: 不存在成功, false: 已存在,不成功
 */
func CheckCode(model *domain.Model, code string) (bool, error) {
	var n int64
	if err := model.Db.Model(&ResCode{
		Code: code,
	}).Count(&n).Error; err != nil {
		return false, myerr.WrapErr(err)
	}
	if n == 0 {
		return true, nil
	} else {
		return false, nil
	}
}