作者 刘锟

update

... ... @@ -7,8 +7,10 @@ use App\Models\Com\Notify;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainInfo;
use App\Models\Product\Keyword;
use App\Models\Project\Project;
use App\Services\BatchExportService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
... ... @@ -29,11 +31,80 @@ class Temp extends Command
protected $description = '临时脚本';
/**
* 关键词首字母
* @author Akun
* @date 2024/10/30 15:37
*/
public function handle()
{
$projects = Project::select(['id'])->get();
foreach ($projects as $project) {
ProjectServer::useProject($project->id);
//处理关键词首字母
Keyword::select(['id', 'title', 'first_word'])->chunk(1000, function ($query) {
foreach ($query as $item) {
if ($item->first_word === null) {
$item->first_word = $this->getTitleFirstLetter($item->title);
$item->save();
}
}
});
$this->output('ID:' . $project->id . ',success');
}
}
protected function getTitleFirstLetter($title)
{
$first = mb_strtolower(mb_substr($title, 0, 1, 'utf-8'), 'utf-8');
if (in_array($first, ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"])) {
$firstLetter = 0;
} else {
if (in_array($first, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'])) {
$rule = [
"a" => 1,
"b" => 2,
"c" => 3,
"d" => 4,
"e" => 5,
"f" => 6,
"g" => 7,
"h" => 8,
"i" => 9,
"j" => 10,
"k" => 11,
"l" => 12,
"m" => 13,
"n" => 14,
"o" => 15,
"p" => 16,
"q" => 17,
"r" => 18,
"s" => 19,
"t" => 20,
"u" => 21,
"v" => 22,
"w" => 23,
"x" => 24,
"y" => 25,
"z" => 26,
];
$firstLetter = $rule[$first];
} else {
$firstLetter = 27;
}
}
return $firstLetter;
}
/**
* 获取指定服务器所有项目
* @author Akun
* @date 2024/09/30 17:01
*/
public function handle()
public function handle3()
{
$server_id = 1;
... ... @@ -79,7 +150,7 @@ class Temp extends Command
* @author Akun
* @date 2024/09/26 10:48
*/
public function handle1()
public function handle2()
{
$server_id = 15;
... ... @@ -131,7 +202,7 @@ class Temp extends Command
* @author Akun
* @date 2024/09/26 10:48
*/
public function handle2()
public function handle1()
{
$notify_model = new Notify();
$project_model = new Project();
... ...