123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace Agent\Lib;
- use Dever;
- class Address
- {
- # 获取某个收货地址
- public function getOne($mid, $id)
- {
- $where['mid'] = $mid;
- $where['id'] = $id;
- $data = Dever::db('agent/member_address')->find($where);
- if ($data && Dever::project('area')) {
- $data = $this->getInfo($data);
- }
- return $data;
- }
- private function getInfo($data)
- {
- $data['address_info'] = $data['add_string'] = $data['address'] . $data['house_number'];
- $data['province_name'] = $data['city_name'] = $data['county_name'] = '';
- if ($data['county']) {
- $info = Dever::db('area/county')->find($data['county']);
- if ($info) {
- $data['county_name'] = $info['name'];
- $data['city'] = $info['city_id'];
- $info = Dever::db('area/city')->find($data['city']);
- $data['city_name'] = $info['name'];
- $data['province'] = $info['province_id'];
- $info = Dever::db('area/province')->find($data['province']);
- $data['province_name'] = $info['name'];
- //$data['address_info'] = $data['province_name'] . $data['city_name'] . $data['county_name'] .','. $data['address'] .','. $data['house_number'];
- $data['add_string'] = $data['province_name'] . $data['city_name'] . $data['county_name'] .','. $data['address'] .','. $data['house_number'] .','. $data['contact'] .','. $data['mobile'];
- }
- } elseif ($data['city']) {
- $info = Dever::db('area/county')->find($data['city']);
- if ($info) {
- $data['county_name'] = $info['name'];
- $data['city'] = $info['city_id'];
- $info = Dever::db('area/city')->find($data['city']);
- $data['city_name'] = $info['name'];
- $data['province'] = $info['province_id'];
- $info = Dever::db('area/province')->find($data['province']);
- $data['province_name'] = $info['name'];
- //$data['address_info'] = $data['province_name'] . $data['city_name'] . $data['county_name'] .','. $data['address'] .','. $data['house_number'];
- $data['add_string'] = $data['province_name'] . $data['city_name'] . $data['county_name'] .','. $data['address'] .','. $data['house_number'] .','. $data['contact'] .','. $data['mobile'];
- }
-
- }
- if (!$data['county_name']) {
- $city = '';
- if (strstr($data['address'], '省')) {
- $temp = explode('省', $data['address']);
- $data['province_name'] = $temp[0] . '省';
- unset($temp[0]);
- $city = $temp[1];
- } elseif (strstr($data['address'], '市')) {
- $temp = explode('市', $data['address']);
- $data['province_name'] = $temp[0] . '市';
- $city = '';
- unset($temp[0]);
- $city = implode('市', $temp);
- } elseif (strstr($data['address'], '区')) {
- $temp = explode('区', $data['address']);
- $data['province_name'] = $temp[0] . '区';
- $city = '';
- unset($temp[0]);
- $city = implode('区', $temp);
- }
- if (strstr($city, '市')) {
- $temp = explode('市', $city);
- $data['city_name'] = $temp[0] . '市';
- }
- if (isset($temp[1])) {
- $data['county_name'] = $temp[1];
- }
- }
- return $data;
- }
- }
|