|
@@ -36,13 +36,25 @@ class areaModel extends Model {
|
|
* @return array 键为id 值为名称字符串
|
|
* @return array 键为id 值为名称字符串
|
|
*/
|
|
*/
|
|
public function getTopLevelAreas() {
|
|
public function getTopLevelAreas() {
|
|
- $data = $this->getCache();
|
|
|
|
|
|
|
|
|
|
+ // 对象属性中有数据则返回
|
|
|
|
+ if ($this->cachedTopLevelAreas !== null)
|
|
|
|
+ return $this->cachedTopLevelAreas;
|
|
|
|
+
|
|
|
|
+ // 缓存中有数据则返回
|
|
$arr = array();
|
|
$arr = array();
|
|
|
|
+ if ($arr = rkcache('area_toplevelareas')) {
|
|
|
|
+ $this->cachedTopLevelAreas = $arr;
|
|
|
|
+ return $arr;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $data = $this->getCache();
|
|
foreach ($data['children'][0] as $i) {
|
|
foreach ($data['children'][0] as $i) {
|
|
$arr[$i] = $data['name'][$i];
|
|
$arr[$i] = $data['name'][$i];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ wkcache('area_toplevelareas', $arr);
|
|
|
|
+ $this->cachedTopLevelAreas = $arr;
|
|
return $arr;
|
|
return $arr;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -52,15 +64,29 @@ class areaModel extends Model {
|
|
* @return array 键为市级id 值为省级id
|
|
* @return array 键为市级id 值为省级id
|
|
*/
|
|
*/
|
|
public function getCityProvince() {
|
|
public function getCityProvince() {
|
|
- $data = $this->getCache();
|
|
|
|
|
|
|
|
|
|
+ // 对象属性中有数据则返回
|
|
|
|
+ if ($this->cachedCityProvince !== null)
|
|
|
|
+ return $this->cachedCityProvince;
|
|
|
|
+
|
|
|
|
+ // 缓存中有数据则返回
|
|
$arr = array();
|
|
$arr = array();
|
|
|
|
+ if ($arr = rkcache('area_cityprovince')) {
|
|
|
|
+ $this->cachedCityProvince = $arr;
|
|
|
|
+ return $arr;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 生成数据
|
|
|
|
+ $data = $this->getCache();
|
|
foreach ($data['parent'] as $k => $v) {
|
|
foreach ($data['parent'] as $k => $v) {
|
|
if ($v && $data['parent'][$v] == 0) {
|
|
if ($v && $data['parent'][$v] == 0) {
|
|
$arr[$k] = $v;
|
|
$arr[$k] = $v;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ wkcache('area_cityprovince', $arr);
|
|
|
|
+ $this->cachedCityProvince = $arr;
|
|
|
|
+
|
|
return $arr;
|
|
return $arr;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -205,5 +231,7 @@ class areaModel extends Model {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- protected $cachedData;
|
|
|
|
|
|
+ protected $cachedData; // 地区表缓存
|
|
|
|
+ protected $cachedTopLevelAreas; // 省名字缓存
|
|
|
|
+ protected $cachedCityProvince; // 市id缓存
|
|
}
|
|
}
|