'等待中', 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]); } }