| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Module\Mex\Enums;
- /**
- * 农贸市场订单状态枚举
- */
- enum OrderStatus: string
- {
- case PENDING = 'PENDING'; // 等待中
- case COMPLETED = 'COMPLETED'; // 已完成
- case CANCELLED = 'CANCELLED'; // 已取消
- case FAILED = 'FAILED'; // 失败
- /**
- * 获取订单状态描述
- */
- public function getDescription(): string
- {
- return match ($this) {
- self::PENDING => '等待中',
- self::COMPLETED => '已完成',
- self::CANCELLED => '已取消',
- self::FAILED => '失败',
- };
- }
- /**
- * 获取所有订单状态
- */
- public static function getAll(): array
- {
- return [
- self::PENDING->value => self::PENDING->getDescription(),
- self::COMPLETED->value => self::COMPLETED->getDescription(),
- self::CANCELLED->value => self::CANCELLED->getDescription(),
- self::FAILED->value => self::FAILED->getDescription(),
- ];
- }
- /**
- * 判断是否为等待状态
- */
- public function isPending(): bool
- {
- return $this === self::PENDING;
- }
- /**
- * 判断是否为完成状态
- */
- public function isCompleted(): bool
- {
- return $this === self::COMPLETED;
- }
- /**
- * 判断是否为取消状态
- */
- public function isCancelled(): bool
- {
- return $this === self::CANCELLED;
- }
- /**
- * 判断是否为失败状态
- */
- public function isFailed(): bool
- {
- return $this === self::FAILED;
- }
- /**
- * 判断是否为最终状态(不可再变更)
- */
- public function isFinal(): bool
- {
- return in_array($this, [self::COMPLETED, self::CANCELLED, self::FAILED]);
- }
- }
|