本次提交内容包括: 1. 替换13个二级分类为真实商业实拍图,同步更新本地与线上数据库 2. 新增会员拨打额度耗尽引导开通会员功能 3. 优化发布页分类选择逻辑,增加会员权益展示 4. 修复分类名称显示问题,完善相关交互逻辑 5. 新增图片同步工具脚本,确保线上线下数据一致性
77 行
2.7 KiB
PHP
77 行
2.7 KiB
PHP
<?php
|
|
/**
|
|
* 补齐 普工技工 和 鲜活水产
|
|
*/
|
|
|
|
$targetDir = __DIR__ . '/../public/uploads/20261028';
|
|
$jsonFile = __DIR__ . '/real_photos_result.json';
|
|
$existing = file_exists($jsonFile) ? json_decode(file_get_contents($jsonFile), true) : [];
|
|
|
|
$missing = [
|
|
[
|
|
'id' => 27,
|
|
'name' => '普工技工',
|
|
'filename' => 'job-tech.jpg',
|
|
'url' => 'https://images.unsplash.com/photo-1581092335397-9583fe92d232?w=500&q=80&auto=format&fit=crop',
|
|
],
|
|
[
|
|
'id' => 39,
|
|
'name' => '鲜活水产',
|
|
'filename' => 'poultry-fish.jpg',
|
|
'url' => 'https://images.unsplash.com/photo-1524704654690-b56c05c78a00?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;
|
|
}
|
|
|
|
foreach ($missing as $item) {
|
|
echo "正在补齐 [{$item['name']}] 真实实拍照: {$item['url']} ...\n";
|
|
$raw = @file_get_contents($item['url']);
|
|
if (!$raw) {
|
|
// 备用地址
|
|
$backupUrl = ($item['id'] === 27)
|
|
? 'https://images.unsplash.com/photo-1581092160607-ee22621dd758?w=500&q=80&auto=format&fit=crop'
|
|
: 'https://images.unsplash.com/photo-1516684732162-798a0062be99?w=500&q=80&auto=format&fit=crop';
|
|
$raw = @file_get_contents($backupUrl);
|
|
}
|
|
|
|
if ($raw) {
|
|
$tmpName = md5($raw . $item['name']) . '.jpg';
|
|
$saveAbs = $targetDir . '/' . $tmpName;
|
|
if (cropToSquare240($raw, $saveAbs)) {
|
|
$finalSize = filesize($saveAbs);
|
|
$url = '/uploads/20261028/' . $tmpName;
|
|
echo " ✓ 成功补齐: {$url} (" . round($finalSize / 1024, 2) . " KB)\n";
|
|
$existing[] = [
|
|
'id' => $item['id'],
|
|
'name' => $item['name'],
|
|
'filename' => $item['filename'],
|
|
'local' => $saveAbs,
|
|
'rel_url' => $url,
|
|
'size' => $finalSize,
|
|
'sha1' => sha1_file($saveAbs),
|
|
];
|
|
}
|
|
} else {
|
|
echo " ✗ 仍失败: {$item['name']}\n";
|
|
}
|
|
}
|
|
|
|
file_put_contents($jsonFile, json_encode($existing, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
|
echo "当前清单已有 " . count($existing) . " 个分类的真实照片!\n";
|