feat: add GeneratesUniqueSlug class for unique slug generation

feat: create PostCategoryFactory for generating post category data

feat: create PostFactory for generating post data

feat: add retry_requested_at column to services table

feat: add vcenter provisioning fields to products table

feat: add module_host_id to os table

feat: create email_notification_templates table for email templates

feat: add scenario and format fields to template table

feat: add admin fields to transactions table

fix: update ticket table columns and types

feat: add uuid to ticket table and backfill existing records

fix: make ticket_reply user_id nullable

feat: create notifications table for user notifications

fix: make ticket uuid nullable

feat: create post_categories table for blog categories

feat: create posts table for blog posts

feat: add invoice email template for PDF generation
This commit is contained in:
baodev0
2026-05-25 15:39:42 +07:00
parent a31d238135
commit 520f21cb11
73 changed files with 4682 additions and 440 deletions
@@ -32,9 +32,24 @@ class ProductResource extends JsonResource
'bandwidth' => $this->bandwidth,
'setup_fee' => $this->setup_fee,
'min_price' => $minPrice,
'billing_type' => $this->whenLoaded('pricings', function () {
$hasOnetime = $this->pricings->where('billing_cycle', 'onetime')->isNotEmpty();
$hasRecurring = $this->pricings->where('billing_cycle', '!=', 'onetime')->isNotEmpty();
return ($hasOnetime && !$hasRecurring) ? 'onetime' : 'recurring';
}),
'currency' => $this->whenLoaded('pricings', fn () => $this->pricings->first()?->currency ?? 'VND'),
'price_monthly' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'monthly'))->price),
'price_quarterly' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'quarterly'))->price),
'price_semiannually' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'semiannually'))->price),
'price_annually' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'annually'))->price),
'price_biennially' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'biennially'))->price),
'price_triennially' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'triennially'))->price),
'price_onetime' => $this->whenLoaded('pricings', fn () => optional($this->pricings->firstWhere('billing_cycle', 'onetime'))->price),
'is_active' => $this->is_active,
'created_at' => $this->created_at,
'os_ids' => $osIds,
'module_host_id' => $this->module_host_id,
'module_datastore_id' => $this->module_datastore_id,
];
}
@@ -0,0 +1,25 @@
<?php
namespace App\Http\Resources\Api;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PostCategoryResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'description' => $this->description,
'icon' => $this->icon,
'sort_order' => $this->sort_order,
'status' => $this->status,
'posts_count' => $this->whenCounted('posts'),
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace App\Http\Resources\Api;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PostResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'post_category_id' => $this->post_category_id,
'title' => $this->title,
'slug' => $this->slug,
'excerpt' => $this->excerpt,
'content' => $this->content,
'thumbnail' => $this->thumbnail,
'status' => $this->status,
'is_featured' => (bool) $this->is_featured,
'view_count' => (int) $this->view_count,
'reading_time' => $this->reading_time,
'meta_title' => $this->meta_title,
'meta_description' => $this->meta_description,
'published_at' => $this->published_at?->toISOString(),
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
'category' => $this->whenLoaded('category', fn () => new PostCategoryResource($this->category)),
'related_posts' => $this->when(isset($this->related_posts), fn () => $this->related_posts->map(fn ($post) => [
'id' => $post->id,
'post_category_id' => $post->post_category_id,
'title' => $post->title,
'slug' => $post->slug,
'excerpt' => $post->excerpt,
'thumbnail' => $post->thumbnail,
'status' => $post->status,
'is_featured' => (bool) $post->is_featured,
'view_count' => (int) $post->view_count,
'reading_time' => $post->reading_time,
'published_at' => $post->published_at?->toISOString(),
'category' => $post->relationLoaded('category') && $post->category
? new PostCategoryResource($post->category)
: null,
])->values()),
];
}
}
@@ -15,19 +15,33 @@ class ServiceResource extends JsonResource
public function toArray(Request $request): array
{
$billingCycleLabels = [
'monthly' => 'Hàng tháng',
'quarterly' => 'Hàng quý',
'semi_annually' => 'Nửa năm',
'annually' => 'Hàng năm',
'onetime' => 'Một lần',
'monthly' => 'Hàng tháng',
'quarterly' => 'Hàng quý',
'semiannually' => 'Nửa năm',
'annually' => 'Hàng năm',
'biennially' => '2 năm',
'triennially' => '3 năm',
'onetime' => 'Một lần',
];
$periodUnits = [
'monthly' => 'month',
'quarterly' => 'quarter',
'semi_annually' => 'semi_year',
'annually' => 'year',
'onetime' => 'none',
'monthly' => 'month',
'quarterly' => 'quarter',
'semiannually' => 'semi_year',
'annually' => 'year',
'biennially' => 'biennially',
'triennially' => 'triennially',
'onetime' => 'none',
];
$periodMonths = [
'monthly' => 1,
'quarterly' => 3,
'semiannually' => 6,
'annually' => 12,
'biennially' => 24,
'triennially' => 36,
'onetime' => 0,
];
return [
@@ -62,20 +76,17 @@ class ServiceResource extends JsonResource
])->values(),
];
})->values(),
'pricing' => $this->pricings->map(fn($p) => [
'id' => $p->id,
'name' => $billingCycleLabels[$p->billing_cycle] ?? $p->billing_cycle,
'price' => (int) $p->price,
'price_sale' => $p->price_sale ? (int) $p->price_sale : null,
'period' => $p->billing_cycle ? (int) match($p->billing_cycle) {
'monthly' => 1,
'quarterly' => 3,
'semi_annually' => 6,
'annually' => 12,
default => 1,
} : 1,
'period_unit' => $periodUnits[$p->billing_cycle] ?? 'month',
]),
'pricing' => $this->pricings
->sortBy(fn($p) => $periodMonths[$p->billing_cycle] ?? 999)
->values()
->map(fn($p) => [
'id' => $p->id,
'name' => $billingCycleLabels[$p->billing_cycle] ?? $p->billing_cycle,
'price' => (int) $p->price,
'price_sale' => $p->price_sale ? (int) $p->price_sale : null,
'period' => $periodMonths[$p->billing_cycle] ?? 1,
'period_unit' => $periodUnits[$p->billing_cycle] ?? 'month',
]),
];
}
@@ -0,0 +1,29 @@
<?php
namespace App\Http\Resources\Api\Ticket;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class TicketReplyResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'ticket_id' => $this->ticket_id,
'message' => $this->message,
'sender_type' => $this->user_id ? 'staff' : 'client',
'sender_name' => $this->when(
$this->user_id,
fn() => optional($this->user)->username ?? optional($this->user)->name ?? 'Admin',
'Khách hàng'
),
'sender_role' => $this->user_id ? 'Nhân viên hỗ trợ' : 'Khách hàng',
'user_id' => $this->user_id,
'customer_id' => $this->customer_id,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}
@@ -0,0 +1,31 @@
<?php
namespace App\Http\Resources\Api\Ticket;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class TicketResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'ticket_num' => $this->ticket_num,
'subject' => $this->subject,
'description' => $this->description,
'status' => $this->status,
'room' => $this->room,
'data' => $this->data ? (is_string($this->data) ? json_decode($this->data, true) : $this->data) : null,
'customer_id' => $this->customer_id,
'customer' => $this->whenLoaded('customer', fn() => [
'id' => $this->customer->id,
'fullname' => $this->customer->fullname,
'email' => $this->customer->email,
]),
'replies' => TicketReplyResource::collection($this->whenLoaded('reply')),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}