country.go 697 Bytes
Newer Older
1 2 3 4 5
package user_m

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
hujiebin's avatar
hujiebin committed
6
	"gorm.io/gorm"
7 8 9
	"hilo-group/myerr"
)

hujiebin's avatar
hujiebin committed
10 11
// 获取用户的国家,和所属的区域(是否阿语区)
// 默认国家给沙特
12 13 14 15 16 17 18
func GetUserCountryArea(model *domain.Model, id mysql.ID) (string, int, error) {
	type info struct {
		Name string
		Area int
	}
	res := new(info)
	if err := model.DB().Raw("select name, area from res_country where name = (select country from user where id = ?)", id).First(&res).Error; err != nil {
hujiebin's avatar
hujiebin committed
19 20 21 22 23
		if err != gorm.ErrRecordNotFound {
			return "", 0, myerr.WrapErr(err)
		}
		// gorm.ErrRecordNotFound
		return "KSA", 1, nil
24 25 26
	}
	return res.Name, res.Area, nil
}