public function cityzone($city_id, $reseller, $zonereseller_id, $distance) { $city = Model::City()->find($city_id); if ($city) { $tab = $city->assoc(); $tab['distance'] = ['km' => 0, 'miles' => 0]; $near = [$tab]; $near = array_merge($near, getNearCitiesFromZip($city->zip, $distance)); foreach ($near as $c) { $cz = Model::Cityzone()->create(['zonereseller_id' => (int) $zonereseller_id, 'reseller_id' => (int) $reseller, 'zip' => (string) $c['zip'], 'city_id' => (int) $c['id'], 'distance' => (double) $c['distance']['km']])->save(); } } }
public function getSiretByApeAndCityAndDpt($ape, $city, $dpt) { ini_set('memory_limit', '1024M'); $cityM = Model::City()->where(['name', '=', (string) strtolower($city)])->first(true); if (!$cityM) { return false; } $zip = $cityM->zip; $d = substr($zip, 0, 2); if ($dpt != $d) { return false; } require_once APPLICATION_PATH . DS . '..' . '/public/vendeur/lib/simple_html_dom.php'; set_time_limit(0); $cache = redis(); $url = 'http://www.societe.com/cgi-bin/liste?ens=on&nom=&ape=' . $ape . '&adr=&num=&ville=' . $city . '&dep=' . $d; $key = 'siret.ape.city.dep.' . $ape . '.' . $city . '.' . $dpt; $cached = $cache->get($key); if (empty($cached)) { $html = dwn($url); $cache->set($key, $html); $cache->expire($key, strtotime('+1 month') - time()); } else { $html = $cached; } $html = str_get_html($html); $links = $html->find('.linkresult'); $sirens = []; foreach ($links as $link) { $href = $link->attr['href']; $siren = (int) str_replace('.html', '', Arrays::last(explode('-', $href))); $sirens[] = $siren; } $data = []; foreach ($sirens as $siren) { $infos = $this->siren($siren); if (isset($infos['code_postal'])) { $cp = $infos['code_postal']; $d = (int) substr($cp, 0, 2); if (!is_null($infos['siret']) && $dpt == $d) { $data[] = $infos; } } } dd($data); }
public function getResellersByZip($zip) { $region = $department = null; $resellersCity = $resellersRegion = $resellersDepartment = []; $city = Model::City()->where(['zip', '=', (string) $zip])->first(true); if ($city instanceof ZeliftCityModel) { $department = $city->department(); $region = $city->region(); $zones = Model::Customzonereseller()->where(['type', '=', 'city'])->where(['type_id', '=', $city->id])->exec(); dd($zones); $resellersCity = $this->getResellersByZones($zones); } else { $dpt = substr($zip, 0, 2); $department = Model::Department()->where(['code', '=', (string) $dpt])->first(true); if ($department) { $region = $department->region(); } } if ($region instanceof ZeliftRegionModel) { $zones = Model::Customzonereseller()->where(['type', '=', 'region'])->where(['type_id', '=', $region->id])->exec(); $resellersRegion = $this->getResellersByZones($zones); } if ($department instanceof ZeliftDepartmentModel) { $zones = Model::Customzonereseller()->where(['type', '=', 'department'])->where(['type_id', '=', $department->id])->exec(); $resellersDepartment = $this->getResellersByZones($zones); } return $this->unTuple($resellersCity, $resellersRegion, $resellersDepartment); }
public function searchInsee($sellzone_id, $q, $limit = 30, $offset = 0, $lat = 0, $lng = 0) { $number = true; $first = 1; if (fnmatch('* *', $q)) { $tab = explode(' ', $q); $first = Arrays::first($tab); if (is_numeric($first)) { array_shift($tab); $q = implode(' ', $tab); } } $insees = redis()->get('insee.data.' . $sellzone_id); if (!$insees) { $zips = Model::Coveredcity()->where(['sellzone_id', '=', (int) $sellzone_id])->cursor(); foreach ($zips as $zip) { $cs = Model::City()->where(['zip', '=', (string) $zip['zip']])->cursor(); foreach ($cs as $c) { $n = str_replace(' ', '_', Inflector::unaccent(Inflector::lower($zip['name']))); $n2 = str_replace(' ', '_', Inflector::unaccent(Inflector::lower($c['name']))); if ($n == $n2) { $coll[] = ['insee' => $c['insee'], 'zip' => $zip['zip'], 'name' => $c['name']]; } } } // $coll = array_values(array_unique($coll)); redis()->set('insee.data.' . $sellzone_id, serialize($coll)); $insees = $coll; } else { $insees = unserialize($insees); } $res = []; foreach ($insees as $insee) { $i = $insee['insee']; $data = json_decode(dwn("http://www.ariase.com/scripts/eligibilite/rechercheVoie.php?insee={$i}&term=" . urlencode($q)), true); foreach ($data as $row) { $res[] = ['street' => isAke($row, 'label', ''), 'zip' => isAke($insee, 'zip', ''), 'city' => isAke($insee, 'name', '')]; } } dd($res); }