2013-07-08 15:08:14 +04:00
|
|
|
|
<?php
|
|
|
|
|
namespace IntaroCrm;
|
|
|
|
|
|
|
|
|
|
class RestApi
|
|
|
|
|
{
|
|
|
|
|
protected $apiUrl;
|
|
|
|
|
protected $apiKey;
|
2014-05-19 13:41:10 +04:00
|
|
|
|
protected $apiVersion = '3';
|
2014-03-22 14:52:17 +04:00
|
|
|
|
protected $generatedAt;
|
2013-07-29 12:29:41 +04:00
|
|
|
|
|
2013-07-09 19:03:56 +04:00
|
|
|
|
protected $parameters;
|
2013-07-08 15:08:14 +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 19:03:56 +04:00
|
|
|
|
$this->parameters = array('apiKey' => $this->apiKey);
|
2013-07-08 15:08:14 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Методы для работы с заказами */
|
|
|
|
|
/**
|
|
|
|
|
* Получение заказа по id
|
|
|
|
|
*
|
|
|
|
|
* @param string $id - идентификатор заказа
|
2013-07-09 19:03:56 +04:00
|
|
|
|
* @param string $by - поиск заказа по id или externalId
|
2013-07-08 15:08:14 +04:00
|
|
|
|
* @return array - информация о заказе
|
|
|
|
|
*/
|
2013-07-09 19:03:56 +04:00
|
|
|
|
public function orderGet($id, $by = 'externalId')
|
2013-07-08 15:08:14 +04:00
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'orders/'.$id;
|
2013-07-09 19:03:56 +04:00
|
|
|
|
|
|
|
|
|
if ($by != 'externalId')
|
|
|
|
|
$this->parameters['by'] = $by;
|
2013-07-08 15:08:14 +04:00
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Создание заказа
|
|
|
|
|
*
|
|
|
|
|
* @param array $order- информация о заказе
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function orderCreate($order)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($order);
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$this->parameters['order'] = $dataJson;
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'orders/create';
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-08 15:08:14 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Изменение заказа
|
|
|
|
|
*
|
|
|
|
|
* @param array $order- информация о заказе
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function orderEdit($order)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($order);
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$this->parameters['order'] = $dataJson;
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$url = $this->apiUrl.'orders/'.$order['externalId'].'/edit';
|
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-08 15:08:14 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-07-29 12:29:41 +04:00
|
|
|
|
* Пакетная загрузка заказов
|
2013-07-08 15:08:14 +04:00
|
|
|
|
*
|
|
|
|
|
* @param array $orders - массив заказов
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function orderUpload($orders)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($orders);
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$this->parameters['orders'] = $dataJson;
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'orders/upload';
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-29 12:29:41 +04:00
|
|
|
|
if (is_null($result) && isset($result['uploadedOrders']))
|
|
|
|
|
return $result['uploadedOrders'];
|
2013-07-08 15:08:14 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-18 22:55:52 +04:00
|
|
|
|
/**
|
|
|
|
|
* Обновление externalId у заказов с переданными id
|
|
|
|
|
*
|
2014-03-22 14:52:17 +04:00
|
|
|
|
* @param array $orders- массив, содержащий id и externalId заказа
|
2013-07-18 22:55:52 +04:00
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2014-03-22 14:52:17 +04:00
|
|
|
|
public function orderFixExternalIds($order)
|
2013-07-18 22:55:52 +04:00
|
|
|
|
{
|
2014-03-22 14:52:17 +04:00
|
|
|
|
$dataJson = json_encode($order);
|
2013-07-18 22:55:52 +04:00
|
|
|
|
$this->parameters['orders'] = $dataJson;
|
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'orders/fix-external-ids';
|
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-08 15:08:14 +04:00
|
|
|
|
/**
|
|
|
|
|
* Удаление заказа
|
|
|
|
|
*
|
|
|
|
|
* @param string $id - идентификатор заказа
|
2013-07-09 19:03:56 +04:00
|
|
|
|
* @param string $by - поиск заказа по id или externalId
|
2013-07-08 15:08:14 +04:00
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2013-07-18 22:55:52 +04:00
|
|
|
|
/*
|
2013-07-09 19:03:56 +04:00
|
|
|
|
public function orderDelete($id, $by = 'externalId')
|
2013-07-08 15:08:14 +04:00
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'orders/'.$id.'/delete';
|
2013-07-09 19:03:56 +04:00
|
|
|
|
if ($by != 'externalId')
|
|
|
|
|
$this->parameters['by'] = $by;
|
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-08 15:08:14 +04:00
|
|
|
|
return $result;
|
2013-07-18 22:55:52 +04:00
|
|
|
|
}*/
|
2013-07-08 15:08:14 +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)
|
|
|
|
|
{
|
2014-10-08 23:24:26 +04:00
|
|
|
|
$url = $this->apiUrl.'orders/history';
|
|
|
|
|
$this->parameters['skipMyChanges'] = true;
|
2013-07-29 12:29:41 +04:00
|
|
|
|
$this->parameters['startDate'] = $startDate;
|
|
|
|
|
$this->parameters['endDate'] = $endDate;
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$this->parameters['limit'] = $limit;
|
|
|
|
|
$this->parameters['offset'] = $offset;
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$result = $this->curlRequest($url);
|
2013-07-08 15:08:14 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Методы для работы с клиентами */
|
|
|
|
|
/**
|
|
|
|
|
* Получение клиента по id
|
|
|
|
|
*
|
|
|
|
|
* @param string $id - идентификатор
|
2013-07-09 19:03:56 +04:00
|
|
|
|
* @param string $by - поиск заказа по id или externalId
|
2013-07-08 15:08:14 +04:00
|
|
|
|
* @return array - информация о клиенте
|
|
|
|
|
*/
|
2013-07-09 19:03:56 +04:00
|
|
|
|
public function customerGet($id, $by = 'externalId')
|
2013-07-08 15:08:14 +04:00
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'customers/'.$id;
|
2013-07-09 19:03:56 +04:00
|
|
|
|
if ($by != 'externalId')
|
|
|
|
|
$this->parameters['by'] = $by;
|
2013-07-08 15:08:14 +04:00
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-20 17:59:52 +04:00
|
|
|
|
/**
|
|
|
|
|
* Получение списка клиентов в соответсвии с запросом
|
|
|
|
|
*
|
|
|
|
|
* @param string $phone - телефон
|
|
|
|
|
* @param string $email - почтовый адрес
|
|
|
|
|
* @param string $fio - фио пользователя
|
|
|
|
|
* @param int $limit - ограничение на размер выборки
|
|
|
|
|
* @param int $offset - сдвиг
|
|
|
|
|
* @return array - массив клиентов
|
|
|
|
|
*/
|
|
|
|
|
public function customers($phone = null, $email = null, $fio = null, $limit = 200, $offset = 0)
|
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'customers';
|
|
|
|
|
$this->parameters['phone'] = $phone;
|
|
|
|
|
$this->parameters['email'] = $email;
|
|
|
|
|
$this->parameters['fio'] = $fio;
|
|
|
|
|
$this->parameters['limit'] = $limit;
|
|
|
|
|
$this->parameters['offset'] = $offset;
|
|
|
|
|
|
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-08 15:08:14 +04:00
|
|
|
|
/**
|
|
|
|
|
* Создание клиента
|
|
|
|
|
*
|
|
|
|
|
* @param array $customer - информация о клиенте
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function customerCreate($customer)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($customer);
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$this->parameters['customer'] = $dataJson;
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'customers/create';
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-08 15:08:14 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Редактирование клиента
|
|
|
|
|
*
|
|
|
|
|
* @param array $customer - информация о клиенте
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function customerEdit($customer)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($customer);
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$this->parameters['customer'] = $dataJson;
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$url = $this->apiUrl.'customers/'.$customer['externalId'].'/edit';
|
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-08 15:08:14 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-29 12:29:41 +04:00
|
|
|
|
/**
|
|
|
|
|
* Пакетная загрузка клиентов
|
|
|
|
|
*
|
|
|
|
|
* @param array $customers - массив клиентов
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function customerUpload($customers)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($customers);
|
|
|
|
|
$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;
|
2014-01-28 12:44:20 +04:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-22 15:15:37 +04:00
|
|
|
|
/**
|
|
|
|
|
* Обновление externalId у клиентов с переданными id
|
|
|
|
|
*
|
|
|
|
|
* @param array $customers- массив, содержащий id и externalId заказа
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function customerFixExternalIds($customers)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($customers);
|
|
|
|
|
$this->parameters['customers'] = $dataJson;
|
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'customers/fix-external-ids';
|
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-08 15:08:14 +04:00
|
|
|
|
/**
|
|
|
|
|
* Удаление клиента
|
|
|
|
|
*
|
|
|
|
|
* @param string $id - идентификатор
|
2013-07-09 19:03:56 +04:00
|
|
|
|
* @param string $by - поиск заказа по id или externalId
|
2013-07-08 15:08:14 +04:00
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2013-07-18 22:55:52 +04:00
|
|
|
|
/*
|
2013-07-09 19:03:56 +04:00
|
|
|
|
public function customerDelete($id, $by = 'externalId')
|
2013-07-08 15:08:14 +04:00
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'customers/'.$id.'/delete';
|
2013-07-09 19:03:56 +04:00
|
|
|
|
if ($by != 'externalId')
|
|
|
|
|
$this->parameters['by'] = $by;
|
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-08 15:08:14 +04:00
|
|
|
|
return $result;
|
2013-07-18 22:55:52 +04:00
|
|
|
|
}*/
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Получение списка заказов клиента
|
|
|
|
|
*
|
|
|
|
|
* @param string $id - идентификатор клиента
|
2013-07-09 19:03:56 +04:00
|
|
|
|
* @param string $by - поиск заказа по id или externalId
|
2013-07-08 15:08:14 +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 19:03:56 +04:00
|
|
|
|
$limit = 100, $offset = 0, $by = 'externalId')
|
2013-07-08 15:08:14 +04:00
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'customers/'.$id.'/orders';
|
2013-07-09 19:03:56 +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-08 15:08:14 +04:00
|
|
|
|
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$result = $this->curlRequest($url);
|
2013-07-08 15:08:14 +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 19:03:56 +04:00
|
|
|
|
$this->parameters['deliveryType'] = $dataJson;
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
2013-08-27 18:05:55 +04:00
|
|
|
|
$url = $this->apiUrl.'reference/delivery-types/'.$deliveryType['code'].'/edit';
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-08 15:08:14 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-22 15:08:51 +04:00
|
|
|
|
/**
|
|
|
|
|
* Получение списка служб доставки
|
|
|
|
|
*
|
|
|
|
|
* @return array - массив типов доставки
|
|
|
|
|
*/
|
|
|
|
|
public function deliveryServicesList()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'reference/delivery-services';
|
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Редактирование службы доставки
|
|
|
|
|
*
|
|
|
|
|
* @param array $deliveryService - информация о типе доставки
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function deliveryServiceEdit($deliveryService)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($deliveryService);
|
|
|
|
|
$this->parameters['deliveryService'] = $dataJson;
|
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'reference/delivery-services/'.$deliveryService['code'].'/edit';
|
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Получение списка типов оплаты
|
|
|
|
|
*
|
|
|
|
|
* @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 19:03:56 +04:00
|
|
|
|
$this->parameters['paymentType'] = $dataJson;
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
2013-08-27 18:05:55 +04:00
|
|
|
|
$url = $this->apiUrl.'reference/payment-types/'.$paymentType['code'].'/edit';
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-08 15:08:14 +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 19:03:56 +04:00
|
|
|
|
$this->parameters['paymentStatus'] = $dataJson;
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
2013-08-27 18:05:55 +04:00
|
|
|
|
$url = $this->apiUrl.'reference/payment-statuses/'.$paymentStatus['code'].'/edit';
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-08 15:08:14 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Получение списка типов заказа
|
|
|
|
|
*
|
|
|
|
|
* @return array - массив типов заказа
|
|
|
|
|
*/
|
|
|
|
|
public function orderTypesList()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'reference/order-types';
|
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Редактирование типа заказа
|
|
|
|
|
*
|
2013-07-09 19:03:56 +04:00
|
|
|
|
* @param array $orderType - информация о типе заказа
|
2013-07-08 15:08:14 +04:00
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function orderTypesEdit($orderType)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($orderType);
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$this->parameters['orderType'] = $dataJson;
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
2013-08-27 18:05:55 +04:00
|
|
|
|
$url = $this->apiUrl.'reference/order-types/'.$orderType['code'].'/edit';
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
2013-07-08 15:08:14 +04:00
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-22 14:52:17 +04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Получение списка способов оформления заказа
|
|
|
|
|
*
|
|
|
|
|
* @return array - массив способов оформления заказа
|
|
|
|
|
*/
|
|
|
|
|
public function orderMethodsList()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'reference/order-methods';
|
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Редактирование способа оформления заказа
|
|
|
|
|
*
|
|
|
|
|
* @param array $orderMethod - информация о способе оформления заказа
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function orderMethodsEdit($orderMethod)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($orderMethod);
|
|
|
|
|
$this->parameters['orderMethod'] = $dataJson;
|
|
|
|
|
|
|
|
|
|
$url = $this->apiUrl.'reference/order-methods/'.$orderMethod['code'].'/edit';
|
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-09 19:03:56 +04:00
|
|
|
|
/**
|
|
|
|
|
* Получение списка статусов заказа
|
|
|
|
|
*
|
|
|
|
|
* @return array - массив статусов заказа
|
|
|
|
|
*/
|
|
|
|
|
public function orderStatusesList()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'reference/statuses';
|
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Редактирование статуса заказа
|
|
|
|
|
*
|
|
|
|
|
* @param array $status - информация о статусе заказа
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function orderStatusEdit($status)
|
|
|
|
|
{
|
|
|
|
|
$dataJson = json_encode($status);
|
|
|
|
|
$this->parameters['status'] = $dataJson;
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
2013-08-27 18:05:55 +04:00
|
|
|
|
$url = $this->apiUrl.'reference/statuses/'.$status['code'].'/edit';
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
|
|
|
|
|
2013-07-09 19:03:56 +04:00
|
|
|
|
/**
|
|
|
|
|
* Получение списка групп статусов заказа
|
|
|
|
|
*
|
|
|
|
|
* @return array - массив групп статусов заказа
|
|
|
|
|
*/
|
|
|
|
|
public function orderStatusGroupsList()
|
2013-07-08 15:08:14 +04:00
|
|
|
|
{
|
2013-07-09 19:03:56 +04:00
|
|
|
|
$url = $this->apiUrl.'reference/status-groups';
|
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2014-03-22 14:52:17 +04:00
|
|
|
|
|
2013-07-29 12:29:41 +04:00
|
|
|
|
/**
|
|
|
|
|
* Обновление статистики
|
|
|
|
|
*
|
|
|
|
|
* @return array - статус вып обновления
|
|
|
|
|
*/
|
|
|
|
|
public function statisticUpdate()
|
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'statistic/update';
|
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2013-07-09 19:03:56 +04:00
|
|
|
|
|
2014-03-22 14:52:17 +04:00
|
|
|
|
/**
|
|
|
|
|
* @return \DateTime
|
|
|
|
|
*/
|
|
|
|
|
public function getGeneratedAt() {
|
|
|
|
|
return $this->generatedAt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getErrorMessage($response)
|
|
|
|
|
{
|
|
|
|
|
$str = '';
|
|
|
|
|
if (isset($response['message']))
|
|
|
|
|
$str = $response['message'];
|
|
|
|
|
elseif (isset($response[0]['message']))
|
|
|
|
|
$str = $response[0]['message'];
|
|
|
|
|
elseif (isset($response['error']) && isset($response['error']['message']))
|
|
|
|
|
$str = $response['error']['message'];
|
|
|
|
|
elseif (isset($response['errorMsg']))
|
|
|
|
|
$str = $response['errorMsg'];
|
|
|
|
|
|
|
|
|
|
if (isset($response['errors']) && sizeof($response['errors'])) {
|
|
|
|
|
foreach ($response['errors'] as $error)
|
|
|
|
|
$str .= '. ' . $error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strlen($str))
|
|
|
|
|
return 'Application Error';
|
|
|
|
|
|
|
|
|
|
return $str;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-09 19:03:56 +04:00
|
|
|
|
protected function curlRequest($url, $method = 'GET', $format = 'json')
|
|
|
|
|
{
|
|
|
|
|
if ($method == 'GET' && !is_null($this->parameters))
|
|
|
|
|
$url .= '?'.http_build_query($this->parameters);
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
|
|
|
|
$ch = curl_init();
|
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
|
curl_setopt($ch, CURLOPT_FAILONERROR, FALSE);
|
2014-06-20 17:59:52 +04:00
|
|
|
|
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
|
2013-07-08 15:08:14 +04:00
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
|
2013-07-09 19:03:56 +04:00
|
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 30s
|
2014-06-20 17:59:52 +04:00
|
|
|
|
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
|
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
|
|
|
|
if ($method == 'POST')
|
|
|
|
|
{
|
|
|
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
2013-07-09 19:03:56 +04:00
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->parameters);
|
2013-07-08 15:08:14 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$response = curl_exec($ch);
|
2014-03-22 14:52:17 +04:00
|
|
|
|
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
2013-07-09 19:03:56 +04:00
|
|
|
|
unset($this->parameters);
|
|
|
|
|
/* Сброс массива с параметрами */
|
|
|
|
|
$this->parameters = array('apiKey' => $this->apiKey);
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
2014-03-22 14:52:17 +04:00
|
|
|
|
$errno = curl_errno($ch);
|
|
|
|
|
$error = curl_error($ch);
|
2013-07-08 15:08:14 +04:00
|
|
|
|
curl_close($ch);
|
|
|
|
|
|
2014-03-22 14:52:17 +04:00
|
|
|
|
if ($errno)
|
|
|
|
|
throw new Exception\CurlException($error, $errno);
|
|
|
|
|
|
|
|
|
|
$result = json_decode($response, true);
|
|
|
|
|
|
|
|
|
|
if ($statusCode >= 400 || isset($result['success']) && $result['success'] === false) {
|
|
|
|
|
throw new Exception\ApiException($this->getErrorMessage($result), $statusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($result['generatedAt'])) {
|
|
|
|
|
$this->generatedAt = new \DateTime($result['generatedAt']);
|
|
|
|
|
unset($result['generatedAt']);
|
|
|
|
|
}
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
|
|
|
|
unset($result['success']);
|
2014-03-22 14:52:17 +04:00
|
|
|
|
|
2013-07-08 15:08:14 +04:00
|
|
|
|
if (count($result) == 0)
|
|
|
|
|
return true;
|
2014-03-22 14:52:17 +04:00
|
|
|
|
|
2013-07-08 15:08:14 +04:00
|
|
|
|
return reset($result);
|
|
|
|
|
}
|
2014-06-20 17:59:52 +04:00
|
|
|
|
}
|