getUsersFilter($usersArr, $post['user_id'], $_SESSION['users_admin']); $usersIdReal = array(); //пользователь, по которому смотрим объекты $userId = $post['userId']; $objectId = $post['objectId']; // Определяем текущего пользователя $user = new User; $user->get($_SESSION['id']); $user->checkPermissions(); $arrIdAddUsers = $arrIdWhoWork = $uniqueRecords = $records = $promo_records = []; //если смотрим статистику по агентству, то смотрим по всем, кто в списке if ($user->agency) { foreach ($usersId as $usrId) { $arrIdWhoWork[] = "who_work = $usrId"; $arrIdAddUsers[] = "id_add_user = $usrId"; } $usersIdReal = $usersId; } elseif ($user->manager) { $arrIdWhoWork[] = "who_work = $userId"; $arrIdAddUsers[] = "id_add_user = $userId"; $usersIdReal[] = $userId; $usersResult = mysql_query("SELECT id FROM users WHERE id_manager=" . $userId); while ($usr = mysql_fetch_assoc($usersResult)) { if (in_array($usr['id'], $usersId)) { $arrIdWhoWork[] = "who_work = $usr[id]"; $arrIdAddUsers[] = "id_add_user = $usr[id]"; $usersIdReal[] = $usr['id']; } } } else { $arrIdWhoWork[] = "who_work = $userId"; $arrIdAddUsers[] = "id_add_user = $userId"; $usersIdReal[] = $userId; } $bd_usl_addUsers = " AND (" . implode(" OR ", $arrIdAddUsers) . ")"; $bd_usl_whoWork = " AND (" . implode(" OR ", $arrIdWhoWork) . ")"; $period = 'all'; $bd_piriod = ''; $bd_piriod_objects = ''; if (isset($post['period'])) { $period = $post['period']; if ($period == 'dates') { $onDate = date('Y-m-d 00:00:00', strtotime($post['onDate'])); if (empty($onDate)) { $onDate = '1970-01-01 00:00:00'; } if (!empty($post['offDate'])) { $offDate = date('Y-m-d 23:59:59', strtotime($_POST['offDate'])); } else { $offDate = date('Y-m-d 23:59:59'); } $bd_piriod .= " AND `date_add` between '{$onDate}' AND '{$offDate}'"; $bd_piriod_objects .= " AND `date_really_add` between '{$onDate}' AND '{$offDate}'"; $_SESSION['on_date'] = $post['onDate']; $_SESSION['off_date'] = $post['offDate']; } else { unset($_SESSION['on_date']); unset($_SESSION['off_date']); $arrPeriod = ['today' => '-0 day', 'week' => '-6 day', 'month' => '-30 day', 'quarter' => '-120 day', 'year' => '-365']; $days = date('Y-m-d', strtotime($arrPeriod[$post['period']])); $bd_piriod .= " AND `date_add` > '{$days}'"; $bd_piriod_objects .= " AND `date_really_add` > '{$days}'"; } } $lastDay = ''; $startDate = '1970-01-01 00:00:00'; $endDate = '3000-12-31 23:59:59'; switch ($period) { case 'month': { $totalDays = cal_days_in_month(CAL_GREGORIAN, (int)date('m'), date('Y')); $lastDay = $totalDays; $startDate = date('Y') . "-" . date('m') . "-01 00:00:00"; $endDate = date('Y') . "-" . date('m') . "-" . $lastDay . " 23:59:59"; break; } case 'today':{ $startDate = date("Y-m-d 00:00:00"); $endDate = date("Y-m-d 23:59:59"); break; } case 'quarter' : { $nowMonth = (int)date('m'); if ($nowMonth < 4) { $startDate = date('Y') . "-01-01 00:00:00"; $endDate = date('Y') . "-03-31 23:59:59"; } else if ($nowMonth >= 4 && $nowMonth < 7) { $startDate = date('Y') . "-04-01 00:00:00"; $endDate = date('Y') . "-06-30 23:59:59"; } else if ($nowMonth >= 7 && $nowMonth < 10) { $startDate = date('Y') . "-07-01 00:00:00"; $endDate = date('Y') . "-09-30 23:59:59"; } else if ($nowMonth >= 10 && $nowMonth < 13) { $startDate = date('Y') . "-10-01 00:00:00"; $endDate = date('Y') . "-12-31 23:59:59"; } break; } case 'week': { $startDate = date("Y-m-d 00:00:00", strtotime("monday this week")); $endDate = date("Y-m-d 23:59:59", strtotime("sunday this week")); break; } case '30days': { $startDate = date('Y-m-d', strtotime('-30 day'))." 00:00:00"; $endDate = date("Y-m-d")." 23:59:59"; break; } case '90days': { $startDate = date('Y-m-d', strtotime('-90 day'))." 00:00:00"; $endDate = date("Y-m-d")." 23:59:59"; break; } case 'dates' : { $onDate = $_POST['onDate']; //if(empty($onDate)) $onDate = '1970-01-01 00:00:00'; $offDate = $_POST['offDate']; if (empty($offDate)) { $offDate = date('Y-m-d 23:59:59'); } $startDate = date("Y-m-d 00:00:00", strtotime($onDate)); $endDate = date("Y-m-d 23:59:59", strtotime($offDate)); break; } case 'year' : { $startDate = date('Y') . "-01-01 00:00:00"; $endDate = date('Y') . "-12-31 23:59:59"; break; } } $date_between = "between '" . $startDate . "' AND '" . $endDate . "'"; $usersWhere = $userId == $_SESSION['id'] ? "`user_owner_id` IN (" . implode(', ', $usersId) . ")" : "user_owner_id = '$userId'"; // Запрос статистики на все площадки $sql = "SELECT * FROM object_publish_statistic WHERE `on_moderation` = 0 AND $usersWhere AND `destination` NOT IN (" . "'" . implode("', '", array_keys($PROMO_TARGETS)) . "'" . ") AND ( `publish_start_date` $date_between ) AND `object_id` = '$objectId'"; $rezDatesAndSumInPeriod = mysql_query($sql); // Запрос статистики продвижения $sql = "SELECT * FROM object_publish_statistic WHERE `on_moderation` = 0 AND `user_owner_id` = '$userId' AND `destination` IN (" . "'" . implode("', '", array_keys($PROMO_TARGETS)) . "'" . ") AND ( `publish_start_date` $date_between ) AND `object_id` = '$objectId'"; /*echo ($sql);*/ if ($query2 = mysql_query($sql)) { while($row = mysql_fetch_assoc($query2)) { $promo_records[] = [ 'destination' => trim($row['destination']), 'price' => (float)$row['price'] ]; } } if ($_SESSION['id'] == 7536) { echo $sqlDatesAndPriceInPeriod; } if (mysql_num_rows($rezDatesAndSumInPeriod) > 0 || !empty($promo_records)) { if (mysql_num_rows($rezDatesAndSumInPeriod) > 0) { while ($statRec = mysql_fetch_assoc($rezDatesAndSumInPeriod)) { $records[] = $statRec; } } ?>
0) : ?> ' . $ZIPAL_TARGETS[$rec['destination']] . ''; } } ?> ' . $PROMO_TARGETS[$rec['destination']] . ''; } } ?> ' . $ZIPAL_TARGETS[$rec['destination']] . ''; } } ?> '.number_format($sum, 2, '.', ' ').''; } ?>
ID объекта Продвижение
ID объекта