no message

This commit is contained in:
2025-10-18 14:46:52 +08:00
commit 7a84025b05
387 changed files with 75711 additions and 0 deletions

59
user/get_products.php Normal file
View File

@@ -0,0 +1,59 @@
<?php
function getProductsData($directory) {
// 检查目录是否存在
if (!is_dir($directory)) {
return null;
}
$files = glob($directory . '/*.json');
// 如果没有找到任何JSON文件返回null
if (empty($files)) {
return null;
}
$productsData = [];
$allHidden = true;
foreach ($files as $file) {
$content = file_get_contents($file);
$data = json_decode($content, true);
// 跳过hidden为1的文件
if (isset($data['hidden']) && $data['hidden'] == 1) {
continue;
} else {
$allHidden = false;
}
// 获取文件名(不包括后缀)
$id = basename($file, '.json');
// 只获取指定键的值如果不存在则设为null
$productInfo = [
'name' => isset($data['name']) ? $data['name'] : null,
'describe' => isset($data['describe']) ? $data['describe'] : null,
'fid' => isset($data['fid']) ? $data['fid'] : null,
'sid' => isset($data['sid']) ? $data['sid'] : null,
'nid' => isset($data['sid']) ? $data['nid'] : null,
'day' => isset($data['day']) ? $data['day'] : null,
'have' => isset($data['have']) ? $data['have'] : null,
'star' => isset($data['star']) ? $data['star'] : null,
'bi' => isset($data['bi']) ? $data['bi'] : null
];
$productsData[$id] = $productInfo;
}
// 如果所有内容都是被隐藏的返回null
if ($allHidden) {
return null;
}
return json_encode($productsData, JSON_UNESCAPED_UNICODE);
}
$directory = './products';
echo getProductsData($directory);
?>