Introduce a comprehensive set of commercial features including a multi-step order approval workflow, customer credit management, and specialized import service invoicing. Key changes: - Implement `pending_approval` and `approved` shipment statuses to allow staff verification before customer payment. - Add a credit system to `User` model with `credit_limit` and `credit_used` to manage customer balances and debts. - Develop a new `importInvoice` PDF generation service following the "Sheet ENG Invoice" specification for import services. - Add Filament resources for managing Audit Logs, Commitment Forms, Customer Credits, and Shipment Checklists. - Implement staff-specific APIs for order approval/rejection and customer financial status monitoring. - Integrate Kavenegar SMS service for mobile verification and notifications. - Add bulk tracking import functionality via CSV/Excel. - Update WordPress bridge assets (CSS/JS) to support the new multi-step order form UI and updated redirection logic. - Update deployment configurations and documentation to reflect new production domains and feature sets.
89 lines
2.5 KiB
PHP
89 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
use HasApiTokens, HasFactory, Notifiable, HasRoles;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'phone',
|
|
'role', // فیلد قدیمی - بعداً حذف میکنیم
|
|
'credit_limit', // سقف اعتبار
|
|
'credit_used', // مبلغ استفاده شده از اعتبار
|
|
];
|
|
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'credit_limit' => 'decimal:2',
|
|
'credit_used' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
// ─── Relationships ───────────────────────────────
|
|
|
|
public function wallet()
|
|
{
|
|
return $this->hasOne(Wallet::class);
|
|
}
|
|
|
|
// ─── Helper Methods (Role Checks) ────────────────
|
|
|
|
public function isSuperAdmin(): bool
|
|
{
|
|
return $this->hasRole('super_admin');
|
|
}
|
|
|
|
public function isAdmin(): bool
|
|
{
|
|
return $this->hasAnyRole(['super_admin', 'admin']);
|
|
}
|
|
|
|
public function isStaff(): bool
|
|
{
|
|
return $this->hasRole('staff');
|
|
}
|
|
|
|
public function isCustomer(): bool
|
|
{
|
|
return $this->hasRole('customer');
|
|
}
|
|
|
|
// ─── Credit Methods ──────────────────────────────
|
|
|
|
public function getAvailableCreditAttribute(): float
|
|
{
|
|
return $this->credit_limit - $this->credit_used;
|
|
}
|
|
|
|
public function hasAvailableCredit(float $amount): bool
|
|
{
|
|
return $this->available_credit >= $amount;
|
|
}
|
|
|
|
// ─── Filament Panel Access ───────────────────────
|
|
|
|
public function canAccessPanel(\Filament\Panel $panel): bool
|
|
{
|
|
// فقط super_admin, admin, staff میتوانند به پنل ادمین دسترسی داشته باشند
|
|
// customer فقط از API استفاده میکند
|
|
return $this->hasAnyRole(['super_admin', 'admin', 'staff']);
|
|
}
|
|
} |