OptimizeSetKeywordSync.php
2.0 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
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2025/3/26
* Time: 14:29
*/
namespace App\Console\Commands\Product;
use App\Models\Product\Keyword;
use App\Models\Project\AggregateKeyword;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
/**
* Class OptimizeSetKeywordSync
* @package App\Console\Commands\Product
*/
class OptimizeSetKeywordSync extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'optimize_set_keyword_sync';
/**
* The console command description.
*
* @var string
*/
protected $description = '优化设置聚合页关键词,同步至对应项目产品关键词';
/**
* OptimizeSetKeywordSync constructor.
*/
public function __construct()
{
parent::__construct();
}
/**
* 数据源:App\Http\Logic\Aside\Project\AggregateKeywordLogic::saveKeyword;
* @return bool
*/
public function handle()
{
$task = AggregateKeyword::where(['status' => AggregateKeyword::STATUS_INIT])->where('created_at', '<', date('Y-m-d H:i:s'))->get();
foreach ($task as $item) {
Log::info('同步ID:' . $item->id);
echo $item->project_id . PHP_EOL;
$this->syncKeyword($item->project_id, $item->keywords);
$item->status = AggregateKeyword::STATUS_FINISH;
$item->save();
}
return true;
}
/**
* 关键词同步
* @param $project_id
* @param $keywords
* @return bool
*/
public function syncKeyword($project_id, $keywords)
{
$keywords = explode("\n", $keywords);
$keywords = array_unique(array_filter($keywords));
ProjectServer::useProject($project_id);
$keywordModel = new Keyword();
$keywordModel->saveBKeyword($project_id,$keywords);
DB::disconnect('custom_mysql');
return true;
}
}