Joywork/cron/updatePackageObjectsToZipal.php

104 lines
3.4 KiB
PHP
Raw Permalink Normal View History

2026-05-22 20:21:54 +02:00
<?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);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Обновление пакетных объектов на Zipal.ru</title>
</head>
<body>
<?php
$sql = "SELECT zo.* from advertising_package_object_publish zo, objects o WHERE o.id = zo.object_id and o.archive = 0 and zo.zipal_id IS NOT NULL AND zo.send_to_update = 1 ORDER BY ID";
$rez_obj = mysql_query($sql);
while($obj = mysql_fetch_assoc($rez_obj)) {
$objectId = $obj['object_id'];
$res = Zipal::createObjectForZipal($mdb, $obj['object_id']);
$curUser = new User();
$curUser->get($obj['user_id']);
$requestToSend = [];
$login = $curUser->zipal_login;
$password = $curUser->zipal_password;
if (empty($login) || empty($password)) {
$login = $curUser->agencyZipalLogin;
$password = $curUser->agencyZipalPassword;
}
$requestToSend['login'] = $login;
$requestToSend['password'] = $password;
if ($obj['zipal_id'] != null && $obj['zipal_id']) {
$requestToSend['method'] = 'UpdateProperty';
$requestToSend['request']['requestType'] = 'UpdatePropertyRequestType';
$requestToSend['request']['id'] = $obj['zipal_id'];
$requestToSend['request']['request'] = $res;
$request = json_encode(utf8ize($requestToSend));
//echo $request;
//echo "<br/>";
//var_dump($requestToSend);
$user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; HTC_Touch_Diamond2_T5353; Windows Phone 6.5)';
//делаем запрос к zipal
$result = curl_request_zipal_json("https://zipal.ru/ws/json", $obj['user_id'], $user_agent, $request);
//echo $result;
$jsonResult = json_decode($result, true);
if (!$jsonResult) {
$jsonResult['result'] = [];
$jsonResult['result']['status'] = "SuccessPropertyResponseType";
}
//echo "<br/>";
//var_dump($jsonResult);
if ($jsonResult['resultCode'] == "FAIL") {
$sql = "UPDATE advertising_package_object_publish SET error_when_send_to_update = '$result' WHERE id = $obj[id]";
mysql_query($sql);
} else {
if ($jsonResult['result']['status'] == "ErrorPropertyResponseType") {
$sql = "UPDATE advertising_package_object_publish SET error_when_send_to_update = '$result' WHERE id = $obj[id]";
mysql_query($sql);
} else {
if ($jsonResult['result']['status'] == "SuccessPropertyResponseType") {
$sql = "UPDATE advertising_package_object_publish SET error_when_send_to_update = '', send_to_update = 0 WHERE id = $obj[id]";
mysql_query($sql);
} else {
$sql = "UPDATE advertising_package_object_publish SET error_when_send_to_update = '$result' WHERE id = $obj[id]";
mysql_query($sql);
}
}
}
}
}
function utf8ize($mixed) {
if (is_array($mixed)) {
foreach ($mixed as $key => $value) {
$mixed[$key] = utf8ize($value);
}
} else if (is_string ($mixed)) {
return iconv(mb_detect_encoding($mixed, mb_detect_order(), true), "UTF-8", $mixed);
}
return $mixed;
}
?>
</body>
</html>