- Gửi email theo template cho 1 khách, tab lịch sử email, nhắc gia hạn dịch vụ hàng loạt - Mail lưu from/bcc/sent_by; mẫu MARKETING và mẫu cũ trong TemplateSeeder - Gói hosting: giới hạn, trạng thái, lấy plan Plesk qua CLI gateway - Backfill payment_method và ngày đơn hàng còn thiếu - Bổ sung field CPU/RAM/Disk/Băng thông cho loại sản phẩm vps và cloud Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Admin\Service;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Service;
|
|
use App\Services\ServiceRenewalReminderService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ServiceRenewalReminderController extends Controller
|
|
{
|
|
public function __construct(private readonly ServiceRenewalReminderService $reminders) {}
|
|
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$days = (int) $request->validate(['days' => 'required|integer|min:1|max:365'])['days'];
|
|
|
|
$items = $this->reminders->expiring($days)->map(fn (Service $service) => [
|
|
'id' => $service->id,
|
|
'server_name' => $service->server_name,
|
|
'product_name' => $service->product?->name,
|
|
'expires_at' => $service->expires_at,
|
|
'days_left' => $this->reminders->daysLeft($service),
|
|
'auto_renew' => (bool) $service->auto_renew,
|
|
'customer' => [
|
|
'uuid' => $service->customer->uuid,
|
|
'fullname' => $service->customer->fullname,
|
|
'email' => $service->customer->email,
|
|
],
|
|
]);
|
|
|
|
return response()->json([
|
|
'error' => false,
|
|
'data' => $items->values(),
|
|
'truncated' => $items->count() >= ServiceRenewalReminderService::MAX_RESULTS,
|
|
]);
|
|
}
|
|
|
|
public function send(Request $request): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
'service_ids' => 'required|array|min:1|max:' . ServiceRenewalReminderService::MAX_RESULTS,
|
|
'service_ids.*' => 'integer',
|
|
]);
|
|
|
|
$count = $this->reminders->send($data['service_ids'], Auth::guard('admin')->user());
|
|
|
|
return response()->json([
|
|
'error' => false,
|
|
'message' => "Đã đưa {$count} email nhắc gia hạn vào hàng đợi gửi.",
|
|
]);
|
|
}
|
|
}
|