作者 lyh

gxshuju

... ... @@ -50,7 +50,6 @@ class CopyProject extends Command
continue;
}
foreach ($list as $item){
DB::beginTransaction();
try {
$old_project_id = $item['data']['project_id'];
$this->output('CopyProjectJob start, project_id: ' . $old_project_id);
... ... @@ -70,9 +69,7 @@ class CopyProject extends Command
$this->output('CopyProjectJob end, old project_id: ' . $old_project_id . ', new project_id: ' . $project_id);
$item->status = NoticeLog::STATUS_SUCCESS;
$item->save();
DB::commit();
}catch (\Exception $e){
DB::rollBack();
echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL . date('Y-m-d H:i:s');
errorLog('项目初始化失败', $item, $e);
$item->status = NoticeLog::STATUS_FAIL;
... ... @@ -242,23 +239,21 @@ class CopyProject extends Command
$sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$table}");
DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
// 3. 跳过指定的表
if (in_array($table, [
'gl_customer_visit',
'gl_customer_visit_item',
'gl_inquiry_other',
'gl_inquiry_form_data',
'gl_inquiry_form'
])) {
if (in_array($table, ['gl_customer_visit', 'gl_customer_visit_item', 'gl_inquiry_other', 'gl_inquiry_form_data', 'gl_inquiry_form'])) {
continue;
}
try {
// 4. 重新插入数据
DB::connection('custom_mysql')->table($table)->insertUsing(
[], // 插入所有列
function ($query) use ($table, $project_id) {
$name = 'gl_data_' . $project_id . '.' . $table;
$query->select('*')->from("{$name}");
}
);
}catch (\Exception $e){
continue;
}
// 4. 重新插入数据
DB::connection('custom_mysql')->table($table)->insertUsing(
[], // 插入所有列
function ($query) use ($table, $project_id) {
$name = 'gl_data_' . $project_id . '.' . $table;
$query->select('*')->from("{$name}");
}
);
// 5. 更新 project_id(如果存在)
if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) {
DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]);
... ...