2013-07-02 13:07:10 +04:00
|
|
|
|
<?php
|
2013-07-04 15:33:13 +04:00
|
|
|
|
namespace IntaroCrm;
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
2013-07-04 15:21:23 +04:00
|
|
|
|
class RestApi
|
2013-07-02 13:07:10 +04:00
|
|
|
|
{
|
|
|
|
|
protected $apiUrl;
|
|
|
|
|
protected $apiKey;
|
|
|
|
|
protected $apiVersion = '1';
|
2013-07-26 16:24:49 +04:00
|
|
|
|
|
|
|
|
|
protected $response;
|
2013-07-03 11:34:39 +04:00
|
|
|
|
protected $statusCode;
|
2013-07-09 16:24:28 +04:00
|
|
|
|
protected $parameters;
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $crmUrl - адрес CRM
|
|
|
|
|
* @param string $apiKey - ключ для работы с api
|
|
|
|
|
*/
|
|
|
|
|
public function __construct($crmUrl, $apiKey)
|
|
|
|
|
{
|
|
|
|
|
$this->apiUrl = $crmUrl.'/api/v'.$this->apiVersion.'/';
|
|
|
|
|
$this->apiKey = $apiKey;
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$this->parameters = array('apiKey' => $this->apiKey);
|
2013-07-02 13:07:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-04 15:51:49 +04:00
|
|
|
|
|
2013-07-03 11:34:39 +04:00
|
|
|
|
public function getStatusCode()
|
|
|
|
|
{
|
|
|
|
|
return $this->statusCode;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-04 15:51:49 +04:00
|
|
|
|
/* Получение кода статуса и сообщения об ошибке */
|
2013-07-03 11:34:39 +04:00
|
|
|
|
public function getLastError()
|
|
|
|
|
{
|
2013-07-26 16:24:49 +04:00
|
|
|
|
if (isset($this->response['errorMsg']) && isset($this->response['errors']))
|
|
|
|
|
{
|
|
|
|
|
$result = $this->statusCode . ' ' . $this->response['errorMsg'];
|
|
|
|
|
foreach ($this->response['errors'] as $error)
|
|
|
|
|
$result .= ' ' . $error;
|
|
|
|
|
}
|
|
|
|
|
elseif (isset($this->response['errorMsg']))
|
|
|
|
|
$result = $this->statusCode . ' ' . $this->response['errorMsg'];
|
2013-07-03 11:50:44 +04:00
|
|
|
|
else
|
2013-07-26 16:24:49 +04:00
|
|
|
|
$result = null;
|
|
|
|
|
return $result;
|
2013-07-03 11:34:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-04 15:51:49 +04:00
|
|
|
|
/* Псообщения об ошибке */
|
2013-07-03 11:34:39 +04:00
|
|
|
|
public function getLastErrorMessage()
|
|
|
|
|
{
|
2013-07-26 16:24:49 +04:00
|
|
|
|
return $this->response['errorMsg'];
|
2013-07-03 11:34:39 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-07-02 13:07:10 +04:00
|
|
|
|
/* Методы для работы с заказами */
|
|
|
|
|
/**
|
|
|
|
|
* Получение заказа по id
|
|
|
|
|
*
|
|
|
|
|
* @param string $id - идентификатор заказа
|
2013-07-09 16:24:28 +04:00
|
|
|
|
* @param string $by - поиск заказа по id или externalId
|
2013-07-02 13:07:10 +04:00
|
|
|
|
* @return array - информация о заказе
|
|
|
|
|
*/
|
2013-07-09 16:24:28 +04:00
|
|
|
|
public function orderGet($id, $by = 'externalId')
|
2013-07-02 13:07:10 +04:00
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'orders/'.$id;
|
2013-07-09 16:24:28 +04:00
|
|
|
|
|
|
|
|
|
if ($by != 'externalId')
|
|
|
|
|
$this->parameters['by'] = $by;
|
2013-07-02 13:07:10 +04:00
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Создание заказа
|
|
|
|
|
*
|
|
|
|
|
* @param array $order- информация о заказе
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function orderCreate($order)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($order);
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$this->parameters['order'] = $dataJson;
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'orders/create';
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-02 13:07:10 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Изменение заказа
|
|
|
|
|
*
|
|
|
|
|
* @param array $order- информация о заказе
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function orderEdit($order)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($order);
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$this->parameters['order'] = $dataJson;
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$url = $this->apiUrl.'orders/'.$order['externalId'].'/edit';
|
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-02 13:07:10 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-07-26 16:24:49 +04:00
|
|
|
|
* Пакетная загрузка заказов
|
2013-07-02 13:07:10 +04:00
|
|
|
|
*
|
|
|
|
|
* @param array $orders - массив заказов
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function orderUpload($orders)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($orders);
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$this->parameters['orders'] = $dataJson;
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'orders/upload';
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-26 16:24:49 +04:00
|
|
|
|
if (is_null($result) && isset($result['uploadedOrders']))
|
|
|
|
|
return $result['uploadedOrders'];
|
2013-07-02 13:07:10 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-18 15:39:52 +04:00
|
|
|
|
/**
|
|
|
|
|
* Обновление externalId у заказов с переданными id
|
|
|
|
|
*
|
|
|
|
|
* @param array $orders- массив, содержащий id и externalId заказа
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function orderFixExternalIds($order)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($order);
|
|
|
|
|
$this->parameters['orders'] = $dataJson;
|
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'orders/fix-external-ids';
|
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-02 13:07:10 +04:00
|
|
|
|
/**
|
|
|
|
|
* Удаление заказа
|
|
|
|
|
*
|
|
|
|
|
* @param string $id - идентификатор заказа
|
2013-07-09 16:24:28 +04:00
|
|
|
|
* @param string $by - поиск заказа по id или externalId
|
2013-07-02 13:07:10 +04:00
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2013-07-18 15:39:52 +04:00
|
|
|
|
/*
|
2013-07-09 16:24:28 +04:00
|
|
|
|
public function orderDelete($id, $by = 'externalId')
|
2013-07-02 13:07:10 +04:00
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'orders/'.$id.'/delete';
|
2013-07-09 16:24:28 +04:00
|
|
|
|
if ($by != 'externalId')
|
|
|
|
|
$this->parameters['by'] = $by;
|
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-02 13:07:10 +04:00
|
|
|
|
return $result;
|
2013-07-18 15:39:52 +04:00
|
|
|
|
}*/
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Получение последних измененных заказов
|
|
|
|
|
*
|
|
|
|
|
* @param DateTime $startDate - начальная дата выборки
|
|
|
|
|
* @param DateTime $endDate - конечная дата
|
|
|
|
|
* @param int $limit - ограничение на размер выборки
|
|
|
|
|
* @param int $offset - сдвиг
|
|
|
|
|
* @return array - массив заказов
|
|
|
|
|
*/
|
|
|
|
|
public function orderHistory($startDate = null, $endDate = null, $limit = 100, $offset = 0)
|
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'orders/history';
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$this->parameters['startDate'] = $startDate;
|
|
|
|
|
$this->parameters['endDate'] = $endDate;
|
|
|
|
|
$this->parameters['limit'] = $limit;
|
|
|
|
|
$this->parameters['offset'] = $offset;
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$result = $this->curlRequest($url);
|
2013-07-02 13:07:10 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Методы для работы с клиентами */
|
|
|
|
|
/**
|
|
|
|
|
* Получение клиента по id
|
|
|
|
|
*
|
|
|
|
|
* @param string $id - идентификатор
|
2013-07-09 16:24:28 +04:00
|
|
|
|
* @param string $by - поиск заказа по id или externalId
|
2013-07-02 13:07:10 +04:00
|
|
|
|
* @return array - информация о клиенте
|
|
|
|
|
*/
|
2013-07-09 16:24:28 +04:00
|
|
|
|
public function customerGet($id, $by = 'externalId')
|
2013-07-02 13:07:10 +04:00
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'customers/'.$id;
|
2013-07-09 16:24:28 +04:00
|
|
|
|
if ($by != 'externalId')
|
|
|
|
|
$this->parameters['by'] = $by;
|
2013-07-02 13:07:10 +04:00
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Создание клиента
|
|
|
|
|
*
|
|
|
|
|
* @param array $customer - информация о клиенте
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function customerCreate($customer)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($customer);
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$this->parameters['customer'] = $dataJson;
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'customers/create';
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-02 13:07:10 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Редактирование клиента
|
|
|
|
|
*
|
|
|
|
|
* @param array $customer - информация о клиенте
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function customerEdit($customer)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($customer);
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$this->parameters['customer'] = $dataJson;
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$url = $this->apiUrl.'customers/'.$customer['externalId'].'/edit';
|
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-02 13:07:10 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-26 16:24:49 +04:00
|
|
|
|
/**
|
|
|
|
|
* Пакетная загрузка клиентов
|
|
|
|
|
*
|
|
|
|
|
* @param array $customers - массив клиентов
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function customerUpload($customers)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($customers);
|
|
|
|
|
$dataJson = str_replace(self::$jsonReplaceSource, self::$jsonReplaceTarget,
|
|
|
|
|
$dataJson);
|
|
|
|
|
$this->parameters['customers'] = $dataJson;
|
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'customers/upload';
|
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
|
|
|
|
if (is_null($result) && isset($result['uploaded']))
|
|
|
|
|
return $result['uploaded'];
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-02 13:07:10 +04:00
|
|
|
|
/**
|
|
|
|
|
* Удаление клиента
|
|
|
|
|
*
|
|
|
|
|
* @param string $id - идентификатор
|
2013-07-09 16:24:28 +04:00
|
|
|
|
* @param string $by - поиск заказа по id или externalId
|
2013-07-02 13:07:10 +04:00
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2013-07-18 15:39:52 +04:00
|
|
|
|
/*
|
2013-07-09 16:24:28 +04:00
|
|
|
|
public function customerDelete($id, $by = 'externalId')
|
2013-07-02 13:07:10 +04:00
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'customers/'.$id.'/delete';
|
2013-07-09 16:24:28 +04:00
|
|
|
|
if ($by != 'externalId')
|
|
|
|
|
$this->parameters['by'] = $by;
|
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-02 13:07:10 +04:00
|
|
|
|
return $result;
|
2013-07-18 15:39:52 +04:00
|
|
|
|
}*/
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Получение списка заказов клиента
|
|
|
|
|
*
|
|
|
|
|
* @param string $id - идентификатор клиента
|
2013-07-09 16:24:28 +04:00
|
|
|
|
* @param string $by - поиск заказа по id или externalId
|
2013-07-02 13:07:10 +04:00
|
|
|
|
* @param DateTime $startDate - начальная дата выборки
|
|
|
|
|
* @param DateTime $endDate - конечная дата
|
|
|
|
|
* @param int $limit - ограничение на размер выборки
|
|
|
|
|
* @param int $offset - сдвиг
|
|
|
|
|
* @return array - массив заказов
|
|
|
|
|
*/
|
|
|
|
|
public function customerOrdersList($id, $startDate = null, $endDate = null,
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$limit = 100, $offset = 0, $by = 'externalId')
|
2013-07-02 13:07:10 +04:00
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'customers/'.$id.'/orders';
|
2013-07-09 16:24:28 +04:00
|
|
|
|
if ($by != 'externalId')
|
|
|
|
|
$this->parameters['by'] = $by;
|
|
|
|
|
$this->parameters['startDate'] = $startDate;
|
|
|
|
|
$this->parameters['endDate'] = $endDate;
|
|
|
|
|
$this->parameters['limit'] = $limit;
|
|
|
|
|
$this->parameters['offset'] = $offset;
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$result = $this->curlRequest($url);
|
2013-07-02 13:07:10 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Методы для работы со справочниками */
|
|
|
|
|
/**
|
|
|
|
|
* Получение списка типов доставки
|
|
|
|
|
*
|
|
|
|
|
* @return array - массив типов доставки
|
|
|
|
|
*/
|
|
|
|
|
public function deliveryTypesList()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'reference/delivery-types';
|
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Редактирование типа доставки
|
|
|
|
|
*
|
|
|
|
|
* @param array $deliveryType - информация о типе доставки
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function deliveryTypeEdit($deliveryType)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($deliveryType);
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$this->parameters['deliveryType'] = $dataJson;
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'delivery-types/'.$deliveryType['code'].'/edit';
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-02 13:07:10 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Получение списка типов оплаты
|
|
|
|
|
*
|
|
|
|
|
* @return array - массив типов оплаты
|
|
|
|
|
*/
|
|
|
|
|
public function paymentTypesList()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'reference/payment-types';
|
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Редактирование типа оплаты
|
|
|
|
|
*
|
|
|
|
|
* @param array $paymentType - информация о типе оплаты
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function paymentTypesEdit($paymentType)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($paymentType);
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$this->parameters['paymentType'] = $dataJson;
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'payment-types/'.$paymentType['code'].'/edit';
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-02 13:07:10 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Получение списка статусов оплаты
|
|
|
|
|
*
|
|
|
|
|
* @return array - массив статусов оплаты
|
|
|
|
|
*/
|
|
|
|
|
public function paymentStatusesList()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'reference/payment-statuses';
|
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Редактирование статуса оплаты
|
|
|
|
|
*
|
|
|
|
|
* @param array $paymentStatus - информация о статусе оплаты
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function paymentStatusesEdit($paymentStatus)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($paymentStatus);
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$this->parameters['paymentStatus'] = $dataJson;
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'payment-statuses/'.$paymentStatus['code'].'/edit';
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-02 13:07:10 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-07-04 15:21:23 +04:00
|
|
|
|
/**
|
|
|
|
|
* Получение списка типов заказа
|
|
|
|
|
*
|
|
|
|
|
* @return array - массив типов заказа
|
|
|
|
|
*/
|
|
|
|
|
public function orderTypesList()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'reference/order-types';
|
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Редактирование типа заказа
|
|
|
|
|
*
|
2013-07-08 18:06:55 +04:00
|
|
|
|
* @param array $orderType - информация о типе заказа
|
2013-07-04 15:21:23 +04:00
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function orderTypesEdit($orderType)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($orderType);
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$this->parameters['orderType'] = $dataJson;
|
2013-07-04 15:21:23 +04:00
|
|
|
|
|
2013-07-08 18:06:55 +04:00
|
|
|
|
$url = $this->apiUrl.'order-types/'.$orderType['code'].'/edit';
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-04 15:21:23 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-08 15:30:47 +04:00
|
|
|
|
/**
|
|
|
|
|
* Получение списка статусов заказа
|
|
|
|
|
*
|
|
|
|
|
* @return array - массив статусов заказа
|
|
|
|
|
*/
|
|
|
|
|
public function orderStatusesList()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'reference/statuses';
|
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-08 18:06:55 +04:00
|
|
|
|
/**
|
|
|
|
|
* Редактирование статуса заказа
|
|
|
|
|
*
|
|
|
|
|
* @param array $status - информация о статусе заказа
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function orderStatusEdit($status)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($status);
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$this->parameters['status'] = $dataJson;
|
2013-07-08 18:06:55 +04:00
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'statuses/'.$status['code'].'/edit';
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-08 18:06:55 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-07-08 15:30:47 +04:00
|
|
|
|
/**
|
|
|
|
|
* Получение списка групп статусов заказа
|
|
|
|
|
*
|
|
|
|
|
* @return array - массив групп статусов заказа
|
|
|
|
|
*/
|
|
|
|
|
public function orderStatusGroupsList()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'reference/status-groups';
|
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2013-07-29 12:38:42 +04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Обновление статистики
|
|
|
|
|
*
|
|
|
|
|
* @return array - статус вып обновления
|
|
|
|
|
*/
|
|
|
|
|
public function statisticUpdate()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'statistic/update';
|
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
2013-07-09 16:24:28 +04:00
|
|
|
|
protected function curlRequest($url, $method = 'GET', $format = 'json')
|
2013-07-02 13:07:10 +04:00
|
|
|
|
{
|
2013-07-09 16:24:28 +04:00
|
|
|
|
if ($method == 'GET' && !is_null($this->parameters))
|
|
|
|
|
$url .= '?'.http_build_query($this->parameters);
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
|
|
|
|
$ch = curl_init();
|
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
|
curl_setopt($ch, CURLOPT_FAILONERROR, FALSE);
|
|
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
|
2013-07-29 12:38:42 +04:00
|
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 30s
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
|
|
|
|
if ($method == 'POST')
|
|
|
|
|
{
|
|
|
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
2013-07-09 16:24:28 +04:00
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->parameters);
|
2013-07-02 13:07:10 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$response = curl_exec($ch);
|
2013-07-03 11:34:39 +04:00
|
|
|
|
$this->statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
2013-07-09 16:24:28 +04:00
|
|
|
|
unset($this->parameters);
|
|
|
|
|
/* Сброс массива с параметрами */
|
|
|
|
|
$this->parameters = array('apiKey' => $this->apiKey);
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
2013-07-03 11:34:39 +04:00
|
|
|
|
if (curl_errno($ch))
|
|
|
|
|
{
|
2013-07-26 16:24:49 +04:00
|
|
|
|
$this->response = array('errorMsg' => 'Curl error: ' . curl_error($ch));
|
2013-07-03 11:34:39 +04:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
curl_close($ch);
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
|
|
|
|
$result = (array)json_decode($response, true);
|
2013-07-26 16:24:49 +04:00
|
|
|
|
$this->response = $result;
|
2013-07-03 11:34:39 +04:00
|
|
|
|
if ($result['success'] == false)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
unset($result['success']);
|
|
|
|
|
if (count($result) == 0)
|
|
|
|
|
return true;
|
|
|
|
|
return reset($result);
|
2013-07-02 13:07:10 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|