- PUT v1/client/update: gender theo enum ClientGender (0 Nam/1 Nữ), thêm
birthday (cột mới), province_code/ward_code validate theo bảng provinces/wards
(phường phải thuộc tỉnh). Migration nạp dữ liệu hành chính 2025 từ
province_ward_import.sql (chỉ bảng trống), API GET v1/provinces[/{code}/wards].
- CustomerObserver/OrderObserver log giá trị cũ bằng getRawOriginal: getOriginal
trả enum object, nối chuỗi gây 500 khi khách đổi giới tính.
- ClientResource: các cờ trả boolean, CCCD chỉ trả cccd_updated (không lộ ảnh/số).
- GET v1/setting/menu trả cả items + quick_links, bỏ v1/setting/quick-links.
- Thông báo admin/khách tra theo uuid thay vì id tự tăng.
- Chặn gửi template marketing cho khách đã tắt nhận email marketing.
- Xoá ProvinceWardSeeder và Customer::$updatable không dùng.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
78 lines
2.6 KiB
PHP
78 lines
2.6 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;
|
|
|
|
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->maskedPhone(),
|
|
'address' => $this->address,
|
|
'city' => $this->city,
|
|
'ward' => $this->ward->name ?? '',
|
|
'ward_code' => $this->ward_code,
|
|
'province' => $this->province->name ?? '',
|
|
'province_code' => $this->province_code,
|
|
'gender' => $this->gender?->value,
|
|
'gender_label' => $this->gender_label,
|
|
'birthday' => $this->birthday?->format('Y-m-d'),
|
|
'date' => $this->created_at ? $this->created_at->format('Y-m-d H:i:s') : null,
|
|
'company' => $this->company ?? '',
|
|
'avatar' => $this->avatar,
|
|
'cccd_updated' => (bool) (
|
|
$this->identity_number
|
|
&& $this->front_identity_number
|
|
&& $this->back_identity_number
|
|
),
|
|
'fb_link' => null,
|
|
'active_2fa' => (bool) $this->two_factor_enabled,
|
|
'off_mail_marketing' => (bool) $this->off_mail_marketing,
|
|
'email_marketing' => (bool) $this->email_marketing,
|
|
'receive_deposit' => (bool) $this->receive_deposit,
|
|
'is_recharge_zalo' => false,
|
|
'is_verify_telegram' => false,
|
|
],
|
|
'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),
|
|
]
|
|
];
|
|
}
|
|
|
|
private function maskedPhone(): ?string
|
|
{
|
|
if (!$this->phone) {
|
|
return null;
|
|
}
|
|
|
|
$visibleDigits = mb_substr($this->phone, -3);
|
|
|
|
return str_repeat('*', max(0, mb_strlen($this->phone) - mb_strlen($visibleDigits))) . $visibleDigits;
|
|
}
|
|
}
|