作者 lyh
... ... @@ -294,17 +294,22 @@ class RelayInquiry extends Command
$this->output('没有独立站转发对象');
return 0;
}
//是否有必选的
$require_data = [];
foreach ($task['target'] as $item){
if(!empty($item['is_require'])){
$require_data[] = $item;
//是否有必选的渠道 渠道有一个及以上必选 就在组内随机一个
$require_agent_group = [];
foreach ($task['target'] as $item) {
if (!empty($item['is_require'])) {
$require_agent_group[] = $item['agent_group'];
}
}
$require_agent_group = array_unique($require_agent_group);
$require_agent_group_data = collect($task['target'])->whereIn('agent_group', $require_agent_group)->groupBy('agent_group');
$require_data = $require_agent_group_data->keys()->random(count($require_agent_group))->map(function ($group) use ($require_agent_group_data) {
return $require_agent_group_data[$group]->random();
})->all();
//代理商组 一个组只发一个
$agent_group = collect($task['target'])->whereNotIn('agent_group', array_column($require_data, 'agent_group'))->groupBy('agent_group');
$agent_group = collect($task['target'])->whereNotIn('agent_group', $require_agent_group)->groupBy('agent_group');
// 获取转发对象 重置num数量, array_rand数量不足会报错
$task['num'] = $task['num'] - count($require_data);
$task['num'] = $task['num'] - count($require_agent_group);
$num = $task['num'] > count($agent_group) ? count($agent_group) : $task['num'];
$random_data = $agent_group->keys()->random($num)->map(function ($group) use ($agent_group) {
return $agent_group[$group]->random();
... ... @@ -316,7 +321,7 @@ class RelayInquiry extends Command
$form->remark = $form->remark . '当前任务未发现转发对象,广告ID: ' . $form->ad_id . '!';
return false;
}
$this->logChannel()->info('随机域名', array_column($random_data, 'url'));
foreach ($random_data as $item) {
//手机号过滤
$phone = $form->phone;
... ...
... ... @@ -6,15 +6,16 @@ use App\Helper\Arr;
use App\Models\Com\Notify;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainCreateTask;
use App\Models\Domain\DomainInfo;
use App\Models\Product\Keyword;
use App\Models\Product\KeywordRelated;
use App\Models\Product\Product;
use App\Models\Project\DeployBuild;
use App\Models\Project\Project;
use App\Services\BatchExportService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
class Temp extends Command
{
... ... @@ -33,6 +34,94 @@ class Temp extends Command
protected $description = '临时脚本';
/**
* 伍欣组推广项目:开启AMP站点,首页不强制跳转,批量生成AMP站点页面
* @author Akun
* @date 2024/12/10 10:43
*/
public function handle6()
{
//获取所有组内推广项目
$leader_mid = 16;
$project_ids = DeployBuild::where('leader_mid', $leader_mid)->pluck('project_id')->toArray();
$project_list = Project::where('type', 2)->whereIn('id', $project_ids)->get();
$task_model = new DomainCreateTask();
foreach ($project_list as $project) {
$project_id = $project->id;
//获取项目域名情况
$domain_info = DomainInfo::where('project_id', $project_id)->where('status', 1)->first();
if (!$domain_info) {
$this->output('项目id:' . $project_id . ' | 未绑定正式域名');
continue;
}
$domain_id = $domain_info->id;
$domain = $domain_info->domain;
//获取项目所在服务器
$serve_ip_info = ServersIp::select(['id', 'ip', 'domain', 'servers_id'])->where('id', $project->serve_id)->first()->toArray();
if (!$serve_ip_info) {
$this->output('项目id:' . $project_id . ' | 未查询到服务器数据');
continue;
}
$servers_id = $serve_ip_info['servers_id'];
if ($servers_id == ServerConfig::SELF_SITE_ID) {
$this->output('项目id:' . $project_id . ' | 自建站项目过滤');
continue;
}
if ($servers_id == ServerConfig::SELF_TEST_ID) {
$this->output('项目id:' . $project_id . ' | 测试项目过滤');
continue;
}
if (!check_domain_record($domain_info['domain'], $serve_ip_info)) {
$this->output('项目id:' . $project_id . ', domain:' . $domain . ' | 未解析到目标服务器');
continue;
}
//开启AMP站点
if ($domain_info->amp_status == 0) {
$domain_info->amp_status = 1;
$domain_info->amp_type = 1;
}
//首页不强制跳转
$domain_info->is_redirect = 0;
$domain_info->save();
//创建主站建站任务
$task_model->add([
'server_id' => $servers_id,
'project_id' => $project_id,
'domain_id' => $domain_id,
'type' => DomainCreateTask::TYPE_MAIN
]);
//创建AMP站建站任务
$task_model->add([
'server_id' => $servers_id,
'project_id' => $project_id,
'domain_id' => $domain_id,
'type' => DomainCreateTask::TYPE_AMP
]);
//请求对应C端页面更新接口
$c_url = 'https://' . $domain . '/api/update_page/';
$c_params = [
'project_id' => $project_id,
'type' => 3
];
$re = http_post($c_url, json_encode($c_params), [], true);
if (isset($re['status']) && $re['status'] == 200) {
$this->output($c_url . ' | 请求成功');
} else {
$this->output($c_url . ' | ' . ($re['message'] ?? '未返回失败原因'));
}
}
}
/**
* 关联所有项目关键词
* @author Akun
* @date 2024/11/18 15:07
... ... @@ -236,7 +325,7 @@ class Temp extends Command
* @author Akun
* @date 2024/09/26 10:48
*/
public function handle()
public function handle1()
{
$notify_model = new Notify();
$project_model = new Project();
... ... @@ -292,7 +381,7 @@ class Temp extends Command
}
} else {
//其他服务器:请求对应C端接口
$c_url = $domain . '/api/update_page/';
$c_url = 'https://' . $domain . '/api/update_page/';
$c_params = [
'project_id' => $project_id,
'type' => 3
... ...
... ... @@ -134,10 +134,12 @@ class AdsController extends BaseController
if(!$task){
return $this->response('广告不存在!', Code::USER_ERROR, []);
}
if(empty($target)){
return $this->response('请添加关联网站!', Code::USER_ERROR, []);
}
$is_require_num = 0;
foreach ($target as $k=>$v){
if(empty($item['url'])){
unset($target[$k]);
}
}
foreach ($target as &$item){
if(empty($item['url'])){
return $this->response('网站域名不能为空!', Code::USER_ERROR, []);
... ...