| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- <?php
- namespace App\Module\OpenAPI\Enums;
- /**
- * 应用状态枚举
- */
- enum APP_STATUS: string
- {
- case PENDING = 'PENDING'; // 待审核
- case APPROVED = 'APPROVED'; // 已审核通过
- case REJECTED = 'REJECTED'; // 已拒绝
- case ACTIVE = 'ACTIVE'; // 激活状态
- case SUSPENDED = 'SUSPENDED'; // 暂停状态
- case DISABLED = 'DISABLED'; // 禁用状态
- case EXPIRED = 'EXPIRED'; // 已过期
- /**
- * 获取状态的中文描述
- *
- * @return string
- */
- public function getLabel(): string
- {
- return match ($this) {
- self::PENDING => '待审核',
- self::APPROVED => '已审核',
- self::REJECTED => '已拒绝',
- self::ACTIVE => '激活',
- self::SUSPENDED => '暂停',
- self::DISABLED => '禁用',
- self::EXPIRED => '已过期',
- };
- }
- /**
- * 获取状态的颜色
- *
- * @return string
- */
- public function getColor(): string
- {
- return match ($this) {
- self::PENDING => 'warning',
- self::APPROVED => 'info',
- self::REJECTED => 'danger',
- self::ACTIVE => 'success',
- self::SUSPENDED => 'warning',
- self::DISABLED => 'secondary',
- self::EXPIRED => 'dark',
- };
- }
- /**
- * 获取状态的图标
- *
- * @return string
- */
- public function getIcon(): string
- {
- return match ($this) {
- self::PENDING => 'fa-clock',
- self::APPROVED => 'fa-check',
- self::REJECTED => 'fa-times',
- self::ACTIVE => 'fa-play',
- self::SUSPENDED => 'fa-pause',
- self::DISABLED => 'fa-stop',
- self::EXPIRED => 'fa-calendar-times',
- };
- }
- /**
- * 获取状态描述
- *
- * @return string
- */
- public function getDescription(): string
- {
- return match ($this) {
- self::PENDING => '应用已提交,等待管理员审核',
- self::APPROVED => '应用已通过审核,可以激活使用',
- self::REJECTED => '应用审核未通过,需要修改后重新提交',
- self::ACTIVE => '应用正常运行中,可以调用API',
- self::SUSPENDED => '应用已暂停,暂时无法调用API',
- self::DISABLED => '应用已禁用,无法调用API',
- self::EXPIRED => '应用已过期,需要续期后才能使用',
- };
- }
- /**
- * 判断是否可以调用API
- *
- * @return bool
- */
- public function canCallApi(): bool
- {
- return $this === self::ACTIVE;
- }
- /**
- * 判断是否可以编辑
- *
- * @return bool
- */
- public function canEdit(): bool
- {
- return in_array($this, [
- self::PENDING,
- self::REJECTED,
- self::SUSPENDED,
- ]);
- }
- /**
- * 判断是否需要审核
- *
- * @return bool
- */
- public function needsApproval(): bool
- {
- return $this === self::PENDING;
- }
- /**
- * 获取可以转换到的状态
- *
- * @return array
- */
- public function getTransitionableStates(): array
- {
- return match ($this) {
- self::PENDING => [self::APPROVED, self::REJECTED],
- self::APPROVED => [self::ACTIVE, self::REJECTED],
- self::REJECTED => [self::PENDING],
- self::ACTIVE => [self::SUSPENDED, self::DISABLED, self::EXPIRED],
- self::SUSPENDED => [self::ACTIVE, self::DISABLED],
- self::DISABLED => [self::ACTIVE],
- self::EXPIRED => [self::ACTIVE],
- };
- }
- /**
- * 获取所有状态的选项数组
- *
- * @return array
- */
- public static function getOptions(): array
- {
- $options = [];
- foreach (self::cases() as $case) {
- $options[$case->value] = $case->getLabel();
- }
- return $options;
- }
- /**
- * 获取可用状态(可以调用API的状态)
- *
- * @return array
- */
- public static function getActiveStates(): array
- {
- return [self::ACTIVE];
- }
- /**
- * 获取不可用状态
- *
- * @return array
- */
- public static function getInactiveStates(): array
- {
- return [
- self::PENDING,
- self::REJECTED,
- self::SUSPENDED,
- self::DISABLED,
- self::EXPIRED,
- ];
- }
- /**
- * 获取需要管理员处理的状态
- *
- * @return array
- */
- public static function getAdminActionStates(): array
- {
- return [
- self::PENDING,
- self::SUSPENDED,
- self::EXPIRED,
- ];
- }
- }
|