2013-07-02 13:07:10 +04:00
|
|
|
|
<?php
|
2014-09-18 21:33:50 +04:00
|
|
|
|
|
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;
|
2014-06-20 17:56:13 +04:00
|
|
|
|
protected $apiVersion = '3';
|
2014-03-22 15:09:44 +04:00
|
|
|
|
protected $generatedAt;
|
2013-07-26 16:24:49 +04:00
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Методы для работы с заказами */
|
|
|
|
|
/**
|
|
|
|
|
* Получение заказа по 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
|
|
|
|
/**
|
|
|
|
|
* Получение последних измененных заказов
|
|
|
|
|
*
|
2014-09-18 21:33:50 +04:00
|
|
|
|
* @param \DateTime|string|int $startDate - начальная дата и время выборки (Y-m-d H:i:s)
|
|
|
|
|
* @param \DateTime|string|int $endDate - конечная дата и время выборки (Y-m-d H:i:s)
|
2013-07-02 13:07:10 +04:00
|
|
|
|
* @param int $limit - ограничение на размер выборки
|
|
|
|
|
* @param int $offset - сдвиг
|
|
|
|
|
* @return array - массив заказов
|
|
|
|
|
*/
|
|
|
|
|
public function orderHistory($startDate = null, $endDate = null, $limit = 100, $offset = 0)
|
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'orders/history';
|
2014-09-18 21:33:50 +04:00
|
|
|
|
$this->parameters['startDate'] = $this->ensureDateTime($startDate);
|
|
|
|
|
$this->parameters['endDate'] = $this->ensureDateTime($endDate);
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-03 13:47:51 +04:00
|
|
|
|
/**
|
|
|
|
|
* Получение списка клиентов в соответсвии с запросом
|
|
|
|
|
*
|
|
|
|
|
* @param string $phone - телефон
|
|
|
|
|
* @param string $email - почтовый адрес
|
|
|
|
|
* @param string $fio - фио пользователя
|
|
|
|
|
* @param int $limit - ограничение на размер выборки
|
|
|
|
|
* @param int $offset - сдвиг
|
|
|
|
|
* @return array - массив клиентов
|
|
|
|
|
*/
|
2014-04-03 13:52:08 +04:00
|
|
|
|
public function customers($phone = null, $email = null, $fio = null, $limit = 200, $offset = 0)
|
2014-04-03 13:47:51 +04:00
|
|
|
|
{
|
|
|
|
|
$url = $this->apiUrl.'customers';
|
2014-07-11 17:19:46 +04:00
|
|
|
|
if($phone) $this->parameters['phone'] = $phone;
|
|
|
|
|
if($email) $this->parameters['email'] = $email;
|
|
|
|
|
if($fio) $this->parameters['fio'] = $fio;
|
2014-04-03 13:47:51 +04:00
|
|
|
|
$this->parameters['limit'] = $limit;
|
|
|
|
|
$this->parameters['offset'] = $offset;
|
|
|
|
|
|
|
|
|
|
$result = $this->curlRequest($url);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-02 13:07:10 +04:00
|
|
|
|
/**
|
|
|
|
|
* Создание клиента
|
|
|
|
|
*
|
|
|
|
|
* @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);
|
|
|
|
|
$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-03-22 15:17:55 +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-02 13:07:10 +04:00
|
|
|
|
/**
|
|
|
|
|
* Получение списка заказов клиента
|
|
|
|
|
*
|
|
|
|
|
* @param string $id - идентификатор клиента
|
2013-07-09 16:24:28 +04:00
|
|
|
|
* @param string $by - поиск заказа по id или externalId
|
2014-09-18 21:33:50 +04:00
|
|
|
|
* @param \DateTime|string|int $startDate - начальная дата выборки (Y-m-d H:i:s)
|
|
|
|
|
* @param \DateTime|string|int $endDate - конечная дата выборки (Y-m-d H:i:s)
|
2013-07-02 13:07:10 +04:00
|
|
|
|
* @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;
|
2014-09-18 21:33:50 +04:00
|
|
|
|
$this->parameters['startDate'] = $this->ensureDateTime($startDate);
|
|
|
|
|
$this->parameters['endDate'] = $this->ensureDateTime($endDate);
|
2013-07-09 16:24:28 +04:00
|
|
|
|
$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
|
|
|
|
|
2013-08-27 18:07:57 +04:00
|
|
|
|
$url = $this->apiUrl.'reference/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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-22 15:09:44 +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-02 13:07:10 +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 16:24:28 +04:00
|
|
|
|
$this->parameters['paymentType'] = $dataJson;
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
2013-08-27 18:07:57 +04:00
|
|
|
|
$url = $this->apiUrl.'reference/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
|
|
|
|
|
2013-08-27 18:07:57 +04:00
|
|
|
|
$url = $this->apiUrl.'reference/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-08-27 18:07:57 +04:00
|
|
|
|
$url = $this->apiUrl.'reference/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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-04 20:29:24 +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;
|
|
|
|
|
|
2014-03-04 20:45:17 +04:00
|
|
|
|
$url = $this->apiUrl.'reference/order-methods/'.$orderMethod['code'].'/edit';
|
2014-03-04 20:29:24 +04:00
|
|
|
|
$result = $this->curlRequest($url, 'POST');
|
|
|
|
|
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
|
|
|
|
|
2013-08-27 18:07:57 +04:00
|
|
|
|
$url = $this->apiUrl.'reference/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-10-15 14:11:57 +04:00
|
|
|
|
|
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
|
|
|
|
|
2014-03-22 15:09:44 +04:00
|
|
|
|
/**
|
|
|
|
|
* @return \DateTime
|
|
|
|
|
*/
|
2014-09-18 21:33:50 +04:00
|
|
|
|
public function getGeneratedAt()
|
|
|
|
|
{
|
2014-03-22 15:09:44 +04:00
|
|
|
|
return $this->generatedAt;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-18 21:33:50 +04:00
|
|
|
|
protected function ensureDateTime($value)
|
|
|
|
|
{
|
|
|
|
|
if ($value instanceof \DateTime) {
|
|
|
|
|
return $value->format('Y-m-d H:i:s');
|
|
|
|
|
} elseif (is_int($value)) {
|
|
|
|
|
return date('Y-m-d H:i:s', $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-15 14:11:57 +04:00
|
|
|
|
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 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);
|
2014-04-13 13:58:37 +04:00
|
|
|
|
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
|
2013-07-02 13:07:10 +04:00
|
|
|
|
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
|
2014-06-17 07:32:13 +04:00
|
|
|
|
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
|
|
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-10-15 14:11:57 +04:00
|
|
|
|
$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-10-15 14:11:57 +04:00
|
|
|
|
$errno = curl_errno($ch);
|
2013-10-15 14:59:09 +04:00
|
|
|
|
$error = curl_error($ch);
|
2013-07-03 11:34:39 +04:00
|
|
|
|
curl_close($ch);
|
2013-07-02 13:07:10 +04:00
|
|
|
|
|
2013-10-15 14:11:57 +04:00
|
|
|
|
if ($errno)
|
2013-10-15 14:59:09 +04:00
|
|
|
|
throw new Exception\CurlException($error, $errno);
|
2013-10-15 14:11:57 +04:00
|
|
|
|
|
|
|
|
|
$result = json_decode($response, true);
|
|
|
|
|
|
|
|
|
|
if ($statusCode >= 400 || isset($result['success']) && $result['success'] === false) {
|
2013-10-15 14:59:09 +04:00
|
|
|
|
throw new Exception\ApiException($this->getErrorMessage($result), $statusCode);
|
2013-10-15 14:11:57 +04:00
|
|
|
|
}
|
2013-07-03 11:34:39 +04:00
|
|
|
|
|
2014-03-22 15:09:44 +04:00
|
|
|
|
if (isset($result['generatedAt'])) {
|
|
|
|
|
$this->generatedAt = new \DateTime($result['generatedAt']);
|
|
|
|
|
unset($result['generatedAt']);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-03 11:34:39 +04:00
|
|
|
|
unset($result['success']);
|
2013-10-15 14:11:57 +04:00
|
|
|
|
|
2013-07-03 11:34:39 +04:00
|
|
|
|
if (count($result) == 0)
|
|
|
|
|
return true;
|
2013-10-15 14:11:57 +04:00
|
|
|
|
|
2013-07-03 11:34:39 +04:00
|
|
|
|
return reset($result);
|
2013-07-02 13:07:10 +04:00
|
|
|
|
}
|
2014-04-13 13:58:37 +04:00
|
|
|
|
}
|