@php $itemThumbs = $order->items->map(fn ($orderItem) => $orderItem->thumbnailUrl())->filter()->values(); $pStat = $phoneStats[$order->customer_phone] ?? ['delivered'=>0,'returned'=>0,'total'=>0,'score'=>0]; $score = $pStat['score'] ?? ($pStat['total'] ? round($pStat['delivered']/$pStat['total']*100) : 0); $cStatDefaults = ['steadfast' => ['d' => 0, 'r' => 0], 'pathao' => ['d' => 0, 'r' => 0], 'redx' => ['d' => 0, 'r' => 0], 'carrybee' => ['d' => 0, 'r' => 0]]; $cStat = array_replace_recursive($cStatDefaults, $courierStats[$order->customer_phone] ?? []); $normPhone = app(\App\Services\CourierFraudCheckService::class)->normalizePhone($order->customer_phone); $fraudData = ($fraudCache ?? [])[$normPhone] ?? null; if ($fraudData) { if (empty($fraudData['steadfast']['error'] ?? null) && (int) ($fraudData['steadfast']['total'] ?? 0) > 0) { $cStat['steadfast'] = ['d' => (int) $fraudData['steadfast']['success'], 'r' => (int) $fraudData['steadfast']['cancel']]; } if (empty($fraudData['pathao']['error'] ?? null) && (int) ($fraudData['pathao']['total'] ?? 0) > 0) { $cStat['pathao'] = ['d' => (int) $fraudData['pathao']['success'], 'r' => (int) $fraudData['pathao']['cancel']]; } if (empty($fraudData['redx']['error'] ?? null) && (int) ($fraudData['redx']['total'] ?? 0) > 0) { $cStat['redx'] = ['d' => (int) $fraudData['redx']['success'], 'r' => (int) $fraudData['redx']['cancel']]; } if (empty($fraudData['carrybee']['error'] ?? null) && (int) ($fraudData['carrybee']['total'] ?? 0) > 0) { $cStat['carrybee'] = ['d' => (int) $fraudData['carrybee']['success'], 'r' => (int) $fraudData['carrybee']['cancel']]; } } $siteHost = parse_url(config('app.url'), PHP_URL_HOST) ?: request()->getHost(); $fraudAgg = $fraudData['aggregate'] ?? null; $fraudRisk = $fraudData['risk'] ?? null; $fraudScoreClass = match ($fraudRisk['level'] ?? '') { 'good' => 'oc-pill-fraud-good', 'medium' => 'oc-pill-fraud-medium', 'warning' => 'oc-pill-fraud-warn', 'bad' => 'oc-pill-fraud-bad', default => 'oc-pill-score', }; $showFraudAvg = $fraudAgg && (int) ($fraudAgg['couriers_count'] ?? 0) > 0; $activeBlock = ($blockedMap ?? [])[$order->customer_phone] ?? null; $isBlocked = (bool) $activeBlock; $customerOrderTotal = (int) ($pStat['total'] ?? 0); $customerDeliveredTotal = (int) ($pStat['delivered'] ?? 0); $isNewCustomer = $customerOrderTotal <= 1; $orderCustomer = $order->customer ?? null; $customerTier = \App\Services\CustomerInsightsSettingsService::resolveTier( (float) ($pStat['delivered_spend'] ?? 0), (int) ($pStat['total'] ?? 0), $orderCustomer, $insightsSettings ?? null ); $claimService = app(\App\Services\OrderClaimService::class); $claimReady = $claimService->isReady() && (int) $order->order_status === \App\Models\Order::STATUS_PENDING; $claim = $claimReady ? $claimService->serializeClaim($order, (int) auth()->id()) : null; $claimLocked = $claim && ($claim['claim_state'] ?? '') === 'other'; $actionsLocked = $claim && ! ($claim['can_work'] ?? true); @endphp