|
@@ -2,7 +2,9 @@ package init
|
|
|
|
|
|
import (
|
|
|
MC "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
+ "log"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
@@ -14,7 +16,24 @@ type labelStruct struct {
|
|
|
Url string `json:"url"`
|
|
|
}
|
|
|
|
|
|
+// 地区code 信息
|
|
|
+type areaCodeInfo struct {
|
|
|
+ Code string `json:"code"` //地区编码
|
|
|
+ Area string `json:"area"` //省份
|
|
|
+ City string `json:"city"` //城市
|
|
|
+ District string `json:"district"` //区县
|
|
|
+ Class int `json:"class"` //1:省份 2:城市 3:直辖市 4:县区
|
|
|
+ RegionalCode string `json:"pcode"` //地区拼音简称
|
|
|
+ Location int `json:"location"` //区位 1:华北 2:华中,3:东北,4:华中 5:华南 6:西南 7:西北
|
|
|
+}
|
|
|
+
|
|
|
var LabelMap = map[string]labelStruct{}
|
|
|
+var (
|
|
|
+ AreaMap = map[string]string{}
|
|
|
+ CityMap = map[string]string{}
|
|
|
+ DistrictMap = map[string]string{}
|
|
|
+ AreaInfos []areaCodeInfo
|
|
|
+)
|
|
|
|
|
|
/*
|
|
|
*包含地区标签、信息类型标签、行业标签;
|
|
@@ -51,3 +70,44 @@ func LabelInit() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func AreaInit() {
|
|
|
+ sql := `SELECT * FROM global_common_data.seo_area_code;`
|
|
|
+ areaInfos := BaseMysql.SelectBySql(sql)
|
|
|
+ if areaInfos != nil && len(*areaInfos) > 0 {
|
|
|
+ AreaMap = map[string]string{}
|
|
|
+ CityMap = map[string]string{}
|
|
|
+ DistrictMap = map[string]string{}
|
|
|
+ b, err := json.Marshal(*areaInfos)
|
|
|
+ if err == nil {
|
|
|
+ err = json.Unmarshal(b, &AreaInfos)
|
|
|
+ }
|
|
|
+ if err != nil {
|
|
|
+ log.Println("初始化地区信息 err :", err)
|
|
|
+ }
|
|
|
+ if len(AreaInfos) > 0 {
|
|
|
+ for _, a := range AreaInfos {
|
|
|
+ if a.RegionalCode == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ switch a.Class {
|
|
|
+ case 1, 3:
|
|
|
+ if a.Area == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ AreaMap[a.Area] = a.RegionalCode
|
|
|
+ case 2:
|
|
|
+ if a.City == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ CityMap[a.City] = a.RegionalCode
|
|
|
+ case 4:
|
|
|
+ if a.District == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ DistrictMap[a.District] = a.RegionalCode
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|