/
itp_practice
/
itp_backend
Обзор
Документация
Войти
/
itp_practice
/
itp_backend
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
app/Models/OrderStatus.php
96 строк
2 KB
vivanenko
fix taps and others structure
27 май 2025, 18:06
27 май 2025, 18:06
8cdc7d9
Код
Авторство
О чём код?
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; /** * @property string $code * @property string $name * @property string|null $description * @property bool $is_final * @property \DateTime $created_at * @property \DateTime $updated_at */ class OrderStatus extends Model { protected $table = 'order_statuses'; protected $primaryKey = 'code'; protected $keyType = 'string'; public $incrementing = false; protected $fillable = [ 'code', 'name', 'description', 'is_final', ]; protected $casts = [ 'code' => 'string', 'name' => 'string', 'description' => 'string', 'is_final' => 'boolean', ]; // Константы статусов public const PENDING = 'pending'; public const PROCESSING = 'processing'; public const PAID = 'paid'; public const FAILED = 'failed'; public const CANCELLED = 'cancelled'; public const REFUNDED = 'refunded'; public function orders(): HasMany { return $this->hasMany(Order::class, 'status_code', 'code'); } public static function getDefaultStatuses(): array { return [ self::PENDING => 'Ожидает оплаты', self::PROCESSING => 'Обрабатывается', self::PAID => 'Оплачен', self::FAILED => 'Ошибка оплаты', self::CANCELLED => 'Отменен', self::REFUNDED => 'Возвращен', ]; } public function isPending(): bool { return $this->code === self::PENDING; } public function isProcessing(): bool { return $this->code === self::PROCESSING; } public function isPaid(): bool { return $this->code === self::PAID; } public function isFailed(): bool { return $this->code === self::FAILED; } public function isCancelled(): bool { return $this->code === self::CANCELLED; } public function isRefunded(): bool { return $this->code === self::REFUNDED; } public function isFinal(): bool { return $this->is_final; } }