feat: add domain registration form and email notifications
- Create a new Blade view for domain registration (`registrant-tochuc.blade.php`) to capture organization and manager details. - Implement email templates for new domain orders for both admin (`domain-order-new.blade.php`) and customers (`domain-order-received.blade.php`). - Add CSV exports for client and domain data. - Introduce tests for customer mass assignment, password reset, login throttling, and permission gating. - Ensure service renewals use current pricing and validate ownership for virtual machines. - Validate mass assignment behavior in service model.
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DomainPricing extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'type',
|
||||
'tld',
|
||||
'name',
|
||||
'setup_fee',
|
||||
'first_year',
|
||||
'recurring_fee',
|
||||
'note',
|
||||
'sort_order',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'first_year' => 'integer',
|
||||
'sort_order' => 'integer',
|
||||
];
|
||||
|
||||
public function scopeDomains($query)
|
||||
{
|
||||
return $query->where('type', 'domain');
|
||||
}
|
||||
|
||||
public function scopeServices($query)
|
||||
{
|
||||
return $query->where('type', 'service');
|
||||
}
|
||||
|
||||
/** Cast to int when the value is a plain number (e.g. "300000"), otherwise keep as-is (e.g. "Miễn phí"). */
|
||||
private static function numericOrString(?string $value): string|int
|
||||
{
|
||||
return is_numeric($value) ? (int) $value : (string) $value;
|
||||
}
|
||||
|
||||
public function toDomainArray(): array
|
||||
{
|
||||
return [
|
||||
'tld' => $this->tld,
|
||||
'setupFee' => self::numericOrString($this->setup_fee),
|
||||
'firstYear' => (int) $this->first_year,
|
||||
'renewal' => (int) $this->recurring_fee,
|
||||
];
|
||||
}
|
||||
|
||||
public function toServiceArray(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->name,
|
||||
'setupFee' => self::numericOrString($this->setup_fee),
|
||||
'maintenance' => self::numericOrString($this->recurring_fee),
|
||||
'note' => (string) $this->note,
|
||||
];
|
||||
}
|
||||
|
||||
/** Shape consumed by both the client and admin domain-pricing endpoints. */
|
||||
public static function toResponseArray(): array
|
||||
{
|
||||
$rows = static::query()->where('is_active', true)->orderBy('sort_order')->get();
|
||||
|
||||
return [
|
||||
'domains' => $rows->where('type', 'domain')->map->toDomainArray()->values()->all(),
|
||||
'services' => $rows->where('type', 'service')->map->toServiceArray()->values()->all(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Longest-TLD-match lookup used when pricing a domain order.
|
||||
*
|
||||
* @throws \InvalidArgumentException if no matching TLD is configured
|
||||
*/
|
||||
public static function findByDomain(string $domain): self
|
||||
{
|
||||
$candidates = static::domains()->where('is_active', true)->get()
|
||||
->sortByDesc(fn (self $row) => strlen((string) $row->tld));
|
||||
|
||||
foreach ($candidates as $row) {
|
||||
$tld = ltrim((string) $row->tld, '.');
|
||||
if ($tld !== '' && str_ends_with($domain, '.' . $tld)) {
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Tên miền không được hỗ trợ. Vui lòng chọn đuôi tên miền có trong danh sách.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ExportJob extends Model
|
||||
{
|
||||
protected $table = 'export_jobs';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'filters' => 'array',
|
||||
'fields' => 'array',
|
||||
'completed_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function creator()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
}
|
||||
+25
-1
@@ -20,7 +20,30 @@ class Service extends Model
|
||||
|
||||
protected $table = 'services';
|
||||
|
||||
protected $guarded = [];
|
||||
protected $fillable = [
|
||||
'uuid',
|
||||
'customer_id',
|
||||
'product_id',
|
||||
'type',
|
||||
'order_item_id',
|
||||
'invoice_id',
|
||||
'vm_id',
|
||||
'server_name',
|
||||
'status',
|
||||
'auto_renew',
|
||||
'started_at',
|
||||
'expires_at',
|
||||
'suspended_at',
|
||||
'cancelled_at',
|
||||
'refunded_at',
|
||||
'retry_requested_at',
|
||||
'note',
|
||||
'registrar_reference',
|
||||
'kyc_url',
|
||||
'rejection_reason',
|
||||
'registrant_type',
|
||||
'registrant_info',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'auto_renew' => 'boolean',
|
||||
@@ -30,6 +53,7 @@ class Service extends Model
|
||||
'cancelled_at' => 'datetime',
|
||||
'refunded_at' => 'datetime',
|
||||
'retry_requested_at' => 'datetime',
|
||||
'registrant_info' => 'array',
|
||||
];
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Traits\LogsActivity;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Traits\HasUuid;
|
||||
|
||||
class Transaction extends Model
|
||||
@@ -26,6 +27,7 @@ class Transaction extends Model
|
||||
'proof_image',
|
||||
];
|
||||
|
||||
protected $appends = ['direction', 'proof_image_urls'];
|
||||
|
||||
public function customer()
|
||||
{
|
||||
@@ -36,4 +38,48 @@ class Transaction extends Model
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this transaction added ('credit'), removed ('debit') or left
|
||||
* ('neutral') the customer's balance untouched. `amount` is always stored
|
||||
* positive, so the direction has to be derived from `type` (and, for
|
||||
* 'invoice', from the note) to mirror the actual balance mutation logic
|
||||
* in InvoicePaymentService / CustomerController / AdminTransactionController.
|
||||
*/
|
||||
public function getDirectionAttribute(): string
|
||||
{
|
||||
return match ($this->type) {
|
||||
'admin_add_total', 'admin_add_credit', 'manual', 'refund' => 'credit',
|
||||
'admin_deduct_credit' => 'debit',
|
||||
'balance' => 'debit',
|
||||
'transfer' => 'neutral',
|
||||
'invoice' => str_starts_with((string) $this->note, 'Admin xác nhận')
|
||||
? 'neutral'
|
||||
: 'debit',
|
||||
default => 'credit',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* `proof_image` stores either a single relative storage path, or a
|
||||
* JSON-encoded array of paths (admin-created service with multiple
|
||||
* proofs). Resolve both shapes into absolute, browsable URLs so the
|
||||
* raw path string never leaks into the frontend as a literal href.
|
||||
*/
|
||||
public function getProofImageUrlsAttribute(): array
|
||||
{
|
||||
if (! $this->proof_image) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$paths = json_decode($this->proof_image, true);
|
||||
if (! is_array($paths)) {
|
||||
$paths = [$this->proof_image];
|
||||
}
|
||||
|
||||
return array_values(array_map(
|
||||
fn (string $path) => Storage::disk('public')->url($path),
|
||||
array_filter($paths, fn ($path) => is_string($path) && $path !== '')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ class User extends Authenticatable implements JWTSubject
|
||||
'birthday',
|
||||
'address',
|
||||
'phone',
|
||||
'department',
|
||||
'start_date',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -51,6 +53,7 @@ class User extends Authenticatable implements JWTSubject
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'start_date' => 'date',
|
||||
];
|
||||
|
||||
public function getJWTIdentifier()
|
||||
|
||||
Reference in New Issue
Block a user