作者 刘锟

update

@@ -7,8 +7,10 @@ use App\Models\Com\Notify; @@ -7,8 +7,10 @@ use App\Models\Com\Notify;
7 use App\Models\Devops\ServerConfig; 7 use App\Models\Devops\ServerConfig;
8 use App\Models\Devops\ServersIp; 8 use App\Models\Devops\ServersIp;
9 use App\Models\Domain\DomainInfo; 9 use App\Models\Domain\DomainInfo;
  10 +use App\Models\Product\Keyword;
10 use App\Models\Project\Project; 11 use App\Models\Project\Project;
11 use App\Services\BatchExportService; 12 use App\Services\BatchExportService;
  13 +use App\Services\ProjectServer;
12 use Illuminate\Console\Command; 14 use Illuminate\Console\Command;
13 use Symfony\Component\Process\Process; 15 use Symfony\Component\Process\Process;
14 16
@@ -29,11 +31,80 @@ class Temp extends Command @@ -29,11 +31,80 @@ class Temp extends Command
29 protected $description = '临时脚本'; 31 protected $description = '临时脚本';
30 32
31 /** 33 /**
  34 + * 关键词首字母
  35 + * @author Akun
  36 + * @date 2024/10/30 15:37
  37 + */
  38 + public function handle()
  39 + {
  40 + $projects = Project::select(['id'])->get();
  41 + foreach ($projects as $project) {
  42 + ProjectServer::useProject($project->id);
  43 +
  44 + //处理关键词首字母
  45 + Keyword::select(['id', 'title', 'first_word'])->chunk(1000, function ($query) {
  46 + foreach ($query as $item) {
  47 + if ($item->first_word === null) {
  48 + $item->first_word = $this->getTitleFirstLetter($item->title);
  49 + $item->save();
  50 + }
  51 + }
  52 + });
  53 +
  54 + $this->output('ID:' . $project->id . ',success');
  55 + }
  56 + }
  57 +
  58 + protected function getTitleFirstLetter($title)
  59 + {
  60 + $first = mb_strtolower(mb_substr($title, 0, 1, 'utf-8'), 'utf-8');
  61 + if (in_array($first, ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"])) {
  62 + $firstLetter = 0;
  63 + } else {
  64 + 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'])) {
  65 + $rule = [
  66 + "a" => 1,
  67 + "b" => 2,
  68 + "c" => 3,
  69 + "d" => 4,
  70 + "e" => 5,
  71 + "f" => 6,
  72 + "g" => 7,
  73 + "h" => 8,
  74 + "i" => 9,
  75 + "j" => 10,
  76 + "k" => 11,
  77 + "l" => 12,
  78 + "m" => 13,
  79 + "n" => 14,
  80 + "o" => 15,
  81 + "p" => 16,
  82 + "q" => 17,
  83 + "r" => 18,
  84 + "s" => 19,
  85 + "t" => 20,
  86 + "u" => 21,
  87 + "v" => 22,
  88 + "w" => 23,
  89 + "x" => 24,
  90 + "y" => 25,
  91 + "z" => 26,
  92 + ];
  93 + $firstLetter = $rule[$first];
  94 + } else {
  95 + $firstLetter = 27;
  96 + }
  97 + }
  98 + return $firstLetter;
  99 + }
  100 +
  101 +
  102 + /**
32 * 获取指定服务器所有项目 103 * 获取指定服务器所有项目
33 * @author Akun 104 * @author Akun
34 * @date 2024/09/30 17:01 105 * @date 2024/09/30 17:01
35 */ 106 */
36 - public function handle() 107 + public function handle3()
37 { 108 {
38 $server_id = 1; 109 $server_id = 1;
39 110
@@ -79,7 +150,7 @@ class Temp extends Command @@ -79,7 +150,7 @@ class Temp extends Command
79 * @author Akun 150 * @author Akun
80 * @date 2024/09/26 10:48 151 * @date 2024/09/26 10:48
81 */ 152 */
82 - public function handle1() 153 + public function handle2()
83 { 154 {
84 $server_id = 15; 155 $server_id = 15;
85 156
@@ -131,7 +202,7 @@ class Temp extends Command @@ -131,7 +202,7 @@ class Temp extends Command
131 * @author Akun 202 * @author Akun
132 * @date 2024/09/26 10:48 203 * @date 2024/09/26 10:48
133 */ 204 */
134 - public function handle2() 205 + public function handle1()
135 { 206 {
136 $notify_model = new Notify(); 207 $notify_model = new Notify();
137 $project_model = new Project(); 208 $project_model = new Project();