mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-02-03 02:54:41 +08:00
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
// =================================================================================
|
|
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
|
// =================================================================================
|
|
|
|
package dao
|
|
|
|
import (
|
|
"context"
|
|
"github.com/gogf/gf/v2/container/gvar"
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
"hotgo/internal/consts"
|
|
"hotgo/internal/dao/internal"
|
|
)
|
|
|
|
// internalSysProvincesDao is internal type for wrapping internal DAO implements.
|
|
type internalSysProvincesDao = *internal.SysProvincesDao
|
|
|
|
// sysProvincesDao is the data access object for table hg_sys_provinces.
|
|
// You can define custom methods on it to extend its functionality as you wish.
|
|
type sysProvincesDao struct {
|
|
internalSysProvincesDao
|
|
}
|
|
|
|
var (
|
|
// SysProvinces is globally common accessible object for table hg_sys_provinces operations.
|
|
SysProvinces = sysProvincesDao{
|
|
internal.NewSysProvincesDao(),
|
|
}
|
|
)
|
|
|
|
// Fill with you ideas below.
|
|
|
|
// GetRegion 获取省市编码对应的地区名称
|
|
func (dao *sysProvincesDao) GetRegion(ctx context.Context, province int, city int, spilt ...string) (string, error) {
|
|
|
|
var (
|
|
provinceName *gvar.Var
|
|
cityName *gvar.Var
|
|
err error
|
|
)
|
|
// TODO 默认分隔符
|
|
spiltSymbol := "-"
|
|
if len(spilt) > 0 {
|
|
spiltSymbol = spilt[0]
|
|
}
|
|
|
|
if province > 0 {
|
|
provinceName, err = dao.Ctx(ctx).Where("id", province).Fields("title").Value()
|
|
if err != nil {
|
|
err = gerror.Wrap(err, consts.ErrorORM)
|
|
return "", err
|
|
}
|
|
|
|
if city > 0 {
|
|
cityName, err = dao.Ctx(ctx).Where("id", city).Fields("title").Value()
|
|
if err != nil {
|
|
err = gerror.Wrap(err, consts.ErrorORM)
|
|
return "", err
|
|
}
|
|
}
|
|
} else {
|
|
return "内网IP", nil
|
|
}
|
|
|
|
return provinceName.String() + spiltSymbol + cityName.String(), nil
|
|
}
|