dever 3 years ago
parent
commit
0ebad9f875
1 changed files with 6 additions and 7 deletions
  1. 6 7
      src/Api.php

+ 6 - 7
src/Api.php

@@ -117,25 +117,25 @@ class Api
      *
      * @return mixed
      */
-    public function string($area, $im = ',', $unset = true)
+    public function string($area, $im = ',', $unset = true, $name = '不限')
     {
         if ($area) {
             $area = explode(',', $area);
             $result = array();
             foreach ($area as $k => $v) {
                 if ($k == 0) {
-                    $result[$k] = $this->getName('province', $v);
+                    $result[$k] = $this->getName('province', $v, false, 'id', $name);
                 } 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);
+                    $result[$k] = $this->getName('county', $v, false, 'id', $name);
                 } elseif ($k == 3) {
-                    $result[$k] = $this->getName('town', $v);
+                    $result[$k] = $this->getName('town', $v, false, 'id', $name);
                 } elseif ($k == 4) {
-                    $result[$k] = $this->getName('village', $v);
+                    $result[$k] = $this->getName('village', $v, false, 'id', $name);
                 }
             }
             return implode($im, $result);
@@ -144,9 +144,8 @@ class Api
     }
 
 
-    private function getName($table, $value, $state = false, $col = 'id')
+    private function getName($table, $value, $state = false, $col = 'id', $name = '不限')
     {
-        $name = '不限';
         if (($col == 'id' && $value > 0) || ($col != 'id' && $value)) {
             $where[$col] = $value;
             $data = Dever::db('area/' . $table)->one($where);