Created
January 28, 2015 09:04
-
-
Save sakilimran/51aca3e9ca7554d2338e to your computer and use it in GitHub Desktop.
Important Query of CakePHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getOderAmountByOrderType($options = array()) | |
{ | |
$orderDec = 'Desc'; | |
$limit = false; | |
$conditions = array(); | |
if(isset($options['conditions'])){ | |
$conditions = array_merge($conditions, $options['conditions']); | |
} | |
if(isset($options['orderDesc'])){ | |
$orderDec = $options['orderDesc']; | |
} | |
if(isset($options['limit'])){ | |
$limit = $options['limit']; | |
} | |
$fields = array( | |
'SUM(CASE WHEN Order.is_paid = 0 THEN 1 ELSE 0 END) AS freeOrder', | |
'SUM(CASE WHEN Order.is_paid = 0 THEN Order.cost_total ELSE 0 END) AS freeOrderAmount', | |
'SUM(CASE WHEN Order.is_paid = 1 THEN 1 ELSE 0 END) AS paidOrder', | |
'SUM(CASE WHEN Order.is_paid = 1 THEN Order.cost_total ELSE 0 END) AS paidOrderAmount', | |
'SUM(CASE WHEN Order.is_paid = 2 THEN 1 ELSE 0 END) AS sampleOrder', | |
'SUM(CASE WHEN Order.is_paid = 2 THEN Order.cost_total ELSE 0 END) AS sampleOrderAmount', | |
'COUNT(Order.is_paid) as totalOrder', | |
'SUM(Order.cost_total) as totalOrderAmount' | |
); | |
$option = array( | |
'fields' => $fields, | |
'conditions' => $conditions, | |
'recursive' => -1, | |
'limit' => $limit | |
); | |
$result = $this->find('all', $option); | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment