Added home page pricing break down func to cache

Added home page pricing break down func to cache
This commit is contained in:
cp6 2022-05-29 16:56:13 +10:00
parent f72eec01f7
commit 8e5a1f62c3
2 changed files with 38 additions and 35 deletions

View File

@ -60,6 +60,7 @@ class SettingsController extends Controller
Cache::forget('due_soon');//Main page due_soon cache Cache::forget('due_soon');//Main page due_soon cache
Cache::forget('recently_added');//Main page recently_added 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 Cache::forget('settings');//Main page settings cache

View File

@ -116,45 +116,47 @@ class Home extends Model
{ {
$pricing = json_decode($all_pricing, true); $pricing = json_decode($all_pricing, true);
$total_cost_weekly = $total_cost_pm = $inactive_count = 0; return Cache::remember('pricing_breakdown', now()->addWeek(1), function () use ($pricing) {
foreach ($pricing as $price) { $total_cost_weekly = $total_cost_pm = $inactive_count = 0;
if ($price['active'] === 1) { foreach ($pricing as $price) {
if (Session::get('dashboard_currency') !== 'USD') { if ($price['active'] === 1) {
$the_price = Pricing::convertFromUSD($price['as_usd'], Session::get('dashboard_currency')); 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 { } 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( return array(
'total_cost_weekly' => $total_cost_weekly, 'total_cost_weekly' => $total_cost_weekly,
'total_cost_montly' => $total_cost_pm, 'total_cost_montly' => $total_cost_pm,
'total_cost_yearly' => $total_cost_yearly, 'total_cost_yearly' => $total_cost_yearly,
'inactive_count' => $inactive_count, 'inactive_count' => $inactive_count,
); );
});
} }
public static function doServicesCount($services_count): array public static function doServicesCount($services_count): array