Beispiel #1
0
function getTotalTransactions($id = NULL, $useCode = false, $withCurrency = true)
{
    if ($id) {
        $key = 'id';
        if ($useCode) {
            $key = "code";
        }
        $orderPayment = OrderPayment::where($key, $id)->select(['unique', 'box', 'item', 'space_credit_used']);
    } else {
        $orderPayment = OrderPayment::select([DB::raw("SUM(box) box"), DB::raw("SUM(item) item"), DB::raw("SUM(space_credit_used) space_credit_used")]);
    }
    $orderPayment = $orderPayment->first();
    $box = $orderPayment->box * Config::get('thankspace.box.price');
    $item = $orderPayment->item * Config::get('thankspace.item.price');
    $space_credit_used = $orderPayment->space_credit_used;
    $total = $box + $item - $space_credit_used;
    if ($id) {
        if ($total != 0) {
            $total += $orderPayment->unique;
        }
    }
    if ($withCurrency) {
        return number_format($total, 0, '', '.');
    }
    return $total;
}