@php // type: bw-1 (s-day) $promotions = \App\Module\Db\Promotion::getInstance()->getPromotionsByWeb([ 'type' => 2 ]); $currentDate = strtotime(date('Y-m-d')); $currentDay = (int)date('d'); $currentTime = ((int)date('H') * 60) + (int)date('i'); @endphp @if(isset($promotions) && is_array($promotions) && count($promotions) > 0) @foreach($promotions as $promotion) @php $promotionName = $promotion->name ?? ''; $promotionImage = !empty($promotion->image_thumb ?? '') ? ImageOS::photo($promotion->image_thumb, 0, 0) : ''; if(empty($promotionImage)) { $promotionImage = !empty($promotion->image ?? '') ? ImageOS::photo($promotion->image, 490, 0) : ''; } $startsDate2Time = !empty($promotion->starts_at ?? '') ? strtotime($promotion->starts_at) : 0; $endsDate2Time = !empty($promotion->ends_at ?? '') ? strtotime($promotion->ends_at) : 0; $dayOfWeek = (int)($promotion->dayofweek ?? 0); $dayOfWeekCurrent = (int)($promotion->current_dow ?? 0); $happyHourBegin = (int)($promotion->happy_hours_begin ?? 0); $happyHourEnd = (int)($promotion->happy_hours_end ?? 0); $dayOfMonthBegin = (int)($promotion->dayofmonth_begin ?? 0); $dayOfMonthEnd = (int)($promotion->dayofmonth_end ?? 0); $frequency = $promotion->frequency ?? 0; // 0: none; 1: week; 2: month $frequencyMonthStart = (int)($promotion->frequency_month_start ?? 0); // date $frequencyMonthEnd = (int)($promotion->frequency_month_end ?? 0); // date $isJoin = true; if(($startsDate2Time > 0 && $startsDate2Time > $currentDate) || ($endsDate2Time > 0 && $endsDate2Time < $currentDate) || ($dayOfMonthBegin > 0 && $dayOfMonthBegin > $currentDay) || ($dayOfMonthEnd > 0 && $dayOfMonthEnd < $currentDay) || ($dayOfWeek > 0 && (int)($dayOfWeek&(1<<$dayOfWeekCurrent)) < 1) || ($frequency == 2 && ( $frequencyMonthStart > $currentDate || $frequencyMonthEnd < $currentDate )) ) { $isJoin = false; } else { if(($happyHourBegin > 0 && $happyHourBegin > $currentTime) || ($happyHourEnd > 0 && $happyHourEnd < $currentTime) ) { $isJoin = false; } } $noneAction = __('messages.front.comeback_later'); // validate quick [x] payment if($isJoin) { $topAction = $promotion->top_action ?? 0; $promotionId = $promotion->id ?? 0; $ruleId = $promotion->rule_id ?? 0; if($topAction > 0) { $log = \App\Module\Db\Promotion::getInstance()->getLog($promotionId, $ruleId); $countAction = $log->count ?? 0; if($countAction >= $topAction) { $noneAction = $topAction . __('messages.front.sold_out'); $isJoin = false; } } } @endphp
@if(!empty($promotionImage))
{{ $promotionName }}
@endif

{{ $promotionName }}

{!! $promotion->summary !!}

{!! ($promotion->remark ?? '') !!} @if($isJoin) {{ __('messages.product_detail.buy_now') }} @else @endif
@endforeach @endif