删除 More/t.php.bak

This commit is contained in:
2025-10-17 23:32:12 +08:00
committed by cssfw
parent 917d269c83
commit 1f5ac5e0ca
79 changed files with 13493 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
<?php
include_once "../Hv4.Function.php";
$语句 = "SELECT * FROM products WHERE status = 'visible';";
$商品元数据 = @数据库运行($语句);
// 原始数据
$data = $商品元数据;
// 用来存储分类结果的数组
$categories = [];
// 分类和整理数据
foreach ($data as $item) {
// 移除分类中的 [xxx] 数字部分
$category1 = preg_replace('/\[\d+\]$/', '', $item['category_1']);
$category2 = preg_replace('/\[\d+\]$/', '', $item['category_2']);
// 分类1和分类2作为键来组织数据
if (!isset($categories[$category1])) {
$categories[$category1] = [];
}
// 确保分类2的存在并添加产品到分类2
if (!isset($categories[$category1][$category2])) {
$categories[$category1][$category2] = [];
}
// 将当前商品添加到相应的分类下
$categories[$category1][$category2][] = $item;
}
// 对每个分类内的数据进行排序
foreach ($categories as $category1 => &$category1Items) {
foreach ($category1Items as $category2 => &$category2Items) {
// 按照 sort_order 字段降序排序
usort($category2Items, function ($a, $b) {
return $b['sort_order'] - $a['sort_order'];
});
}
}
// 转换为 JSON 格式输出
echo 转JSON($categories);
?>