dever 3 gadi atpakaļ
vecāks
revīzija
ba2a488eea
8 mainītis faili ar 503 papildinājumiem un 23 dzēšanām
  1. 46 1
      database/city.php
  2. 74 4
      database/county.php
  3. 165 0
      database/level.php
  4. 1 1
      database/province.php
  5. 66 7
      database/town.php
  6. 54 4
      database/village.php
  7. 58 0
      lib/Manage.php
  8. 39 6
      src/Import.php

+ 46 - 1
database/city.php

@@ -11,6 +11,24 @@ $province = function()
 	return $array;
 };
 
+$level = function()
+{
+	$array = array
+	(
+		-1 => array
+		(
+			'id' => -1,
+			'name' => '普通城市',
+		),
+	);
+	$data = Dever::load('area/level-state');
+	if($data)
+	{
+		$array += $data;
+	}
+	return $array;
+};
+
 return array
 (
 	# 表名
@@ -18,7 +36,7 @@ return array
 	# 显示给用户看的名称
 	'lang' => '城市',
 	# 是否显示在后台菜单
-	'order' => 11,
+	'order' => 80,
 	# 数据结构
 	'struct' => array
 	(
@@ -81,6 +99,20 @@ return array
 			'list'		=> true,
 		),
 
+		'level_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '城市等级',
+			'default' 	=> '-1',
+			'desc' 		=> '城市等级',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'select',
+			'update'	=> 'select',
+			'option'	=> $level,
+			'list'		=> true,
+			'edit'		=> true,
+		),
+
 		'reorder'		=> array
 		(
 			'type' 		=> 'int-11',
@@ -163,5 +195,18 @@ return array
 			'type' => 'one',
 			'col' => '*',
 		),
+
+		'updateLevel' => array
+		(
+			'where' => array
+			(
+				'level_id' => 'yes',
+			),
+			'set' => array
+			(
+				'level_id' => 'yes',
+			),
+			'type' => 'update',
+		),
 	)
 );

+ 74 - 4
database/county.php

@@ -11,6 +11,22 @@ $city = function()
 	return $array;
 };
 
+$type = array
+(
+	1 => '城区',
+	2 => '郊区',
+	3 => '县城',
+	4 => '经济技术开发区',
+	5 => '县级市',
+);
+
+$level = array
+(
+	1 => '核心区',
+	2 => '普通区',
+	3 => '边缘区',
+);
+
 return array
 (
 	# 表名
@@ -18,7 +34,12 @@ return array
 	# 显示给用户看的名称
 	'lang' => '区县',
 	# 是否显示在后台菜单
-	'order' => 12,
+	'order' => 70,
+	'end' => array
+    (
+        'insert' => 'area/lib/manage.up',
+        'update' => 'area/lib/manage.up',
+    ),
 	# 数据结构
 	'struct' => array
 	(
@@ -69,6 +90,29 @@ return array
 			'list'		=> true,
 		),
 
+		'area'       => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '所在城市',
+            'default'   => '',
+            'desc'      => '所在城市',
+            'match'     => 'option',
+            'search'    => 'linkage',
+            'update'    => 'linkage',
+            'option'    => Dever::url('api.get?level_total=2', 'area'),
+            'list'      => 'Dever::load("area/api.string", "{area}")',
+        ),
+
+		'province_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '省份',
+			'default' 	=> '0',
+			'desc' 		=> '省份',
+			'match' 	=> 'is_numeric',
+			//'list'		=> 'Dever::load("area/province-find#name", {province_id})',
+		),
+
 		'city_id'		=> array
 		(
 			'type' 		=> 'int-11',
@@ -76,11 +120,37 @@ return array
 			'default' 	=> '0',
 			'desc' 		=> '城市',
 			'match' 	=> 'is_numeric',
-			'update'	=> 'select',
-			'option'	=> $city,
-			'list'		=> true,
+			//'list'		=> 'Dever::load("area/city-find#name", {city_id})',
 		),
 
