rabin 5 years ago
parent
commit
d04451522e
2 changed files with 45 additions and 7 deletions
  1. 1 1
      database/province.php
  2. 44 6
      src/Api.php

+ 1 - 1
database/province.php

@@ -92,7 +92,7 @@ return array
 			),
 			'type' => 'all',
 			'order' => array('reorder' => 'desc', 'id' => 'asc'),
-			'col' => 'id as value, name',
+			'col' => 'id,id as value, name',
 		),
 
 		'getData' => array

+ 44 - 6
src/Api.php

@@ -83,8 +83,12 @@ class Api
         $path = Dever::data() . 'upload/';
         $create = Dever::input('create', 1);
         $type = Dever::input('type', 'js');
-        $file = $path . 'city.' . $type;
-
+        if ($type == 'klist') {
+            $file = $path . 'city.' . $type . '.js';
+        } else {
+            $file = $path . 'city.' . $type;
+        }
+        
         if (!is_file($file)) {
             $create = 2;
         }
@@ -98,7 +102,14 @@ class Api
                 ),
             );
 
-            $province = array_merge($array, Dever::db('area/province')->getAll());
+            $klist = Dever::db('area/province')->getAll();
+
+            if ($type == 'klist') {
+                $province = $klist;
+            } else {
+                $province = array_merge($array, $klist);
+            }
+            
 
             $province_data = array();
             $city_data = array();
@@ -112,7 +123,15 @@ class Api
                     continue;
                 }
 
-                $city = array_merge($array, Dever::db('area/city')->getAll(array('province_id' => $v['value'])));
+                $klist[$k]['text'] = $v['name'];
+                $klist[$k]['value'] = $v['value'];
+                $klist[$k]['children'] = Dever::db('area/city')->getAll(array('province_id' => $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'];
@@ -122,9 +141,21 @@ class Api
                     if ($v1['value'] <= 0) {
                         continue;
                     }
-                    $county = array_merge($array, Dever::db('area/county')->getAll(array('city_id' => $v1['value'])));
+
+                    $klist[$k]['children'][$k1]['text'] = $v1['name'];
+                    $klist[$k]['children'][$k1]['value'] = $v1['value'];
+                    $klist[$k]['children'][$k1]['children'] = Dever::db('area/county')->getAll(array('city_id' => $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'];
@@ -132,7 +163,9 @@ class Api
                 }
             }
 
-            if ($type == 'js') {
+            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) . ';';
@@ -267,4 +300,9 @@ class Api
         $id = str_pad($id, 6, '0', STR_PAD_RIGHT);
         return $id;
     }
+
+    public function getProvince()
+    {
+        return Dever::db('area/province')->getAll();
+    }
 }