package dal import ( "xiaoniaokuaiyan.com/xiaoniao/entity" "xiaoniaokuaiyan.com/xiaoniao/util" ) type City struct{} func (c *City) GetOpenList() ([]entity.City, error) { db := util.GetSqlDB() strSql := "select * from t_city where is_open = 1" var cityList = []entity.City{} err := db.Select(&cityList, strSql) if err != nil { return nil, err } return cityList, nil } func (c *City) GetCityListById(ids []int) ([]entity.City, error) { strIds := util.IntJoin(ids, ",") db := util.GetSqlDB() strSql := "select * from t_city where id in(" + strIds + ");" var cityList = []entity.City{} err := db.Select(&cityList, strSql) return cityList, err } func (c *City) GetCountyByCityId(cityId int) ([]entity.County, error) { db := util.GetSqlDB() strSql := "select * from t_county where city_id = ? and flag = 'Y';" var countyList = []entity.County{} err := db.Select(&countyList, strSql, cityId) return countyList, err } func (c *City) GetCityAllList() ([]entity.CityAll, error) { db := util.GetSqlDB() strSql := `SELECT t1.id AS province_id, t1.name AS province, t2.id AS city_id, t2.NAME AS city, t3.id AS country_id, t3.name AS country FROM t_province t1 LEFT JOIN t_city t2 ON t1.id = t2.province_id LEFT JOIN t_county t3 ON t3.city_id = t2.id where t3.flag = 'Y'` var cityAll = []entity.CityAll{} err := db.Select(&cityAll, strSql) return cityAll, err } var DefaultCityDal = &City{}