| | |
| | | : Region::getNameById($data['region_id']), |
| | | ]; |
| | | } |
| | | |
| | | /** |
| | | * 整理地图选择的地址 by lyzflash |
| | | */ |
| | | public function setLocationAddress($address) |
| | | { |
| | | $region = $this->checkPCA($address); |
| | | $short_address = str_replace($region['province'] . $region['city'] . $region['area'], '', $address); |
| | | if (in_array($region['province'], array('北京市', '天津市', '天津市', '天津市'))) { |
| | | $region['area'] = $region['city']; |
| | | $region['city'] = $region['province']; |
| | | } |
| | | $province_id = Region::getIdByName($region['province'], 1); |
| | | $city_id = Region::getIdByName($region['city'], 2, $province_id); |
| | | $region_id = Region::getIdByName($region['area'], 3, $city_id); |
| | | return ['cityCode'=> [$province_id, $city_id, $region_id], 'region' => [$region['province'], $region['city'], $region['area']], 'short_address' => $short_address]; |
| | | } |
| | | |
| | | /** |
| | | * 截取省市区 by lyzflash |
| | | */ |
| | | private function checkPCA($address) { |
| | | preg_match('/(.*?(省|自治区|北京市|天津市|上海市|重庆市))/', $address, $matches); |
| | | if (count($matches) > 1) { |
| | | $province = $matches[count($matches) - 2]; |
| | | $address = str_replace($province, '', $address); |
| | | } |
| | | preg_match('/(.*?(市|自治州|地区|区划|县))/', $address, $matches); |
| | | if (count($matches) > 1) { |
| | | $city = $matches[count($matches) - 2]; |
| | | $address = str_replace($city, '', $address); |
| | | } |
| | | preg_match('/(.*?(市|区|县))/', $address, $matches); |
| | | if (count($matches) > 1) { |
| | | $area = $matches[count($matches) - 2]; |
| | | $address = str_replace($area, '', $address); |
| | | } |
| | | return [ |
| | | 'province' => isset($province) ? $province : '', |
| | | 'city' => isset($city) ? $city : '', |
| | | 'area' => isset($area) ? $area : '', |
| | | ]; |
| | | } |
| | | } |