浏览代码

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

refactoring
父节点
当前提交
b9e75c456e
共有 1 个文件被更改,包括 18 次插入19 次删除
  1. +18
    -19
      backend/views/producer-admin/index.php

+ 18
- 19
backend/views/producer-admin/index.php 查看文件

@@ -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']) ;

}
],
],

正在加载...
取消
保存