|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: zhl
|
|
|
|
* Date: 2025/3/11
|
|
|
|
* Time: 14:13
|
|
|
|
*/
|
|
|
|
namespace App\Console\Commands\Product;
|
|
|
|
|
|
|
|
use App\Models\Product\Keyword;
|
|
|
|
use App\Models\Project\OnlineCheck;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Models\RankData\RankData;
|
|
|
|
use App\Services\ProjectServer;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class SendKeyword
|
|
|
|
* @package App\Console\Commands\Product
|
|
|
|
*/
|
|
|
|
class SendKeyword extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'send_product_tag_keyword';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = '未达标项目 自动推送拼接关键词 到监控系统';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SendKeyword constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO 查询不达标优化项目, 按照规则推送拼接关键词到监控系统
|
|
|
|
* http://zentao.globalso.com/index.php?m=task&f=view&taskID=185918
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$field = ['gl_project.id', 'gl_project.company', 'gl_project.main_lang_id', 'gl_project.is_upgrade', 'b.start_date', 'b.api_no', 'd.domain'];
|
|
|
|
$projects = Project::select($field)->leftJoin('gl_project_deploy_optimize as b', 'gl_project.id', '=', 'b.project_id')
|
|
|
|
->leftJoin('gl_project_online_check as c', 'gl_project.id', '=', 'c.project_id')
|
|
|
|
->leftJoin('gl_domain_info as d', 'gl_project.id', '=', 'd.project_id')
|
|
|
|
->where('gl_project.type', Project::TYPE_TWO)
|
|
|
|
->where('gl_project.extend_type', 0) // 是否续费是由extend_type字段控制
|
|
|
|
->where('gl_project.delete_status', Project::IS_DEL_FALSE)
|
|
|
|
->where('gl_project.main_lang_id', '<>', 8) // 不需要俄语站点项目
|
|
|
|
->where(function ($subQuery) {
|
|
|
|
$subQuery->orwhere('c.qa_status', OnlineCheck::STATUS_ONLINE_TRUE)->orwhere('gl_project.is_upgrade', Project::IS_UPGRADE_TRUE);
|
|
|
|
})
|
|
|
|
->get();
|
|
|
|
$time = time();
|
|
|
|
$send_num = [30 => 1000, 60 => 3000, 90 => 6000];
|
|
|
|
foreach ($projects as $item) {
|
|
|
|
if (empty($item->api_no)) {
|
|
|
|
$this->output('项目ID:' . $item->id . ', api_no为空;');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (empty($item->start_date)) {
|
|
|
|
$this->output('项目ID:' . $item->id . ', 推广开始时间为空;');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// 按照间隔时间发送不同关键词数量
|
|
|
|
$start_time = strtotime($item->start_date);
|
|
|
|
$day = intval(($time - $start_time) / 86400);
|
|
|
|
if (empty($send_num[$day])) {
|
|
|
|
$this->output('项目ID:' . $item->id . ', 推广天数:' . $day . ', 不需要推送;');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 项目是否达标
|
|
|
|
$compliance = RankData::where(['project_id' => $item->id, 'api_no' => $item->api_no, 'lang' => ''])->value('is_compliance');
|
|
|
|
if (FALSE == empty($compliance))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$project = ProjectServer::useProject($item->id);
|
|
|
|
if (empty($project)) {
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$send = $this->extendKeyword($item, $send_num[$day]);
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
// 数据成功后推送同志
|
|
|
|
if ($send) {
|
|
|
|
$this->sendNotice($item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 截取关键词
|
|
|
|
* @param $item
|
|
|
|
* @param int $num
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function extendKeyword($item, $num = 1000)
|
|
|
|
{
|
|
|
|
$keywords = Keyword::extendKeyword($item->id);
|
|
|
|
if (empty($keywords))
|
|
|
|
return false;
|
|
|
|
$keywords = array_filter(array_unique($keywords));
|
|
|
|
$sort = [];
|
|
|
|
foreach ($keywords as $keyword) {
|
|
|
|
$sort[] = strlen($keyword);
|
|
|
|
}
|
|
|
|
array_multisort($sort, SORT_ASC, $keywords);
|
|
|
|
$result = array_slice($keywords, 0, $num);
|
|
|
|
file_put_contents(storage_path('data/send_product_tag_keyword/' . $item->id . '.json'), json_encode($result, 256));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function sendNotice($item)
|
|
|
|
{
|
|
|
|
$itme = $item->toArray();
|
|
|
|
try {
|
|
|
|
// TODO 推送通知 待定
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->output('推送通知失败,项目ID:' . $item['id']);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $message
|
|
|
|
*/
|
|
|
|
public function output($message)
|
|
|
|
{
|
|
|
|
$message = date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL;
|
|
|
|
echo $message;
|
|
|
|
file_put_contents(storage_path('data/send_product_tag_keyword.log'), $message, FILE_APPEND);
|
|
|
|
}
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|