正在显示
4 个修改的文件
包含
97 行增加
和
23 行删除
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * Created by PhpStorm. | ||
| 4 | + * User: zhl | ||
| 5 | + * Date: 2025/3/26 | ||
| 6 | + * Time: 14:29 | ||
| 7 | + */ | ||
| 8 | +namespace App\Console\Commands\Product; | ||
| 9 | + | ||
| 10 | +use App\Models\Product\Keyword; | ||
| 11 | +use App\Models\Project\AggregateKeyword; | ||
| 12 | +use App\Services\ProjectServer; | ||
| 13 | +use Illuminate\Console\Command; | ||
| 14 | +use Illuminate\Support\Facades\DB; | ||
| 15 | +use Illuminate\Support\Facades\Log; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * Class OptimizeSetKeywordSync | ||
| 19 | + * @package App\Console\Commands\Product | ||
| 20 | + */ | ||
| 21 | +class OptimizeSetKeywordSync extends Command | ||
| 22 | +{ | ||
| 23 | + /** | ||
| 24 | + * The name and signature of the console command. | ||
| 25 | + * | ||
| 26 | + * @var string | ||
| 27 | + */ | ||
| 28 | + protected $signature = 'optimize_set_keyword_sync'; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * The console command description. | ||
| 32 | + * | ||
| 33 | + * @var string | ||
| 34 | + */ | ||
| 35 | + protected $description = '优化设置聚合页关键词,同步至对应项目产品关键词'; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * OptimizeSetKeywordSync constructor. | ||
| 39 | + */ | ||
| 40 | + public function __construct() | ||
| 41 | + { | ||
| 42 | + parent::__construct(); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 数据源:App\Http\Logic\Aside\Project\AggregateKeywordLogic::saveKeyword; | ||
| 47 | + * @return bool | ||
| 48 | + */ | ||
| 49 | + public function handle() | ||
| 50 | + { | ||
| 51 | + $task = AggregateKeyword::where(['status' => AggregateKeyword::STATUS_INIT])->where('created_at', '<', date('Y-m-d H:i:s'))->get(); | ||
| 52 | + foreach ($task as $item) { | ||
| 53 | + Log::info('同步ID:' . $item->id); | ||
| 54 | + echo $item->project_id . PHP_EOL; | ||
| 55 | + $this->syncKeyword($item->project_id, $item->keywords); | ||
| 56 | + $item->status = AggregateKeyword::STATUS_FINISH; | ||
| 57 | + $item->save(); | ||
| 58 | + } | ||
| 59 | + return true; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * 关键词同步 | ||
| 64 | + * @param $project_id | ||
| 65 | + * @param $keywords | ||
| 66 | + * @return bool | ||
| 67 | + */ | ||
| 68 | + public function syncKeyword($project_id, $keywords) | ||
| 69 | + { | ||
| 70 | + $keywords = explode("\n", $keywords); | ||
| 71 | + $keywords = array_unique(array_filter($keywords)); | ||
| 72 | + | ||
| 73 | + ProjectServer::useProject($project_id); | ||
| 74 | + $keywordModel = new Keyword(); | ||
| 75 | + $keywordModel->saveBKeyword($project_id,$keywords); | ||
| 76 | + DB::disconnect('custom_mysql'); | ||
| 77 | + return true; | ||
| 78 | + } | ||
| 79 | +} |
| @@ -37,6 +37,8 @@ class Kernel extends ConsoleKernel | @@ -37,6 +37,8 @@ class Kernel extends ConsoleKernel | ||
| 37 | $schedule->command('sync_inquiry_text')->dailyAt('09:00')->withoutOverlapping(1); | 37 | $schedule->command('sync_inquiry_text')->dailyAt('09:00')->withoutOverlapping(1); |
| 38 | //FB询盘费用同步 | 38 | //FB询盘费用同步 |
| 39 | $schedule->command('sync_ad_cost')->everyThirtyMinutes()->withoutOverlapping(1); | 39 | $schedule->command('sync_ad_cost')->everyThirtyMinutes()->withoutOverlapping(1); |
| 40 | + // 优化预设关键词 同步 20点会开始TDK生成 | ||
| 41 | + $schedule->command('optimize_set_keyword_sync')->dailyAt('20:00')->withoutOverlapping(1); | ||
| 40 | } | 42 | } |
| 41 | 43 | ||
| 42 | /** | 44 | /** |
| @@ -25,28 +25,17 @@ class AggregateKeywordLogic extends BaseLogic | @@ -25,28 +25,17 @@ class AggregateKeywordLogic extends BaseLogic | ||
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | /** | 27 | /** |
| 28 | - * @remark :保存关键词 | ||
| 29 | - * @name :saveKeyword | ||
| 30 | - * @author :lyh | ||
| 31 | - * @method :post | ||
| 32 | - * @time :2025/3/17 16:11 | 28 | + * @return array |
| 33 | */ | 29 | */ |
| 34 | public function saveKeyword(){ | 30 | public function saveKeyword(){ |
| 35 | - if(isset($this->param['id']) && !empty($this->param['id'])){ | ||
| 36 | - $id = $this->param['id']; | 31 | + if (FALSE == empty($this->param['id'])) { |
| 37 | $this->model->edit($this->param,['id'=>$this->param['id']]); | 32 | $this->model->edit($this->param,['id'=>$this->param['id']]); |
| 38 | - }else{ | ||
| 39 | - $id = $this->model->addReturnId($this->param); | ||
| 40 | - //保存到客户关键词 | ||
| 41 | - $keywords = explode("\n", $this->param['keywords']); | ||
| 42 | - if(!empty($keywords)){ | ||
| 43 | - ProjectServer::useProject($this->param['project_id']); | ||
| 44 | - $keywordModel = new Keyword(); | ||
| 45 | - $keywordModel->saveBKeyword($this->param['project_id'],$keywords); | ||
| 46 | - DB::disconnect('custom_mysql'); | 33 | + } else { |
| 34 | + $this->param['id'] = $this->model->addReturnId($this->param); | ||
| 35 | + // 添加预设功能 同步关键词 迁入到 namespace App\Console\Commands\Product\SetKeywordSync | ||
| 47 | } | 36 | } |
| 48 | - } | ||
| 49 | - return $this->success(['id'=>$id]); | 37 | + |
| 38 | + return $this->success(['id'=>$this->param['id']]); | ||
| 50 | } | 39 | } |
| 51 | 40 | ||
| 52 | } | 41 | } |
| @@ -12,13 +12,17 @@ namespace App\Models\Project; | @@ -12,13 +12,17 @@ namespace App\Models\Project; | ||
| 12 | use App\Models\Base; | 12 | use App\Models\Base; |
| 13 | 13 | ||
| 14 | /** | 14 | /** |
| 15 | - * @remark :聚合页关键词设置 | ||
| 16 | - * @name :AggregateKeyword | ||
| 17 | - * @author :lyh | ||
| 18 | - * @method :post | ||
| 19 | - * @time :2025/3/17 16:02 | 15 | + * 聚合页关键词设置 |
| 16 | + * Class AggregateKeyword | ||
| 17 | + * @package App\Models\Project | ||
| 20 | */ | 18 | */ |
| 21 | class AggregateKeyword extends Base | 19 | class AggregateKeyword extends Base |
| 22 | { | 20 | { |
| 23 | protected $table = 'gl_aggregate_keyword'; | 21 | protected $table = 'gl_aggregate_keyword'; |
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 关键词是否导入项目聚合页关键词 | ||
| 25 | + */ | ||
| 26 | + const STATUS_INIT = 0; | ||
| 27 | + const STATUS_FINISH = 1; | ||
| 24 | } | 28 | } |
-
请 注册 或 登录 后发表评论