本次提交内容包括: 1. 替换13个二级分类为真实商业实拍图,同步更新本地与线上数据库 2. 新增会员拨打额度耗尽引导开通会员功能 3. 优化发布页分类选择逻辑,增加会员权益展示 4. 修复分类名称显示问题,完善相关交互逻辑 5. 新增图片同步工具脚本,确保线上线下数据一致性
113 行
3.9 KiB
PHP
113 行
3.9 KiB
PHP
<?php
|
|
/**
|
|
* 为水果专区 (PID: 2) 补充 8 个真实实拍二级分类,模拟上传至 /uploads/20261028/
|
|
* 并同步到本地和线上数据库与服务器
|
|
*/
|
|
|
|
$targetDir = __DIR__ . '/../public/uploads/20261028';
|
|
if (!is_dir($targetDir)) {
|
|
mkdir($targetDir, 0755, true);
|
|
}
|
|
|
|
$fruits = [
|
|
[
|
|
'name' => '芒果',
|
|
'filename' => 'fruit-mango.jpg',
|
|
'url' => 'https://images.unsplash.com/photo-1553279768-865429fa0078?w=500&q=80&auto=format&fit=crop',
|
|
],
|
|
[
|
|
'name' => '香蕉',
|
|
'filename' => 'fruit-banana.jpg',
|
|
'url' => 'https://images.unsplash.com/photo-1571771894821-ce9b6c11b08e?w=500&q=80&auto=format&fit=crop',
|
|
],
|
|
[
|
|
'name' => '蓝莓',
|
|
'filename' => 'fruit-blueberry.jpg',
|
|
'url' => 'https://images.unsplash.com/photo-1498557850523-fd3d118b962e?w=500&q=80&auto=format&fit=crop',
|
|
],
|
|
[
|
|
'name' => '车厘子',
|
|
'filename' => 'fruit-cherry.jpg',
|
|
'url' => 'https://images.unsplash.com/photo-1528825871115-3581a5387919?w=500&q=80&auto=format&fit=crop',
|
|
],
|
|
[
|
|
'name' => '哈密瓜',
|
|
'filename' => 'fruit-melon.jpg',
|
|
'url' => 'https://images.unsplash.com/photo-1571575173700-afb9492e8c50?w=500&q=80&auto=format&fit=crop',
|
|
],
|
|
[
|
|
'name' => '火龙果',
|
|
'filename' => 'fruit-dragon.jpg',
|
|
'url' => 'https://images.unsplash.com/photo-1527324688151-0e627063f2b1?w=500&q=80&auto=format&fit=crop',
|
|
],
|
|
[
|
|
'name' => '柠檬',
|
|
'filename' => 'fruit-lemon.jpg',
|
|
'url' => 'https://images.unsplash.com/photo-1533089860892-a7c6f0a88666?w=500&q=80&auto=format&fit=crop',
|
|
],
|
|
[
|
|
'name' => '荔枝',
|
|
'filename' => 'fruit-lychee.jpg',
|
|
'url' => 'https://images.unsplash.com/photo-1596386461350-326ccb383e9f?w=500&q=80&auto=format&fit=crop',
|
|
],
|
|
];
|
|
|
|
function cropToSquare240($binaryData, $savePath)
|
|
{
|
|
$src = @imagecreatefromstring($binaryData);
|
|
if (!$src) return false;
|
|
$srcW = imagesx($src);
|
|
$srcH = imagesy($src);
|
|
$cropSize = min($srcW, $srcH);
|
|
$cropX = (int)(($srcW - $cropSize) / 2);
|
|
$cropY = (int)(($srcH - $cropSize) / 2);
|
|
$dst = imagecreatetruecolor(240, 240);
|
|
imagecopyresampled($dst, $src, 0, 0, $cropX, $cropY, 240, 240, $cropSize, $cropSize);
|
|
$res = imagejpeg($dst, $savePath, 82);
|
|
imagedestroy($src);
|
|
imagedestroy($dst);
|
|
return $res;
|
|
}
|
|
|
|
echo "=== [1/3] 下载真实水果实拍照并裁剪为 240x240 ===\n";
|
|
$downloaded = [];
|
|
foreach ($fruits as $f) {
|
|
echo "正在下载 [{$f['name']}] 实拍图: {$f['url']} ...\n";
|
|
$opts = [
|
|
'http' => [
|
|
'method' => 'GET',
|
|
'header' => "User-Agent: Mozilla/5.0\r\n",
|
|
'timeout' => 15,
|
|
]
|
|
];
|
|
$ctx = stream_context_create($opts);
|
|
$raw = @file_get_contents($f['url'], false, $ctx);
|
|
|
|
if (!$raw) {
|
|
// 尝试备用图
|
|
echo " ✗ 下载超时或失败: {$f['name']}\n";
|
|
continue;
|
|
}
|
|
|
|
$md5Name = md5($raw . $f['name']) . '.jpg';
|
|
$savePath = $targetDir . '/' . $md5Name;
|
|
|
|
if (cropToSquare240($raw, $savePath)) {
|
|
$size = filesize($savePath);
|
|
$relUrl = '/uploads/20261028/' . $md5Name;
|
|
echo " ✓ 生成成功: {$f['name']} -> {$relUrl} (" . round($size / 1024, 2) . " KB)\n";
|
|
$downloaded[] = [
|
|
'name' => $f['name'],
|
|
'filename' => $f['filename'],
|
|
'local' => $savePath,
|
|
'rel_url' => $relUrl,
|
|
'size' => $size,
|
|
'sha1' => sha1_file($savePath),
|
|
];
|
|
}
|
|
}
|
|
|
|
// 写入临时 json 供 python 脚本后续同步
|
|
file_put_contents(__DIR__ . '/more_fruits_result.json', json_encode($downloaded, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
|
echo "\n已准备就绪 " . count($downloaded) . " 个水果二级分类图片!\n";
|