Files
portal-api/app/Http/Controllers/Api/Admin/Customer/Concerns/ManagesCustomerAccount.php
T
baodev0andClaude Opus 5.5 46aa138eec feat(admin): IP pool allocation, billing exports, service attachments
- IP pool: sheet import (xlsx/csv) matched by address, bulk allocate/revoke
  with notification email (ip_allocated/ip_revoked), ip_pool_logs history.
- Orders/invoices: Excel export on branded template (BrandedReportWriter),
  shared billing filters, order item service info in list responses.
- Web design quote Excel export; activity log export.
- Service attachments with copy-to-invoice; deployment invoice attachments.
- Customer email attachments stored on disk and attached by path.
- Admin password change endpoint; user.fullname backfill migration;
  orders.user_id backfill from logs.
- Disable deploy workflow until CI/CD is set up.
- Ignore stored customer email and service attachment uploads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 19:58:36 +07:00

113 lines
4.0 KiB
PHP

<?php
namespace App\Http\Controllers\Api\Admin\Customer\Concerns;
use App\Support\MailAttachments;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
trait ManagesCustomerAccount
{
public function loginAs(Request $request, string $uuid): JsonResponse
{
$code = $this->impersonationService->createLoginCode($uuid, Auth::guard('admin')->user(), $request);
return response()->json(['error' => false, 'data' => ['code' => $code]]);
}
public function resetPassword(string $uuid): JsonResponse
{
$this->mailService->resetPassword($uuid);
return response()->json([
'error' => false,
'message' => 'Password reset successfully, new password has been sent to customer email',
]);
}
public function sendPasswordEmail(Request $request, string $uuid): JsonResponse
{
$data = $request->validate(['password' => 'required|string|min:8|max:64']);
$this->mailService->sendPasswordEmail($uuid, $data['password'], $request->ip());
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([
'template_id' => 'nullable|integer|exists:template,id',
'subject' => 'required_without:template_id|nullable|string|max:255',
'message' => 'required_without:template_id|nullable|string',
'to' => 'nullable|string|max:1000',
'cc' => 'nullable|string|max:1000',
'bcc' => 'nullable|string|max:1000',
'with_layout' => 'nullable|boolean',
...MailAttachments::rules(),
]);
$this->mailService->sendCustomEmail($uuid, $data, Auth::guard('admin')->user(), $request->ip());
return response()->json(['error' => false, 'message' => 'Đã gửi email cho khách hàng.']);
}
public function addCredit(Request $request, string $uuid): JsonResponse
{
$request->validate(['amount' => 'required|numeric|min:1', 'action' => 'required|in:+,-']);
$this->walletService->adjustCredit(
$uuid,
Auth::guard('admin')->user(),
(int) $request->amount,
$request->action === '+',
);
return response()->json(['error' => false, 'message' => 'Credit updated successfully']);
}
public function addTotal(Request $request, string $uuid): JsonResponse
{
$data = $request->validate(['amount' => 'required|numeric|min:1', 'note' => 'required|string|max:1000']);
$admin = Auth::guard('admin')->user();
abort_if(!$admin, 401, 'Unauthorized');
$transaction = $this->walletService->addTotal($uuid, $admin, (int) $data['amount'], trim($data['note']), $request->ip());
return response()->json([
'error' => false,
'message' => 'Total updated successfully',
'data' => [
'transaction' => [
'uuid' => $transaction->uuid,
'amount' => $transaction->amount,
'note' => $transaction->note,
'admin' => $admin->username ?? $admin->email,
],
],
]);
}
}