*/ public function resolve(string $scopeType, int $scopeId): array { $scopeType = trim($scopeType); if (!in_array($scopeType, [ self::SCOPE_INSTANCE, self::SCOPE_HOST, self::SCOPE_PUBLIC_IP_POOL, ], true) || $scopeId < 1) { throw new CloudError('受影响实例范围无效', 422); } if ($scopeType === self::SCOPE_INSTANCE) { return DB::table('cloud_instances') ->where('id', $scopeId) ->where('status', '<>', 'deleted') ->orderBy('id')->get($this->columns())->all(); } if ($scopeType === self::SCOPE_HOST) { return DB::table('cloud_instances') ->where('host_id', $scopeId) ->where('status', '<>', 'deleted') ->orderBy('id')->get($this->columns())->all(); } return DB::table('cloud_resource_reservation_ips as claim') ->join('cloud_resource_reservations as reservation', 'reservation.id', '=', 'claim.reservation_id') ->join('cloud_instances as instance', static function ($join): void { $join->on('instance.id', '=', 'reservation.instance_id') ->on('instance.reservation_id', '=', 'reservation.id'); }) ->where('claim.public_ip_pool_id', $scopeId) ->where('claim.active_claim', 1) ->where('claim.state', 'committed') ->where('reservation.state', 'committed') ->where('instance.status', '<>', 'deleted') ->orderBy('instance.id') ->distinct()->get([ 'instance.id', 'instance.user_id', 'instance.host_id', 'instance.reservation_id', 'instance.name', 'instance.spec_json', ])->all(); } /** @return array */ private function columns(): array { return [ 'id', 'user_id', 'host_id', 'reservation_id', 'name', 'spec_json', ]; } }