|
@@ -3775,6 +3775,7 @@ class AnimeService
|
|
|
$source = (array)$source;
|
|
$source = (array)$source;
|
|
|
$roles = json_decode(getProp($source, 'roles', '[]'), true) ?: [];
|
|
$roles = json_decode(getProp($source, 'roles', '[]'), true) ?: [];
|
|
|
$scenes = json_decode(getProp($source, 'scenes', '[]'), true) ?: [];
|
|
$scenes = json_decode(getProp($source, 'scenes', '[]'), true) ?: [];
|
|
|
|
|
+ $props = json_decode(getProp($source, 'props', '[]'), true) ?: [];
|
|
|
|
|
|
|
|
// 如果是分集数据,需要处理继承和任务创建逻辑
|
|
// 如果是分集数据,需要处理继承和任务创建逻辑
|
|
|
if ($episode_id) {
|
|
if ($episode_id) {
|
|
@@ -3782,7 +3783,7 @@ class AnimeService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 返回生成器函数,用于 SSE 流式输出
|
|
// 返回生成器函数,用于 SSE 流式输出
|
|
|
- return function() use ($roles, $scenes, $table_name, $id_field, $id_value) {
|
|
|
|
|
|
|
+ return function() use ($roles, $scenes, $props, $table_name, $id_field, $id_value) {
|
|
|
$startTime = time();
|
|
$startTime = time();
|
|
|
$maxDuration = 600; // 10分钟超时
|
|
$maxDuration = 600; // 10分钟超时
|
|
|
$checkInterval = 3; // 每3秒检查一次
|
|
$checkInterval = 3; // 每3秒检查一次
|
|
@@ -3791,12 +3792,12 @@ class AnimeService
|
|
|
$cacheKey = "anime:pics_info:{$table_name}:{$id_value}";
|
|
$cacheKey = "anime:pics_info:{$table_name}:{$id_value}";
|
|
|
|
|
|
|
|
// 生成当前数据的哈希值用于比较
|
|
// 生成当前数据的哈希值用于比较
|
|
|
- $generateHash = function($roles, $scenes) {
|
|
|
|
|
- return md5(json_encode(['roles' => $roles, 'scenes' => $scenes], JSON_UNESCAPED_UNICODE));
|
|
|
|
|
|
|
+ $generateHash = function($roles, $scenes, $props) {
|
|
|
|
|
+ return md5(json_encode(['roles' => $roles, 'scenes' => $scenes, 'props' => $props], JSON_UNESCAPED_UNICODE));
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 发送初始数据
|
|
// 发送初始数据
|
|
|
- $currentHash = $generateHash($roles, $scenes);
|
|
|
|
|
|
|
+ $currentHash = $generateHash($roles, $scenes, $props);
|
|
|
Redis::setex($cacheKey, 600, $currentHash); // 缓存10分钟
|
|
Redis::setex($cacheKey, 600, $currentHash); // 缓存10分钟
|
|
|
|
|
|
|
|
echo "data: " . json_encode([
|
|
echo "data: " . json_encode([
|
|
@@ -3804,6 +3805,7 @@ class AnimeService
|
|
|
'data' => [
|
|
'data' => [
|
|
|
'roles' => $roles,
|
|
'roles' => $roles,
|
|
|
'scenes' => $scenes,
|
|
'scenes' => $scenes,
|
|
|
|
|
+ 'props' => $props,
|
|
|
'start_time' => $startTime
|
|
'start_time' => $startTime
|
|
|
]
|
|
]
|
|
|
], JSON_UNESCAPED_UNICODE) . "\n\n";
|
|
], JSON_UNESCAPED_UNICODE) . "\n\n";
|
|
@@ -3901,9 +3903,51 @@ class AnimeService
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 检查道具任务状态
|
|
|
|
|
+ foreach ($props as $index => &$prop) {
|
|
|
|
|
+ $task_id = getProp($prop, 'task_id');
|
|
|
|
|
+ $task_status = getProp($prop, 'task_status');
|
|
|
|
|
+ $existing_url = getProp($prop, 'url');
|
|
|
|
|
+
|
|
|
|
|
+ // 只处理有任务ID且状态为processing的道具,或者状态为success但没有URL的道具
|
|
|
|
|
+ if ($task_id && ($task_status === 'processing' || (in_array($task_status, ['success', 'completed']) && empty($existing_url)))) {
|
|
|
|
|
+ $hasProcessing = ($task_status === 'processing');
|
|
|
|
|
+
|
|
|
|
|
+ // 查询任务状态
|
|
|
|
|
+ $task = DB::table('mp_generate_pic_tasks')
|
|
|
|
|
+ ->where('id', $task_id)
|
|
|
|
|
+ ->select('id', 'status', 'result_url', 'error_message')
|
|
|
|
|
+ ->first();
|
|
|
|
|
+
|
|
|
|
|
+ if ($task) {
|
|
|
|
|
+ $task = (array)$task;
|
|
|
|
|
+ $status = getProp($task, 'status');
|
|
|
|
|
+
|
|
|
|
|
+ // 如果任务完成或失败
|
|
|
|
|
+ if (in_array($status, ['success', 'failed'])) {
|
|
|
|
|
+ $prop['task_status'] = $status;
|
|
|
|
|
+
|
|
|
|
|
+ if ($status === 'success') {
|
|
|
|
|
+ $result_url = getProp($task, 'result_url');
|
|
|
|
|
+ if ($result_url) {
|
|
|
|
|
+ $result_urls = is_json($result_url) ? json_decode($result_url, true) : [$result_url];
|
|
|
|
|
+ if (is_array($result_urls) && !empty($result_urls[0])) {
|
|
|
|
|
+ $prop['url'] = $result_urls[0];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $updated = true;
|
|
|
|
|
+ } else if ($status === 'processing') {
|
|
|
|
|
+ $hasProcessing = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 如果有更新,检查数据是否真的变化了(通过哈希对比)
|
|
// 如果有更新,检查数据是否真的变化了(通过哈希对比)
|
|
|
if ($updated) {
|
|
if ($updated) {
|
|
|
- $newHash = $generateHash($roles, $scenes);
|
|
|
|
|
|
|
+ $newHash = $generateHash($roles, $scenes, $props);
|
|
|
$cachedHash = Redis::get($cacheKey);
|
|
$cachedHash = Redis::get($cacheKey);
|
|
|
|
|
|
|
|
// 只有当数据真正变化时才更新数据库和发送事件
|
|
// 只有当数据真正变化时才更新数据库和发送事件
|
|
@@ -3913,6 +3957,7 @@ class AnimeService
|
|
|
DB::table($table_name)->where($id_field, $id_value)->update([
|
|
DB::table($table_name)->where($id_field, $id_value)->update([
|
|
|
'roles' => json_encode($roles, JSON_UNESCAPED_UNICODE),
|
|
'roles' => json_encode($roles, JSON_UNESCAPED_UNICODE),
|
|
|
'scenes' => json_encode($scenes, JSON_UNESCAPED_UNICODE),
|
|
'scenes' => json_encode($scenes, JSON_UNESCAPED_UNICODE),
|
|
|
|
|
+ 'props' => json_encode($props, JSON_UNESCAPED_UNICODE),
|
|
|
'updated_at' => date('Y-m-d H:i:s')
|
|
'updated_at' => date('Y-m-d H:i:s')
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
@@ -3925,6 +3970,7 @@ class AnimeService
|
|
|
'data' => [
|
|
'data' => [
|
|
|
'roles' => $roles,
|
|
'roles' => $roles,
|
|
|
'scenes' => $scenes,
|
|
'scenes' => $scenes,
|
|
|
|
|
+ 'props' => $props,
|
|
|
'elapsed_time' => time() - $startTime
|
|
'elapsed_time' => time() - $startTime
|
|
|
]
|
|
]
|
|
|
], JSON_UNESCAPED_UNICODE) . "\n\n";
|
|
], JSON_UNESCAPED_UNICODE) . "\n\n";
|
|
@@ -3933,7 +3979,7 @@ class AnimeService
|
|
|
}
|
|
}
|
|
|
flush();
|
|
flush();
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
- dLog('anime')->error('更新角色/场景信息失败: ' . $e->getMessage());
|
|
|
|
|
|
|
+ dLog('anime')->error('更新角色/场景/道具信息失败: ' . $e->getMessage());
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
// 即使哈希相同,如果有URL更新也要发送事件
|
|
// 即使哈希相同,如果有URL更新也要发送事件
|
|
@@ -3952,6 +3998,14 @@ class AnimeService
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!$hasUrlUpdate) {
|
|
|
|
|
+ foreach ($props as $prop) {
|
|
|
|
|
+ if (!empty(getProp($prop, 'url')) && getProp($prop, 'task_status') === 'success') {
|
|
|
|
|
+ $hasUrlUpdate = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if ($hasUrlUpdate) {
|
|
if ($hasUrlUpdate) {
|
|
|
// 强制更新数据库和发送事件
|
|
// 强制更新数据库和发送事件
|
|
@@ -3959,6 +4013,7 @@ class AnimeService
|
|
|
DB::table($table_name)->where($id_field, $id_value)->update([
|
|
DB::table($table_name)->where($id_field, $id_value)->update([
|
|
|
'roles' => json_encode($roles, JSON_UNESCAPED_UNICODE),
|
|
'roles' => json_encode($roles, JSON_UNESCAPED_UNICODE),
|
|
|
'scenes' => json_encode($scenes, JSON_UNESCAPED_UNICODE),
|
|
'scenes' => json_encode($scenes, JSON_UNESCAPED_UNICODE),
|
|
|
|
|
+ 'props' => json_encode($props, JSON_UNESCAPED_UNICODE),
|
|
|
'updated_at' => date('Y-m-d H:i:s')
|
|
'updated_at' => date('Y-m-d H:i:s')
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
@@ -3971,6 +4026,7 @@ class AnimeService
|
|
|
'data' => [
|
|
'data' => [
|
|
|
'roles' => $roles,
|
|
'roles' => $roles,
|
|
|
'scenes' => $scenes,
|
|
'scenes' => $scenes,
|
|
|
|
|
+ 'props' => $props,
|
|
|
'elapsed_time' => time() - $startTime
|
|
'elapsed_time' => time() - $startTime
|
|
|
]
|
|
]
|
|
|
], JSON_UNESCAPED_UNICODE) . "\n\n";
|
|
], JSON_UNESCAPED_UNICODE) . "\n\n";
|
|
@@ -3979,7 +4035,7 @@ class AnimeService
|
|
|
}
|
|
}
|
|
|
flush();
|
|
flush();
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
- dLog('anime')->error('强制更新角色/场景信息失败: ' . $e->getMessage());
|
|
|
|
|
|
|
+ dLog('anime')->error('强制更新角色/场景/道具信息失败: ' . $e->getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -3994,10 +4050,12 @@ class AnimeService
|
|
|
$finalSource = (array)$finalSource;
|
|
$finalSource = (array)$finalSource;
|
|
|
$finalRoles = json_decode(getProp($finalSource, 'roles', '[]'), true) ?: [];
|
|
$finalRoles = json_decode(getProp($finalSource, 'roles', '[]'), true) ?: [];
|
|
|
$finalScenes = json_decode(getProp($finalSource, 'scenes', '[]'), true) ?: [];
|
|
$finalScenes = json_decode(getProp($finalSource, 'scenes', '[]'), true) ?: [];
|
|
|
|
|
+ $finalProps = json_decode(getProp($finalSource, 'props', '[]'), true) ?: [];
|
|
|
|
|
|
|
|
// 使用数据库中的最终数据
|
|
// 使用数据库中的最终数据
|
|
|
$roles = $finalRoles;
|
|
$roles = $finalRoles;
|
|
|
$scenes = $finalScenes;
|
|
$scenes = $finalScenes;
|
|
|
|
|
+ $props = $finalProps;
|
|
|
}
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
dLog('anime')->error('查询最终数据失败: ' . $e->getMessage());
|
|
dLog('anime')->error('查询最终数据失败: ' . $e->getMessage());
|
|
@@ -4012,6 +4070,7 @@ class AnimeService
|
|
|
'data' => [
|
|
'data' => [
|
|
|
'roles' => $roles,
|
|
'roles' => $roles,
|
|
|
'scenes' => $scenes,
|
|
'scenes' => $scenes,
|
|
|
|
|
+ 'props' => $props,
|
|
|
'total_time' => time() - $startTime
|
|
'total_time' => time() - $startTime
|
|
|
]
|
|
]
|
|
|
], JSON_UNESCAPED_UNICODE) . "\n\n";
|
|
], JSON_UNESCAPED_UNICODE) . "\n\n";
|
|
@@ -4035,10 +4094,12 @@ class AnimeService
|
|
|
$finalSource = (array)$finalSource;
|
|
$finalSource = (array)$finalSource;
|
|
|
$finalRoles = json_decode(getProp($finalSource, 'roles', '[]'), true) ?: [];
|
|
$finalRoles = json_decode(getProp($finalSource, 'roles', '[]'), true) ?: [];
|
|
|
$finalScenes = json_decode(getProp($finalSource, 'scenes', '[]'), true) ?: [];
|
|
$finalScenes = json_decode(getProp($finalSource, 'scenes', '[]'), true) ?: [];
|
|
|
|
|
+ $finalProps = json_decode(getProp($finalSource, 'props', '[]'), true) ?: [];
|
|
|
|
|
|
|
|
// 使用数据库中的最终数据
|
|
// 使用数据库中的最终数据
|
|
|
$roles = $finalRoles;
|
|
$roles = $finalRoles;
|
|
|
$scenes = $finalScenes;
|
|
$scenes = $finalScenes;
|
|
|
|
|
+ $props = $finalProps;
|
|
|
}
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
dLog('anime')->error('超时时查询最终数据失败: ' . $e->getMessage());
|
|
dLog('anime')->error('超时时查询最终数据失败: ' . $e->getMessage());
|
|
@@ -4053,7 +4114,8 @@ class AnimeService
|
|
|
'message' => '轮询超时,请刷新页面查看最新状态',
|
|
'message' => '轮询超时,请刷新页面查看最新状态',
|
|
|
'data' => [
|
|
'data' => [
|
|
|
'roles' => $roles,
|
|
'roles' => $roles,
|
|
|
- 'scenes' => $scenes
|
|
|
|
|
|
|
+ 'scenes' => $scenes,
|
|
|
|
|
+ 'props' => $props
|
|
|
]
|
|
]
|
|
|
], JSON_UNESCAPED_UNICODE) . "\n\n";
|
|
], JSON_UNESCAPED_UNICODE) . "\n\n";
|
|
|
if (ob_get_level() > 0) {
|
|
if (ob_get_level() > 0) {
|