Browse Source

feat:版本

super-yimizi 2 months ago
parent
commit
0817da7db9
2 changed files with 20 additions and 9 deletions
  1. 0 8
      application/api/controller/Address.php
  2. 20 1
      application/common/model/Address.php

+ 0 - 8
application/api/controller/Address.php

@@ -30,10 +30,6 @@ class Address extends Base
         if (!$row) {
             $this->error('未找到记录');
         }
-        $areainfo = $row->areainfo;
-        $row['province'] = $areainfo['province'] ? $areainfo['province']['name'] : '';
-        $row['city'] = $areainfo['city'] ? $areainfo['city']['name'] : '';
-        $row['area'] = $areainfo['area'] ? $areainfo['area']['name'] : '';
         $this->success('获取成功', $row);
     }
 
@@ -46,10 +42,6 @@ class Address extends Base
         if (!$row) {
             $this->error('未找到记录');
         }
-        $areainfo = $row->areainfo;
-        $row['province'] = $areainfo['province'] ? $areainfo['province']['name'] : '';
-        $row['city'] = $areainfo['city'] ? $areainfo['city']['name'] : '';
-        $row['area'] = $areainfo['area'] ? $areainfo['area']['name'] : '';
         $this->success('获取成功', $row);
     }
 

+ 20 - 1
application/common/model/Address.php

@@ -23,7 +23,11 @@ class Address extends Model
     protected $deleteTime = 'deletetime';
 
     // 追加属性
-    protected $append = [];
+    protected $append = [
+        'city',
+        'area',
+        'province',
+    ];
 
     public static function init()
     {
@@ -40,6 +44,21 @@ class Address extends Model
             //$row['address'] = $row->address_full;
         });
     }
+    public function getCityAttr($value, $data)
+    {
+        $areainfo = $this->getAreainfoAttr($value, $data);
+        return $areainfo['city'] ? $areainfo['city']['name'] : '';
+    }
+    public function getAreaAttr($value, $data)
+    {
+        $areainfo = $this->getAreainfoAttr($value, $data);
+        return $areainfo['area'] ? $areainfo['area']['name'] : '';
+    }
+    public function getProvinceAttr($value, $data)
+    {
+        $areainfo = $this->getAreainfoAttr($value, $data);
+        return $areainfo['province'] ? $areainfo['province']['name'] : '';
+    }
 
     public function getAddressBaseAttr($value, $data)
     {