|
|
@@ -42,82 +42,91 @@ use linslin\yii2\curl; |
|
|
|
|
|
|
|
class Tiller |
|
|
|
{ |
|
|
|
var $curl; |
|
|
|
var $producer_tiller; |
|
|
|
var $provider_token; |
|
|
|
var $restaurant_token; |
|
|
|
//var $url_api = 'https://developers.tillersystems.com/api/'; |
|
|
|
var $url_api = 'https://app.tillersystems.com/api/'; |
|
|
|
var $curl; |
|
|
|
var $producer_tiller; |
|
|
|
var $provider_token; |
|
|
|
var $restaurant_token; |
|
|
|
//var $url_api = 'https://developers.tillersystems.com/api/'; |
|
|
|
var $url_api = 'https://app.tillersystems.com/api/'; |
|
|
|
|
|
|
|
public function __construct() |
|
|
|
{ |
|
|
|
$this->curl = new curl\Curl(); |
|
|
|
$this->producer_tiller = Producer::getConfig('tiller'); |
|
|
|
$this->provider_token = Producer::getConfig('tiller_provider_token'); |
|
|
|
$this->restaurant_token = Producer::getConfig('tiller_restaurant_token'); |
|
|
|
} |
|
|
|
public function __construct() |
|
|
|
{ |
|
|
|
$this->curl = new curl\Curl(); |
|
|
|
$this->producer_tiller = Producer::getConfig('tiller'); |
|
|
|
$this->provider_token = Producer::getConfig('tiller_provider_token'); |
|
|
|
$this->restaurant_token = Producer::getConfig('tiller_restaurant_token'); |
|
|
|
} |
|
|
|
|
|
|
|
public function getOrders($date) |
|
|
|
{ |
|
|
|
if ($this->producer_tiller) { |
|
|
|
$orders = $this->curl->setGetParams([ |
|
|
|
'provider_token' => $this->provider_token, |
|
|
|
'restaurant_token' => $this->restaurant_token, |
|
|
|
'dateFrom' => date('Y-m-d H-i-s', strtotime($date)), |
|
|
|
'dateTo' => date('Y-m-d H-i-s', strtotime($date) + 24 * 60 * 60 - 1), |
|
|
|
'status' => 'IN_PROGRESS', |
|
|
|
])->get($this->url_api . 'orders'); |
|
|
|
public function getOrders($date) |
|
|
|
{ |
|
|
|
if ($this->producer_tiller) { |
|
|
|
$orders = $this->curl->setGetParams([ |
|
|
|
'provider_token' => $this->provider_token, |
|
|
|
'restaurant_token' => $this->restaurant_token, |
|
|
|
'dateFrom' => date('Y-m-d H-i-s', strtotime($date)), |
|
|
|
'dateTo' => date( |
|
|
|
'Y-m-d H-i-s', |
|
|
|
strtotime($date) + 24 * 60 * 60 - 1 |
|
|
|
), |
|
|
|
'status' => 'IN_PROGRESS', |
|
|
|
])->get($this->url_api . 'orders'); |
|
|
|
|
|
|
|
return json_decode($orders); |
|
|
|
} |
|
|
|
return json_decode($orders); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function isSynchro($date) |
|
|
|
{ |
|
|
|
if ($this->producer_tiller) { |
|
|
|
$ordersTiller = $this->getOrders($date); |
|
|
|
$ordersOpendistrib = Order::searchAll([ |
|
|
|
'distribution.date' => $date, |
|
|
|
'order.tiller_synchronization' => 1 |
|
|
|
], [ |
|
|
|
'conditions' => 'date_delete IS NULL' |
|
|
|
]); |
|
|
|
|
|
|
|
$ordersOpendistribSynchro = []; |
|
|
|
public function isSynchro($date) |
|
|
|
{ |
|
|
|
if ($this->producer_tiller) { |
|
|
|
$ordersTiller = $this->getOrders($date); |
|
|
|
$ordersOpendistrib = Order::searchAll([ |
|
|
|
'distribution.date' => $date, |
|
|
|
'order.tiller_synchronization' => 1 |
|
|
|
], [ |
|
|
|
'conditions' => 'date_delete IS NULL' |
|
|
|
]); |
|
|
|
|
|
|
|
if ($ordersOpendistrib) { |
|
|
|
foreach ($ordersOpendistrib as $orderOpendistrib) { |
|
|
|
$ordersOpendistribSynchro[$orderOpendistrib->id] = false; |
|
|
|
if(isset($ordersTiller->orders)) { |
|
|
|
foreach ($ordersTiller->orders as $orderTiller) { |
|
|
|
if ($orderOpendistrib->tiller_external_id == $orderTiller->id |
|
|
|
&& (int) round($orderOpendistrib->getAmountWithTax(Order::AMOUNT_TOTAL) * 100) == (int) $orderTiller->currentBill) { |
|
|
|
$ordersOpendistribSynchro = []; |
|
|
|
|
|
|
|
$ordersOpendistribSynchro[$orderOpendistrib->id] = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach ($ordersOpendistribSynchro as $idOrder => $isSynchro) { |
|
|
|
if (!$isSynchro) { |
|
|
|
return false; |
|
|
|
if ($ordersOpendistrib) { |
|
|
|
foreach ($ordersOpendistrib as $orderOpendistrib) { |
|
|
|
$ordersOpendistribSynchro[$orderOpendistrib->id] = false; |
|
|
|
if (isset($ordersTiller->orders)) { |
|
|
|
foreach ($ordersTiller->orders as $orderTiller) { |
|
|
|
if ($orderOpendistrib->tiller_external_id == $orderTiller->id) { |
|
|
|
$amountTotalOrderOpendistrib = (int)round( |
|
|
|
$orderOpendistrib->getAmountWithTax(Order::AMOUNT_TOTAL) * 100 |
|
|
|
); |
|
|
|
if ($amountTotalOrderOpendistrib == (int)$orderTiller->currentPayedAmount |
|
|
|
|| $amountTotalOrderOpendistrib == (int)$orderTiller->currentBill) { |
|
|
|
$ordersOpendistribSynchro[$orderOpendistrib->id] = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
foreach ($ordersOpendistribSynchro as $idOrder => $isSynchro) { |
|
|
|
if (!$isSynchro) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function postOrder($params) |
|
|
|
{ |
|
|
|
if ($this->producer_tiller) { |
|
|
|
return $this->curl->setPostParams(array_merge([ |
|
|
|
'provider_token' => $this->provider_token, |
|
|
|
'restaurant_token' => $this->restaurant_token, |
|
|
|
], $params)) |
|
|
|
->post($this->url_api . 'orders'); |
|
|
|
} |
|
|
|
public function postOrder($params) |
|
|
|
{ |
|
|
|
if ($this->producer_tiller) { |
|
|
|
return $this->curl->setPostParams( |
|
|
|
array_merge([ |
|
|
|
'provider_token' => $this->provider_token, |
|
|
|
'restaurant_token' => $this->restaurant_token, |
|
|
|
], $params) |
|
|
|
) |
|
|
|
->post($this->url_api . 'orders'); |
|
|
|
} |
|
|
|
} |
|
|
|
} |