label.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package init
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. "encoding/json"
  5. "fmt"
  6. "log"
  7. "strings"
  8. )
  9. type labelStruct struct {
  10. Code string `json:"code"`
  11. Title string `json:"title"`
  12. Keywords string `json:"keywords"`
  13. Description string `json:"description"`
  14. Url string `json:"url"`
  15. }
  16. // 地区code 信息
  17. type areaCodeInfo struct {
  18. Code string `json:"code"` //地区编码
  19. Area string `json:"area"` //省份
  20. City string `json:"city"` //城市
  21. District string `json:"district"` //区县
  22. Class int `json:"class"` //1:省份 2:城市 3:直辖市 4:县区
  23. RegionalCode string `json:"pcode"` //地区拼音简称
  24. Location int `json:"location"` //区位 1:华北 2:华中,3:东北,4:华中 5:华南 6:西南 7:西北
  25. }
  26. var LabelMap = map[string]labelStruct{}
  27. var (
  28. AreaMap = map[string]string{}
  29. CityMap = map[string]string{}
  30. DistrictMap = map[string]string{}
  31. AreaInfos []areaCodeInfo
  32. )
  33. /*
  34. *包含地区标签、信息类型标签、行业标签;
  35. *1、SEO信息展示
  36. *2、地区标签访问地址
  37. */
  38. func LabelInit() {
  39. labelList := MainMysql.SelectBySql(`select * from jy_label where status = ?`, 0)
  40. if labelList != nil && len(*labelList) > 0 {
  41. for _, v := range *labelList {
  42. names := MC.ObjToString(v["name"])
  43. url := ""
  44. switch MC.IntAll(v["mold"]) {
  45. case 1:
  46. url = fmt.Sprintf(C.LabelUrl.Area, MC.ObjToString(v["code"]))
  47. case 2:
  48. url = fmt.Sprintf(C.LabelUrl.Industry, MC.ObjToString(v["code"]))
  49. case 3:
  50. url = fmt.Sprintf(C.LabelUrl.SType, MC.ObjToString(v["code"]))
  51. if names == "拟建" || names == "采购意向" {
  52. continue
  53. }
  54. }
  55. for _, nv := range strings.Split(names, ",") {
  56. LabelMap[nv] = labelStruct{
  57. Code: MC.ObjToString(v["code"]),
  58. Title: MC.ObjToString(v["title"]),
  59. Keywords: MC.ObjToString(v["keywords"]),
  60. Description: MC.ObjToString(v["description"]),
  61. Url: url,
  62. }
  63. }
  64. }
  65. }
  66. }
  67. func AreaInit() {
  68. sql := `SELECT * FROM global_common_data.seo_area_code;`
  69. areaInfos := BaseMysql.SelectBySql(sql)
  70. if areaInfos != nil && len(*areaInfos) > 0 {
  71. AreaMap = map[string]string{}
  72. CityMap = map[string]string{}
  73. DistrictMap = map[string]string{}
  74. b, err := json.Marshal(*areaInfos)
  75. if err == nil {
  76. err = json.Unmarshal(b, &AreaInfos)
  77. }
  78. if err != nil {
  79. log.Println("初始化地区信息 err :", err)
  80. }
  81. if len(AreaInfos) > 0 {
  82. for _, a := range AreaInfos {
  83. if a.RegionalCode == "" {
  84. continue
  85. }
  86. switch a.Class {
  87. case 1, 3:
  88. if a.Area == "" {
  89. continue
  90. }
  91. AreaMap[a.Area] = a.RegionalCode
  92. case 2:
  93. if a.City == "" {
  94. continue
  95. }
  96. CityMap[a.City] = a.RegionalCode
  97. case 4:
  98. if a.District == "" {
  99. continue
  100. }
  101. DistrictMap[a.District] = a.RegionalCode
  102. }
  103. }
  104. }
  105. }
  106. }