Ver código fonte

[backend] Optimisation requête producteurs (montant dons)

refactoring
Guillaume Bourgeois 5 anos atrás
pai
commit
b9e75c456e
1 arquivos alterados com 18 adições e 19 exclusões
  1. +18
    -19
      backend/views/producer-admin/index.php

+ 18
- 19
backend/views/producer-admin/index.php Ver arquivo

@@ -145,25 +145,24 @@ $this->addButton(['label' => '+', 'url' => 'producer-admin/create', 'class' => '
'format' => 'raw',
'value' => function($model) {
$productGift = Product::getProductGift() ;
$distributionsArray = Distribution::find()
->where(['>=', 'distribution.date', date('Y-m-01', strtotime("-1 month"))])
->andWhere(['<=', 'distribution.date', date('Y-m-31', strtotime("-1 month"))])
->andWhere(['distribution.id_producer' => $model->id])
->with(['order','order.productOrder'])
->all() ;
$gifts = 0 ;
foreach($distributionsArray as $distribution) {
foreach($distribution->order as $order) {
foreach($order->productOrder as $productOrder) {
if($productOrder->id_product == $productGift->id) {
$gifts += $productOrder->quantity * $productGift->price ;
}
}
}
}
return Price::format($gifts) ;

$res = Yii::$app->db->createCommand("SELECT SUM(product_order.price * product_order.quantity) AS total
FROM `order`, product_order, distribution
WHERE distribution.id_producer = :id_producer
AND `order`.id_distribution = distribution.id
AND `order`.id = product_order.id_order
AND distribution.date >= :date_start
AND distribution.date <= :date_end
AND product_order.id_product = :id_product_gift
")
->bindValue(':id_producer', $model->id)
->bindValue(':date_start', date('Y-m-01', strtotime("-1 month")))
->bindValue(':date_end', date('Y-m-31', strtotime("-1 month")))
->bindValue(':id_product_gift', $productGift->id)
->queryOne();

return Price::format($res['total']) ;

}
],
],

Carregando…
Cancelar
Salvar