作者 lyh

gx

@@ -19,6 +19,7 @@ use App\Services\AmazonS3Service; @@ -19,6 +19,7 @@ use App\Services\AmazonS3Service;
19 use App\Services\ProjectServer; 19 use App\Services\ProjectServer;
20 use Illuminate\Console\Command; 20 use Illuminate\Console\Command;
21 use Illuminate\Support\Facades\DB; 21 use Illuminate\Support\Facades\DB;
  22 +use Illuminate\Support\Facades\Schema;
22 23
23 24
24 class Demo extends Command 25 class Demo extends Command
@@ -71,32 +72,66 @@ class Demo extends Command @@ -71,32 +72,66 @@ class Demo extends Command
71 // return true; 72 // return true;
72 // } 73 // }
73 74
  75 +// public function handle(){
  76 +// $keywordVideoModel = new KeywordVideoTask();
  77 +// $project_id_arr = $keywordVideoModel::where('id','>',0)->pluck('project_id')->toArray();
  78 +// $projectModel = new Project();
  79 +// $list = $projectModel->list(['type'=>['!=',0],'delete_status'=>0,'id'=>['in',$project_id_arr]]);
  80 +// $data = [];
  81 +// foreach ($list as $v){
  82 +// echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
  83 +// ProjectServer::useProject($v['id']);
  84 +// $this->saveKeyword();
  85 +// DB::disconnect('custom_mysql');
  86 +// }
  87 +// echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
  88 +// }
  89 +//
  90 +// /**
  91 +// * @remark :关键字有视频的改为1
  92 +// * @name :getProductKeywordInfo
  93 +// * @author :lyh
  94 +// * @method :post
  95 +// * @time :2024/5/31 9:54
  96 +// */
  97 +// public function saveKeyword(){
  98 +// $keywordModel = new Keyword();
  99 +// $rs = $keywordModel->edit(['is_video_keyword'=>1],['video'=>['!=',null]]);
  100 +// echo date('Y-m-d H:i:s') . 'end'.$rs . PHP_EOL;
  101 +// return true;
  102 +// }
  103 +
74 public function handle(){ 104 public function handle(){
75 - $keywordVideoModel = new KeywordVideoTask();  
76 - $project_id_arr = $keywordVideoModel::where('id','>',0)->pluck('project_id')->toArray();  
77 - $projectModel = new Project();  
78 - $list = $projectModel->list(['type'=>['!=',0],'delete_status'=>0,'id'=>['in',$project_id_arr]]);  
79 - $data = [];  
80 - foreach ($list as $v){  
81 - echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;  
82 - ProjectServer::useProject($v['id']);  
83 - $this->saveKeyword();  
84 - DB::disconnect('custom_mysql');  
85 - }  
86 - echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; 105 + return $this->initTable(1380,1862);
87 } 106 }
88 107
89 - /**  
90 - * @remark :关键字有视频的改为1  
91 - * @name :getProductKeywordInfo  
92 - * @author :lyh  
93 - * @method :post  
94 - * @time :2024/5/31 9:54  
95 - */  
96 - public function saveKeyword(){  
97 - $keywordModel = new Keyword();  
98 - $rs = $keywordModel->edit(['is_video_keyword'=>1],['video'=>['!=',null]]);  
99 - echo date('Y-m-d H:i:s') . 'end'.$rs . PHP_EOL; 108 + public function initTable($project_id,$news_project_id)
  109 + {
  110 + config(['database.connections.custom_tmp_mysql_copy.database' => 'gl_data_'.$project_id]);
  111 + $database_name = DB::connection('custom_tmp_mysql_copy')->getDatabaseName();
  112 + $tables = Schema::connection('custom_tmp_mysql_copy')->getAllTables();
  113 + $tables = array_column($tables, 'Tables_in_' . $database_name);
  114 + foreach ($tables as $table) {
  115 + $has_table = Schema::connection('custom_mysql')->hasTable($table);
  116 + if (!$has_table) {
  117 + $sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$table}");
  118 + DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
  119 + }
  120 + if($table == 'gl_customer_visit' || $table == 'gl_customer_visit_item' || $table == 'gl_inquiry_other' || $table == 'gl_inquiry_form_data' || $table == 'gl_inquiry_form'){
  121 + continue;
  122 + }
  123 +// DB::connection('custom_mysql')->table($table)->truncate(); // 清空目标表数据
  124 + DB::connection('custom_mysql')->table($table)->insertUsing(
  125 + [], // 列名数组,留空表示插入所有列
  126 + function ($query) use ($table,$project_id) {
  127 + $name = 'gl_data_'.$project_id.'.'.$table;
  128 + $query->select('*')->from("{$name}");
  129 + }
  130 + );
  131 + if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) {
  132 + DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]);
  133 + }
  134 + }
100 return true; 135 return true;
101 } 136 }
102 } 137 }