108 lines
3.5 KiB
PHP
108 lines
3.5 KiB
PHP
<?php
|
|
set_time_limit(0);
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
|
|
|
|
ini_set('display_errors', 1);
|
|
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
|
|
header('Content-Type: application/json');
|
|
|
|
$pdo = new MysqlPdo(hst, ndb, user, pass);
|
|
$pdo->query("SET NAMES 'utf8'");
|
|
$db_sphinx = new MysqlPdo(hstsph2, null, null, null, true, '9306');
|
|
|
|
$arrDestination = [
|
|
'AVITO_JW_FEED' => 'Авито',
|
|
'EMLS_JW_FEED' => 'Jcat',
|
|
'CIAN_JW_FEED' => 'Циан',
|
|
'YANDEX_JW_FEED' => 'Яндекс',
|
|
'FREE_JW_FEED' => 'Бесплатные',
|
|
'DOMCLICK_JW_FEED' => 'Домклик',
|
|
];
|
|
|
|
$user_ids = array();
|
|
$object_sends = array();
|
|
$object_ids = array();
|
|
|
|
$object_users = array();
|
|
$object_adres = array();
|
|
$object_archive = array();
|
|
|
|
$users = array();
|
|
$sql = "SELECT * FROM object_unpublish_telegram_send WHERE is_read = 0";
|
|
$q = $pdo->query($sql);
|
|
while($r = $pdo->fetch_assoc($q)){
|
|
//$user_ids[] = (int)$r['user_id'];
|
|
$object_sends[] = $r;
|
|
$object_ids[] = (int)$r['object_id'];
|
|
}
|
|
|
|
$sql_obj = "SELECT id_add_user, id, adres, archive FROM objects WHERE id in (".implode(',',$object_ids).") LIMIT 1000000 OPTION max_matches=1000000";
|
|
$q_obj = $db_sphinx->query($sql_obj);
|
|
while($r_obj = $db_sphinx->fetch_assoc($q_obj)){
|
|
$user_ids[] = (int)$r_obj['id_add_user'];
|
|
$object_users[$r_obj['id']] = (int)$r_obj['id_add_user'];
|
|
$object_adres[$r_obj['id']] = $r_obj['adres'];
|
|
$object_archive[$r_obj['id']] = (int)$r_obj['archive'];
|
|
}
|
|
|
|
|
|
|
|
$user_ids = array_unique($user_ids);
|
|
$sql_user = "SELECT * FROM users WHERE id in (".implode(',', $user_ids).")";
|
|
$q_user = $pdo->query($sql_user);
|
|
while($r_user = $pdo->fetch_assoc($q_user)){
|
|
$users[$r_user['id']] = $r_user;
|
|
}
|
|
|
|
//var_dump($users);
|
|
|
|
$Telega = new Telegram(false, $pdo);
|
|
$max = new MaxClass();
|
|
//var_dump($object_sends);
|
|
|
|
foreach($object_sends as $send){
|
|
if($object_archive[$send['object_id']] == 0){
|
|
$send_t = 0;
|
|
$send_m = 0;
|
|
$user_id = $object_users[$send['object_id']];
|
|
|
|
if(isset($users[$user_id])){
|
|
$user = $users[$user_id];
|
|
if($user['telegramm_notice'] > 0 && $user['telegramm_chat_id'] > 0){
|
|
$chatId = $user['telegramm_chat_id'];
|
|
$text = "Истек срок размещения объекта ID {$send['object_id']} на ";
|
|
if(isset($arrDestination[$send['destination']])){
|
|
$text .= $arrDestination[$send['destination']];
|
|
} else {
|
|
$text .= $send['destination'];
|
|
}
|
|
$text .= "\nАдрес: ".$object_adres[$send['object_id']];
|
|
$Telega->send($text, $chatId);
|
|
$send_t = 1;
|
|
|
|
}
|
|
|
|
if($user['max_notice'] > 0 && $user['max_user_id'] > 0){
|
|
$userMaxId = $user['max_user_id'];
|
|
$text = "Истек срок размещения объекта ID {$send['object_id']} на ";
|
|
if(isset($arrDestination[$send['destination']])){
|
|
$text .= $arrDestination[$send['destination']];
|
|
} else {
|
|
$text .= $send['destination'];
|
|
}
|
|
$text .= "\nАдрес: ".$object_adres[$send['object_id']];
|
|
$max->send_messages_to_user($userMaxId, $text);
|
|
$send_m = 1;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
} else {
|
|
$send_t = 2;
|
|
}
|
|
|
|
$pdo->query("UPDATE object_unpublish_telegram_send SET is_read=1, send={$send_t}, send_max={$send_m} WHERE id = {$send['id']}", true);
|
|
|
|
}
|