Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6
正在显示
6 个修改的文件
包含
199 行增加
和
23 行删除
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :CopyOldProject.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2025/2/18 14:10 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\Project; | ||
| 11 | + | ||
| 12 | +use App\Services\ProjectServer; | ||
| 13 | +use Illuminate\Console\Command; | ||
| 14 | +use Illuminate\Support\Facades\DB; | ||
| 15 | +use Illuminate\Support\Facades\Log; | ||
| 16 | +use Illuminate\Support\Facades\Schema; | ||
| 17 | + | ||
| 18 | +class CopyOldProject extends Command | ||
| 19 | +{ | ||
| 20 | + /** | ||
| 21 | + * The name and signature of the console command. | ||
| 22 | + * | ||
| 23 | + * @var string | ||
| 24 | + */ | ||
| 25 | + protected $signature = 'copy_project_s {old_project_id} {project_id}'; | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * The console command description. | ||
| 29 | + * | ||
| 30 | + * @var string | ||
| 31 | + */ | ||
| 32 | + protected $description = 'copy--复制项目'; | ||
| 33 | + | ||
| 34 | + public function handle() | ||
| 35 | + { | ||
| 36 | + $old_project_id = $this->argument('old_project_id'); | ||
| 37 | + $this->output('CopyProjectJob start, old_project_id: ' . $old_project_id); | ||
| 38 | + $project_id = $this->argument('project_id'); | ||
| 39 | + $this->output('CopyProjectJob start, project_id: ' . $project_id); | ||
| 40 | + $this->copyMysql($old_project_id,$project_id); | ||
| 41 | + return true; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + | ||
| 45 | + | ||
| 46 | + //复制数据库 | ||
| 47 | + public function copyMysql($project_id,$new_project_id){ | ||
| 48 | + //切换数据库配置 | ||
| 49 | + $project = ProjectServer::useProject($new_project_id); | ||
| 50 | + //创建数据库 | ||
| 51 | + ProjectServer::createDatabase($project); | ||
| 52 | + //创建表 | ||
| 53 | + $this->initTable($project_id,$new_project_id); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * @remark :创建数据库 | ||
| 58 | + * @name :initTable | ||
| 59 | + * @author :lyh | ||
| 60 | + * @method :post | ||
| 61 | + * @time :2023/12/11 10:09 | ||
| 62 | + */ | ||
| 63 | + public function initTable($project_id, $news_project_id) | ||
| 64 | + { | ||
| 65 | + // 设置源数据库 | ||
| 66 | + config(['database.connections.custom_tmp_mysql_copy.database' => 'gl_data_' . $project_id]); | ||
| 67 | + $database_name = DB::connection('custom_tmp_mysql_copy')->getDatabaseName(); | ||
| 68 | + // 获取源数据库的所有表 | ||
| 69 | + $tables = Schema::connection('custom_tmp_mysql_copy')->getAllTables(); | ||
| 70 | + $tables = array_column($tables, 'Tables_in_' . $database_name); | ||
| 71 | + foreach ($tables as $table) { | ||
| 72 | + // 目标数据库是否存在该表 | ||
| 73 | + $has_table = Schema::connection('custom_mysql')->hasTable($table); | ||
| 74 | + if ($has_table) { | ||
| 75 | + // 1. 删除目标数据库中的表 | ||
| 76 | + DB::connection('custom_mysql')->statement("DROP TABLE IF EXISTS {$table}"); | ||
| 77 | + } | ||
| 78 | + // 2. 重新创建表 | ||
| 79 | + $sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$table}"); | ||
| 80 | + DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']); | ||
| 81 | + // 3. 跳过指定的表 | ||
| 82 | + if (in_array($table, [ | ||
| 83 | + 'gl_customer_visit', | ||
| 84 | + 'gl_customer_visit_item', | ||
| 85 | + 'gl_inquiry_other', | ||
| 86 | + 'gl_inquiry_form_data', | ||
| 87 | + 'gl_inquiry_form' | ||
| 88 | + ])) { | ||
| 89 | + continue; | ||
| 90 | + } | ||
| 91 | + // 4. 重新插入数据 | ||
| 92 | + DB::connection('custom_mysql')->table($table)->insertUsing( | ||
| 93 | + [], // 插入所有列 | ||
| 94 | + function ($query) use ($table, $project_id) { | ||
| 95 | + $name = 'gl_data_' . $project_id . '.' . $table; | ||
| 96 | + $query->select('*')->from("{$name}"); | ||
| 97 | + } | ||
| 98 | + ); | ||
| 99 | + // 5. 更新 project_id(如果存在) | ||
| 100 | + if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) { | ||
| 101 | + DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]); | ||
| 102 | + } | ||
| 103 | + } | ||
| 104 | + return true; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * @param $message | ||
| 109 | + * @return bool | ||
| 110 | + */ | ||
| 111 | + public function output($message) | ||
| 112 | + { | ||
| 113 | + $date = date('Y-m-d H:i:s'); | ||
| 114 | + $output = $date . ', ' . $message . PHP_EOL; | ||
| 115 | + echo $output; | ||
| 116 | + Log::info($output); | ||
| 117 | + return true; | ||
| 118 | + } | ||
| 119 | +} |
| @@ -224,29 +224,43 @@ class CopyProject extends Command | @@ -224,29 +224,43 @@ class CopyProject extends Command | ||
| 224 | * @method :post | 224 | * @method :post |
| 225 | * @time :2023/12/11 10:09 | 225 | * @time :2023/12/11 10:09 |
| 226 | */ | 226 | */ |
| 227 | - public function initTable($project_id,$news_project_id) | 227 | + public function initTable($project_id, $news_project_id) |
| 228 | { | 228 | { |
| 229 | - config(['database.connections.custom_tmp_mysql_copy.database' => 'gl_data_'.$project_id]); | 229 | + // 设置源数据库 |
| 230 | + config(['database.connections.custom_tmp_mysql_copy.database' => 'gl_data_' . $project_id]); | ||
| 230 | $database_name = DB::connection('custom_tmp_mysql_copy')->getDatabaseName(); | 231 | $database_name = DB::connection('custom_tmp_mysql_copy')->getDatabaseName(); |
| 232 | + // 获取源数据库的所有表 | ||
| 231 | $tables = Schema::connection('custom_tmp_mysql_copy')->getAllTables(); | 233 | $tables = Schema::connection('custom_tmp_mysql_copy')->getAllTables(); |
| 232 | $tables = array_column($tables, 'Tables_in_' . $database_name); | 234 | $tables = array_column($tables, 'Tables_in_' . $database_name); |
| 233 | foreach ($tables as $table) { | 235 | foreach ($tables as $table) { |
| 236 | + // 目标数据库是否存在该表 | ||
| 234 | $has_table = Schema::connection('custom_mysql')->hasTable($table); | 237 | $has_table = Schema::connection('custom_mysql')->hasTable($table); |
| 235 | - if (!$has_table) { | ||
| 236 | - $sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$table}"); | ||
| 237 | - DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']); | 238 | + if ($has_table) { |
| 239 | + // 1. 删除目标数据库中的表 | ||
| 240 | + DB::connection('custom_mysql')->statement("DROP TABLE IF EXISTS {$table}"); | ||
| 238 | } | 241 | } |
| 239 | - if($table == 'gl_customer_visit' || $table == 'gl_customer_visit_item' || $table == 'gl_inquiry_other' || $table == 'gl_inquiry_form_data' || $table == 'gl_inquiry_form'){ | 242 | + // 2. 重新创建表 |
| 243 | + $sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$table}"); | ||
| 244 | + DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']); | ||
| 245 | + // 3. 跳过指定的表 | ||
| 246 | + if (in_array($table, [ | ||
| 247 | + 'gl_customer_visit', | ||
| 248 | + 'gl_customer_visit_item', | ||
| 249 | + 'gl_inquiry_other', | ||
| 250 | + 'gl_inquiry_form_data', | ||
| 251 | + 'gl_inquiry_form' | ||
| 252 | + ])) { | ||
| 240 | continue; | 253 | continue; |
| 241 | } | 254 | } |
| 242 | - DB::connection('custom_mysql')->table($table)->truncate(); // 清空目标表数据 | 255 | + // 4. 重新插入数据 |
| 243 | DB::connection('custom_mysql')->table($table)->insertUsing( | 256 | DB::connection('custom_mysql')->table($table)->insertUsing( |
| 244 | - [], // 列名数组,留空表示插入所有列 | ||
| 245 | - function ($query) use ($table,$project_id) { | ||
| 246 | - $name = 'gl_data_'.$project_id.'.'.$table; | 257 | + [], // 插入所有列 |
| 258 | + function ($query) use ($table, $project_id) { | ||
| 259 | + $name = 'gl_data_' . $project_id . '.' . $table; | ||
| 247 | $query->select('*')->from("{$name}"); | 260 | $query->select('*')->from("{$name}"); |
| 248 | } | 261 | } |
| 249 | ); | 262 | ); |
| 263 | + // 5. 更新 project_id(如果存在) | ||
| 250 | if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) { | 264 | if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) { |
| 251 | DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]); | 265 | DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]); |
| 252 | } | 266 | } |
| @@ -42,6 +42,7 @@ use App\Models\Template\BCustomTemplate; | @@ -42,6 +42,7 @@ use App\Models\Template\BCustomTemplate; | ||
| 42 | use App\Models\Template\BTemplateCom; | 42 | use App\Models\Template\BTemplateCom; |
| 43 | use App\Models\Template\Setting; | 43 | use App\Models\Template\Setting; |
| 44 | use App\Models\Template\Template; | 44 | use App\Models\Template\Template; |
| 45 | +use Hashids\Hashids; | ||
| 45 | use Illuminate\Console\Command; | 46 | use Illuminate\Console\Command; |
| 46 | use Illuminate\Support\Facades\Config; | 47 | use Illuminate\Support\Facades\Config; |
| 47 | use Illuminate\Support\Facades\DB; | 48 | use Illuminate\Support\Facades\DB; |
| @@ -66,12 +67,33 @@ class Demo extends Command | @@ -66,12 +67,33 @@ class Demo extends Command | ||
| 66 | protected $description = 'demo'; | 67 | protected $description = 'demo'; |
| 67 | 68 | ||
| 68 | public function handle(){ | 69 | public function handle(){ |
| 69 | -// echo date('Y-m-d H:i:s') . 'project_id:' . PHP_EOL; | ||
| 70 | -// ProjectServer::useProject(3092); | ||
| 71 | -// $this->delProduct(); | ||
| 72 | -// DB::disconnect('custom_mysql'); | ||
| 73 | -// echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; | ||
| 74 | - return $this->projectList(); | 70 | + $this->copyMysql($old_project_id,$project_id); |
| 71 | + } | ||
| 72 | + public function copyProject($old_project_id){ | ||
| 73 | + $projectModel = new Project(); | ||
| 74 | + $data = $projectModel::where('id', $old_project_id)->first(); | ||
| 75 | + $data = $data->getAttributes(); | ||
| 76 | + $type = $data['type']; | ||
| 77 | + $data['type'] = 0; | ||
| 78 | + $data['status'] = 0; | ||
| 79 | + $data['finish_remain_day'] = 0; | ||
| 80 | + $data['title'] = $data['title'].'-copy'; | ||
| 81 | + $data['delete_status'] = 1; | ||
| 82 | + unset($data['id'],$data['robots'],$data['is_translate_tag'],$data['is_translate'],$data['is_minor_languages'],$data['uptime']); | ||
| 83 | + $project_id = $projectModel->insertGetId($data); | ||
| 84 | + $hashids = new Hashids($data['from_order_id'], 13, 'abcdefghjkmnpqrstuvwxyz1234567890'); | ||
| 85 | + $projectModel->edit(['from_order_id'=>$hashids->encode($project_id)],['id'=>$project_id]); | ||
| 86 | + //复制设置的模版 | ||
| 87 | + $settingTemplateModel = new Setting(); | ||
| 88 | + $settingData = $settingTemplateModel::where('project_id', $old_project_id)->first(); | ||
| 89 | + if(!empty($settingData)){ | ||
| 90 | + $data = [ | ||
| 91 | + 'template_id' =>$settingData['template_id'], | ||
| 92 | + 'project_id' => $project_id | ||
| 93 | + ]; | ||
| 94 | + $settingTemplateModel->add($data); | ||
| 95 | + } | ||
| 96 | + return ['project_id'=>$project_id,'type'=>$type]; | ||
| 75 | } | 97 | } |
| 76 | 98 | ||
| 77 | public function toQueue(){ | 99 | public function toQueue(){ |
| @@ -121,6 +121,10 @@ class ComController extends BaseController | @@ -121,6 +121,10 @@ class ComController extends BaseController | ||
| 121 | if($is_comment != 1){ | 121 | if($is_comment != 1){ |
| 122 | $info['role_menu'] = trim(str_replace(',55,',',',','.$info['role_menu'].','),','); | 122 | $info['role_menu'] = trim(str_replace(',55,',',',','.$info['role_menu'].','),','); |
| 123 | } | 123 | } |
| 124 | + $is_blogs = $this->getIsBlog(); | ||
| 125 | + if($is_blogs != 1){ | ||
| 126 | + $info['role_menu'] = trim(str_replace(',57,',',',','.$info['role_menu'].','),','); | ||
| 127 | + } | ||
| 124 | $this->map = [ | 128 | $this->map = [ |
| 125 | 'status'=>0, | 129 | 'status'=>0, |
| 126 | 'is_role'=>0, | 130 | 'is_role'=>0, |
| @@ -165,6 +169,10 @@ class ComController extends BaseController | @@ -165,6 +169,10 @@ class ComController extends BaseController | ||
| 165 | if($is_comment != 1){ | 169 | if($is_comment != 1){ |
| 166 | $data[] = 55; | 170 | $data[] = 55; |
| 167 | } | 171 | } |
| 172 | + $is_ai_blog = $this->getIsAiBlog(); | ||
| 173 | + if($is_ai_blog != 1){ | ||
| 174 | + $data[] = 57; | ||
| 175 | + } | ||
| 168 | if(!empty($data)){ | 176 | if(!empty($data)){ |
| 169 | $this->map['id'] = ['not in',$data]; | 177 | $this->map['id'] = ['not in',$data]; |
| 170 | } | 178 | } |
| @@ -236,7 +244,7 @@ class ComController extends BaseController | @@ -236,7 +244,7 @@ class ComController extends BaseController | ||
| 236 | 244 | ||
| 237 | 245 | ||
| 238 | public function getIsSubscribe(){ | 246 | public function getIsSubscribe(){ |
| 239 | - return $this->project['is_subscribe']; | 247 | + return $this->project['is_subscribe'] ?? 0; |
| 240 | } | 248 | } |
| 241 | 249 | ||
| 242 | /** | 250 | /** |
| @@ -251,26 +259,33 @@ class ComController extends BaseController | @@ -251,26 +259,33 @@ class ComController extends BaseController | ||
| 251 | } | 259 | } |
| 252 | 260 | ||
| 253 | /** | 261 | /** |
| 262 | + * @remark :是否开启了ai——blog | ||
| 263 | + * @name :getIsAiBlog | ||
| 264 | + * @author :lyh | ||
| 265 | + * @method :post | ||
| 266 | + * @time :2025/2/19 9:39 | ||
| 267 | + */ | ||
| 268 | + public function getIsAiBlog(){ | ||
| 269 | + return $this->user['is_ai_blog'] ?? 0; | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + | ||
| 273 | + /** | ||
| 254 | * @name :登录用户编辑资料/修改密码 | 274 | * @name :登录用户编辑资料/修改密码 |
| 255 | * @author :liyuhang | 275 | * @author :liyuhang |
| 256 | * @method | 276 | * @method |
| 257 | */ | 277 | */ |
| 258 | public function edit_info(){ | 278 | public function edit_info(){ |
| 259 | $this->request->validate([ | 279 | $this->request->validate([ |
| 260 | -// 'oldPassword'=>'required', | ||
| 261 | 'password' => 'required', | 280 | 'password' => 'required', |
| 262 | 'confirm'=>'required', | 281 | 'confirm'=>'required', |
| 263 | ], [ | 282 | ], [ |
| 264 | -// 'oldPassword.required' => '请输入原密码', | ||
| 265 | 'password.required' => '请输入新密码', | 283 | 'password.required' => '请输入新密码', |
| 266 | 'confirm.required' => '请再次输入新密码', | 284 | 'confirm.required' => '请再次输入新密码', |
| 267 | ]); | 285 | ]); |
| 268 | //查询员密码是否正确 | 286 | //查询员密码是否正确 |
| 269 | $userModel = new User(); | 287 | $userModel = new User(); |
| 270 | $info = $userModel->read(['id'=>$this->user['id']]); | 288 | $info = $userModel->read(['id'=>$this->user['id']]); |
| 271 | -// if($info['password'] != base64_encode(md5($this->param['oldPassword']))){ | ||
| 272 | -// $this->response('原密码错误',Code::USER_ERROR); | ||
| 273 | -// } | ||
| 274 | if($this->param['password'] != $this->param['confirm']){ | 289 | if($this->param['password'] != $this->param['confirm']){ |
| 275 | $this->response('两次密码不一致'); | 290 | $this->response('两次密码不一致'); |
| 276 | } | 291 | } |
| @@ -408,7 +423,6 @@ class ComController extends BaseController | @@ -408,7 +423,6 @@ class ComController extends BaseController | ||
| 408 | */ | 423 | */ |
| 409 | public function month_counts(){ | 424 | public function month_counts(){ |
| 410 | shell_exec('php artisan month_project '.$this->user['project_id']); | 425 | shell_exec('php artisan month_project '.$this->user['project_id']); |
| 411 | -// Artisan::call('month_project '.$this->user['project_id']); | ||
| 412 | $this->response('重新刷新中,请稍后刷新查询'); | 426 | $this->response('重新刷新中,请稍后刷新查询'); |
| 413 | } | 427 | } |
| 414 | } | 428 | } |
| @@ -818,6 +818,12 @@ class ProjectLogic extends BaseLogic | @@ -818,6 +818,12 @@ class ProjectLogic extends BaseLogic | ||
| 818 | * @time :2023/11/8 14:23 | 818 | * @time :2023/11/8 14:23 |
| 819 | */ | 819 | */ |
| 820 | public function copyProject(){ | 820 | public function copyProject(){ |
| 821 | + //查看当前是否有执行任务 | ||
| 822 | + $noticeModel = new NoticeLog(); | ||
| 823 | + $info = $noticeModel->read(['type'=>NoticeLog::TYPE_COPY_PROJECT,'status'=>0,'data'=>['like','%"'.$this->param['project_id'].'"%']]); | ||
| 824 | + if($info !== false){ | ||
| 825 | + return $this->success('当前项目已在复制中'); | ||
| 826 | + } | ||
| 821 | NoticeLog::createLog(NoticeLog::TYPE_COPY_PROJECT, ['project_id' => $this->param['project_id']]); | 827 | NoticeLog::createLog(NoticeLog::TYPE_COPY_PROJECT, ['project_id' => $this->param['project_id']]); |
| 822 | return $this->success('项目复制中,请稍后前往初始化项目查看;'); | 828 | return $this->success('项目复制中,请稍后前往初始化项目查看;'); |
| 823 | } | 829 | } |
| @@ -262,6 +262,7 @@ class UserLoginLogic | @@ -262,6 +262,7 @@ class UserLoginLogic | ||
| 262 | $info['is_show_blog'] = $project['is_show_blog']; | 262 | $info['is_show_blog'] = $project['is_show_blog']; |
| 263 | $info['upload_config'] = $project['upload_config']; | 263 | $info['upload_config'] = $project['upload_config']; |
| 264 | $info['main_lang_id'] = $project['main_lang_id']; | 264 | $info['main_lang_id'] = $project['main_lang_id']; |
| 265 | + $info['is_ai_blog'] = $project['is_ai_blog']; | ||
| 265 | $info['image_max'] = $project['image_max']; | 266 | $info['image_max'] = $project['image_max']; |
| 266 | $info['is_del_inquiry'] = $project['is_del_inquiry'] ?? 0; | 267 | $info['is_del_inquiry'] = $project['is_del_inquiry'] ?? 0; |
| 267 | $info['uptime_type'] = $this->getHistory($project); | 268 | $info['uptime_type'] = $this->getHistory($project); |
-
请 注册 或 登录 后发表评论