作者 zhl

优化设置关键词设置预设功能

<?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;
}
}
\ No newline at end of file
... ...
... ... @@ -37,6 +37,8 @@ class Kernel extends ConsoleKernel
$schedule->command('sync_inquiry_text')->dailyAt('09:00')->withoutOverlapping(1);
//FB询盘费用同步
$schedule->command('sync_ad_cost')->everyThirtyMinutes()->withoutOverlapping(1);
// 优化预设关键词 同步 20点会开始TDK生成
$schedule->command('optimize_set_keyword_sync')->dailyAt('20:00')->withoutOverlapping(1);
}
/**
... ...
... ... @@ -25,28 +25,17 @@ class AggregateKeywordLogic extends BaseLogic
}
/**
* @remark :保存关键词
* @name :saveKeyword
* @author :lyh
* @method :post
* @time :2025/3/17 16:11
* @return array
*/
public function saveKeyword(){
if(isset($this->param['id']) && !empty($this->param['id'])){
$id = $this->param['id'];
if (FALSE == empty($this->param['id'])) {
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$id = $this->model->addReturnId($this->param);
//保存到客户关键词
$keywords = explode("\n", $this->param['keywords']);
if(!empty($keywords)){
ProjectServer::useProject($this->param['project_id']);
$keywordModel = new Keyword();
$keywordModel->saveBKeyword($this->param['project_id'],$keywords);
DB::disconnect('custom_mysql');
}
} else {
$this->param['id'] = $this->model->addReturnId($this->param);
// 添加预设功能 同步关键词 迁入到 namespace App\Console\Commands\Product\SetKeywordSync
}
return $this->success(['id'=>$id]);
return $this->success(['id'=>$this->param['id']]);
}
}
... ...
... ... @@ -12,13 +12,17 @@ namespace App\Models\Project;
use App\Models\Base;
/**
* @remark :聚合页关键词设置
* @name :AggregateKeyword
* @author :lyh
* @method :post
* @time :2025/3/17 16:02
* 聚合页关键词设置
* Class AggregateKeyword
* @package App\Models\Project
*/
class AggregateKeyword extends Base
{
protected $table = 'gl_aggregate_keyword';
/**
* 关键词是否导入项目聚合页关键词
*/
const STATUS_INIT = 0;
const STATUS_FINISH = 1;
}
... ...