Преглед на файлове

Merge branch 'dev'

prodstable
Guillaume преди 2 години
родител
ревизия
5bfb325b50
променени са 1 файла, в които са добавени 45 реда и са изтрити 27 реда
  1. +45
    -27
      producer/controllers/OrderController.php

+ 45
- 27
producer/controllers/OrderController.php Целия файл

@@ -661,6 +661,9 @@ class OrderController extends ProducerBaseController
// PointSale current
$pointSaleCurrent = PointSale::findOne($pointSaleId);

// Commande de l'utilisateur
$orderUser = $this->_getOrderUser($date, $pointSaleId);

// Producteur
$producer = Producer::searchOne([
'id' => $this->getProducer()->id
@@ -697,7 +700,19 @@ class OrderController extends ProducerBaseController
for ($i = 0; $i < count($distributionsArray); $i++) {
$distribution = $distributionsArray[$i];
if (Distribution::isPointSaleActive($distribution, $pointSaleId)) {
$distributionsArrayFilterPointSale[] = $distribution;

$countOrders = (int) Order::searchCount([
'id_distribution' => $distribution->id,
'id_point_sale' => $pointSaleId
]);
$orderUserPointSale = $this->_getOrderUser($distribution->date, $pointSaleId);

if(!$pointSaleCurrent->maximum_number_orders
|| ($orderUserPointSale && $orderUserPointSale->id_point_sale == $pointSaleId)
|| ($pointSaleCurrent->maximum_number_orders &&
($countOrders < $pointSaleCurrent->maximum_number_orders))) {
$distributionsArrayFilterPointSale[] = $distribution;
}
}
}

@@ -757,32 +772,6 @@ class OrderController extends ProducerBaseController
}

if ($dateObject && $dateObject->format($format) === $date) {
// Commande de l'utilisateur
$orderUser = false;
if (User::getCurrentId()) {
$conditionOrderUser = [
'distribution.date' => $date,
'id_user' => User::getCurrentId(),
];

if ($pointSaleId) {
$conditionOrderUser['id_point_sale'] = $pointSaleId;
}

$orderUser = Order::searchOne($conditionOrderUser);

if ($orderUser && $orderUser->online_payment_url) {
$orderUser = false;
}
}

if ($orderUser) {
$json['order'] = array_merge($orderUser->getAttributes(), [
'amount_total' => $orderUser->getAmountWithTax(Order::AMOUNT_TOTAL),
'amount_paid' => $orderUser->getAmount(Order::AMOUNT_PAID),
]);
}

// distribution
$distribution = Distribution::initDistribution($date, $producer->id);
$json['distribution'] = $distribution;
@@ -889,6 +878,35 @@ class OrderController extends ProducerBaseController
return $json;
}

private function _getOrderUser($date, $pointSaleId = false) {
$orderUser = false;
if (User::getCurrentId()) {
$conditionOrderUser = [
'distribution.date' => $date,
'id_user' => User::getCurrentId(),
];

if ($pointSaleId) {
$conditionOrderUser['id_point_sale'] = $pointSaleId;
}

$orderUser = Order::searchOne($conditionOrderUser);

if ($orderUser && $orderUser->online_payment_url) {
$orderUser = false;
}
}

if ($orderUser) {
$json['order'] = array_merge($orderUser->getAttributes(), [
'amount_total' => $orderUser->getAmountWithTax(Order::AMOUNT_TOTAL),
'amount_paid' => $orderUser->getAmount(Order::AMOUNT_PAID),
]);
}

return $orderUser;
}

private function _initPointsSale($idProducer, $distribution = false)
{
$pointsSaleArray = PointSale::find();

Loading…
Отказ
Запис