|
@@ -39,6 +39,7 @@ use Illuminate\Support\Facades\Auth;
|
|
|
* @property string|null $recipient_document
|
|
* @property string|null $recipient_document
|
|
|
* @property string|null $recipient_type
|
|
* @property string|null $recipient_type
|
|
|
* @property string|null $recipient_code
|
|
* @property string|null $recipient_code
|
|
|
|
|
+ * @property string|null $share_code
|
|
|
* @property string|null $recipient_payment_mode
|
|
* @property string|null $recipient_payment_mode
|
|
|
* @property array<array-key, mixed>|null $recipient_default_bank_account
|
|
* @property array<array-key, mixed>|null $recipient_default_bank_account
|
|
|
* @property array<array-key, mixed>|null $recipient_transfer_settings
|
|
* @property array<array-key, mixed>|null $recipient_transfer_settings
|
|
@@ -106,7 +107,11 @@ class Provider extends Model
|
|
|
|
|
|
|
|
protected $table = "providers";
|
|
protected $table = "providers";
|
|
|
|
|
|
|
|
- protected $guarded = ["id", "recipient_code"];
|
|
|
|
|
|
|
+ public const SHARE_CODE_ALPHABET = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
|
|
|
|
|
+
|
|
|
|
|
+ public const SHARE_CODE_LENGTH = 6;
|
|
|
|
|
+
|
|
|
|
|
+ protected $guarded = ["id", "recipient_code", "share_code"];
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Get the attributes that should be cast.
|
|
* Get the attributes that should be cast.
|
|
@@ -134,6 +139,15 @@ class Provider extends Model
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ protected static function booted(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ static::creating(function (self $provider) {
|
|
|
|
|
+ if (empty($provider->share_code)) {
|
|
|
|
|
+ $provider->share_code = self::generateUniqueShareCode();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function user(): BelongsTo
|
|
public function user(): BelongsTo
|
|
|
{
|
|
{
|
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
@@ -276,4 +290,27 @@ class Provider extends Model
|
|
|
->where('provider_bank_accounts.is_active', true)
|
|
->where('provider_bank_accounts.is_active', true)
|
|
|
->whereNull('provider_bank_accounts.deleted_at');
|
|
->whereNull('provider_bank_accounts.deleted_at');
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public static function generateUniqueShareCode(): string
|
|
|
|
|
+ {
|
|
|
|
|
+ $alphabet = self::SHARE_CODE_ALPHABET;
|
|
|
|
|
+ $lastIndex = strlen($alphabet) - 1;
|
|
|
|
|
+
|
|
|
|
|
+ do {
|
|
|
|
|
+ $code = '';
|
|
|
|
|
+
|
|
|
|
|
+ for ($i = 0; $i < self::SHARE_CODE_LENGTH; $i++) {
|
|
|
|
|
+ $code .= $alphabet[random_int(0, $lastIndex)];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $exists = self::withTrashed()->where('share_code', $code)->exists();
|
|
|
|
|
+ } while ($exists);
|
|
|
|
|
+
|
|
|
|
|
+ return $code;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function normalizeShareCode(?string $code): string
|
|
|
|
|
+ {
|
|
|
|
|
+ return strtoupper(trim((string) $code));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|