作者 lyh
@@ -294,17 +294,22 @@ class RelayInquiry extends Command @@ -294,17 +294,22 @@ class RelayInquiry extends Command
294 $this->output('没有独立站转发对象'); 294 $this->output('没有独立站转发对象');
295 return 0; 295 return 0;
296 } 296 }
297 - //是否有必选的  
298 - $require_data = [];  
299 - foreach ($task['target'] as $item){  
300 - if(!empty($item['is_require'])){  
301 - $require_data[] = $item; 297 + //是否有必选的渠道 渠道有一个及以上必选 就在组内随机一个
  298 + $require_agent_group = [];
  299 + foreach ($task['target'] as $item) {
  300 + if (!empty($item['is_require'])) {
  301 + $require_agent_group[] = $item['agent_group'];
302 } 302 }
303 } 303 }
  304 + $require_agent_group = array_unique($require_agent_group);
  305 + $require_agent_group_data = collect($task['target'])->whereIn('agent_group', $require_agent_group)->groupBy('agent_group');
  306 + $require_data = $require_agent_group_data->keys()->random(count($require_agent_group))->map(function ($group) use ($require_agent_group_data) {
  307 + return $require_agent_group_data[$group]->random();
  308 + })->all();
304 //代理商组 一个组只发一个 309 //代理商组 一个组只发一个
305 - $agent_group = collect($task['target'])->whereNotIn('agent_group', array_column($require_data, 'agent_group'))->groupBy('agent_group'); 310 + $agent_group = collect($task['target'])->whereNotIn('agent_group', $require_agent_group)->groupBy('agent_group');
306 // 获取转发对象 重置num数量, array_rand数量不足会报错 311 // 获取转发对象 重置num数量, array_rand数量不足会报错
307 - $task['num'] = $task['num'] - count($require_data); 312 + $task['num'] = $task['num'] - count($require_agent_group);
308 $num = $task['num'] > count($agent_group) ? count($agent_group) : $task['num']; 313 $num = $task['num'] > count($agent_group) ? count($agent_group) : $task['num'];
309 $random_data = $agent_group->keys()->random($num)->map(function ($group) use ($agent_group) { 314 $random_data = $agent_group->keys()->random($num)->map(function ($group) use ($agent_group) {
310 return $agent_group[$group]->random(); 315 return $agent_group[$group]->random();
@@ -316,7 +321,7 @@ class RelayInquiry extends Command @@ -316,7 +321,7 @@ class RelayInquiry extends Command
316 $form->remark = $form->remark . '当前任务未发现转发对象,广告ID: ' . $form->ad_id . '!'; 321 $form->remark = $form->remark . '当前任务未发现转发对象,广告ID: ' . $form->ad_id . '!';
317 return false; 322 return false;
318 } 323 }
319 - 324 + $this->logChannel()->info('随机域名', array_column($random_data, 'url'));
320 foreach ($random_data as $item) { 325 foreach ($random_data as $item) {
321 //手机号过滤 326 //手机号过滤
322 $phone = $form->phone; 327 $phone = $form->phone;
@@ -6,15 +6,16 @@ use App\Helper\Arr; @@ -6,15 +6,16 @@ use App\Helper\Arr;
6 use App\Models\Com\Notify; 6 use App\Models\Com\Notify;
7 use App\Models\Devops\ServerConfig; 7 use App\Models\Devops\ServerConfig;
8 use App\Models\Devops\ServersIp; 8 use App\Models\Devops\ServersIp;
  9 +use App\Models\Domain\DomainCreateTask;
9 use App\Models\Domain\DomainInfo; 10 use App\Models\Domain\DomainInfo;
10 use App\Models\Product\Keyword; 11 use App\Models\Product\Keyword;
11 use App\Models\Product\KeywordRelated; 12 use App\Models\Product\KeywordRelated;
12 use App\Models\Product\Product; 13 use App\Models\Product\Product;
  14 +use App\Models\Project\DeployBuild;
13 use App\Models\Project\Project; 15 use App\Models\Project\Project;
14 use App\Services\BatchExportService; 16 use App\Services\BatchExportService;
15 use App\Services\ProjectServer; 17 use App\Services\ProjectServer;
16 use Illuminate\Console\Command; 18 use Illuminate\Console\Command;
17 -use Symfony\Component\Process\Process;  
18 19
19 class Temp extends Command 20 class Temp extends Command
20 { 21 {
@@ -33,6 +34,94 @@ class Temp extends Command @@ -33,6 +34,94 @@ class Temp extends Command
33 protected $description = '临时脚本'; 34 protected $description = '临时脚本';
34 35
35 /** 36 /**
  37 + * 伍欣组推广项目:开启AMP站点,首页不强制跳转,批量生成AMP站点页面
  38 + * @author Akun
  39 + * @date 2024/12/10 10:43
  40 + */
  41 + public function handle6()
  42 + {
  43 + //获取所有组内推广项目
  44 + $leader_mid = 16;
  45 + $project_ids = DeployBuild::where('leader_mid', $leader_mid)->pluck('project_id')->toArray();
  46 + $project_list = Project::where('type', 2)->whereIn('id', $project_ids)->get();
  47 +
  48 + $task_model = new DomainCreateTask();
  49 + foreach ($project_list as $project) {
  50 + $project_id = $project->id;
  51 +
  52 + //获取项目域名情况
  53 + $domain_info = DomainInfo::where('project_id', $project_id)->where('status', 1)->first();
  54 + if (!$domain_info) {
  55 + $this->output('项目id:' . $project_id . ' | 未绑定正式域名');
  56 + continue;
  57 + }
  58 + $domain_id = $domain_info->id;
  59 + $domain = $domain_info->domain;
  60 +
  61 + //获取项目所在服务器
  62 + $serve_ip_info = ServersIp::select(['id', 'ip', 'domain', 'servers_id'])->where('id', $project->serve_id)->first()->toArray();
  63 + if (!$serve_ip_info) {
  64 + $this->output('项目id:' . $project_id . ' | 未查询到服务器数据');
  65 + continue;
  66 + }
  67 + $servers_id = $serve_ip_info['servers_id'];
  68 +
  69 + if ($servers_id == ServerConfig::SELF_SITE_ID) {
  70 + $this->output('项目id:' . $project_id . ' | 自建站项目过滤');
  71 + continue;
  72 + }
  73 +
  74 + if ($servers_id == ServerConfig::SELF_TEST_ID) {
  75 + $this->output('项目id:' . $project_id . ' | 测试项目过滤');
  76 + continue;
  77 + }
  78 +
  79 + if (!check_domain_record($domain_info['domain'], $serve_ip_info)) {
  80 + $this->output('项目id:' . $project_id . ', domain:' . $domain . ' | 未解析到目标服务器');
  81 + continue;
  82 + }
  83 +
  84 + //开启AMP站点
  85 + if ($domain_info->amp_status == 0) {
  86 + $domain_info->amp_status = 1;
  87 + $domain_info->amp_type = 1;
  88 + }
  89 + //首页不强制跳转
  90 + $domain_info->is_redirect = 0;
  91 + $domain_info->save();
  92 +
  93 + //创建主站建站任务
  94 + $task_model->add([
  95 + 'server_id' => $servers_id,
  96 + 'project_id' => $project_id,
  97 + 'domain_id' => $domain_id,
  98 + 'type' => DomainCreateTask::TYPE_MAIN
  99 + ]);
  100 +
  101 + //创建AMP站建站任务
  102 + $task_model->add([
  103 + 'server_id' => $servers_id,
  104 + 'project_id' => $project_id,
  105 + 'domain_id' => $domain_id,
  106 + 'type' => DomainCreateTask::TYPE_AMP
  107 + ]);
  108 +
  109 + //请求对应C端页面更新接口
  110 + $c_url = 'https://' . $domain . '/api/update_page/';
  111 + $c_params = [
  112 + 'project_id' => $project_id,
  113 + 'type' => 3
  114 + ];
  115 + $re = http_post($c_url, json_encode($c_params), [], true);
  116 + if (isset($re['status']) && $re['status'] == 200) {
  117 + $this->output($c_url . ' | 请求成功');
  118 + } else {
  119 + $this->output($c_url . ' | ' . ($re['message'] ?? '未返回失败原因'));
  120 + }
  121 + }
  122 + }
  123 +
  124 + /**
36 * 关联所有项目关键词 125 * 关联所有项目关键词
37 * @author Akun 126 * @author Akun
38 * @date 2024/11/18 15:07 127 * @date 2024/11/18 15:07
@@ -236,7 +325,7 @@ class Temp extends Command @@ -236,7 +325,7 @@ class Temp extends Command
236 * @author Akun 325 * @author Akun
237 * @date 2024/09/26 10:48 326 * @date 2024/09/26 10:48
238 */ 327 */
239 - public function handle() 328 + public function handle1()
240 { 329 {
241 $notify_model = new Notify(); 330 $notify_model = new Notify();
242 $project_model = new Project(); 331 $project_model = new Project();
@@ -292,7 +381,7 @@ class Temp extends Command @@ -292,7 +381,7 @@ class Temp extends Command
292 } 381 }
293 } else { 382 } else {
294 //其他服务器:请求对应C端接口 383 //其他服务器:请求对应C端接口
295 - $c_url = $domain . '/api/update_page/'; 384 + $c_url = 'https://' . $domain . '/api/update_page/';
296 $c_params = [ 385 $c_params = [
297 'project_id' => $project_id, 386 'project_id' => $project_id,
298 'type' => 3 387 'type' => 3
@@ -134,10 +134,12 @@ class AdsController extends BaseController @@ -134,10 +134,12 @@ class AdsController extends BaseController
134 if(!$task){ 134 if(!$task){
135 return $this->response('广告不存在!', Code::USER_ERROR, []); 135 return $this->response('广告不存在!', Code::USER_ERROR, []);
136 } 136 }
137 - if(empty($target)){  
138 - return $this->response('请添加关联网站!', Code::USER_ERROR, []);  
139 - }  
140 $is_require_num = 0; 137 $is_require_num = 0;
  138 + foreach ($target as $k=>$v){
  139 + if(empty($item['url'])){
  140 + unset($target[$k]);
  141 + }
  142 + }
141 foreach ($target as &$item){ 143 foreach ($target as &$item){
142 if(empty($item['url'])){ 144 if(empty($item['url'])){
143 return $this->response('网站域名不能为空!', Code::USER_ERROR, []); 145 return $this->response('网站域名不能为空!', Code::USER_ERROR, []);