country_mgr.go 997 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 31 32 33 34 35 36 37 38 39 40
package country_m

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
	"gorm.io/gorm"
	"hilo-user/_const/enum/country_e"
	"hilo-user/myerr"
)

type CountryMgrUser struct {
	mysql.Entity
	Country string
	UserId  mysql.ID
	Role    country_e.CountryMgrRole
}

// 获取国家管理人员
func GetCountryMgr(model *domain.Model, userId mysql.ID) (*CountryMgrUser, error) {
	cmu := new(CountryMgrUser)
	if err := model.Db.WithContext(model.MyContext.Context).Where("user_id = ?", userId).First(&cmu).Error; err != nil {
		if err == gorm.ErrRecordNotFound {
			return nil, nil
		} else {
			return nil, myerr.WrapErr(err)
		}
	}
	return cmu, nil
}

// 更新国家管理人员
func (cmu *CountryMgrUser) UpdateCountryMgr(userId mysql.ID, role country_e.CountryMgrRole, country string) *CountryMgrUser {
	cmu.UserId, cmu.Role, cmu.Country = userId, role, country
	return cmu
}

// 删除国家管理人员
func (cmu *CountryMgrUser) DeleteCountryMgr() {
	cmu.SetDel()
}