table('fct_order_items') ->select([ $db->raw('SUM(line_total) as total_amount'), $db->raw('SUM(quantity) as total_quantity') ]) ->join('fct_orders', 'fct_orders.id', '=', 'fct_order_items.order_id') ->whereIn('fct_order_items.object_id', $productIds) ->whereIn('fct_orders.status', Status::getTransactionSuccessStatuses()); if ($range != 'all_time') { $statsQuery = $statsQuery->where('fct_orders.created_at', '>', gmdate('Y-m-d 00:00:00', strtotime($range))); } $stats[$range] = $statsQuery->first(); } return $stats; } }