ソースを参照

Délais de commande : filtre des distributions en fonction des délais définis dans les paramètres du producteur

dev
Guillaume 4年前
コミット
155a165ed2
6個のファイルの変更67行の追加41行の削除
  1. +0
    -1
      backend/views/producer/update.php
  2. +42
    -0
      common/models/Distribution.php
  3. +0
    -24
      common/models/Producer.php
  4. +2
    -1
      common/models/Subscription.php
  5. +2
    -2
      producer/controllers/OrderController.php
  6. +21
    -13
      producer/web/js/vuejs/order-order.js

+ 0
- 1
backend/views/producer/update.php ファイルの表示

@@ -123,7 +123,6 @@ $this->addBreadcrumb($this->getTitle()) ;
] ;

$deadlinesArray = [
24 => 'Minuit',
23 => '23h',
22 => '22h',
21 => '21h',

+ 42
- 0
common/models/Distribution.php ファイルの表示

@@ -222,6 +222,48 @@ class Distribution extends ActiveRecordCommon
return $distributionsArray;
}

public static function filterDistributionsByDateDelay($distributionsArray)
{
$producer = GlobalParam::getCurrentProducer() ;
$dateToday = date('Y-m-d') ;

foreach($distributionsArray as $keyDistribution => $distribution) {

$dateDistribution = $distribution->date ;
$dayDistribution = strtolower(date('l', strtotime($dateDistribution))) ;
$fieldDayDistributionDelay = 'order_delay_'.$dayDistribution ;
$fieldDayDistributionDeadline = 'order_deadline_'.$dayDistribution ;

$delay = $producer->order_delay ;
$deadline = $producer->order_deadline ;

if($producer->$fieldDayDistributionDelay) {
$delay = $producer->$fieldDayDistributionDelay ;
}

if($producer->$fieldDayDistributionDeadline) {
$deadline = $producer->$fieldDayDistributionDeadline ;
}

$countDaysTodayDistribution = number_format((strtotime($dateDistribution) - strtotime($dateToday)) / (24 * 60 * 60) , 0);

if(date('H') >= $deadline) {
$countDaysTodayDistribution -- ;
}

if($countDaysTodayDistribution < $delay) {
unset($distributionsArray[$keyDistribution]) ;
}
}

$newDistributionsArray = [] ;
foreach($distributionsArray as $distribution) {
$newDistributionsArray[] = $distribution ;
}

return $newDistributionsArray ;
}

/**
* Lie un produit aux jours de distribution futurs.
*

+ 0
- 24
common/models/Producer.php ファイルの表示

@@ -440,30 +440,6 @@ class Producer extends ActiveRecordCommon
return $userProducer;
}

/**
* Retourne la date la plus proche où il est possible de commander.
* Attention, cette méthode ne garantit pas qu'une distribution a été initialisée
* à cette date.
*
* @return string
*/
public function getEarliestDateOrder()
{
$deadline = 20;
$earliestDateOrder = date('Y-m-d');

if ($this->order_deadline) {
$deadline = $this->order_deadline;
}
if (date('H') >= $deadline) {
$earliestDateOrder = date('Y-m-d', strtotime(date('Y-m-d')) + ($this->order_delay) * (24 * 60 * 60));
} else {
$earliestDateOrder = date('Y-m-d', strtotime(date('Y-m-d')) + ($this->order_delay - 1) * (24 * 60 * 60));
}

return $earliestDateOrder;
}

/**
* Retourne le chemin vers le fichier contenant la clé secrète d'API de Payplug
*

+ 2
- 1
common/models/Subscription.php ファイルの表示

@@ -371,7 +371,7 @@ class Subscription extends ActiveRecordCommon
{
$producer = GlobalParam::getCurrentProducer();
$params = [
':date_earliest_order' => $producer->getEarliestDateOrder(),
':date_earliest_order' => date('Y-m-d'),
':date_begin' => date('Y-m-d', strtotime($this->date_begin)),
':id_producer' => GlobalParam::getCurrentProducerId()
];
@@ -380,6 +380,7 @@ class Subscription extends ActiveRecordCommon
->where('id_producer = :id_producer')
->andWhere('date >= :date_begin')
->andWhere('date >= :date_earliest_order');
$incomingDistributions = Distribution::filterDistributionsByDateDelay($incomingDistributions) ;

if ($this->date_end) {
$incomingDistributions->andWhere('date < :date_end');

+ 2
- 2
producer/controllers/OrderController.php ファイルの表示

@@ -236,7 +236,6 @@ class OrderController extends ProducerBaseController
if (isset($order->id_distribution)) {
// date de commande
$distribution = Distribution::find()->where(['id' => $order->id_distribution])->one();
$date = $this->getProducer()->getEarliestDateOrder();

if ($order->getState() != Order::STATE_OPEN) {
$errorDate = true;
@@ -487,7 +486,7 @@ class OrderController extends ProducerBaseController
];

// Distributions
$dateMini = $producer->getEarliestDateOrder();
$dateMini = date('Y-m-d') ;

$distributionsArray = Distribution::searchAll([
'active' => 1
@@ -495,6 +494,7 @@ class OrderController extends ProducerBaseController
'conditions' => ['date > :date'],
'params' => [':date' => $dateMini],
]);
$distributionsArray = Distribution::filterDistributionsByDateDelay($distributionsArray) ;
$json['distributions'] = $distributionsArray;

// Commandes de l'utilisateur

+ 21
- 13
producer/web/js/vuejs/order-order.js ファイルの表示

@@ -134,6 +134,7 @@ var app = new Vue({
start: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]),
end: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2])
}) ;

}
}
var orders = [] ;
@@ -142,20 +143,26 @@ var app = new Vue({
}
if(orders.length) {

for(var i= 0; i < orders.length; i++) {
app.calendar.attrs.push({
highlight: {
backgroundColor: '#FF7F00'
},
contentStyle: {
color: 'white'
},
popover: {
label: orders[i].pointSale.name + ' / '+app.formatPrice(orders[i].amount_total),
hideIndicator: true
},
dates: orders[i].date_distribution,
}) ;
arrayDate = orders[i].date_distribution.split('-') ;
var dateOrder = new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]) ;
if(app.isAvailableDate(dateOrder)) {

app.calendar.attrs.push({
highlight: {
backgroundColor: '#FF7F00'
},
contentStyle: {
color: 'white'
},
popover: {
label: orders[i].pointSale.name + ' / '+app.formatPrice(orders[i].amount_total),
hideIndicator: true
},
dates: orders[i].date_distribution,
}) ;
}
}
}
@@ -221,6 +228,7 @@ var app = new Vue({
return true ;
}
}

return false ;
},
pointSaleClick: function(event) {

読み込み中…
キャンセル
保存