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); }