예제 #1
0
 protected function setAddress($em, $direct_cities, Client $client, $hkmt)
 {
     //将地址写入数组
     if ($_POST['area'] && $_POST['area'][0] != -1) {
         $areaData = $em->getRepository('AppBundle:Area');
         $add = array();
         //储存省市区地址名称
         foreach ($_POST['area'] as $value) {
             if ($value != -1) {
                 $add[] = $areaData->find($value)->getName();
             }
         }
         $add[] = $_POST['address_detail'];
         //再将地址写入省市区镇,作经纬度之用
         if (in_array($add[0], $direct_cities)) {
             //4个直辖市、2个特别行政区和台湾
             $client->setProvince($add[0]);
             $client->setCity($add[0]);
             if (!in_array($add[0], $hkmt)) {
                 $client->setDistrict($add[1]);
                 $client->setTown($add[2]);
             } else {
                 $client->setDistrict($add[2]);
             }
             $client->setAddressDetail($add[3]);
             $latlng_data = $em->getRepository('AppBundle:LatLng')->findBy(array('province' => $client->getProvince(), 'district' => $client->getDistrict()));
             $this->setLatLng($latlng_data, $client);
         } else {
             //非直辖市
             $client->setProvince($add[0]);
             $client->setCity($add[1]);
             if ($add[1] != "中山市") {
                 //非中山市
                 $client->setDistrict($add[2]);
                 $client->setTown($add[3]);
                 if (!empty($add[4])) {
                     $client->setAddressDetail($add[4]);
                 }
                 $latlng_data = $em->getRepository('AppBundle:LatLng')->findBy(array('province' => $client->getProvince(), 'city' => $client->getCity(), 'district' => $client->getDistrict()));
             } else {
                 //是中山市
                 $client->setTown($add[2]);
                 $client->setAddressDetail($add[3]);
                 $latlng_data = $em->getRepository('AppBundle:LatLng')->findBy(array('province' => $client->getProvince(), 'city' => $client->getCity(), 'district' => $client->getDistrict()));
             }
             $this->setLatLng($latlng_data, $client);
         }
     }
 }