From 8e5a1f62c3e0c8bcf3e5b8eb211cfa79ca47ab96 Mon Sep 17 00:00:00 2001 From: cp6 Date: Sun, 29 May 2022 16:56:13 +1000 Subject: [PATCH] Added home page pricing break down func to cache Added home page pricing break down func to cache --- app/Http/Controllers/SettingsController.php | 1 + app/Models/Home.php | 72 +++++++++++---------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index cac7965..c474492 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -60,6 +60,7 @@ class SettingsController extends Controller Cache::forget('due_soon');//Main page due_soon cache Cache::forget('recently_added');//Main page recently_added cache + Cache::forget('pricing_breakdown');//Main page pricing breakdown Cache::forget('settings');//Main page settings cache diff --git a/app/Models/Home.php b/app/Models/Home.php index baeddd5..dd0011c 100644 --- a/app/Models/Home.php +++ b/app/Models/Home.php @@ -116,45 +116,47 @@ class Home extends Model { $pricing = json_decode($all_pricing, true); - $total_cost_weekly = $total_cost_pm = $inactive_count = 0; - foreach ($pricing as $price) { - if ($price['active'] === 1) { - if (Session::get('dashboard_currency') !== 'USD') { - $the_price = Pricing::convertFromUSD($price['as_usd'], Session::get('dashboard_currency')); + return Cache::remember('pricing_breakdown', now()->addWeek(1), function () use ($pricing) { + $total_cost_weekly = $total_cost_pm = $inactive_count = 0; + foreach ($pricing as $price) { + if ($price['active'] === 1) { + if (Session::get('dashboard_currency') !== 'USD') { + $the_price = Pricing::convertFromUSD($price['as_usd'], Session::get('dashboard_currency')); + } else { + $the_price = $price['as_usd']; + } + if ($price['term'] === 1) {//1 month + $total_cost_weekly += ($the_price / 4); + $total_cost_pm += $the_price; + } elseif ($price['term'] === 2) {//3 months + $total_cost_weekly += ($the_price / 12); + $total_cost_pm += ($the_price / 3); + } elseif ($price['term'] === 3) {// 6 month + $total_cost_weekly += ($the_price / 24); + $total_cost_pm += ($the_price / 6); + } elseif ($price['term'] === 4) {// 1 year + $total_cost_weekly += ($the_price / 48); + $total_cost_pm += ($the_price / 12); + } elseif ($price['term'] === 5) {//2 years + $total_cost_weekly += ($the_price / 96); + $total_cost_pm += ($the_price / 24); + } elseif ($price['term'] === 6) {//3 years + $total_cost_weekly += ($the_price / 144); + $total_cost_pm += ($the_price / 36); + } } else { - $the_price = $price['as_usd']; + $inactive_count++; } - if ($price['term'] === 1) {//1 month - $total_cost_weekly += ($the_price / 4); - $total_cost_pm += $the_price; - } elseif ($price['term'] === 2) {//3 months - $total_cost_weekly += ($the_price / 12); - $total_cost_pm += ($the_price / 3); - } elseif ($price['term'] === 3) {// 6 month - $total_cost_weekly += ($the_price / 24); - $total_cost_pm += ($the_price / 6); - } elseif ($price['term'] === 4) {// 1 year - $total_cost_weekly += ($the_price / 48); - $total_cost_pm += ($the_price / 12); - } elseif ($price['term'] === 5) {//2 years - $total_cost_weekly += ($the_price / 96); - $total_cost_pm += ($the_price / 24); - } elseif ($price['term'] === 6) {//3 years - $total_cost_weekly += ($the_price / 144); - $total_cost_pm += ($the_price / 36); - } - } else { - $inactive_count++; } - } - $total_cost_yearly = ($total_cost_pm * 12); + $total_cost_yearly = ($total_cost_pm * 12); - return array( - 'total_cost_weekly' => $total_cost_weekly, - 'total_cost_montly' => $total_cost_pm, - 'total_cost_yearly' => $total_cost_yearly, - 'inactive_count' => $inactive_count, - ); + return array( + 'total_cost_weekly' => $total_cost_weekly, + 'total_cost_montly' => $total_cost_pm, + 'total_cost_yearly' => $total_cost_yearly, + 'inactive_count' => $inactive_count, + ); + }); } public static function doServicesCount($services_count): array