+		'type'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '区县类型',
+            'default'   => '1',
+            'desc'      => '区县类型',
+            'match'     => 'is_numeric',
+            'update'  	=> 'radio',
+            'option'    => $type,
+            'search'    => 'select',
+            'list'      => true,
+            'edit'		=> true,
+        ),
+
+        'level'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '区县档次',
+            'default'   => '1',
+            'desc'      => '区县档次',
+            'match'     => 'is_numeric',
+            'update'  	=> 'radio',
+            'option'    => $level,
+            'search'    => 'select',
+            'list'      => true,
+            'edit'		=> true,
+        ),
+
 		'reorder'		=> array
 		(
 			'type' 		=> 'int-11',

+ 165 - 0
database/level.php

@@ -0,0 +1,165 @@
+<?php
+
+return array
+(
+    # 表名
+    'name' => 'level',
+    # 显示给用户看的名称
+    'lang' => '城市等级设置',
+    # 后台菜单排序
+    'order' => 100,
+    'end' => array
+    (
+        'insert' => 'area/lib/manage.level',
+        'update' => 'area/lib/manage.level',
+    ),
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            //'list'      => true,
+            'order'     => 'desc',
+        ),
+        
+        'name'      => array
+        (
+            'type'      => 'varchar-200',
+            'name'      => '名称',
+            'default'   => '',
+            'desc'      => '名称',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'level'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '等级数字-这里就是几线城市的等级,填写1就是特级城市,2就是1线城市,以此类推',
+            'default'   => '1',
+            'desc'      => '等级数字',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            //'list'      => true,
+            'order'     => 'asc',
+        ),
+
+        'city'      => array
+        (
+            'type'      => 'text-255',
+            'name'      => '城市-多个用中文叹号、隔开',
+            'default'   => '',
+            'desc'      => '城市',
+            'match'     => 'is_string',
+            'update'    => 'textarea',
+            'list'      => true,
+        ),
+
+        'city_price'      => array
+        (
+            'type'      => 'varchar-15',
+            'name'      => '城市价值-城市代理价格,以万为单位',
+            'default'   => '0',
+            'desc'      => '城市价值',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'county_price'      => array
+        (
+            'type'      => 'varchar-15',
+            'name'      => '区县价值-区县代理价格,以万为单位',
+            'default'   => '0',
+            'desc'      => '区县价值',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'town_price'      => array
+        (
+            'type'      => 'varchar-15',
+            'name'      => '街道价值-街道代理价格,以万为单位',
+            'default'   => '0',
+            'desc'      => '街道价值',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '创建时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            'list'      => 'date("Y-m-d H:i:s", {cdate})',
+        ),
+    ),
+
+    'default' => array
+	(
+		'col' => 'id,name,level,city,city_price,county_price,town_price,state,cdate',
+		'value' => array
+		(
+			'1,"特级城市", 1, "北京、上海、广州、深圳", "1000", "100", "10", 1,' . DEVER_TIME,
+
+			'2,"一线城市", 2, "成都、重庆、杭州、武汉、西安、郑州、青岛、长沙、天津、苏州、南京、东莞、沈阳、合肥、佛山", "500", "50", "6", 1,' . DEVER_TIME,
+
+			'3,"二线城市", 3, "昆明、福州、无锡、厦门、哈尔滨、长春、南昌、济南、宁波、大连、贵阳、温州、石家庄、泉州、南宁、金华、常州、珠海、惠州、嘉兴、南通、中山、保定、兰州、台州、徐州、太原、绍兴、烟台、廊坊、海口、扬州", "400", "40", "6", 1,' . DEVER_TIME,
+
+			'4,"三线城市", 4, "汕头、潍坊、洛阳、乌鲁木齐、临沂、唐山、镇江、盐城、湖州、赣州、漳州、揭阳、江门、桂林、邯郸、泰州、济宁、呼和浩特、咸阳、芜湖、三亚、阜阳、淮安 、银川、衡阳、上饶、柳州、淄博、莆田、绵阳、湛江、商丘、宜昌、沧州、连云港、南阳、蚌埠、驻马店、滁州、邢台、潮州、秦皇岛、肇庆、荆州、周口、马鞍山、清远、宿州、威海、九江、新乡、信阳、襄阳、岳阳、安庆、菏泽、宜春、黄冈、泰安、宿迁、株洲、宁德、鞍山、南充、六安、大庆、舟山、丽水、龙岩、湘潭、三明、梅州、南平、吉林、包头、郴州", "300", "30", "4", 1,' . DEVER_TIME,
+
+			'5,"四线城市", 5, "常德、渭南湖、孝感、运城、德州、张家口、鄂尔多斯、阳江、泸州、丹东、曲靖、乐山、许昌、晋中、安阳、齐齐哈尔、北海、宝鸡、抚州、景德镇、延安、抚顺、亳州、日照、西宁、衢州、、拉萨、淮北、焦作、平顶山、滨州、吉安、濮阳、眉山、池州、荆门、铜仁、长治、衡水、铜陵、承德、达州、邵阳、德阳、淮南、黄石、营口、东营、韶关、枣庄、怀化、宣城、临汾、聊城、盘锦、锦州、榆林、玉林、十堰、汕尾、咸宁、宜宾、永州、益阳、黔南州、黔东南、恩施、红河、大理、大同、鄂州、忻州、吕梁、黄山、开封、茂名、漯河、葫芦岛、河源、娄底、延边、丽江、佳木斯、牡丹江、西双版纳、六盘水、保山、毕节、安顺、百色、梧州、德宏、鹰潭、绥化、赤峰", "200", "20", "4", 1,' . DEVER_TIME,
+
+
+			'6,"五线城市", 6, "汉中、辽阳、四平、内江、新余、晋城、自贡、三门峡、本溪、防城港、铁岭、随州、广安、广元、天水、遂宁、萍乡、鹤壁、湘西、松原、阜新、酒泉、张家界、黔西南、昭通、河池、来宾、玉溪、钦州、云浮、克拉玛依、呼伦贝尔、贺州、通化、阳泉、朝阳、贵港、安康、通辽、朔州、伊犁、文山、楚雄、嘉峪关、凉山、资阳、锡林郭勒盟、雅安、普洱、崇左、庆阳、巴音郭楞(巴州)、乌兰察布、白山、昌吉、白城、兴安盟、定西、喀什、白银、陇南、巴彦淖尔、巴中、鸡西、乌海、临沧、海东、张掖、商洛、黑河、哈密、吴忠、攀枝花、双鸭山、阿克苏、石嘴山、阿拉善盟、海西、平凉、林芝、固原、武威、儋州、吐鲁番、甘孜、辽源、临夏、铜川、金昌、鹤岗、伊春、中卫、怒江、和田、迪庆、甘南、阿坝、 大兴安岭、七台河、山南、日喀则、塔城、博尔塔拉、昌都、阿勒泰、玉树、海南、黄南、果洛、克孜勒苏、阿里、海北、那曲、三沙", "100", "10", "2", 1,' . DEVER_TIME,
+		),
+	),
+
+    'manage' => array
+    (
+    	//'insert' => false,
+        'delete' => false,
+        'edit' => false,
+        'list_button' => array
+        (
+        	'fast' => array('编辑', '"level&where_id={id}&oper_save_jump=level&oper_table=level&oper_parent=level"'),
+        )
+    ),
+
+    'request' => array
+    (
+        'getAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'type' => array('yes', 'in'),
+                //'state' => 1,
+            ),
+            'type' => 'all',
+            'col' => '*|id',
+        ),
+    ),
+);

