Files
portal-api/app/Models/EmailNotificationTemplate.php
T
baodev0 520f21cb11 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
2026-05-25 15:39:42 +07:00

98 lines
5.1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class EmailNotificationTemplate extends Model
{
protected $table = 'email_notification_templates';
protected $fillable = [
'name',
'type',
'subject',
'header_color',
'header_title',
'blocks',
'is_active',
];
protected $casts = [
'blocks' => 'array',
'is_active' => 'boolean',
];
/** Default blocks by template type */
public static function defaultBlocks(string $type = 'invoice_notification'): array
{
if ($type === 'vm_credentials') {
return [
['id' => 'greeting', 'type' => 'greeting', 'label' => 'Lời chào', 'enabled' => true, 'order' => 1, 'config' => []],
['id' => 'vm_credentials', 'type' => 'vm_credentials', 'label' => 'Thông tin truy cập VPS','enabled' => true, 'order' => 2, 'config' => [
'fields' => ['service_host', 'service_username', 'service_port', 'service_password', 'os_name'],
]],
['id' => 'product_info', 'type' => 'product_info', 'label' => 'Thông tin sản phẩm', 'enabled' => true, 'order' => 3, 'config' => [
'fields' => ['product_name', 'product_billing', 'product_price', 'service_due_exp'],
]],
['id' => 'custom_text', 'type' => 'custom_text', 'label' => 'Lời nhắn', 'enabled' => true, 'order' => 4, 'config' => [
'content' => 'Nếu bạn có bất kỳ thắc mắc nào, vui lòng liên hệ với chúng tôi để được hỗ trợ.',
]],
['id' => 'footer', 'type' => 'footer', 'label' => 'Footer', 'enabled' => true, 'order' => 5, 'config' => []],
];
}
// invoice_notification (default)
return [
['id' => 'greeting', 'type' => 'greeting', 'label' => 'Lời chào', 'enabled' => true, 'order' => 1, 'config' => []],
['id' => 'invoice_info', 'type' => 'invoice_info', 'label' => 'Thông tin hóa đơn', 'enabled' => true, 'order' => 2, 'config' => [
'fields' => ['invoice_number', 'created_at', 'due_date', 'total', 'status'],
]],
['id' => 'customer_info','type' => 'customer_info','label' => 'Thông tin khách hàng', 'enabled' => false, 'order' => 3, 'config' => [
'fields' => ['name', 'email'],
]],
['id' => 'order_items', 'type' => 'order_items', 'label' => 'Chi tiết sản phẩm', 'enabled' => true, 'order' => 4, 'config' => []],
['id' => 'attachments', 'type' => 'attachments', 'label' => 'File đính kèm', 'enabled' => true, 'order' => 5, 'config' => []],
['id' => 'custom_text', 'type' => 'custom_text', 'label' => 'Lời nhắn', 'enabled' => true, 'order' => 6, 'config' => [
'content' => 'Nếu bạn có bất kỳ thắc mắc nào, vui lòng liên hệ với chúng tôi để được hỗ trợ.',
]],
['id' => 'footer', 'type' => 'footer', 'label' => 'Footer', 'enabled' => true, 'order' => 7, 'config' => []],
];
}
/** Field definitions exposed per block type */
public static function blockFieldDefinitions(): array
{
return [
'invoice_info' => [
['key' => 'invoice_number', 'label' => 'Số hóa đơn'],
['key' => 'created_at', 'label' => 'Ngày tạo'],
['key' => 'due_date', 'label' => 'Hạn thanh toán'],
['key' => 'total', 'label' => 'Tổng tiền'],
['key' => 'sub_total', 'label' => 'Tiền dịch vụ'],
['key' => 'tax', 'label' => 'Thuế'],
['key' => 'status', 'label' => 'Trạng thái'],
['key' => 'payment_method', 'label' => 'Phương thức TT'],
],
'customer_info' => [
['key' => 'name', 'label' => 'Tên khách hàng'],
['key' => 'email', 'label' => 'Email'],
['key' => 'address', 'label' => 'Địa chỉ'],
],
'vm_credentials' => [
['key' => 'service_host', 'label' => 'Địa chỉ IP'],
['key' => 'service_username', 'label' => 'Username'],
['key' => 'service_port', 'label' => 'Port'],
['key' => 'service_password', 'label' => 'Mật khẩu'],
['key' => 'os_name', 'label' => 'Hệ điều hành'],
],
'product_info' => [
['key' => 'product_name', 'label' => 'Tên sản phẩm'],
['key' => 'product_billing', 'label' => 'Chu kỳ thanh toán'],
['key' => 'product_price', 'label' => 'Giá dịch vụ'],
['key' => 'service_due_exp', 'label' => 'Ngày hết hạn'],
],
];
}
}