2
此刻我寫了一個函數來檢查訂單是否完全支付。在該函數中,第二個函數用於確定總訂單價格。在第一個函數中,將總訂單價格與訂單的所有交易進行比較,並基於此,訂單是否被支付。從功能查詢
下面提到的功能。我正在尋找的是一種可以將功能更改爲單個查詢的方法。例如:
SELECT *
FROM order
WHERE
((Grandtotal - TransactionTotal) <= 0)
以便查詢返回例如如果付費爲true,則返回false,如果未付款。
功能IsOrderPaid:
function IsOrderPaid($order_id){
$returnvalue = false;
$ordertotal = CalculateOrderTotal($order_id);
$sql = "SELECT SUM(amount) AS TransactionTotal FROM order_transaction WHERE order_id='".mysql_real_escape_string($order_id)."' AND status='9'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($result);
if(($ordertotal - $row->TransactionTotal) <= 0){
$returnvalue = true;
}
return $returnvalue;
}
funcion CalculateOrderTotal
function CalculateOrderTotal($order_id){
$sql = "SELECT
order_id, SUM(total) GrandTotal
FROM
(
SELECT ordering_id AS order_id, SUM(price * quantity) AS total
FROM order_products
WHERE order_id = ".mysql_real_escape_string($order_id)."
UNION ALL
SELECT ordering_id AS order_id, SUM(price * quantity * -1) AS total
FROM rma_products
WHERE bestelling_id = ".mysql_real_escape_string($order_id)."
UNION ALL
SELECT order_id, amount AS total
FROM order_shipping
WHERE order_id = ".mysql_real_escape_string($order_id)."
UNION ALL
SELECT order_id, amount AS total
FROM order_service
WHERE order_id = ".mysql_real_escape_string($order_id)."
UNION ALL
SELECT order_id, SUM(amount * -1) AS total
FROM order_gift
WHERE order_id = ".mysql_real_escape_string($order_id)."
)subTable
WHERE order_id <> 0
GROUP BY order_id";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($result);
return $row->GrandTotal;
}
我知道mysql_*
已過時,但是這是下一個問題。
爲什麼不製作兩個mysql函數並使用它們 – user991554 2013-03-20 12:16:44
Finaly我想在另一個查詢中使用此查詢的結果。現在我執行我的第一個查詢,同時我打電話給該函數。根據結果,我填寫了我需要的所有訂單的數組。 – Timo002 2013-03-20 12:32:48