+ 1 - 1
database/province.php

@@ -11,7 +11,7 @@ return array
 	# 显示给用户看的名称
 	'lang' => '省份',
 	# 是否显示在后台菜单
-	'order' => 10,
+	'order' => 90,
 	'desc' => '导入数据请访问:' . Dever::url('area/import.load') . '<br />或者在服务器执行(推荐):php '.$path.'daemon/import.php',
 	# 数据结构
 	'struct' => array

+ 66 - 7
database/town.php

@@ -11,14 +11,26 @@ $county = function()
 	return $array;
 };
 
+$type = array
+(
+	1 => '普通街镇',
+	2 => '国家镇级市',
+	3 => '超级街道',
+);
+
 return array
 (
 	# 表名
 	'name' => 'town',
 	# 显示给用户看的名称
-	'lang' => '街道',
+	'lang' => '街',
 	# 是否显示在后台菜单
-	'order' => 13,
+	'order' => 60,
+	'end' => array
+    (
+        'insert' => 'area/lib/manage.up',
+        'update' => 'area/lib/manage.up',
+    ),
 	# 数据结构
 	'struct' => array
 	(
@@ -69,18 +81,65 @@ return array
 			'list'		=> true,
 		),
 
+		'area'       => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '所在区县',
+            'default'   => '',
+            'desc'      => '所在区县',
+            'match'     => 'option',
+            'search'    => 'linkage',
+            'update'    => 'linkage',
+            'option'    => Dever::url('api.get?level_total=3', 'area'),
+            'list'      => 'Dever::load("area/api.string", "{area}")',
+        ),
+
+		'province_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '省份',
+			'default' 	=> '0',
+			'desc' 		=> '省份',
+			'match' 	=> 'is_numeric',
+			//'list'		=> 'Dever::load("area/province-find#name", {province_id})',
+		),
+
+		'city_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '城市',
+			'default' 	=> '0',
+			'desc' 		=> '城市',
+			'match' 	=> 'is_numeric',
+			//'list'		=> 'Dever::load("area/city-find#name", {city_id})',
+		),
+
 		'county_id'		=> array
 		(
 			'type' 		=> 'int-11',
-			'name' 		=> '县区',
+			'name' 		=> '区',
 			'default' 	=> '0',
-			'desc' 		=> '县区',
+			'desc' 		=> '区',
 			'match' 	=> 'is_numeric',
-			'update'	=> 'select',
-			'option'	=> $county,
-			'list'		=> true,
+			//'update'	=> 'select',
+			//'option'	=> $county,
+			//'list'		=> true,
 		),
 
