作者 赵彬吉

Merge remote-tracking branch 'origin/zhl' into dev

@@ -14,4 +14,5 @@ yarn-error.log @@ -14,4 +14,5 @@ yarn-error.log
14 /.idea 14 /.idea
15 /.vscode 15 /.vscode
16 composer.lock 16 composer.lock
  17 +app/Console/Commands/Test/Demo.php
17 /public/upload 18 /public/upload
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: zhl
  5 + * Date: 2023/4/19
  6 + * Time: 15:04
  7 + */
  8 +namespace App\Console\Commands;
  9 +
  10 +use App\Models\Project;
  11 +use App\Services\ProjectServer;
  12 +use Illuminate\Console\Command;
  13 +use Illuminate\Support\Facades\DB;
  14 +
  15 +/**
  16 + * Class ProjectDatabaseUpdate
  17 + * @package App\Console\Commands
  18 + */
  19 +class ProjectDatabaseUpdate extends Command
  20 +{
  21 + /**
  22 + * The name and signature of the console command.
  23 + *
  24 + * @var string
  25 + */
  26 + protected $signature = 'project:database_update';
  27 +
  28 + /**
  29 + * The console command description.
  30 + *
  31 + * @var string
  32 + */
  33 + protected $description = '项目数据库更新';
  34 +
  35 + /**
  36 + * Create a new command instance.
  37 + *
  38 + * @return void
  39 + */
  40 + public function __construct()
  41 + {
  42 + parent::__construct();
  43 + }
  44 +
  45 + /**
  46 + * @return bool
  47 + */
  48 + public function handle()
  49 + {
  50 + #TODO 未处理更新 更新对象(base, project) 更新内容
  51 + return true;
  52 + }
  53 +
  54 + /**
  55 + * 主库内容更新
  56 + * @param $sql
  57 + * @return array
  58 + */
  59 + public function baseUpdate($sql)
  60 + {
  61 + return DB::select($sql);
  62 + }
  63 +
  64 + /**
  65 + * 客户数据表更新
  66 + * @param $sql
  67 + * @return bool
  68 + */
  69 + public function projectDatabaseUpdate($sql)
  70 + {
  71 + $project = Project::get();
  72 + foreach ($project as $val) {
  73 + ProjectServer::useProject($val->id);
  74 + DB::connection('custom_mysql')->select($sql);
  75 + }
  76 + return true;
  77 + }
  78 +
  79 + /**
  80 + * 指定项目数据库更新
  81 + * @param $project_id
  82 + * @param $sql
  83 + */
  84 + public function appointProjectUpdate($project_id, $sql)
  85 + {
  86 + ProjectServer::useProject($project_id);
  87 + DB::connection('custom_mysql')->select($sql);
  88 + }
  89 +}
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 namespace App\Console\Commands; 8 namespace App\Console\Commands;
9 9
10 use App\Models\Project; 10 use App\Models\Project;
  11 +use App\Services\ProjectServer;
11 use Illuminate\Console\Command; 12 use Illuminate\Console\Command;
12 use Illuminate\Support\Facades\DB; 13 use Illuminate\Support\Facades\DB;
13 use Illuminate\Support\Facades\Schema; 14 use Illuminate\Support\Facades\Schema;
@@ -71,11 +72,7 @@ class ProjectInit extends Command @@ -71,11 +72,7 @@ class ProjectInit extends Command
71 // 创建数据库失败 添加通知以及再次处理 72 // 创建数据库失败 添加通知以及再次处理
72 } 73 }
73 // 设置 database.connections.custom_mysql 数据 74 // 设置 database.connections.custom_mysql 数据
74 - config(['database.connections.custom_mysql.host' => $project->mysqlConfig()->host]);  
75 - config(['database.connections.custom_mysql.port' => $project->mysqlConfig()->port]);  
76 - config(['database.connections.custom_mysql.database' => $project->databaseName()]);  
77 - config(['database.connections.custom_mysql.username' => $project->mysqlConfig()->user]);  
78 - config(['database.connections.custom_mysql.password' => $project->mysqlConfig()->password]); 75 + ProjectServer::useProject($project->id);
79 76
80 // TODO 创建对应库 初始化数据表 77 // TODO 创建对应库 初始化数据表
81 $this->initTable(); 78 $this->initTable();
@@ -87,12 +84,6 @@ class ProjectInit extends Command @@ -87,12 +84,6 @@ class ProjectInit extends Command
87 */ 84 */
88 public function initTable() 85 public function initTable()
89 { 86 {
90 -// $table = DB::select('show tables');  
91 -// $table = array_column($table, 'Tables_in_globalso_dev');  
92 -// $table = DB::connection('custom_tmp_mysql')->select('show tables');  
93 -// $table_in = DB::connection('custom_tmp_mysql')->getDatabaseName();  
94 -// dd($table, $table_in);  
95 -  
96 $database_name = DB::connection('custom_tmp_mysql')->getDatabaseName(); 87 $database_name = DB::connection('custom_tmp_mysql')->getDatabaseName();
97 88
98 $table = Schema::connection('custom_tmp_mysql')->getAllTables(); 89 $table = Schema::connection('custom_tmp_mysql')->getAllTables();