@if(Auth::check()) @php $finalPrice = $data->price; $user = auth()->user(); $userRank = $user->rank; $rankId = $userRank->id ?? null; if ($rankId) { $discount = \App\Models\RankProduct::where('product_id', $data->id) ->where('rank_id', $rankId) ->first(); $hasValidDiscount = false; if ($discount) { if ($discount->type == 1 && $discount->percent > 0) { $finalPrice = $data->price - ($data->price * $discount->percent / 100); $hasValidDiscount = true; } elseif ($discount->type == 0 && $discount->price > 0) { $finalPrice = $discount->price; $hasValidDiscount = true; } } if (!$hasValidDiscount) { $lowerRanks = \App\Models\Rank::where('total', '<', $userRank->total) ->orderBy('total', 'desc') ->get(); foreach ($lowerRanks as $lowerRank) { $lowerDiscount = \App\Models\RankProduct::where('product_id', $data->id) ->where('rank_id', $lowerRank->id) ->first(); if ($lowerDiscount) { if ($lowerDiscount->type == 1 && $lowerDiscount->percent > 0) { $finalPrice = $data->price - ($data->price * $lowerDiscount->percent / 100); break; } elseif ($lowerDiscount->type == 0 && $lowerDiscount->price > 0) { $finalPrice = $lowerDiscount->price; break; } } } } } @endphp @if($data->price > 0 && $data->price > $finalPrice)
-{{ number_format((($data->price - $finalPrice) / $data->price) * 100, 0) }}%
@endif @endif