+		'type'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '街镇类型',
+            'default'   => '1',
+            'desc'      => '街镇类型',
+            'match'     => 'is_numeric',
+            'update'  	=> 'radio',
+            'option'    => $type,
+            'search'    => 'select',
+            'list'      => true,
+            'edit'		=> true,
+        ),
+
 		'reorder'		=> array
 		(
 			'type' 		=> 'int-11',

+ 54 - 4
database/village.php

@@ -18,8 +18,13 @@ return array
 	# 显示给用户看的名称
 	'lang' => '社区',
 	# 是否显示在后台菜单
-	'order' => 14,
+	'order' => 50,
 	'menu' => false,
+	'end' => array
+    (
+        'insert' => 'area/lib/manage.up',
+        'update' => 'area/lib/manage.up',
+    ),
 	# 数据结构
 	'struct' => array
 	(
@@ -82,6 +87,51 @@ return array
 			'list'		=> true,
 		),
 
+		'area'       => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '所在街道',
+            'default'   => '',
+            'desc'      => '所在街道',
+            'match'     => 'option',
+            'search'    => 'linkage',
+            'update'    => 'linkage',
+            'option'    => Dever::url('api.get?level_total=4', 'area'),
+            'list'      => 'Dever::load("area/api.string", "{area}")',
+        ),
+
+		'province_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '省份',
+			'default' 	=> '0',
+			'desc' 		=> '省份',
+			'match' 	=> 'is_numeric',
+			//'list'		=> 'Dever::load("area/province-find#name", {province_id})',
+		),
+
+		'city_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '城市',
+			'default' 	=> '0',
+			'desc' 		=> '城市',
+			'match' 	=> 'is_numeric',
+			//'list'		=> 'Dever::load("area/city-find#name", {city_id})',
+		),
+
+		'county_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '区县',
+			'default' 	=> '0',
+			'desc' 		=> '区县',
+			'match' 	=> 'is_numeric',
+			//'update'	=> 'select',
+			//'option'	=> $county,
+			//'list'		=> true,
+		),
+
 		'town_id'		=> array
 		(
 			'type' 		=> 'int-11',
@@ -89,9 +139,9 @@ return array
 			'default' 	=> '0',
 			'desc' 		=> '街道',
 			'match' 	=> 'is_numeric',
-			'update'	=> 'select',
-			'option'	=> $town,
-			'list'		=> true,
+			//'update'	=> 'select',
+			//'option'	=> $town,
+			//'list'		=> true,
 		),
 
 		'reorder'		=> array

+ 58 - 0
lib/Manage.php

@@ -0,0 +1,58 @@
+<?php
+
+namespace Area\Lib;
+
+use Dever;
+
+class Manage
+{
+    /**
+     * 更新信息
+     *
+     * @return mixed
+     */
+    public function up($id, $name, $data)
+    {
+        $update = array();
+        $area = Dever::param('area', $data);
+        $name = Dever::param('name', $data);
+        if ($area) {
+            $temp = is_string($area) ? explode(',', $area) : $area;
+            $update['province_id'] = $temp[0];
+            $update['city_id'] = $temp[1];
+            $table = 'area/county';
+            if (isset($temp[2])) {
+            	$table = 'area/town';
+                $update['county_id'] = $temp[2];
+            }
+            if (isset($temp[3])) {
+            	$table = 'area/village';
+                $update['town_id'] = $temp[3];
+            }
+
+            $update['name'] = $name;
+	        Dever::load('area/import')->pinyin($update);
+	        $update['where_id'] = $id;
+	        Dever::db($table)->update($update);
+        }
+    }
+
+    public function level($id, $name, $data)
+    {
+        $update = array();
+        $city = Dever::param('city', $data);
+        if ($city) {
+            Dever::db('area/city')->updateLevel(array('where_level_id' => $id, 'set_level_id' => -1));
+            $city = explode('、', $city);
+            foreach ($city as $k => $v) {
+                $w['name'] = $v;
+                $source = Dever::db('area/city')->getOne($w);
+                if ($source) {
+                    $update['where_id'] = $source['id'];
+                    $update['level_id'] = $id;
+                    Dever::db('area/city')->update($update);
+                }
+            }
+        }
+    }
+}

+ 39 - 6
src/Import.php

@@ -22,6 +22,8 @@ class Import
 
         preg_match_all('/<td><a href=\'(.*?)\'>(.*?)<br\/><\/a><\/td>/i', $html, $result);
 
+        Dever::config('base')->hook = true;
+
         # 获取省份
         $this->getProvince($result);
 
@@ -68,12 +70,12 @@ class Import
                 $id = Dever::upinto('area/city', $update, $update);
 
                 # 获取县区
-                $this->getCounty($id, $result[3][$k]);
+                $this->getCounty($province, $id, $result[3][$k]);
             }
         }
     }
 
-    public function getCounty($city, $link)
+    public function getCounty($province, $city, $link)
     {
         $url = $this->url . $link;
 
@@ -92,16 +94,40 @@ class Import
                 $update['id'] = $this->id($result[2][$k]);
                 $update['name'] = $v;
                 $update['city_id'] = $city;
+                $update['province_id'] = $province;
+                $update['area'] = $province . ',' . $city;
+                $num = substr($update['id'], 4);
+
+                # type = 1城区 2郊区 3县城 4经济技术开发 5县级市
+                if ($v == '门头沟区') {
+                    $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;
+                }
                 $this->pinyin($update);
                 $id = Dever::upinto('area/county', $update, $update);
 
                 # 获取街道
-                $this->getTown($id, $link . '/' . $result[3][$k]);
+                $this->getTown($province, $city, $id, $link . '/' . $result[3][$k]);
             }
         }
     }
 
-    public function getTown($county, $link)
+    public function getTown($province, $city, $county, $link)
     {
         $url = $this->url . $link;
 
@@ -120,16 +146,19 @@ class Import
                 $update['id'] = $this->id($result[2][$k], 9);
                 $update['name'] = $v;
                 $update['county_id'] = $county;
+                $update['city_id'] = $city;
+                $update['province_id'] = $province;
+                $update['area'] = $province . ',' . $city . ',' . $county;
                 $this->pinyin($update);
                 $id = Dever::upinto('area/town', $update, $update);
 
                 # 获取社区
-                //$this->getVillage($id, $link . '/' . $result[3][$k]);
+                //$this->getVillage($province, $city, $county, $id, $link . '/' . $result[3][$k]);
             }
         }
     }
 
-    public function getVillage($town, $link)
+    public function getVillage($province, $city, $county, $town, $link)
     {
         $url = $this->url . $link;
         
@@ -146,6 +175,10 @@ class Import
                 $update['code'] = $result[2][$k];
                 $update['name'] = $v;
                 $update['town_id'] = $town;
+                $update['county_id'] = $county;
+                $update['city_id'] = $city;
+                $update['province_id'] = $province;
+                $update['area'] = $province . ',' . $city . ',' . $county . ',' . $town;
                 $this->pinyin($update);
                 Dever::upinto('area/village', $update, $update);
             }