*/ public static function sampleValues(MailCampaign $campaign): array { $first = $campaign->renewal_services[0]['service_id'] ?? null; $service = $first ? Service::with('customer')->find($first) : null; return $service?->customer ? (self::valuesFor($campaign, $service->customer, $service->id) ?? []) : []; } public static function isRenewalTemplate(MailCampaign $campaign): bool { $keys = MailPlaceholders::extract($campaign->subject, $campaign->message); return in_array('period_end', $keys, true) && in_array('bank_qr_url', $keys, true); } /** * @return array|null null khi dịch vụ không còn thuộc khách hoặc không thể gia hạn */ public static function valuesFor(MailCampaign $campaign, Customer $customer, int $serviceId): ?array { $months = collect($campaign->renewal_services)->firstWhere('service_id', $serviceId)['months'] ?? null; $service = Service::with(['orderItem', 'product', 'customProduct']) ->whereKey($serviceId) ->where('customer_id', $customer->id) ->first(); $quote = $service ? RenewalQuote::forService($service, $months) : null; if (! $quote) { return null; } unset($quote['service_id'], $quote['cycles'], $quote['months']); $bank = Bank::where('account_no', $campaign->variables['bank_account_no'] ?? '')->first(); return $bank ? [...$quote, 'bank_qr_url' => VietQr::url($bank, $quote['total_amount'], $quote['payment_content'])] : $quote; } }