作者 lyh

变更数据

... ... @@ -244,20 +244,18 @@ class CopyProject extends Command
if (!$exists) {
@file_put_contents(
storage_path('logs/copy_mysql_error.log'),
"源库中不存在表:{$table}" . PHP_EOL,
date('Y-m-d H:i:s')."源库中不存在表:{$table}" . PHP_EOL,
FILE_APPEND
);
continue;
}
// 2. 删除目标数据库中的表
$result = DB::connection('custom_mysql')->statement("DROP TABLE IF EXISTS `{$table}`");
@file_put_contents(storage_path('logs/copy_mysql_error.log'), "删除旧表:{$table} => {$result}" . PHP_EOL, FILE_APPEND);
// 3. 复制建表 SQL
$sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE `{$table}`");
$createSql = get_object_vars($sql[0])['Create Table'];
$result1 = DB::connection('custom_mysql')->statement($createSql);
@file_put_contents(storage_path('logs/copy_mysql_error.log'), "创建表:{$table} => {$result1}" . PHP_EOL, FILE_APPEND);
@file_put_contents(storage_path('logs/copy_mysql_error.log'), date('Y-m-d H:i:s')."创建表:{$table} => {$result1}" . PHP_EOL, FILE_APPEND);
// 4. 跳过指定表
if (in_array($table, [
'gl_customer_visit', 'gl_customer_visit_item',
... ... @@ -268,14 +266,13 @@ class CopyProject extends Command
}
// 5. 插入数据前,再次确认源表存在(双保险)
if (!Schema::connection('custom_tmp_mysql_copy')->hasTable($table)) {
@file_put_contents(storage_path('logs/copy_mysql_error.log'), "插入数据前发现表不存在:{$table}" . PHP_EOL, FILE_APPEND);
continue;
}
// 6. 原生 SQL 插入数据(完全复制)
$insert_sql = "INSERT INTO `{$table}` SELECT * FROM `gl_data_{$project_id}`.`{$table}`";
try {
$result2 = DB::connection('custom_mysql')->statement($insert_sql);
@file_put_contents(storage_path('logs/copy_mysql_error.log'), "插入数据成功:{$table} => {$result2}" . PHP_EOL, FILE_APPEND);
@file_put_contents(storage_path('logs/copy_mysql_error.log'), date('Y-m-d H:i:s')."插入数据成功:{$table} => {$result2}" . PHP_EOL, FILE_APPEND);
} catch (\Exception $e) {
@file_put_contents(storage_path('logs/copy_mysql_error.log'),
"插入数据失败:{$table} => " . $e->getMessage() . PHP_EOL,
... ...
... ... @@ -11,6 +11,7 @@ namespace App\Http\Logic\Aside\Geo;
use App\Console\Commands\Geo\GeoQuestionRes;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Geo\GeoArticle;
use App\Models\Geo\GeoConf;
use App\Models\Geo\GeoLink;
use App\Models\Geo\GeoQuestion;
... ... @@ -122,6 +123,7 @@ class GeoLogic extends BaseLogic
}
$geo_pr_count = GeoLink::where('project_id',$this->param['project_id'])->count();
$geo_writings_count = GeoWritings::where('project_id',$this->param['project_id'])->count();
$geo_writings_count += GeoArticle::where('project_id',$this->param['project_id'])->count();
return $this->success(['geo_writings_count'=>$geo_writings_count,'geo_pr_count'=>$geo_pr_count,'geo_question_count'=>$geo_question_count]);
}
... ...