我想从订单表中计算CashonDelivery,PayPal,Payu,Cavenue的总数。
在订单表中,有一列payment_method。
在该列中,有多个付款选项。
我想计算通过CashonDelivery,PayPal,Payu等方式支付的金额...(使用yii框架时)。
$list = Order::model()->findAll(payment_method=cashondelivery);
var_dump($list);
exit;
我该怎么做,这样我的输出如下
cashondelivery = 50
paypal = 25
payu = 35
最佳答案
尝试这个:
$CodCount = Order::model()->countByAttributes(array(
'payment_method'=>'cashondelivery'
));
echo $CodCount; //returns number of cashondelivery
....//similarly for other payment types
要么,
$CodCount = Order::model()->count("payment_method=:val", array("val" => "cashondelivery"));
echo $CodCount; //returns number of cashondelivery
....//similarly for other payment types
要么,
$dbCommand = Yii::app()->db->createCommand("
SELECT payment_method,COUNT(*) as tot FROM `order` GROUP BY `payment_method`
");
$data = $dbCommand->queryAll();
foreach($data AS $val) {
echo "Payment Method: ".$val["payment_method"]." total: ".$val["tot"]."<br/>";
}
输出:
Payment Mode: cashondelivery total: 50
Payment Mode: paypal total: 25
Payment Mode: payu total: 35