feat: email gửi tay/nhắc gia hạn, gói hosting, sửa dữ liệu sản phẩm
- 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>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
8651dde6b1
commit
30898ea46f
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\Customer\Concerns;
|
||||
|
||||
use App\Models\Mail;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
trait ListsCustomerEmails
|
||||
{
|
||||
public function emails(Request $request, string $uuid): JsonResponse
|
||||
{
|
||||
$customer = $this->resolveCustomer($uuid);
|
||||
$search = trim((string) $request->get('search', ''));
|
||||
|
||||
$paginator = Mail::query()
|
||||
->with(['sender', 'template:id,name'])
|
||||
->where('customer_id', $customer->id)
|
||||
->when($search !== '', fn ($q) => $q->where(fn ($q) => $q
|
||||
->where('subject', 'like', "%{$search}%")
|
||||
->orWhere('to', 'like', "%{$search}%")))
|
||||
->latest('id')
|
||||
->paginate(min((int) $request->get('per_page', 10), 100), ['id', 'template_id', 'subject', 'from_address', 'to', 'cc', 'bcc', 'sent_by', 'status', 'created_at']);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => [
|
||||
'items' => $paginator->getCollection()->map($this->mapCustomerEmail(...))->all(),
|
||||
'total' => $paginator->total(),
|
||||
'current_page' => $paginator->currentPage(),
|
||||
'per_page' => $paginator->perPage(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function emailDetail(string $uuid, int $id): JsonResponse
|
||||
{
|
||||
$customer = $this->resolveCustomer($uuid);
|
||||
$mail = Mail::with(['sender', 'template:id,name'])
|
||||
->where('customer_id', $customer->id)
|
||||
->find($id);
|
||||
|
||||
if (!$mail) {
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy email'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => [...$this->mapCustomerEmail($mail), 'html' => $mail->message],
|
||||
]);
|
||||
}
|
||||
|
||||
private function mapCustomerEmail(Mail $mail): array
|
||||
{
|
||||
return [
|
||||
'id' => $mail->id,
|
||||
'subject' => $mail->subject,
|
||||
'from_address' => $mail->from_address,
|
||||
'sent_by' => $mail->sender ? ($mail->sender->name ?: $mail->sender->username) : null,
|
||||
'to' => $mail->to,
|
||||
'cc' => $mail->cc,
|
||||
'bcc' => $mail->bcc,
|
||||
'template' => $mail->template?->name,
|
||||
'status' => $mail->status,
|
||||
'created_at' => $mail->created_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,26 @@ trait ManagesCustomerAccount
|
||||
return response()->json(['error' => false, 'message' => 'Đã gửi mật khẩu mới cho khách hàng.']);
|
||||
}
|
||||
|
||||
public function emailPreview(Request $request, string $uuid): JsonResponse
|
||||
{
|
||||
$data = $request->validate(['template_id' => 'required|integer']);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => $this->mailService->previewTemplateEmail($uuid, (int) $data['template_id']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function emailLayout(Request $request, string $uuid): JsonResponse
|
||||
{
|
||||
$data = $request->validate(['message' => 'nullable|string']);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => ['html' => $this->mailService->wrapWithLayout($uuid, (string) ($data['message'] ?? ''))],
|
||||
]);
|
||||
}
|
||||
|
||||
public function sendEmail(Request $request, string $uuid): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
@@ -43,6 +63,7 @@ trait ManagesCustomerAccount
|
||||
'to' => 'nullable|string|max:1000',
|
||||
'cc' => 'nullable|string|max:1000',
|
||||
'bcc' => 'nullable|string|max:1000',
|
||||
'with_layout' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
$this->mailService->sendCustomEmail($uuid, $data, Auth::guard('admin')->user(), $request->ip());
|
||||
|
||||
@@ -35,6 +35,7 @@ trait ManagesCustomerServices
|
||||
'requirements' => 'nullable|string',
|
||||
'feedback' => 'nullable|string',
|
||||
'price' => 'nullable|numeric|min:0',
|
||||
'billing_cycle' => 'nullable|in:monthly,quarterly,semi_annually,annually,biennially,triennially',
|
||||
'virtual_machine_id' => 'nullable|integer|exists:virtual_machines,id',
|
||||
'os_id' => 'nullable|integer|exists:os,id',
|
||||
'vm_cpu' => 'nullable|integer|min:1',
|
||||
|
||||
@@ -24,6 +24,7 @@ use App\Http\Controllers\Api\Admin\Customer\Concerns\ManagesCustomerDomains;
|
||||
use App\Http\Controllers\Api\Admin\Customer\Concerns\ManagesCustomerServices;
|
||||
use App\Http\Controllers\Api\Admin\Customer\Concerns\ManagesCustomerBulkActions;
|
||||
use App\Http\Controllers\Api\Admin\Customer\Concerns\ManagesCustomerNotes;
|
||||
use App\Http\Controllers\Api\Admin\Customer\Concerns\ListsCustomerEmails;
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
@@ -34,6 +35,7 @@ class CustomerController extends Controller
|
||||
use ManagesCustomerServices;
|
||||
use ManagesCustomerBulkActions;
|
||||
use ManagesCustomerNotes;
|
||||
use ListsCustomerEmails;
|
||||
|
||||
public function __construct(
|
||||
private readonly CustomerRepositoryInterface $customerRepository,
|
||||
|
||||
Reference in New Issue
Block a user