feat(admin): star/tags marks, service product-type filter, campaign bulk actions, SMTP test

- Star (is_starred) and colored tags for services, customers, orders, invoices:
  Markable trait, tags/taggables tables, PATCH administrator/marks/{type}/{key},
  tag CRUD, list filters starred / tag_ids[]
- GET administrator/services accepts product_type (falls back to product type
  for legacy rows without services.type)
- Mail campaigns: bulk cancel / retry failed / delete; cancelled campaigns are
  skipped by SendMailCampaignRecipient
- POST administrator/settings/test-smtp sends a test email through the saved
  mail transport

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
baodev0
2026-10-15 21:53:41 +07:00
co-authored by Claude Opus 5.5
parent 46aa138eec
commit 40bf6b54f9
33 changed files with 780 additions and 11 deletions
+37
View File
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace App\Models\Concerns;
use App\Models\Tag;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
trait Markable
{
public function initializeMarkable(): void
{
$this->mergeCasts(['is_starred' => 'boolean']);
}
public function tags(): MorphToMany
{
return $this->morphToMany(Tag::class, 'taggable')->orderBy('tags.title');
}
/**
* @param array<string, mixed> $filters
*/
public function scopeMarked(Builder $query, array $filters): Builder
{
$tagIds = array_values(array_filter(array_map('intval', (array) ($filters['tag_ids'] ?? []))));
return $query
->when(
filter_var($filters['starred'] ?? false, FILTER_VALIDATE_BOOL),
fn (Builder $q) => $q->where($this->qualifyColumn('is_starred'), true),
)
->when($tagIds, fn (Builder $q) => $q->whereHas('tags', fn (Builder $tags) => $tags->whereIn('tags.id', $tagIds)));
}
}
+2 -1
View File
@@ -3,6 +3,7 @@
namespace App\Models;
use App\Services\Cache\CacheServiceInterface;
use App\Models\Concerns\Markable;
use App\Traits\LogsActivity;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -13,7 +14,7 @@ use Tymon\JWTAuth\Contracts\JWTSubject;
class Customer extends Authenticatable implements JWTSubject
{
use HasFactory, HasUuids, SoftDeletes, LogsActivity;
use HasFactory, HasUuids, SoftDeletes, LogsActivity, Markable;
protected $table = 'customers';
+2 -1
View File
@@ -3,6 +3,7 @@
namespace App\Models;
use App\Enums\Invoice\InvoiceStatus;
use App\Models\Concerns\Markable;
use App\Traits\LogsActivity;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -11,7 +12,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class Invoice extends Model
{
use HasFactory, SoftDeletes, LogsActivity;
use HasFactory, SoftDeletes, LogsActivity, Markable;
protected $table = 'invoices';
+6
View File
@@ -10,6 +10,12 @@ class MailCampaign extends Model
{
use HasFactory;
public const STATUS_CANCELLED = 'cancelled';
public const ACTIVE_STATUSES = ['queued', 'sending'];
public const FINISHED_STATUSES = ['completed', 'failed', self::STATUS_CANCELLED];
protected $table = 'mail_campaigns';
protected $fillable = [
+2 -1
View File
@@ -2,6 +2,7 @@
namespace App\Models;
use App\Models\Concerns\Markable;
use App\Traits\LogsActivity;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -10,7 +11,7 @@ use App\Models\ModuleVmware;
class Order extends Model
{
use HasFactory, SoftDeletes, LogsActivity;
use HasFactory, SoftDeletes, LogsActivity, Markable;
protected $table = 'orders';
+2 -1
View File
@@ -2,6 +2,7 @@
namespace App\Models;
use App\Models\Concerns\Markable;
use App\Traits\LogsActivity;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -10,7 +11,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class Service extends Model
{
use HasFactory, HasUuids, SoftDeletes, LogsActivity;
use HasFactory, HasUuids, SoftDeletes, LogsActivity, Markable;
public function uniqueIds(): array
{
+37
View File
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
class Tag extends Model
{
public const COLOR_PATTERN = '/^#[0-9a-fA-F]{6}$/';
protected $fillable = ['title', 'color'];
protected $hidden = ['pivot'];
public function services(): MorphToMany
{
return $this->morphedByMany(Service::class, 'taggable');
}
public function customers(): MorphToMany
{
return $this->morphedByMany(Customer::class, 'taggable');
}
public function orders(): MorphToMany
{
return $this->morphedByMany(Order::class, 'taggable');
}
public function invoices(): MorphToMany
{
return $this->morphedByMany(Invoice::class, 'taggable');
}
}