update api register
This commit is contained in:
@@ -95,4 +95,9 @@ class Customer extends Model
|
||||
{
|
||||
return $this->hasMany(CustomerContact::class);
|
||||
}
|
||||
|
||||
public function linkedUsers()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'customer_user_links')->withPivot(['tenant_id', 'relationship', 'is_primary'])->withTimestamps();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CustomerUserLink extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['is_primary' => 'boolean'];
|
||||
}
|
||||
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class HotspotVoucher extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $hidden = ['password'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'password' => 'encrypted', 'profile_snapshot' => 'array', 'valid_until' => 'datetime',
|
||||
'activated_at' => 'datetime', 'used_at' => 'datetime', 'synced_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function sale()
|
||||
{
|
||||
return $this->belongsTo(VoucherSale::class, 'voucher_sale_id');
|
||||
}
|
||||
|
||||
public function packageProfile()
|
||||
{
|
||||
return $this->belongsTo(NasPackageProfile::class, 'nas_package_profile_id');
|
||||
}
|
||||
|
||||
public function mikrotik()
|
||||
{
|
||||
return $this->belongsTo(NasMikrotik::class, 'nas_mikrotik_id');
|
||||
}
|
||||
}
|
||||
@@ -30,4 +30,9 @@ class NotificationChannel extends Model
|
||||
{
|
||||
return $this->hasMany(NotificationTemplate::class);
|
||||
}
|
||||
|
||||
public function deliveries()
|
||||
{
|
||||
return $this->hasMany(NotificationDelivery::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RoleApplication extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['payload' => 'array', 'submitted_at' => 'datetime', 'reviewed_at' => 'datetime'];
|
||||
}
|
||||
|
||||
public function applicant()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'applicant_user_id');
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
|
||||
public function reviewer()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'reviewed_by');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SystemNotificationCampaign extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['audience' => 'array', 'completed_at' => 'datetime'];
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
|
||||
public function creator()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
public function notifications()
|
||||
{
|
||||
return $this->hasMany(UserNotification::class);
|
||||
}
|
||||
}
|
||||
+35
-2
@@ -36,6 +36,7 @@ class User extends Authenticatable
|
||||
'profile_photo_file_id',
|
||||
'password',
|
||||
'is_master',
|
||||
'is_platform_staff',
|
||||
'access_level',
|
||||
'status',
|
||||
'verification_channel',
|
||||
@@ -66,6 +67,7 @@ class User extends Authenticatable
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'is_master' => 'boolean',
|
||||
'is_platform_staff' => 'boolean',
|
||||
'access_level' => UserAccessLevel::class,
|
||||
'verification_code_expires_at' => 'datetime',
|
||||
'verified_at' => 'datetime',
|
||||
@@ -112,14 +114,45 @@ class User extends Authenticatable
|
||||
return $this->morphMany(Wallet::class, 'owner');
|
||||
}
|
||||
|
||||
public function voucherAgents()
|
||||
{
|
||||
return $this->hasMany(VoucherAgent::class);
|
||||
}
|
||||
|
||||
public function roleApplications()
|
||||
{
|
||||
return $this->hasMany(RoleApplication::class, 'applicant_user_id');
|
||||
}
|
||||
|
||||
public function linkedCustomers()
|
||||
{
|
||||
return $this->belongsToMany(Customer::class, 'customer_user_links')->withPivot(['tenant_id', 'relationship', 'is_primary'])->withTimestamps();
|
||||
}
|
||||
|
||||
public function isMasterAdmin(): bool
|
||||
{
|
||||
return $this->is_master || $this->access_level === UserAccessLevel::MASTER_ADMIN;
|
||||
}
|
||||
|
||||
public function isTenantOwner(): bool
|
||||
public function isTenantOwner(?int $tenantId = null): bool
|
||||
{
|
||||
return $this->access_level === UserAccessLevel::TENANT_OWNER;
|
||||
if ($this->access_level !== UserAccessLevel::TENANT_OWNER) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->userTenants()
|
||||
->where('role', 'tenant_owner')
|
||||
->when($tenantId, fn ($query) => $query->where('tenant_id', $tenantId))
|
||||
->exists();
|
||||
}
|
||||
|
||||
public function tenantRole(?int $tenantId): ?string
|
||||
{
|
||||
if (! $tenantId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->userTenants()->where('tenant_id', $tenantId)->value('role');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,5 +13,13 @@ class UserNotification extends Model
|
||||
return ['read_at' => 'datetime'];
|
||||
}
|
||||
|
||||
public function user() { return $this->belongsTo(User::class); }
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function campaign()
|
||||
{
|
||||
return $this->belongsTo(SystemNotificationCampaign::class, 'system_notification_campaign_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ class UserTenant extends Model
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'tenant_id',
|
||||
'role',
|
||||
'is_default',
|
||||
];
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VoucherAgent extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'discount_percent' => 'decimal:2', 'commission_percent' => 'decimal:2',
|
||||
'credit_limit' => 'decimal:2', 'outstanding_balance' => 'decimal:2',
|
||||
];
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function sales()
|
||||
{
|
||||
return $this->hasMany(VoucherSale::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VoucherLoginPageSetting extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'enabled' => 'boolean', 'allowed_package_profile_ids' => 'array',
|
||||
'settings' => 'array', 'enabled_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
|
||||
public function gatewayAccount()
|
||||
{
|
||||
return $this->belongsTo(PaymentGatewayAccount::class, 'payment_gateway_account_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class VoucherSale extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'unit_price' => 'decimal:2', 'discount_amount' => 'decimal:2',
|
||||
'total_amount' => 'decimal:2', 'pricing_snapshot' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
|
||||
public function agent()
|
||||
{
|
||||
return $this->belongsTo(VoucherAgent::class, 'voucher_agent_id');
|
||||
}
|
||||
|
||||
public function packageProfile()
|
||||
{
|
||||
return $this->belongsTo(NasPackageProfile::class, 'nas_package_profile_id');
|
||||
}
|
||||
|
||||
public function creator()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
public function vouchers()
|
||||
{
|
||||
return $this->hasMany(HotspotVoucher::class);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,11 @@ class Wallet extends Model
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
}
|
||||
|
||||
public function ledgerEntries()
|
||||
{
|
||||
return $this->hasMany(WalletLedgerEntry::class);
|
||||
|
||||
Reference in New Issue
Block a user