112 lines
3.1 KiB
PHP
112 lines
3.1 KiB
PHP
<?php
|
||
/**
|
||
* 重新生成商品 118 的 VR 座位规格数据
|
||
* 用法: php regenerate_spec.php
|
||
*/
|
||
|
||
require '/var/www/html/think';
|
||
|
||
use think\facade\Db;
|
||
use app\plugins\vr_ticket\service\SeatSkuService;
|
||
|
||
// 连接 vrticket 数据库
|
||
Db::setConfig([
|
||
'default' => 'mysql',
|
||
'connections' => [
|
||
'mysql' => [
|
||
'type' => 'mysql',
|
||
'hostname' => '127.0.0.1',
|
||
'hostport' => '10001',
|
||
'database' => 'vrticket',
|
||
'username' => 'root',
|
||
'password' => 'shopxo_root_2024',
|
||
'charset' => 'utf8mb4',
|
||
'prefix' => 'vrt_',
|
||
]
|
||
]
|
||
]);
|
||
|
||
$goodsId = 118;
|
||
|
||
// 1. 读取商品配置
|
||
$goods = Db::name('goods')->find($goodsId);
|
||
if (!$goods) {
|
||
echo "Goods {$goodsId} not found\n";
|
||
exit(1);
|
||
}
|
||
|
||
echo "Goods: {$goods['title']}\n";
|
||
echo "Item type: {$goods['item_type']}\n";
|
||
|
||
// 2. 解析 vr_goods_config
|
||
$configData = $goods['spec_base'] ?? '';
|
||
if (empty($configData)) {
|
||
echo "No spec_base found for goods {$goodsId}\n";
|
||
exit(1);
|
||
}
|
||
|
||
// 尝试解析 JSON(spec_base 可能是 JSON 字符串)
|
||
$configs = json_decode($configData, true);
|
||
if (json_last_error() !== JSON_ERROR_NONE || !is_array($configs)) {
|
||
echo "Invalid spec_base JSON for goods {$goodsId}\n";
|
||
exit(1);
|
||
}
|
||
|
||
echo "Found " . count($configs) . " config(s)\n";
|
||
|
||
// 3. 清空现有规格数据
|
||
echo "Clearing existing spec data...\n";
|
||
Db::name('GoodsSpecType')->where('goods_id', $goodsId)->delete();
|
||
Db::name('GoodsSpecBase')->where('goods_id', $goodsId)->delete();
|
||
Db::name('GoodsSpecValue')->where('goods_id', $goodsId)->delete();
|
||
|
||
// 4. 重新生成 SKU
|
||
foreach ($configs as $idx => $config) {
|
||
$templateId = intval($config['template_id'] ?? 0);
|
||
if ($templateId <= 0) {
|
||
echo "Skipping config {$idx}: no template_id\n";
|
||
continue;
|
||
}
|
||
|
||
$selectedRooms = $config['selected_rooms'] ?? [];
|
||
$selectedSections = $config['selected_sections'] ?? [];
|
||
$sessions = $config['sessions'] ?? [];
|
||
|
||
echo "Generating SKU for template {$templateId}...\n";
|
||
$result = SeatSkuService::BatchGenerate(
|
||
$goodsId, $templateId,
|
||
$selectedRooms, $selectedSections, $sessions
|
||
);
|
||
|
||
if ($result['code'] === 0) {
|
||
echo " Generated: {$result['data']['generated']} seats\n";
|
||
} else {
|
||
echo " Error: {$result['msg']}\n";
|
||
}
|
||
}
|
||
|
||
// 5. 刷新商品基础信息
|
||
echo "Refreshing goods base info...\n";
|
||
SeatSkuService::refreshGoodsBase($goodsId);
|
||
|
||
// 6. 验证结果
|
||
$specCount = Db::name('GoodsSpecBase')->where('goods_id', $goodsId)->count();
|
||
$valueCount = Db::name('GoodsSpecValue')->where('goods_id', $goodsId)->count();
|
||
$typeCount = Db::name('GoodsSpecType')->where('goods_id', $goodsId)->count();
|
||
|
||
echo "\nDone!\n";
|
||
echo "GoodsSpecBase: {$specCount}\n";
|
||
echo "GoodsSpecValue: {$valueCount}\n";
|
||
echo "GoodsSpecType: {$typeCount}\n";
|
||
|
||
// 7. 显示 sample 数据
|
||
echo "\nSample GoodsSpecBase (first 3):\n";
|
||
$sample = Db::name('GoodsSpecBase')
|
||
->where('goods_id', $goodsId)
|
||
->limit(3)
|
||
->select()
|
||
->toArray();
|
||
foreach ($sample as $spec) {
|
||
echo " ID: {$spec['id']}, extends: {$spec['extends']}\n";
|
||
}
|