From e6c9945e3e03a08982bd45bb0436df1cce937905 Mon Sep 17 00:00:00 2001 From: elf <360197197@qq.com> Date: Mon, 8 Jul 2024 00:40:59 +0800 Subject: [PATCH] yh --- .../Controller/AutoPackController.class.php | 32 ++++++++++++++++++- Application/Base/Tool/OssClient.class.php | 9 ++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Application/Admin/Controller/AutoPackController.class.php b/Application/Admin/Controller/AutoPackController.class.php index 5f75bc2c9..9ef2272d9 100644 --- a/Application/Admin/Controller/AutoPackController.class.php +++ b/Application/Admin/Controller/AutoPackController.class.php @@ -1082,6 +1082,36 @@ class AutoPackController extends Think public function clearPkg() { $client = new ToolOssClient(); - $client->listObjects(); + $marker = ''; + do { + $list = $client->listObjects('GamePack/', $marker, 100); + $urls = []; + foreach ($list->getObjectList() as $obj) { + $urls[] = '"https://qy-plat.oss-cn-hangzhou.aliyuncs.com/' . $obj->getKey() . '"'; + } + if (empty($urls)) { + break; + } + $urlsStr = implode(",", $urls); + + $rows = M("apply", 'tab_')->field('pack_url, game_id')->where("group_id in ({$urlsStr})")->find(); + $packUrls = []; + $needDelUrls = []; + foreach ($rows as $row) { + $packUrls[] = $row['pack_url']; + if (!in_array($row['game_id'], [282, 283, 277, 273])) { + $needDelUrls[] = $row['pack_url']; + } + } + + $needDelUrls = array_unique(array_merge($needDelUrls, array_diff($urls, $packUrls))); + var_dump($needDelUrls); + + if (empty($list->getNextMarker())) { + break; + } else { + $marker = $list->getNextMarker(); + } + } while (true); } } diff --git a/Application/Base/Tool/OssClient.class.php b/Application/Base/Tool/OssClient.class.php index c59b6c872..6c856e491 100644 --- a/Application/Base/Tool/OssClient.class.php +++ b/Application/Base/Tool/OssClient.class.php @@ -119,9 +119,12 @@ class OssClient implements StorageClient { /** * 删除文件 */ - public function listObjects() + public function listObjects($prefix, $marker = '', $maxKeys = 500) { - $listObject = $this->client->listObjects($this->bucket, ['prefix' => 'GamePack/', 'max-keys' => 1000, 'marker' => 'GamePack/278_71a13facf90535fe.ipa']); - var_dump($listObject); + $options = ['prefix' => $prefix, 'max-keys' => $maxKeys]; + if ($marker) { + $options['marker'] = $marker; + } + return $this->client->listObjects($this->bucket, ['prefix' => $prefix, 'max-keys' => $maxKeys, 'marker' => $marker]); } } \ No newline at end of file