rabin 8 months ago
commit
8edc6918de
19 changed files with 1659 additions and 0 deletions
  1. 294 0
      api/Data.php
  2. 251 0
      api/Import.php
  3. 7 0
      daemon/import.php
  4. 9 0
      index.php
  5. 157 0
      lib/Data.php
  6. 155 0
      lib/Manage.php
  7. 37 0
      manage/area_level.php
  8. 54 0
      manage/city.php
  9. 63 0
      manage/core.php
  10. 63 0
      manage/county.php
  11. 54 0
      manage/province.php
  12. 61 0
      manage/town.php
  13. 59 0
      manage/village.php
  14. 58 0
      table/city.php
  15. 90 0
      table/county.php
  16. 48 0
      table/level.php
  17. 44 0
      table/province.php
  18. 81 0
      table/town.php
  19. 74 0
      table/village.php

+ 294 - 0
api/Data.php

@@ -0,0 +1,294 @@
+<?php
+namespace Area\Api;
+use Dever;
+class Data
+{
+    private $default = array
+    (
+        'id' => -1,
+        'name' => '请选择',
+    );
+
+    private $search_default = array
+    (
+        'id' => -1,
+        'name' => '地区选择',
+    );
+
+	/**
+     * 获取地区数据
+     *
+     * @return mixed
+     */
+    public function get()
+    {
+        # 联动总数,默认到县区
+        $total = Dever::input('total');
+        if (!$total) {
+            $total = 3;
+        }
+        # 当前联动级别
+        $level = Dever::input('level');
+        if (!$level) {
+            $level = 1;
+        }
+        # 当前联动的上级id
+        $parent = Dever::input('parent');
+        if (!$parent) {
+            $parent = 0;
+        }
+
+        # 是否是搜索列表页
+        $search = Dever::input('search');
+        if ($search) {
+            $default = $this->search_default;
+            if ($level == 1) {
+                $default['name'] = '省份选择';
+            } elseif ($level == 2) {
+                $default['name'] = '城市选择';
+            } elseif ($level == 3) {
+                $default['name'] = '县区选择';
+            } elseif ($level == 4) {
+                $default['name'] = '街道选择';
+            } else {
+                $default['name'] = '社区选择';
+            }
+        } else {
+            $default = $this->default;
+        }
+        if ($parent < 0) {
+            Dever::error('error');
+        }
+        # 四级联动
+        if ($level == 1) {
+            $data = Dever::load('data', 'area')->getProvince();
+        } elseif ($level == 2) {
+            $data = Dever::load('data', 'area')->getCity($parent);
+        } elseif ($level == 3) {
+            $data = Dever::load('data', 'area')->getCounty($parent);
+        } elseif ($level == 4) {
+            $data = Dever::load('data', 'area')->getTown($parent);
+        } else {
+            $data = Dever::load('data', 'area')->getVillage($parent);
+        }
+
+        if (!$data) {
+            Dever::error('error');
+        }
+
+        if ($search) {
+            array_unshift($data, $default);
+        }
+        if ($level >= $total) {
+            foreach ($data as &$v) {
+                $v['leaf'] = true;
+            }
+        }
+        $result['total'] = $total;
+        $result['list'] = $data;
+        return $result;
+    }
+
+    # 获取区域状态
+    public function getStatus($area)
+    {
+        $temp = explode(',', $area);
+        $num = count($temp);
+        if ($num == 4 && isset($temp[3]) && $temp[3] > 0) {
+            # 街道
+            $where['id'] = $temp[3];
+            $table = 'town';
+        } elseif ($num == 3 && isset($temp[2]) && $temp[2] > 0) {
+            # 区县
+            $where['id'] = $temp[2];
+            $table = 'county';
+        } elseif ($num == 2 && isset($temp[1]) && $temp[1] > 0) {
+            # 城市
+            $where['id'] = $temp[1];
+            $table = 'city';
+        }
+        if ($table) {
+            $where['clear'] = true;
+            $info = Dever::db($table, 'area')->find($where);
+            if ($info && $info['status'] == 2) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    # 修改区域状态
+    public function upStatus($area, $status = 2)
+    {
+        $table = '';
+        $update['status'] = $status;
+        $temp = explode(',', $area);
+        $num = count($temp);
+        if ($num == 4 && isset($temp[3]) && $temp[3] > 0) {
+            # 街道
+            $update['where_id'] = $temp[3];
+            $table = 'town';
+        } elseif ($num == 3 && isset($temp[2]) && $temp[2] > 0) {
+            # 区县
+            $update['where_id'] = $temp[2];
+            $table = 'county';
+        } elseif ($num == 2 && isset($temp[1]) && $temp[1] > 0) {
+            # 城市
+            $update['where_id'] = $temp[1];
+            $table = 'city';
+        }
+
+        $state = false;
+        if ($table) {
+            $update['clear'] = true;
+            $state = Dever::db($table, 'area')->update($update);  
+        }
+        return $state;
+    }
+
+    /**
+     * 获取三级地区数据:json格式,生成js文件
+     *
+     * @return mixed
+     */
+    public function createJson()
+    {
+        $path = Dever::data() . 'upload/';
+        $create = Dever::input('create');
+        if (!$create) {
+            $create = 1;
+        }
+        $type = Dever::input('type');
+        if (!$type) {
+            $type = 'js';
+        }
+        if ($type == 'klist') {
+            $file = $path . 'city.' . $type . '.js';
+        } else {
+            $file = $path . 'city.' . $type;
+        }
+        
+        if (!is_file($file)) {
+            $create = 2;
+        }
+        if ($create == 2) {
+            $array = array
+            (
+                array
+                (
+                    'value' => "-1",
+                    'name' => '请选择',
+                ),
+            );
+
+            $klist = Dever::load('data', 'area')->getProvince();
+
+            if ($type == 'klist') {
+                $province = $klist;
+            } else {
+                $province = array_merge($array, $klist);
+            }
+            $province_data = array();
+            $city_data = array();
+            $county_data = array();
+
+            foreach ($province as $k => $v) {
+                $province_data[$k]['name'] = $v['name'];
+                $province_data[$k]['id'] = $v['value'];
+
+                if ($v['value'] <= 0) {
+                    continue;
+                }
+
+                $klist[$k]['text'] = $v['name'];
+                $klist[$k]['value'] = $v['value'];
+                $klist[$k]['children'] = Dever::load('data', 'area')->getCity($v['value']);
+
+                if ($type == 'klist') {
+                    $city = $klist[$k]['children'];
+                } else {
+                    $city = array_merge($array, $klist[$k]['children']);
+                }
+
+                foreach ($city as $k1 => $v1) {
+                    $city_data[$v['value']][$k1]['province'] = $v['name'];
+                    $city_data[$v['value']][$k1]['name'] = $v1['name'];
+                    $city_data[$v['value']][$k1]['id'] = $v1['value'];
+
+                    if ($v1['value'] <= 0) {
+                        continue;
+                    }
+
+                    $klist[$k]['children'][$k1]['text'] = $v1['name'];
+                    $klist[$k]['children'][$k1]['value'] = $v1['value'];
+                    $klist[$k]['children'][$k1]['children'] = Dever::load('data', 'area')->getCounty($v1['value']);
+
+                    if ($type == 'klist') {
+                        $county = $klist[$k]['children'][$k1]['children'];
+                    } else {
+                        $county = array_merge($array, $klist[$k]['children'][$k1]['children']);
+                    }
+
+                    foreach ($county as $k2 => $v2) {
+                        $klist[$k]['children'][$k1]['children'][$k2]['text'] = $v2['name'];
+                        $klist[$k]['children'][$k1]['children'][$k2]['value'] = $v2['value'];
+
+                        $county_data[$v1['value']][$k2]['city'] = $v1['name'];
+                        $county_data[$v1['value']][$k2]['name'] = $v2['name'];
+                        $county_data[$v1['value']][$k2]['id'] = $v2['value'];
+                    }
+                }
+            }
+
+            if ($type == 'klist') {
+                 $content = 'var cities = ' . Dever::json_encode($klist) . ';';
+            } elseif ($type == 'js') {
+                $content = 'var provinces = ' . Dever::json_encode($province_data) . ';';
+                $content .= 'var citys = ' . Dever::json_encode($city_data) . ';';
+                $content .= 'var areas = ' . Dever::json_encode($county_data) . ';';
+            } elseif ($type == 'plist') {
+                $content = '<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<array>' . "\r\n";
+
+                foreach ($province_data as $k => $v) {
+                    $content .= '    <dict>
+        <key>province</key>
+        <string>'.$v['name'].'</string>
+        <key>citys</key>
+        <array>';
+
+                    if (isset($city_data[$v['id']])) {
+                        foreach ($city_data[$v['id']] as $k1 => $v1) {
+                            $content .= "\r\n" . '            <dict>
+                <key>city</key>
+                <string>'.$v1['name'].'</string>
+                <key>districts</key>
+                <array>';
+
+                            if (isset($county_data[$v1['id']])) {
+                                foreach ($county_data[$v1['id']] as $k2 => $v2) {
+                                    $content .= "\r\n" . '                    <string>'.$v2['name'].'</string>';
+                                }
+
+                                $content .= "\r\n                ";
+                            }
+
+                            $content .= '</array>' . "\r\n" . '            </dict>';
+                        }
+
+                        $content .= "\r\n        ";
+                    }
+                    
+
+                    $content .= '</array>' . "\r\n" . '    </dict>' . "\r\n";
+                }
+                $content .= '</array>' . "\r\n" . '</plist>';
+            }
+            file_put_contents($file, $content);
+        }
+        $assets = Dever::config('host')->uploadRes;
+        return str_replace($path, $assets, $file);
+    }
+}

+ 251 - 0
api/Import.php

@@ -0,0 +1,251 @@
+<?php
+namespace Area\Api;
+set_time_limit(0);
+use Dever;
+
+class Import
+{
+    private $url = 'https://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/';
+
+    public function getUrl()
+    {
+        return $this->url;
+    }
+
+	/**
+     * 获取国家统计局最新的地区数据
+     *
+     * @return mixed
+     */
+    public function load()
+    {
+        $url = $this->url . 'index.html';
+        
+        $html = $this->html($url);
+
+        preg_match_all('/<td><a href="(.*?)">(.*?)<br \/><\/a><\/td>/i', $html, $result);
+
+        # 获取省份
+        $this->getProvince($result);
+
+        return 1;
+    }
+
+    public function getProvince($result)
+    {
+        $province = Dever::input('province');
+        $update = array();
+        if (isset($result[1]) && isset($result[2]) && $result[2]) {
+            foreach ($result[2] as $k => $v) {
+                $update['id'] = $this->id(trim($result[1][$k], '.html'));
+                $update['name'] = strip_tags($v);
+                $update = Dever::load('data', 'area')->pinyin($update);
+                $id = $this->up('province', $update['id'], $update);
+
+                # 获取城市
+                if ($province) {
+                    if ($update['name'] == $province) {
+                        $this->getCity($id, $update['name'], $result[1][$k]);
+                    }
+                } else {
+                    $this->getCity($id, $update['name'], $result[1][$k]);
+                }
+            }
+        }
+    }
+
+    public function getCity($province, $province_name, $link)
+    {
+        $city = Dever::input('city');
+
+        $url = $this->url . $link;
+        
+        $html = $this->html($url);
+
+        preg_match_all('/<tr class="citytr"><td><a href="(.*?)">(.*?)<\/a><\/td><td><a href="(.*?)">(.*?)<\/a><\/td><\/tr>/is', $html, $result);
+
+        $update = array();
+        if (isset($result[3]) && isset($result[4]) && $result[4]) {
+            foreach ($result[4] as $k => $v) {
+                $v = strip_tags($v);
+                if ($v == '市辖区') {
+                    $v = $province_name;
+                }
+                $update['id'] = $this->id($result[2][$k]);
+                $update['name'] = $v;
+                $update['province_id'] = $province;
+
+                $update = Dever::load('data', 'area')->pinyin($update);
+                $id = $this->up('city', $update['id'], $update);
+
+                if ($city) {
+                    if ($update['name'] == $city) {
+                        $this->getCounty($province, $id, $result[3][$k]);
+                    }
+                } else {
+                    $this->getCounty($province, $id, $result[3][$k]);
+                }
+            }
+        }
+    }
+
+    public function getCounty($province, $city, $source_link)
+    {
+        $url = $this->url . $source_link;
+
+        $temp = explode('/', $source_link);
+        $link = $temp[0];
+        
+        $html = $this->html($url);
+
+        preg_match_all('/<tr class="countytr"><td><a href="(.*?)">(.*?)<\/a><\/td><td><a href="(.*?)">(.*?)<\/a><\/td><\/tr>/i', $html, $result);
+
+        $update = array();
+        if (isset($result[3]) && isset($result[4]) && $result[4]) {
+            foreach ($result[4] as $k => $v) {
+                $update['id'] = $this->id($result[2][$k]);
+                $update['name'] = strip_tags($v);
+                $update['city_id'] = $city;
+                $update['province_id'] = $province;
+                $update['area'] = $province . ',' . $city;
+                $this->setLevelCounty($update);
+                $update = Dever::load('data', 'area')->pinyin($update);
+                $id = $this->up('county', $update['id'], $update);
+
+                # 获取街道
+                $this->getTown($province, $city, $id, $link . '/' . $result[3][$k]);
+            }
+        } else {
+            $city_info = Dever::db('city')->find($city);
+            $update['id'] = $city_info['id'];
+            $update['name'] = $city_info['name'] . '辖区';
+            $update['city_id'] = $city;
+            $update['province_id'] = $province;
+            $update['area'] = $province . ',' . $city;
+            $update['type'] = 1;
+            $update['level'] = 1;
+            $update['pinyin'] = $city_info['pinyin'];
+            $update['pinyin_first'] = $city_info['pinyin_first'];
+
+            $id = $this->up('county', $update['id'], $update);
+
+            # 获取街道
+            $this->getTown($province, $city, $id, $source_link, $html);
+        }
+    }
+
+    public function getTown($province, $city, $county, $link = false, $html = false)
+    {
+        if ($link) {
+            $url = $this->url . $link;
+
+            $temp = explode('/', $link);
+            $link = $temp[0] . '/' . $temp[1];
+            
+            $html = $this->html($url);
+        }
+        if (!$link && !$html) {
+            return;
+        }
+
+        preg_match_all('/<tr class="towntr"><td><a href="(.*?)">(.*?)<\/a><\/td><td><a href="(.*?)">(.*?)<\/a><\/td><\/tr>/i', $html, $result);
+
+        $update = array();
+        if (isset($result[3]) && isset($result[4]) && $result[4]) {
+            foreach ($result[4] as $k => $v) {
+                $update['id'] = $this->id($result[2][$k], 9);
+                $update['name'] = strip_tags($v);
+                $update['county_id'] = $county;
+                $update['city_id'] = $city;
+                $update['province_id'] = $province;
+                $update['area'] = $province . ',' . $city . ',' . $county;
+                $update = Dever::load('data', 'area')->pinyin($update);
+                $id = $this->up('town', $update['id'], $update);
+
+                # 获取社区
+                //$this->getVillage($province, $city, $county, $id, $link . '/' . $result[3][$k]);
+            }
+        }
+    }
+
+    public function getVillage($province, $city, $county, $town, $link)
+    {
+        $url = $this->url . $link;
+        
+        $html = $this->html($url);
+
+        preg_match_all('/<tr class="villagetr"><td>(.*?)<\/td><td>(.*?)<\/td><td>(.*?)<\/td><\/tr>/i', $html, $result);
+
+        $update = array();
+        if (isset($result[1]) && isset($result[2]) && isset($result[3])) {
+            foreach ($result[3] as $k => $v) {
+                $update['id'] = $this->id($result[1][$k], 12);
+                $update['code'] = $result[2][$k];
+                $update['name'] = strip_tags($v);
+                $update['town_id'] = $town;
+                $update['county_id'] = $county;
+                $update['city_id'] = $city;
+                $update['province_id'] = $province;
+                $update['area'] = $province . ',' . $city . ',' . $county . ',' . $town;
+                $update = Dever::load('data', 'area')->pinyin($update);
+                $this->up('village', $update['id'], $update);
+            }
+        }
+    }
+
+    public function id($id, $len = 6)
+    {
+        $id = substr($id, 0, $len);
+        $id = str_pad($id, $len, '0', STR_PAD_RIGHT);
+        return $id;
+    }
+
+    public function setLevelCounty(&$update)
+    {
+        $num = substr($update['id'], 4);
+
+        # type = 1城区 2郊区 3县城 4经济技术开发 5县级市
+        if ($update['name'] == '门头沟区') {
+            $update['type'] = 2;
+            $update['level'] = 2;
+        } elseif ($num <= 10) {
+            $update['type'] = 1;
+            $update['level'] = 1;
+        } elseif ($num > 10 && $num <= 20) {
+            $update['type'] = 2;
+            $update['level'] = 2;
+        } elseif ($num > 20 && $num <= 70) {
+            $update['type'] = 3;
+            $update['level'] = 3;
+        } elseif ($num > 70 && $num <= 80) {
+            $update['type'] = 4;
+            $update['level'] = 2;
+        } elseif ($num >= 80) {
+            $update['type'] = 5;
+            $update['level'] = 2;
+        }
+    }
+
+    public function up($table, $id, $data)
+    {
+        $db = Dever::db($table, 'area');
+        $info = $db->find($id);
+        if (!$info) {
+            $db->insert($data);
+        } else {
+            $db->update($info['id'], $data);
+        }
+        return $id;
+    }
+
+    private function html($url)
+    {
+        $html = Dever::curl($url)->result();
+
+        //$html = Dever::convert($html, "UTF-8", "GBK");
+        $html = preg_replace('//', '', $html); // 去掉HTML注释
+        $html = preg_replace('/\s+/', ' ', $html); // 清除多余的空格
+        $html = preg_replace('/>\s</', '><', $html); // 去掉标记之间的空格
+        return $html;
+    }
+}

+ 7 - 0
daemon/import.php

@@ -0,0 +1,7 @@
+<?php
+
+define('DEVER_DAEMON', true);
+
+include(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../index.php');
+
+Dever::load('area/import.load');

+ 9 - 0
index.php

@@ -0,0 +1,9 @@
+<?php
+
+if (!defined('DEVER_APP_NAME')) {
+	# 这样定义就可以将组件重复使用
+	define('DEVER_APP_NAME', 'area');
+}
+define('DEVER_APP_LANG', '地区设置');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+include(DEVER_APP_PATH . '../../boot.php');

+ 157 - 0
lib/Data.php

@@ -0,0 +1,157 @@
+<?php
+namespace Area\Lib;
+use Dever;
+class Data 
+{
+    public function getProvince()
+    {
+        return Dever::db('province', 'area')->select(array('status' => 1));
+    }
+
+    public function getCity($province_id)
+    {
+        if ($province_id) {
+            $where['province_id'] = $province_id;
+        }
+        $where['status'] = 1;
+        return Dever::db('city', 'area')->select($where);
+    }
+
+    public function getCounty($city_id)
+    {
+        if ($city_id) {
+            $where['city_id'] = $city_id;
+        }
+        $where['status'] = 1;
+        return Dever::db('county', 'area')->select($where);
+    }
+
+    public function getTown($county_id)
+    {
+        if ($county_id) {
+            $where['county_id'] = $county_id;
+        }
+        $where['status'] = 1;
+        return Dever::db('town', 'area')->select($where);
+    }
+
+    public function getVillage($town_id)
+    {
+        if ($town_id) {
+            $where['town_id'] = $town_id;
+        }
+        $where['status'] = 1;
+        return Dever::db('village', 'area')->select($where);
+    }
+
+    # 获取城市并根据首字母排序的
+    public function getCityToFirst()
+    {
+        $result = array();
+        $data = $this->getCity(false);
+        if (Dever::import('pinyin')) {
+            $result = Dever::sortPinyinFirst($data, 'pinyin_first');
+        }
+        return $result;
+    }
+
+    /**
+     * 获取详细信息
+     *
+     * @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 = ',', $name = '不限', $unset = true, $check = false)
+    {
+        if ($area) {
+            if (is_string($area)) {
+                $area = explode(',', $area);
+            }
+            
+            $result = array();
+            foreach ($area as $k => $v) {
+                if ($k == 0) {
+                    $result[$k] = $this->getName('province', $v, false, 'id', $name);
+                } elseif ($k == 1) {
+                    $result[$k] = $this->getName('city', $v, false, 'id', $name);
+                    if (isset($result[0]) && $result[0] == $result[1] && $unset) {
+                        unset($result[1]);
+                    }
+                } elseif ($k == 2) {
+                    $parent = $area[0] . ',' . $area[1];
+                    $result[$k] = $this->getName('county', $v, false, 'id', $name, $check, $parent);
+                } elseif ($k == 3) {
+                    $parent = $area[0] . ',' . $area[1] . ',' . $area[2];
+                    $result[$k] = $this->getName('town', $v, false, 'id', $name, $check, $parent);
+                } elseif ($k == 4) {
+                    $result[$k] = $this->getName('village', $v, false, 'id', $name);
+                } else {
+                    $result[$k] = '';
+                }
+                if (isset($result[$k]) && !$result[$k]) {
+                    unset($result[$k]);
+                }
+            }
+            return implode($im, $result);
+        }
+        return '';
+    }
+
+
+    private function getName($table, $value, $state = false, $col = 'id', $name = '不限', $check = false, $area = array())
+    {
+        if (($col == 'id' && $value > 0) || ($col != 'id' && $value)) {
+            $where[$col] = $value;
+            $data = Dever::db($table, 'area')->find($where);
+            if ($state) {
+                return $data;
+            }
+            if ($data) {
+                $name = $data['name'];
+                if ($check && $area && $data['area'] != $area) {
+                    $name = '<font style="color:red">'.$name.'(错误)</font>';
+                }
+            }
+        }
+        return $name;
+    }
+
+    public function pinyin($data)
+    {
+        if (Dever::project('pinyin') && $data['name']) {
+            $data['pinyin'] = Dever::load('convert', 'pinyin')->getPinyin($data['name']);
+            $data['pinyin_first'] = Dever::load('convert', 'pinyin')->getPinyinFirst($data['name']);
+        }
+        return $data;
+    }
+}

+ 155 - 0
lib/Manage.php

@@ -0,0 +1,155 @@
+<?php
+namespace Area\Lib;
+use Dever;
+class Manage
+{
+    public function up($db, $data)
+    {
+        if (isset($data['area'])) {
+            $temp = is_string($data['area']) ? explode(',', $data['area']) : $data['area'];
+            $data['province_id'] = $temp[0];
+            $data['city_id'] = $temp[1];
+            if (isset($temp[2])) {
+                $data['county_id'] = $temp[2];
+            }
+            if (isset($temp[3])) {
+                $data['town_id'] = $temp[3];
+            }
+        }
+        $data = Dever::load('area/data')->pinyin($data);
+        return $data;
+    }
+
+    public function upLevel($db, $data)
+    {
+        $update = array();
+        $city = $data['city'];
+        if ($city) {
+            Dever::db('city', 'area')->update(array('level_id' => $data['id']), array('level_id' => -1));
+            $city = explode('、', $city);
+            foreach ($city as $k => $v) {
+                $v = trim($v);
+                if (!$v) {
+                    continue;
+                }
+                Dever::db('city', 'area')->update(array('name' => array('like', $v)), array('level_id' => $data['id']));
+            }
+            if ($data['id'] == 1) {
+                $this->setTown();
+            }
+        }
+    }
+
+    # 设置国家镇级市、超级街道
+    public function setTown()
+    {
+        $data = array
+        (
+            # 镇级市
+            '河南省,安阳市,安阳县,水冶镇',
+            '河南省,信阳市,平桥区,明港镇',
+            '河南省,郑州市,巩义市,回郭镇',//'河南省,巩义市,安阳县,回郭镇',
+
+            '甘肃省,武威市,凉州区,黄羊镇',
+            '甘肃省,定西市,陇西县,首阳镇',
+            '甘肃省,天水市,甘谷县,磐安镇',
+
+            '广西,南宁市,宾阳县,黎塘镇',
+            '广西,梧州市,藤县,太平镇',
+            '广西,北海市,合浦县,公馆镇',
+            '广西,贵港市,平南县,大安镇',
+
+            '吉林省,长春市,公主岭市,范家屯镇',//'吉林省,四平市,公主岭市,范家屯镇',
+            '吉林省,四平市,梨树县,郭家店镇',
+            '吉林省,吉林市,吉林中国新加坡食品区,岔路河镇',// '吉林省,吉林市,永吉县,岔路河镇',
+            '吉林省,白山市,抚松县,松江河镇',//'吉林省,吉林市,抚松县,松江河镇',
+
+            '辽宁省,锦州市,北镇市,沟帮子街道  ',//'辽宁省,锦州市,北镇市,沟帮子镇',
+            '辽宁省,辽阳市,辽阳县,刘二堡镇',//'辽宁省,辽阳市,辽阳县,刘二堡新市镇',
+            '辽宁省,铁岭市,昌图县,八面城镇',
+
+            '黑龙江省,哈尔滨市,巴彦县,兴隆镇',
+            '黑龙江省,牡丹江市,海林市,柴河镇',
+            '黑龙江省,牡丹江市,宁安市,东京城镇',
+            '黑龙江省,伊春市,大箐山县,朗乡镇',//'黑龙江省,伊春市,铁力市,朗乡镇',
+            '黑龙江省,黑龙江农垦总局,建三江农垦分局,三江镇',//未知
+            '黑龙江省,红兴隆市,红兴隆农垦分局,兴隆镇',//未知
+            '黑龙江省,鹤岗市,萝北县,宝泉岭农场',//'黑龙江省,宝泉岭市,宝泉岭农垦分局,宝泉岭镇',
+            '黑龙江省,鸡西市,密山市,裴德镇',//'黑龙江省,牡丹江市,牡丹江农垦分局,裴德镇',
+            '黑龙江省,黑河市,嫩江市,双山镇',//'黑龙江省,九三垦区分局,九三垦区分局,双山镇',
+
+            '江苏省,苏州市,吴江区,盛泽镇',
+            '江苏省,无锡市,宜兴市,丁蜀镇',
+            '江苏省,南通市,启东市,启东吕四镇',//未知
+
+            '河北省,廊坊市,三河市,燕郊镇',
+            '河北省,廊坊市,霸州市,胜芳镇',
+
+            '江西省,南昌市,南昌县,向塘镇',
+
+            '安徽省,宿州市,萧县,黄口镇',
+            '安徽省,亳州市,谯城区,古城镇',
+
+            '湖南省,郴州市,永兴县,马田镇',
+            '湖南省,怀化市,洪江市,安江镇',
+            '湖南省,益阳市,桃江县,灰山港镇',
+
+            '湖北省,襄阳市,樊城区,太平店镇',//'湖北省,襄阳市,襄阳区,太平店镇',
+            '湖北省,荆门市,钟祥市,胡集镇',
+            '湖北省,孝感市,汉川市,马口镇',
+            '湖北省,宜昌市,夷陵区,龙泉镇',
+
+            '福建省,漳州市,龙海市,角美镇',
+            '福建省,泉州市,南安市,水头镇',
+            '福建省,泉州市,晋江市,东石镇',
+            '福建省,莆田市,秀屿区,忠门镇',
+
+            '浙江省,温州,苍南县,龙港镇',
+            '浙江省,绍兴市,诸暨市,店口镇',
+
+            '重庆市,重庆市,江津区,白沙镇',
+            '重庆市,重庆市,大足区,龙水镇',
+            '重庆市,重庆市,九龙坡区,西彭镇',
+
+            '四川省,南充市,仪陇县,金城镇',
+            '四川省,内江市,资中县,重龙镇',
+            '四川省,广元市,利州区,宝轮镇',
+            '四川省,达州市,宣汉县,南坝镇',
+
+            '广东省,佛山市,南海区,狮山镇',
+            '广东省,东莞市,东莞市,长安镇',
+            '广东省,东莞市,东莞市,虎门镇',
+            '广东省,东莞市,东莞市,塘厦镇',
+
+            # 超级街道
+            '广东省,深圳市,南山区,粤海街道',
+            '广东省,深圳市,龙岗区,坂田街道',
+            '广东省,深圳市,龙岗区,布吉街道',
+            '广东省,深圳市,龙岗区,龙城街道',
+            '广东省,深圳市,龙岗区,平湖街道',
+            '广东省,深圳市,龙岗区,龙岗街道',
+        );
+
+        foreach ($data as $k => $v) {
+            $temp = explode(',', $v);
+            if (isset($temp[3])) {
+                $province = Dever::db('province', 'area')->find(array('name' => array('like', $temp[0])));
+                if ($province) {
+                    $city = Dever::db('city', 'area')->find(array('name' => array('like', $temp[1]), 'province_id' => $province['id']));
+                    if ($city) {
+                        $county = Dever::db('county', 'area')->find(array('name' => array('like', $temp[2]), 'city_id' => $city['id']));
+                        if ($county) {
+                            if (strstr($temp[3], '街道')) {
+                                $type = 3;
+                            } else {
+                                $type = 2;
+                            }
+                            $town = Dever::db('town', 'area')->find(array('name' => array('like', $temp[3]), 'county_id' => $county['id'], 'type' => $type));
+                        }
+                    }
+                }
+            }
+        }
+        return 'ok';
+    }
+}

+ 37 - 0
manage/area_level.php

@@ -0,0 +1,37 @@
+<?php
+return array
+(
+    'source' => 'area/level',
+    'list' => array
+    (
+        'field'      => array
+        (
+            'name',
+            'level',
+            'city',
+        ),
+        'button' => array
+        (
+            '新增' => 'fastadd',
+        ),
+        'data_button' => array
+        (
+            '编辑' => 'fastedit',
+        ),
+    ),
+    'update' => array
+    (
+        'field'    => array
+        (
+            'name',
+            'level',
+            'city' => array
+            (
+                'type' => 'textarea',
+                'autosize' => array('minRows' => 6),
+                'desc' => '多个城市用叹号、隔开',
+            ),
+        ),
+        'end' => 'area/manage.upLevel',
+    ),
+);

+ 54 - 0
manage/city.php

@@ -0,0 +1,54 @@
+<?php
+return array
+(
+    'list' => array
+    (
+        'field'      => array
+        (
+            'id',
+            'name',
+            'pinyin',
+            'pinyin_first',
+            'province_id',
+            'level_id',
+            'sort' => 'input',
+            'status' => array
+            (
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+            'cdate',
+        ),
+        'button' => array
+        (
+            '新增' => 'fastadd',
+        ),
+        'data_button' => array
+        (
+            '编辑' => 'fastedit',
+        ),
+        'search'    => array
+        (
+            'name',
+            'status',
+        ),
+    ),
+    'update' => array
+    (
+        'field'    => array
+        (
+            'name' => array
+            (
+                'rules' => true,
+            ),
+            //'pinyin',
+            //'pinyin_first',
+            'province_id' => 'select',
+            'level_id',
+            //'sort',
+        ),
+        'start' => 'area/manage.up',
+    ),
+);

+ 63 - 0
manage/core.php

@@ -0,0 +1,63 @@
+<?php
+return array
+(
+    'menu' => array
+    (
+        'area' => array
+        (
+            'parent' => 'set',
+            'name' => '行政区域',
+            'icon' => 'price-tag-2-line',
+            'sort' => '80',
+        ),
+
+        'area_level' => array
+        (
+            'parent'    => 'area',
+            'name'      => '城市等级',
+            'icon'      => 'capsule-line',
+            'sort'      => '1',
+        ),
+
+        'province' => array
+        (
+            'parent'    => 'area',
+            'name'      => '省份',
+            'icon'      => 'copper-coin-line',
+            'sort'      => '2',
+        ),
+
+        'city' => array
+        (
+            'parent'    => 'area',
+            'name'      => '城市',
+            'icon'      => 'coupon-5-line',
+            'sort'      => '3',
+        ),
+
+        'county' => array
+        (
+            'parent'    => 'area',
+            'name'      => '区县',
+            'icon'      => 'coupon-3-line',
+            'sort'      => '4',
+        ),
+
+        'town' => array
+        (
+            'parent'    => 'area',
+            'name'      => '街镇',
+            'icon'      => 'compasses-line',
+            'sort'      => '5',
+        ),
+
+        /*
+        'village' => array
+        (
+            'parent'    => 'area',
+            'name'      => '社区',
+            'icon'      => 'contacts-line',
+            'sort'      => '6',
+        ),*/
+    ),
+);

+ 63 - 0
manage/county.php

@@ -0,0 +1,63 @@
+<?php
+return array
+(
+    'list' => array
+    (
+        'field'      => array
+        (
+            'id',
+            'name',
+            'pinyin',
+            'pinyin_first',
+            'area' => array
+            (
+                'show' => 'Dever::call("area/data.string", "{area}")',
+            ),
+            'type',
+            'level',
+            'sort' => 'input',
+            'status' => array
+            (
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+            'cdate',
+        ),
+        'button' => array
+        (
+            '新增' => 'fastadd',
+        ),
+        'data_button' => array
+        (
+            '编辑' => 'fastedit',
+        ),
+        'search'    => array
+        (
+            'name',
+            'status',
+        ),
+    ),
+    'update' => array
+    (
+        'field'    => array
+        (
+            'name' => array
+            (
+                'rules' => true,
+            ),
+            //'pinyin',
+            //'pinyin_first',
+            'area' => array
+            (
+                'type' => 'cascader',
+                'remote'    => 'area/data.get&total=2',
+            ),
+            'type' => 'radio',
+            'level' => 'radio',
+            //'sort',
+        ),
+        'start' => 'area/manage.up',
+    ),
+);

+ 54 - 0
manage/province.php

@@ -0,0 +1,54 @@
+<?php
+$info = Dever::project('area');
+$path = $info['setup'];
+return array
+(
+    'list' => array
+    (
+        'desc' => '导入数据请在服务器执行:php '.$path.'daemon/import.php 
+        数据来源:' . Dever::load('import', 'area', 'api')->getUrl(),
+        'field'      => array
+        (
+            'id',
+            'name',
+            'pinyin',
+            'pinyin_first',
+            'sort' => 'input',
+            'status' => array
+            (
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+            'cdate',
+        ),
+        'button' => array
+        (
+            '新增' => 'fastadd',
+        ),
+        'data_button' => array
+        (
+            '编辑' => 'fastedit',
+        ),
+        'search'    => array
+        (
+            'name',
+            'status',
+        ),
+    ),
+    'update' => array
+    (
+        'field'    => array
+        (
+            'name' => array
+            (
+                'rules' => true,
+            ),
+            //'pinyin',
+            //'pinyin_first',
+            //'sort',
+        ),
+        'start' => 'area/manage.up',
+    ),
+);

+ 61 - 0
manage/town.php

@@ -0,0 +1,61 @@
+<?php
+return array
+(
+    'list' => array
+    (
+        'field'      => array
+        (
+            'id',
+            'name',
+            'pinyin',
+            'pinyin_first',
+            'area' => array
+            (
+                'show' => 'Dever::call("area/data.string", "{area}")',
+            ),
+            'type',
+            'sort' => 'input',
+            'status' => array
+            (
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+            'cdate',
+        ),
+        'button' => array
+        (
+            '新增' => 'fastadd',
+        ),
+        'data_button' => array
+        (
+            '编辑' => 'fastedit',
+        ),
+        'search'    => array
+        (
+            'name',
+            'status',
+        ),
+    ),
+    'update' => array
+    (
+        'field'    => array
+        (
+            'name' => array
+            (
+                'rules' => true,
+            ),
+            //'pinyin',
+            //'pinyin_first',
+            'area' => array
+            (
+                'type' => 'cascader',
+                'remote'    => 'area/data.get&total=3',
+            ),
+            'type' => 'radio',
+            //'sort',
+        ),
+        'start' => 'area/manage.up',
+    ),
+);

+ 59 - 0
manage/village.php

@@ -0,0 +1,59 @@
+<?php
+return array
+(
+    'list' => array
+    (
+        'field'      => array
+        (
+            'id',
+            'name',
+            'pinyin',
+            'pinyin_first',
+            'area' => array
+            (
+                'show' => 'Dever::call("area/data.string", "{area}")',
+            ),
+            'sort' => 'input',
+            'status' => array
+            (
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+            'cdate',
+        ),
+        'button' => array
+        (
+            '新增' => 'fastadd',
+        ),
+        'data_button' => array
+        (
+            '编辑' => 'fastedit',
+        ),
+        'search'    => array
+        (
+            'name',
+            'status',
+        ),
+    ),
+    'update' => array
+    (
+        'field'    => array
+        (
+            'name' => array
+            (
+                'rules' => true,
+            ),
+            //'pinyin',
+            //'pinyin_first',
+            'area' => array
+            (
+                'type' => 'cascader',
+                'remote'    => 'area/data.get&total=3',
+            ),
+            //'sort',
+        ),
+        'start' => 'area/manage.up',
+    ),
+);

+ 58 - 0
table/city.php

@@ -0,0 +1,58 @@
+<?php
+return array
+(
+	'name' => '城市',
+	'order' => 'sort asc',
+	'struct' => array
+	(
+		'name'		=> array
+		(
+			'type' 		=> 'varchar(150)',
+			'name' 		=> '城市名称',
+		),
+
+		'pinyin'		=> array
+		(
+			'type' 		=> 'varchar(300)',
+			'name' 		=> '拼音',
+		),
+
+		'pinyin_first'		=> array
+		(
+			'type' 		=> 'varchar(30)',
+			'name' 		=> '拼音首字母',
+		),
+
+		'province_id'		=> array
+		(
+			'type' 		=> 'int(11)',
+			'name' 		=> '省份',
+			'value'		=> 'area/province',
+		),
+
+		'level_id'		=> array
+		(
+			'type' 		=> 'int(11)',
+			'name' 		=> '城市等级',
+			'value'		=> 'area/level',
+		),
+
+		'sort' => array
+        (
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => '1',
+        ),
+        'status' => array
+        (
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '启用',
+                2 => '关闭',
+            ),
+        ),
+	),
+);

+ 90 - 0
table/county.php

@@ -0,0 +1,90 @@
+<?php
+return array
+(
+	'name' => '区县',
+	'order' => 'sort asc',
+	'struct' => array
+	(
+		'name'		=> array
+		(
+			'type' 		=> 'varchar(150)',
+			'name' 		=> '区县名称',
+		),
+
+		'pinyin'		=> array
+		(
+			'type' 		=> 'varchar(300)',
+			'name' 		=> '拼音',
+		),
+
+		'pinyin_first'		=> array
+		(
+			'type' 		=> 'varchar(30)',
+			'name' 		=> '拼音首字母',
+		),
+
+		'area'       => array
+        (
+            'type'      => 'varchar(500)',
+            'name'      => '所在城市',
+        ),
+
+		'province_id'		=> array
+		(
+			'type' 		=> 'int(11)',
+			'name' 		=> '省份',
+		),
+
+		'city_id'		=> array
+		(
+			'type' 		=> 'int(11)',
+			'name' 		=> '城市',
+		),
+
+		'type'        => array
+        (
+            'type'      => 'tinyint(1)',
+            'name'      => '区县类型',
+            'default'	=> 1,
+            'value'		=> array
+			(
+				1 => '城区',
+				2 => '郊区',
+				3 => '县城',
+				4 => '经济技术开发区',
+				5 => '县级市',
+			),
+        ),
+
+        'level'        => array
+        (
+            'type'      => 'tinyint(1)',
+            'name'      => '区县级别',
+            'default'	=> 1,
+            'value'		=> array
+			(
+				1 => '核心区',
+				2 => '普通区',
+				3 => '边缘区',
+			),
+        ),
+
+        'sort' => array
+        (
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => '1',
+        ),
+        'status' => array
+        (
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '启用',
+                2 => '关闭',
+            ),
+        ),
+	),
+);

+ 48 - 0
table/level.php

@@ -0,0 +1,48 @@
+<?php
+
+return array
+(
+    'name' => '城市等级设置',
+    'order' => 'level asc',
+    'struct' => array
+    (
+        'name'      => array
+        (
+            'type'      => 'varchar(200)',
+            'name'      => '名称',
+        ),
+
+        'level'      => array
+        (
+            'type'      => 'int(11)',
+            'name'      => '等级数字',
+            'default'   => '1',
+        ),
+
+        'city'      => array
+        (
+            'type'      => 'text(255)',
+            'name'      => '城市',
+        ),
+    ),
+
+    'default' => array
+	(
+		'field' => 'id,name,level,city,cdate',
+		'value' => array
+		(
+			'1,"特一线城市", 1, "北京、上海、广州、深圳",' . DEVER_TIME,
+
+			'2,"一线城市", 2, "成都、重庆、杭州、武汉、西安、郑州、青岛、长沙、天津、苏州、南京、东莞、沈阳、合肥、佛山",' . DEVER_TIME,
+
+			'3,"二线城市", 3, "昆明、福州、无锡、厦门、哈尔滨、长春、南昌、济南、宁波、大连、贵阳、温州、石家庄、泉州、南宁、金华、常州、珠海、惠州、嘉兴、南通、中山、保定、兰州、台州、徐州、太原、绍兴、烟台、廊坊、海口、扬州",' . DEVER_TIME,
+
+			'4,"三线城市", 4, "汕头、潍坊、洛阳、乌鲁木齐、临沂、唐山、镇江、盐城、湖州、赣州、漳州、揭阳、江门、桂林、邯郸、泰州、济宁、呼和浩特、咸阳、芜湖、三亚、阜阳、淮安 、银川、衡阳、上饶、柳州、淄博、莆田、绵阳、湛江、商丘、宜昌、沧州、连云港、南阳、蚌埠、驻马店、滁州、邢台、潮州、秦皇岛、肇庆、荆州、周口、马鞍山、清远、宿州、威海、九江、新乡、信阳、襄阳、岳阳、安庆、菏泽、宜春、黄冈、泰安、宿迁、株洲、宁德、鞍山、南充、六安、大庆、舟山、丽水、龙岩、湘潭、三明、梅州、南平、吉林、包头、郴州",' . DEVER_TIME,
+
+			'5,"四线城市", 5, "常德、渭南湖、孝感、运城、德州、张家口、鄂尔多斯、阳江、泸州、丹东、曲靖、乐山、许昌、晋中、安阳、齐齐哈尔、北海、宝鸡、抚州、景德镇、延安、抚顺、亳州、日照、西宁、衢州、、拉萨、淮北、焦作、平顶山、滨州、吉安、濮阳、眉山、池州、荆门、铜仁、长治、衡水、铜陵、承德、达州、邵阳、德阳、淮南、黄石、营口、东营、韶关、枣庄、怀化、宣城、临汾、聊城、盘锦、锦州、榆林、玉林、十堰、汕尾、咸宁、宜宾、永州、益阳、黔南州、黔东南、恩施、红河、大理、大同、鄂州、忻州、吕梁、黄山、开封、茂名、漯河、葫芦岛、河源、娄底、延边、丽江、佳木斯、牡丹江、西双版纳、六盘水、保山、毕节、安顺、百色、梧州、德宏、鹰潭、绥化、赤峰",' . DEVER_TIME,
+
+
+			'6,"五线城市", 6, "汉中、辽阳、四平、内江、新余、晋城、自贡、三门峡、本溪、防城港、铁岭、随州、广安、广元、天水、遂宁、萍乡、鹤壁、湘西、松原、阜新、酒泉、张家界、黔西南、昭通、河池、来宾、玉溪、钦州、云浮、克拉玛依、呼伦贝尔、贺州、通化、阳泉、朝阳、贵港、安康、通辽、朔州、伊犁、文山、楚雄、嘉峪关、凉山、资阳、锡林郭勒盟、雅安、普洱、崇左、庆阳、巴音郭楞(巴州)、乌兰察布、白山、昌吉、白城、兴安盟、定西、喀什、白银、陇南、巴彦淖尔、巴中、鸡西、乌海、临沧、海东、张掖、商洛、黑河、哈密、吴忠、攀枝花、双鸭山、阿克苏、石嘴山、阿拉善盟、海西、平凉、林芝、固原、武威、儋州、吐鲁番、甘孜、辽源、临夏、铜川、金昌、鹤岗、伊春、中卫、怒江、和田、迪庆、甘南、阿坝、 大兴安岭、七台河、山南、日喀则、塔城、博尔塔拉、昌都、阿勒泰、玉树、海南、黄南、果洛、克孜勒苏、阿里、海北、那曲、三沙",' . DEVER_TIME,
+		),
+	),
+);

+ 44 - 0
table/province.php

@@ -0,0 +1,44 @@
+<?php
+return array
+(
+	'name' => '省份',
+	'order' => 'sort asc',
+	'struct' => array
+	(
+		'name'		=> array
+		(
+			'type' 		=> 'varchar(150)',
+			'name' 		=> '省份名称',
+		),
+
+		'pinyin'		=> array
+		(
+			'type' 		=> 'varchar(300)',
+			'name' 		=> '拼音',
+		),
+
+		'pinyin_first'		=> array
+		(
+			'type' 		=> 'varchar(30)',
+			'name' 		=> '拼音首字母',
+		),
+
+		'sort' => array
+        (
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => '1',
+        ),
+        'status' => array
+        (
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '启用',
+                2 => '关闭',
+            ),
+        ),
+	),
+);

+ 81 - 0
table/town.php

@@ -0,0 +1,81 @@
+<?php
+return array
+(
+	'name' => '街镇',
+	'order' => 'sort asc',
+	'struct' => array
+	(
+		'name'		=> array
+		(
+			'type' 		=> 'varchar(150)',
+			'name' 		=> '街镇名称',
+		),
+
+		'pinyin'		=> array
+		(
+			'type' 		=> 'varchar(300)',
+			'name' 		=> '拼音',
+		),
+
+		'pinyin_first'		=> array
+		(
+			'type' 		=> 'varchar(30)',
+			'name' 		=> '拼音首字母',
+		),
+
+		'area'       => array
+        (
+            'type'      => 'varchar(500)',
+            'name'      => '所在城市',
+        ),
+
+		'province_id'		=> array
+		(
+			'type' 		=> 'int(11)',
+			'name' 		=> '省份',
+		),
+
+		'city_id'		=> array
+		(
+			'type' 		=> 'int(11)',
+			'name' 		=> '城市',
+		),
+
+		'county_id'		=> array
+		(
+			'type' 		=> 'int(11)',
+			'name' 		=> '区县',
+		),
+
+		'type'        => array
+        (
+            'type'      => 'tinyint(1)',
+            'name'      => '街镇类型',
+            'default'   => '1',
+            'value'		=> array
+			(
+				1 => '普通街镇',
+				2 => '国家镇级市',
+				3 => '超级街道',
+			)
+        ),
+
+       	'sort' => array
+        (
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => '1',
+        ),
+        'status' => array
+        (
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '启用',
+                2 => '关闭',
+            ),
+        ),
+	),
+);

+ 74 - 0
table/village.php

@@ -0,0 +1,74 @@
+<?php
+return array
+(
+	'name' => '社区',
+	'order' => 'sort asc',
+	'struct' => array
+	(
+		'name'		=> array
+		(
+			'type' 		=> 'varchar(150)',
+			'name' 		=> '省份名称',
+		),
+
+		'pinyin'		=> array
+		(
+			'type' 		=> 'varchar(300)',
+			'name' 		=> '拼音',
+		),
+
+		'pinyin_first'		=> array
+		(
+			'type' 		=> 'varchar(30)',
+			'name' 		=> '拼音首字母',
+		),
+
+		'area'       => array
+        (
+            'type'      => 'varchar(500)',
+            'name'      => '所在城市',
+        ),
+
+		'province_id'		=> array
+		(
+			'type' 		=> 'int(11)',
+			'name' 		=> '省份',
+		),
+
+		'city_id'		=> array
+		(
+			'type' 		=> 'int(11)',
+			'name' 		=> '城市',
+		),
+
+		'county_id'		=> array
+		(
+			'type' 		=> 'int(11)',
+			'name' 		=> '区县',
+		),
+
+		'town_id'		=> array
+		(
+			'type' 		=> 'int(11)',
+			'name' 		=> '街道',
+		),
+
+		'sort' => array
+        (
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => '1',
+        ),
+        'status' => array
+        (
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '启用',
+                2 => '关闭',
+            ),
+        ),
+	),
+);