- 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>
111 lines
3.9 KiB
PHP
111 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Admin\Customer\Concerns;
|
|
|
|
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',
|
|
]);
|
|
|
|
$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,
|
|
],
|
|
],
|
|
]);
|
|
}
|
|
}
|