dever před 7 roky
rodič
revize
eade5c1057
4 změnil soubory, kde provedl 91 přidání a 0 odebrání
  1. 13 0
      database/city.php
  2. 13 0
      database/county.php
  3. 12 0
      database/province.php
  4. 53 0
      src/Api.php

+ 13 - 0
database/city.php

@@ -113,5 +113,18 @@ return array
 			'order' => array('reorder' => 'desc', 'id' => 'asc'),
 			'col' => 'id as value, name',
 		),
+
+		'getData' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'province_id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc', 'id' => 'asc'),
+			'col' => 'id, name|id',
+		),
 	)
 );

+ 13 - 0
database/county.php

@@ -113,5 +113,18 @@ return array
 			'order' => array('reorder' => 'desc', 'id' => 'asc'),
 			'col' => 'id as value, name',
 		),
+
+		'getData' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'city_id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc', 'id' => 'asc'),
+			'col' => 'id, name|id',
+		),
 	)
 );

+ 12 - 0
database/province.php

@@ -94,5 +94,17 @@ return array
 			'order' => array('reorder' => 'desc', 'id' => 'asc'),
 			'col' => 'id as value, name',
 		),
+
+		'getData' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc', 'id' => 'asc'),
+			'col' => 'id, name',
+		),
 	)
 );

+ 53 - 0
src/Api.php

@@ -73,6 +73,59 @@ class Api
         return $result;
     }
 
+    /**
+     * 获取所有地区数据:json格式,生成js文件
+     *
+     * @return mixed
+     */
+    public function createJson()
+    {
+        $path = Dever::data() . 'upload/';
+        $file = $path . 'city.js';
+        $create = Dever::input('create', 1);
+
+        if (!is_file($file)) {
+            $create = 2;
+        }
+        if ($create == 2) {
+            $province = Dever::db('area/province')->getAll();
+
+            $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'];
+
+                $city = Dever::db('area/city')->getAll(array('province_id' => $v['value']));
+
+                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'];
+
+                    $county = Dever::db('area/county')->getAll(array('city_id' => $v1['value']));
+
+                    foreach ($county as $k2 => $v2) {
+                        $county_data[$v1['value']][$k2]['city'] = $v1['name'];
+                        $county_data[$v1['value']][$k2]['name'] = $v2['name'];
+                        $county_data[$v1['value']][$k2]['id'] = $v2['value'];
+                    }
+                }
+            }
+
+            $content = 'var provinces = ' . Dever::json_encode($province_data) . ';';
+            $content .= 'var citys = ' . Dever::json_encode($city_data) . ';';
+            $content .= 'var areas = ' . Dever::json_encode($county_data) . ';';
+
+            file_put_contents($file, $content);
+        }
+
+        $assets = Dever::config('host')->uploadRes;
+        return str_replace($path, $assets, $file);
+    }
+
     /**
      * 获取详细信息
      *