'待审核', 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, ]; } }