package init import ( MC "app.yhyue.com/moapp/jybase/common" "encoding/json" "fmt" "log" "strings" ) type labelStruct struct { Code string `json:"code"` Title string `json:"title"` Keywords string `json:"keywords"` Description string `json:"description"` 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 ) /* *包含地区标签、信息类型标签、行业标签; *1、SEO信息展示 *2、地区标签访问地址 */ func LabelInit() { labelList := MainMysql.SelectBySql(`select * from jy_label where status = ?`, 0) if labelList != nil && len(*labelList) > 0 { for _, v := range *labelList { names := MC.ObjToString(v["name"]) url := "" switch MC.IntAll(v["mold"]) { case 1: url = fmt.Sprintf(C.LabelUrl.Area, MC.ObjToString(v["code"])) case 2: url = fmt.Sprintf(C.LabelUrl.Industry, MC.ObjToString(v["code"])) case 3: url = fmt.Sprintf(C.LabelUrl.SType, MC.ObjToString(v["code"])) if names == "拟建" || names == "采购意向" { continue } } for _, nv := range strings.Split(names, ",") { LabelMap[nv] = labelStruct{ Code: MC.ObjToString(v["code"]), Title: MC.ObjToString(v["title"]), Keywords: MC.ObjToString(v["keywords"]), Description: MC.ObjToString(v["description"]), Url: url, } } } } } 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 } } } } }