/** * Информация по покупкам для фрилансеров * * «Подключенные» – активные услуги, действующие в данный момент; (active) * «Вы недавно покупали» – уже неактивные услуги, которыми юзер пользовался в ближайшие полгода; (lately) * «Вы еще не использовали» – услуги, которыми не пользовались свыше полугода (с даты истечения срока действия прошло больше 6 месяцев); (notused) * */ public function loadMainDataFrl() { $sql = "\n WITH active_service AS (\n SELECT MAX(from_date + to_date) as d, 'pro' as service, 1 as sort \n FROM orders WHERE from_id = ?i AND from_date + to_date > now()\n UNION\n SELECT MAX(date_create) as d, 'pay_place' as service, 2 as sort \n FROM paid_places WHERE uid = ?i AND is_done = 0\n UNION\n -- сначала находим сроки окончания для всех активных объявлений\n -- а потом минимальный из них\n SELECT MIN(d) as d, 'first_page' as service, 3 as sort\n FROM (\n SELECT MAX(from_date + to_date) as d\n FROM users_first_page\n WHERE user_id = ?i AND from_date + to_date > now() AND payed = true\n GROUP BY profession\n ) as ufp\n ), lately_service AS (\n SELECT MAX(from_date + to_date) as d, 'pro' as service, 1 as sort \n FROM orders WHERE from_id = ?i AND (from_date + to_date + interval '6 month') > NOW() \n UNION\n SELECT MAX(posted_time) as d, 'massending' as service, 1 as sort \n FROM mass_sending WHERE user_id = ?i AND (posted_time + interval '6 month') > NOW() \n UNION\n SELECT MAX(date_create) as d, 'pay_place' as service, 2 as sort \n FROM paid_places WHERE uid = ?i AND (date_create + interval '6 month') > NOW()\n UNION\n SELECT MAX(from_date + to_date) as d, 'first_page' as service, 3 as sort \n FROM users_first_page where user_id = ?i AND payed = true AND (from_date + to_date + interval '6 month') > NOW()\t\n )\n SELECT active_service.*, 'active' as type FROM active_service\n UNION\n SELECT lately_service.*, 'lately' as type FROM lately_service\n ORDER BY type, sort ASC\n "; $services = $this->_db->rows($sql, $this->user['uid'], $this->user['uid'], $this->user['uid'], $this->user['uid'], $this->user['uid'], $this->user['uid'], $this->user['uid']); foreach ($services as $service) { if ($service['d'] == null || isset($result[$service['service']])) { continue; } $service['expired'] = billing::expiredTime($service['d']); if ($service['service'] == 'pro') { // Обновляем сессию if ($service['type'] == 'active') { $_SESSION['pro_last'] = payed::ProLast($this->user['login']); $_SESSION['pro_last'] = $_SESSION['pro_last']['is_freezed'] ? false : $_SESSION['pro_last']['cnt']; if ($_SESSION['pro_last']['is_freezed']) { $_SESSION['payed_to'] = $_SESSION['pro_last']['cnt']; } } $user = new users(); $service['is_auto'] = $user->GetField($this->user['uid'], $e, 'is_pro_auto_prolong', false); $service['auto'] = $service['is_auto']; $service['last_operation'] = $this->getLastOperation($service['service']); // Тестовый не может быть куплен второй раз if ($service['last_operation']['op_code'] == 47) { $service['last_operation']['op_code'] = 48; } } $result[$service['service']] = $service; } foreach (self::$frl_default_service as $type => $val) { if (!isset($result[$type])) { $result[$type] = array('type' => 'notused', 'service' => $type); } } $this->services = $result; return $this->services; }