Files
portal-api/app/Http/Resources/Api/Client/ClientResource.php
T
baodev0andClaude Opus 5.5 c5115b52dd feat: nạp tiền thủ công mã 30 phút, gia hạn trừ số dư, đồng bộ domain từ Plesk
- Nạp tiền: mã thanh toán sống 30 phút (ManualDepositDraft), khôi phục/huỷ mã, lệnh dọn mã hết hạn; total_pending chỉ tính giao dịch đã nộp chứng từ, admin duyệt/từ chối/xoá giao dịch
- Gia hạn dịch vụ: phát hành invoice gia hạn trên order gốc và trừ số dư ngay
- Đồng bộ domain từ Plesk theo server, ServiceOrderRecorder tạo order/invoice cho dịch vụ admin dựng
- Danh sách dịch vụ trả field theo loại (service_plan, dns_records_count), đếm dịch vụ theo loại

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 23:07:51 +07:00

75 lines
2.7 KiB
PHP

<?php
namespace App\Http\Resources\Api\Client;
use App\Services\Api\ServiceClient\ServiceClientService;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
class ClientResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
if (!$this->resource) {
return [];
}
return [
'customer' => [
'fullname' => $this->fullname,
'email' => $this->email,
'phone' => $this->phone,
'address' => $this->address,
'city' => $this->city,
'ward' => $this->ward->name ?? '',
'province' => $this->province->name ?? '',
'gender' => $this->gender_label,
'date' => $this->created_at ? $this->created_at->format('Y-m-d H:i:s') : null,
'company' => $this->company ?? '',
'avatar' => $this->avatar,
'cmnd_before' => $this->cccdUrl('front', $this->front_identity_number),
'cmnd_after' => $this->cccdUrl('back', $this->back_identity_number),
'cmnd' => $this->identity_number ? Str::mask($this->identity_number, '*', 0, -4) : null,
'fb_link' => null,
'active_2fa' => 0,
'off_mail_marketing' => $this->off_mail_marketing,
'is_recharge_zalo' => 0,
'is_verify_telegram' => 0,
],
'credit' => [
'credit' => $this->credit,
'total' => $this->total,
'total_pending' => $this->total_pending ?? 0,
'point' => $this->point,
'point_used' => 0,
'point_total' => $this->point,
],
'service' => [
'proxy' => 0,
...app(ServiceClientService::class)->countByType((int) $this->id),
]
];
}
/**
* Ảnh CCCD trên disk private → URL ký tương đối (/v1/client/cccd/...), hết hạn 60 phút.
*/
private function cccdUrl(string $side, ?string $path): string
{
if (!$path) {
return '';
}
// Giá trị import từ portal cũ (/uploads/... trên host cũ) cũng chỉ trả URL ký — không lộ đường dẫn gốc;
// route trả 404 cho chúng vì file không có trên disk private. Vẫn khác rỗng để hasCccd giữ nguyên hành vi.
return URL::temporarySignedRoute('api.client.cccd', now()->addHour(), ['customer' => $this->id, 'side' => $side], false);
}
}