TdkTest.php
2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
namespace App\Console\Commands\Test;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/**
* 初始化项目
* Class InitProject
* @package App\Console\Commands
* @author zbj
* @date 2023/10/8
*/
class TdkTest extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tdk_test';
/**
* The console command description.
*
* @var string
*/
protected $description = 'keywords ,分割加空格';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* '表' => [
* '指令key' => '表字段'
* ]
* @return array
* @author zbj
* @date 2023/11/3
*/
protected $maps = [
'gl_web_custom_template' => 'keywords',
'gl_product' => 'seo_mate.keyword',
'gl_product_category' => 'seo_keywords',
'gl_blog' => 'seo_keywords',
'gl_blog_category' => 'seo_keywords',
'gl_news' => 'seo_keywords',
'gl_news_category' => 'seo_keywords',
'gl_product_keyword' => 'seo_keywords',
];
/**
* @return bool
*/
public function handle()
{
$project_ids = Project::where('type', Project::TYPE_TWO)->pluck('id')->toArray();
foreach ($project_ids as $project_id){
echo date('Y-m-d H:i:s') . ' start project_id: ' . $project_id . PHP_EOL;
ProjectServer::useProject($project_id);
foreach ($this->maps as $table=>$field){
$list = DB::connection('custom_mysql')->table($table)->get();
foreach ($list as $item){
$item = (array) $item;
$field_arr = explode('.', $field);
if ($field == 'seo_mate.keyword') {
$data = json_decode($item[$field_arr[0]], true);
$value = $data['keyword'] ?? '';
if(!$value){
continue;
}
$data['keyword'] = implode(', ', array_map('trim', explode(',', $value)));
DB::connection('custom_mysql')->table($table)->where('id', $item['id'])->update(['seo_mate' => json_encode($data)]);
} else {
$value = $item[$field];
if(!$value){
continue;
}
$value = implode(', ', array_map('trim', explode(',', $value)));
DB::connection('custom_mysql')->table($table)->where('id', $item['id'])->update([$field => $value]);
}
}
}
}
}
public function ceshi(){
//under_ceshi
$model = new Cesjo();
}
}