Answer the question
In order to leave comments, you need to log in
How to organize the search for round-trip tickets?
Good afternoon.
The site has a ticket search.
The search is carried out on the following fields:
1) City of departure
2) City of arrival
3) Date of departure
4) Date of arrival
5) Checkbox to select the direction, one way or round trip ticket.
Now the search model contains the following conditions:
$query->andWhere(['status' => Flights::STATUS_ACTIVE])
->andWhere(['>=', 'date_start', $this->date_from ? strtotime($this->date_from . ' 00:00:00') : null])
->andWhere(['=', 'city_start_id', $this->city_from])
->andWhere(['=', 'city_end_id', $this->city_to]);
$query->andFilterWhere(['<=', 'date_end', $this->date_to ? strtotime($this->date_to . ' 23:59:59') : null])
->andFilterWhere(['=', 'airline_id', $this->airline])
->andFilterWhere(['in', 'airport_start_id', $this->airport_id])
->andFilterWhere(['in', 'airline_id', $this->company_id])
->andFilterWhere(['=', 'agent', $this->partner]);
// если переменная равна 1, то билеты надо искать туда/обратно, если равна 2, то билеты искать в одну сторону.
public $direction = 1;
Answer the question
In order to leave comments, you need to log in
Usually, services make a fixed departure date. those. if the user is looking for a ticket only "there", then he enters the desired departure date and the system looks for a ticket from point A to point B with a departure on the specified date.
If a round-trip ticket is searched, then the results of the search for the second date are added to the results of the first search, where the starting points are reversed. If you need to set the date of departure and return as an interval, and not a fixed one, then the query will be something like this:
1. to search only "there"
SELECT * FROM `flights` WHERE
(`departure_time` BETWEEN 'user_departure_wants_min' AND 'user_departure_wants_max'
AND `departure_airport` = user_departure_wants_from
AND `arrive_airport` = user_arrive_wants_to);
SELECT * FROM `flights` WHERE
(`departure_time` BETWEEN 'user_departure_1_wants_min' AND 'user_departure_1_wants_max'
AND `departure_airport` = user_departure_wants_from
AND `arrive_airport` = user_arrive_wants_to)
OR
(`departure_time` BETWEEN 'user_departure_2_wants_min' AND 'user_departure_2_wants_max'
AND `departure_airport` = user_arrive_wants_to
AND `arrive_airport` = user_departure_wants_from)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question