| 
					
				 | 
			
			
				@@ -82,7 +82,131 @@ class Api 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * 获取所有地区数据:json格式,生成js文件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 获取详细信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return mixed 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function getInfo($area, $col = 'id') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if ($area) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $area = explode(',', $area); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $result = array(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            foreach ($area as $k => $v) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if ($k == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $result[$k] = $this->getName('province', $v, true, $col); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } elseif ($k == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $result[$k] = $this->getName('city', $v, true, $col); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if ($col == 'id' && isset($result[1]['name']) && $result[0]['name'] == $result[1]['name']) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        unset($result[1]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } elseif ($k == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $result[$k] = $this->getName('county', $v, true, $col); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } elseif ($k == 3) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $result[$k] = $this->getName('town', $v, true, $col); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } elseif ($k == 4) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $result[$k] = $this->getName('village', $v, true, $col); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return $result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return array(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 根据地区id转成名称 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return mixed 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function string($area, $im = ',', $unset = true) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if ($area) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $area = explode(',', $area); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $result = array(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            foreach ($area as $k => $v) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if ($k == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $result[$k] = $this->getName('province', $v); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } elseif ($k == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $result[$k] = $this->getName('city', $v); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if ($result[0] == $result[1] && $unset) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        unset($result[1]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } elseif ($k == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $result[$k] = $this->getName('county', $v); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } elseif ($k == 3) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $result[$k] = $this->getName('town', $v); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } elseif ($k == 4) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $result[$k] = $this->getName('village', $v); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return implode($im, $result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private function getName($table, $value, $state = false, $col = 'id') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $name = '不限'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (($col == 'id' && $value > 0) || ($col != 'id' && $value)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $where[$col] = $value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $data = Dever::db('area/' . $table)->one($where); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if ($state) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return $data; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if ($data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $name = $data['name']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return $name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # 获取6位地区编码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function code($id, $len = 6) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $id = substr($id, 0, $len); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $id = str_pad($id, $len, '0', STR_PAD_RIGHT); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return $id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function getProvince() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return Dever::db('area/province')->getAll(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function getCity($province_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return Dever::db('area/city')->getAll(array('province_id' => $province_id)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function getCounty($city_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return Dever::db('area/county')->getAll(array('city_id' => $city_id)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function getTown($county_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return Dever::db('area/town')->getAll(array('county_id' => $county_id)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function getVillage($town_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return Dever::db('area/village')->getAll(array('town_id' => $town_id)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # 获取城市并根据首字母排序的 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function getCityToFirst() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $result = array(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $data = Dever::db('area/city')->getAll(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (Dever::import('pinyin')) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $result = Dever::sortPinyinFirst($data, 'pinyin_first'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return $result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 获取三级地区数据:json格式,生成js文件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @return mixed 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -229,116 +353,4 @@ class Api 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $assets = Dever::config('host')->uploadRes; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return str_replace($path, $assets, $file); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * 获取详细信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * @return mixed 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public function getInfo($area, $col = 'id') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($area) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $area = explode(',', $area); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $result = array(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            foreach ($area as $k => $v) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if ($k == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $result[$k] = $this->getName('province', $v, true, $col); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } elseif ($k == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $result[$k] = $this->getName('city', $v, true, $col); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if ($col == 'id' && isset($result[1]['name']) && $result[0]['name'] == $result[1]['name']) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        unset($result[1]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } elseif ($k == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $result[$k] = $this->getName('county', $v, true, $col); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } elseif ($k == 3) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $result[$k] = $this->getName('town', $v, true, $col); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } elseif ($k == 4) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $result[$k] = $this->getName('village', $v, true, $col); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return $result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return array(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * 根据地区id转成名称 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * @return mixed 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public function string($area, $im = ',', $unset = true) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($area) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $area = explode(',', $area); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $result = array(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            foreach ($area as $k => $v) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if ($k == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $result[$k] = $this->getName('province', $v); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } elseif ($k == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $result[$k] = $this->getName('city', $v); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if ($result[0] == $result[1] && $unset) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        unset($result[1]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } elseif ($k == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $result[$k] = $this->getName('county', $v); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } elseif ($k == 3) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $result[$k] = $this->getName('town', $v); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } elseif ($k == 4) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $result[$k] = $this->getName('village', $v); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return implode($im, $result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private function getName($table, $value, $state = false, $col = 'id') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $name = '不限'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (($col == 'id' && $value > 0) || ($col != 'id' && $value)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $where[$col] = $value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $data = Dever::db('area/' . $table)->one($where); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($state) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return $data; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $name = $data['name']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return $name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    # 获取6位地区编码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public function code($id, $len = 6) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $id = substr($id, 0, $len); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $id = str_pad($id, $len, '0', STR_PAD_RIGHT); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return $id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public function getProvince() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return Dever::db('area/province')->getAll(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public function getCity($province_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return Dever::db('area/city')->getAll(array('province_id' => $province_id)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public function getCounty($city_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return Dever::db('area/county')->getAll(array('city_id' => $city_id)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public function getTown($county_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return Dever::db('area/town')->getAll(array('county_id' => $county_id)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public function getVillage($town_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return Dever::db('area/village')->getAll(array('town_id' => $town_id)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |