- Created migration to add 'group_label' to 'product_type_fields' table. - Implemented ItSupportCatalogSeeder to populate IT Support features and tiers. - Added ProductCategorySeeder for initial product categories. - Developed ProductMockupSeeder for mockup products in various categories. - Introduced ProductTypeFieldSeeder to define fields for different product types. - Created email templates for VPS service information and service renewal reminders.
77 lines
2.2 KiB
PHP
77 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Customer;
|
|
|
|
use App\Models\Note;
|
|
use App\Repositories\Customer\CustomerRepositoryInterface;
|
|
use App\Services\Customer\Concerns\ResolvesCustomer;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class CustomerNoteService
|
|
{
|
|
use ResolvesCustomer;
|
|
|
|
public function __construct(
|
|
private readonly CustomerRepositoryInterface $customerRepository,
|
|
) {}
|
|
|
|
/**
|
|
* Ghi chú của khách hàng (không gắn với dịch vụ cụ thể).
|
|
*/
|
|
public function getCustomerNotes(string $uuid): Collection
|
|
{
|
|
$customer = $this->resolveCustomer($uuid);
|
|
|
|
return Note::with('user:id,username')
|
|
->where('customer_id', $customer->id)
|
|
->whereNull('service_id')
|
|
->latest()
|
|
->get();
|
|
}
|
|
|
|
public function storeCustomerNote(string $uuid, string $note, int $userId): Note
|
|
{
|
|
return $this->storeNote($uuid, ['note' => $note], $userId);
|
|
}
|
|
|
|
/**
|
|
* Ghi chú gắn với 1 dịch vụ cụ thể của khách hàng.
|
|
*/
|
|
public function getServiceNotes(string $uuid, int $serviceId): Collection
|
|
{
|
|
$customer = $this->resolveCustomer($uuid);
|
|
|
|
return Note::with('user:id,username')
|
|
->where('customer_id', $customer->id)
|
|
->where('service_id', $serviceId)
|
|
->latest()
|
|
->get();
|
|
}
|
|
|
|
public function storeServiceNote(string $uuid, int $serviceId, string $note, int $userId): Note
|
|
{
|
|
return $this->storeNote($uuid, ['note' => $note, 'service_id' => $serviceId], $userId);
|
|
}
|
|
|
|
public function destroyNote(string $uuid, int $noteId): void
|
|
{
|
|
$customer = $this->resolveCustomer($uuid);
|
|
|
|
$deleted = Note::where('id', $noteId)->where('customer_id', $customer->id)->delete();
|
|
abort_if(!$deleted, 404, 'Không tìm thấy ghi chú');
|
|
}
|
|
|
|
private function storeNote(string $uuid, array $attributes, int $userId): Note
|
|
{
|
|
$customer = $this->resolveCustomer($uuid);
|
|
|
|
$note = Note::create([
|
|
...$attributes,
|
|
'customer_id' => $customer->id,
|
|
'user_id' => $userId,
|
|
]);
|
|
|
|
return $note->load('user:id,username');
|
|
}
|
|
}
|