作者 赵彬吉

shop/fob inquiry

@@ -204,7 +204,7 @@ class RelayInquiry extends Command @@ -204,7 +204,7 @@ class RelayInquiry extends Command
204 } 204 }
205 // 未设置对法对象 205 // 未设置对法对象
206 $target_num_arr = array_map(function ($item) { 206 $target_num_arr = array_map(function ($item) {
207 - return count($item['target']); 207 + return count($item['target']) + count($item['shop_site']) + count($item['fob_pro']);
208 }, $ad_task); 208 }, $ad_task);
209 if (!array_sum($target_num_arr)) { 209 if (!array_sum($target_num_arr)) {
210 $val->status = ReInquiryForm::STATUS_FORGO; 210 $val->status = ReInquiryForm::STATUS_FORGO;
@@ -225,6 +225,8 @@ class RelayInquiry extends Command @@ -225,6 +225,8 @@ class RelayInquiry extends Command
225 $res = false; 225 $res = false;
226 foreach ($ad_task as $task){ 226 foreach ($ad_task as $task){
227 $res += $this->relayDetail($task, $val); 227 $res += $this->relayDetail($task, $val);
  228 + $res += $this->relayShopDetail($task, $val);
  229 + $res += $this->relayFobDetail($task, $val);
228 } 230 }
229 $val->status = $res ? ReInquiryForm::STATUS_SUCCESS : ReInquiryForm::STATUS_FORGO; 231 $val->status = $res ? ReInquiryForm::STATUS_SUCCESS : ReInquiryForm::STATUS_FORGO;
230 $val->save(); 232 $val->save();
@@ -288,7 +290,10 @@ class RelayInquiry extends Command @@ -288,7 +290,10 @@ class RelayInquiry extends Command
288 public function relayDetail($task, $form) 290 public function relayDetail($task, $form)
289 { 291 {
290 $this->output('获取转发对象'); 292 $this->output('获取转发对象');
291 - 293 + if(empty($task['target'] )){
  294 + $this->output('没有独立站转发对象');
  295 + return 0;
  296 + }
292 //是否有必选的 297 //是否有必选的
293 $require_data = []; 298 $require_data = [];
294 foreach ($task['target'] as $item){ 299 foreach ($task['target'] as $item){
@@ -327,65 +332,136 @@ class RelayInquiry extends Command @@ -327,65 +332,136 @@ class RelayInquiry extends Command
327 $is_v6 = $item['is_v6']; 332 $is_v6 = $item['is_v6'];
328 $re_website = 'https://' . $domain . '/'; 333 $re_website = 'https://' . $domain . '/';
329 334
330 - $this->output('转发对象:' . $domain);  
331 - $this->output('获取转发链接');  
332 - // v6:有邮箱推送主站,没有邮箱推送AMP站;v5:仅推送有邮箱到主站  
333 - $lang = '';  
334 - if ($is_v6) {  
335 - // 获取语种, 6.0是可以确定语种的  
336 - $project = Project::getProjectByDomain($domain);  
337 - if (empty($project)) {  
338 - $this->logChannel()->info('广告任务ID:' . $task['id'] . ', 转发对象:' . $re_website . '非v6链接,转发失败;', ['广告任务ID:' . $task['id'], '询盘ID:' . $form->id]); 335 + //urls
  336 + list($urls, $lang) = $this->getUrls($is_v6, $domain, $re_website, $form, $task);
  337 + if(!$urls){
339 continue; 338 continue;
340 } 339 }
341 - $lang = WebLanguage::getLangById($project->main_lang_id ?? 1)['short'];  
342 340
343 - // 获取访问明细和着陆页  
344 - $product_url = $this->getLinksFromSitemap($re_website . 'product_sitemap.xml');  
345 - $product_cate_url = $this->getLinksFromSitemap($re_website . 'product_category_sitemap.xml');  
346 - $keywords_url = $this->getLinksFromSitemap($re_website . 'product_keywords_sitemap.xml');  
347 - $page_url = $this->getLinksFromSitemap($re_website . 'page_sitemap.xml');  
348 - } else {  
349 - if($form->email){  
350 - //通过sitemap拿访问页面  
351 - $product_url = $this->getLinksFromSitemap($re_website . 'sitemap_post.xml');  
352 - $product_cate_url = $this->getLinksFromSitemap($re_website . 'sitemap_category.xml');  
353 - $keywords_url = $this->getLinksFromSitemap($re_website . 'sitemap_post_tag.xml');  
354 - $page_url = $this->getLinksFromSitemap($re_website . 'sitemap_page.xml');  
355 - }else{  
356 - //m站先就往contact-us着陆  
357 - $product_url = $product_cate_url = $keywords_url = [];  
358 - $page_url = [$re_website . 'contact-us/']; 341 + //ip
  342 + $ip_data = $this->getIpData($form->country_name);
  343 + $ip = $ip_data->ip;
  344 + $country_name = $ip_data->ip_area;
  345 +
  346 + //message
  347 + list($message, $message_id, $msg_lang) = $this->getMessage($task, $form->message, $domain);
  348 + $lang = $lang ?: $msg_lang;
  349 +
  350 + $this->output('获取转发设备信息');
  351 + // 客户端 头信息 来源
  352 + $device_port = $form->email ? '1' : '2'; //1 pc 2移动端
  353 + $user_agent = $form->email ? Arr::random($this->pc_ua) : Arr::random($this->mobile_ua);
  354 + $referrer = $this->getReferer($country_name, $lang);
  355 + $this->output('写入数据');
  356 +
  357 + $pre = 0;
  358 + $start_time = time();
  359 + $seconds = rand(300, 3000); // 开始时间 从5-50分钟后开始
  360 + $exists = ReInquiryDetail::where('re_website', $domain)->where('email', $form->email)->first();
  361 + if($exists){
  362 + $this->output('转发站点邮件已存在');
  363 + continue;
  364 + }
  365 + // 写入推送详情
  366 + $re_detail = ReInquiryDetail::createInquiry($task['id'], $form->id, $domain, $country_name, $ip, $form->full_name, $form->email, $phone, $message, $message_id, $device_port,
  367 + $user_agent, $referrer, $urls, $is_v6, date('Y-m-d H:i:s', $start_time + $seconds));
  368 + foreach ($urls as $k=>$v){
  369 + $pre++;
  370 + $seconds += rand(3,10);
  371 + ReInquiryDetailLog::createInquiryLog($re_detail->id, ReInquiryDetailLog::TYPE_VISIT, $pre, $v, date('Y-m-d H:i:s', $start_time + $seconds));
  372 + // 最后一次访问询盘 加上询盘
  373 + if($k+1 >= count($urls)){
  374 + $seconds += rand(10,30);
  375 + $pre++;
  376 + ReInquiryDetailLog::createInquiryLog($re_detail->id, ReInquiryDetailLog::TYPE_INQUIRY, $pre, $v, date('Y-m-d H:i:s', $start_time + $seconds));
359 } 377 }
360 } 378 }
  379 + }
  380 + return true;
  381 + }
361 382
362 - // 所有可用url  
363 - $urls = $inquiry_urls = [];  
364 - //入口url 首页30%,单页10%,聚合页60%  
365 - $type = getRandByRatio([30,10,60]);  
366 - $inlet = $re_website;  
367 - $type == 1 && $inlet = $page_url ? Arr::random($page_url) : $re_website;  
368 - $type == 2 && $inlet = $keywords_url ? Arr::random($keywords_url) : $re_website;  
369 - $urls[] = $inquiry_urls[] = $inlet;  
370 - $all_urls = array_merge($urls, $product_url, $product_cate_url, $keywords_url, $page_url);  
371 - $inquiry_urls = array_merge($urls, $product_cate_url, $keywords_url, $page_url); 383 + public function relayShopDetail($task, $form)
  384 + {
  385 + $this->output('获取商城转发对象');
372 386
373 - // 随机访问1-6个页面  
374 - $deep = rand(1,6);  
375 - if($deep > 2) {  
376 - $visit_urls = Arr::random($all_urls, rand(1, count($all_urls) > 4 ? 4 : count($all_urls)));  
377 - $urls = array_merge($urls, $visit_urls); 387 + if(empty($task['shop_site'])){
  388 + $this->output('没有商城转发对象');
  389 + return 0;
378 } 390 }
379 - if($deep > 1) {  
380 - // 推送着落页只能是 首页、产品分类、单页面、聚合页  
381 - if (!in_array(end($urls), $inquiry_urls)) {  
382 - $urls[] = Arr::random($inquiry_urls); 391 +
  392 + foreach ($task['shop_site'] as $item) {
  393 + //手机号过滤
  394 + $phone = $form->phone;
  395 + // 推送站点
  396 + $domain = $item;
  397 + $re_website = 'https://' . $domain . '/';
  398 + $paths = ['', 'contact-us'];
  399 + $url = $re_website . $paths[array_rand($paths)];
  400 + //ip
  401 + $ip_data = $this->getIpData($form->country_name);
  402 + $ip = $ip_data->ip;
  403 + $country_name = $ip_data->ip_area;
  404 + //message
  405 + list($message, $message_id, $lang) = $this->getMessage($task, $form->message, $domain);
  406 +
  407 + $device_port = $form->email ? '1' : '2'; //1 pc 2移动端
  408 + $user_agent = $form->email ? Arr::random($this->pc_ua) : Arr::random($this->mobile_ua);
  409 + $referrer = $this->getReferer($country_name, $lang);
  410 +
  411 + $start_time = time();
  412 + $seconds = rand(300, 3000); // 开始时间 从5-50分钟后开始
  413 + $exists = ReInquiryDetail::where('re_website', $domain)->where('email', $form->email)->first();
  414 + if($exists){
  415 + $this->output('转发站点邮件已存在');
  416 + continue;
  417 + }
  418 + $re_detail = ReInquiryDetail::createInquiry($task['id'], $form->id, $domain, $country_name, $ip, $form->full_name, $form->email, $phone, $message, $message_id,
  419 + $device_port, $user_agent, $referrer, [$url], 0, date('Y-m-d H:i:s', $start_time + $seconds), ReInquiryDetail::STATUS_INIT, 2);
  420 +
  421 + ReInquiryDetailLog::createInquiryLog($re_detail->id, ReInquiryDetailLog::TYPE_INQUIRY, 1, $url, date('Y-m-d H:i:s', $start_time + $seconds));
383 } 422 }
  423 + return true;
384 } 424 }
385 425
  426 +
  427 + public function relayFobDetail($task, $form)
  428 + {
  429 + $this->output('获取FOB转发对象');
  430 +
  431 + if(empty($task['fob_pro'])){
  432 + $this->output('没有FOB转发对象');
  433 + return 0;
  434 + }
  435 +
  436 + foreach ($task['fob_pro'] as $item) {
  437 + //手机号过滤
  438 + $phone = $form->phone;
  439 + // 推送站点
  440 + $postid = $item;
  441 + //message
  442 + list($message, $message_id, $lang) = $this->getMessage($task, $form->message, $postid);
  443 +
  444 + $device_port = $form->email ? '1' : '2'; //1 pc 2移动端
  445 + $user_agent = $form->email ? Arr::random($this->pc_ua) : Arr::random($this->mobile_ua);
  446 +
  447 + $start_time = time();
  448 + $seconds = rand(300, 3000); // 开始时间 从5-50分钟后开始
  449 + $exists = ReInquiryDetail::where('re_website', $postid)->where('email', $form->email)->first();
  450 + if($exists){
  451 + $this->output('转发站点邮件已存在');
  452 + continue;
  453 + }
  454 + $re_detail = ReInquiryDetail::createInquiry($task['id'], $form->id, $postid, $country_name??'', $ip??'', $form->full_name, $form->email, $phone,
  455 + $message, $message_id, $device_port, $user_agent, $referrer??'', [$postid], 0, date('Y-m-d H:i:s', $start_time + $seconds), ReInquiryDetail::STATUS_INIT, 3);
  456 +
  457 + ReInquiryDetailLog::createInquiryLog($re_detail->id, ReInquiryDetailLog::TYPE_INQUIRY, 1, $postid, date('Y-m-d H:i:s', $start_time + $seconds));
  458 + }
  459 + return true;
  460 + }
  461 +
  462 + public function getIpData($country_name){
386 $this->output('获取转发ip'); 463 $this->output('获取转发ip');
387 - // TODO 获取IP:如果是简码,查询数据库获取对应的国家, 如果是国家使用翻译, 再转化成IP  
388 - $country = $form->country_name; 464 + $country = $country_name;
389 // 有国家 通过国家查询, 如果没有获取到就随机获取 465 // 有国家 通过国家查询, 如果没有获取到就随机获取
390 $where = []; 466 $where = [];
391 $country && $where['ip_area'] = $country; 467 $country && $where['ip_area'] = $country;
@@ -393,11 +469,12 @@ class RelayInquiry extends Command @@ -393,11 +469,12 @@ class RelayInquiry extends Command
393 if (empty($ip_data)) { 469 if (empty($ip_data)) {
394 $ip_data = DB::table('gl_xunpan_ipdata')->inRandomOrder()->first(); 470 $ip_data = DB::table('gl_xunpan_ipdata')->inRandomOrder()->first();
395 } 471 }
396 - $ip = $ip_data->ip;  
397 - $country_name = $ip_data->ip_area; 472 + return $ip_data;
  473 + }
398 474
  475 + public function getMessage($task, $message, $domain){
399 $this->output('转发内容'); 476 $this->output('转发内容');
400 - $message = $form->message; 477 + $form_message = $message;
401 $message_id = 0; 478 $message_id = 0;
402 //开启文案替换 479 //开启文案替换
403 if ($task['is_replace_text'] == 2) { 480 if ($task['is_replace_text'] == 2) {
@@ -419,7 +496,6 @@ class RelayInquiry extends Command @@ -419,7 +496,6 @@ class RelayInquiry extends Command
419 } 496 }
420 if ($task['is_replace_text'] == 1 || strlen($message) <= 4) { 497 if ($task['is_replace_text'] == 1 || strlen($message) <= 4) {
421 //配置文案库替换或者字符少于4个,直接替换文案 498 //配置文案库替换或者字符少于4个,直接替换文案
422 -  
423 $use_ids = ReInquiryDetail::where(['re_website' => $domain])->where('status', '<>', ReInquiryDetail::STATUS_FAIL)->pluck('text_id')->toArray(); 499 $use_ids = ReInquiryDetail::where(['re_website' => $domain])->where('status', '<>', ReInquiryDetail::STATUS_FAIL)->pluck('text_id')->toArray();
424 $text = ReInquiryText::whereNotIn('id', $use_ids)->where('status', ReInquiryText::STATUS_USABLE)->inRandomOrder()->first(); 500 $text = ReInquiryText::whereNotIn('id', $use_ids)->where('status', ReInquiryText::STATUS_USABLE)->inRandomOrder()->first();
425 $message = $text->content; 501 $message = $text->content;
@@ -429,10 +505,10 @@ class RelayInquiry extends Command @@ -429,10 +505,10 @@ class RelayInquiry extends Command
429 $text->save(); 505 $text->save();
430 506
431 //原内容非英语,转为对应语种 507 //原内容非英语,转为对应语种
432 - if (is_numeric($form->message)) { //数字会被识别为中文 508 + if (is_numeric($form_message)) { //数字会被识别为中文
433 $lang = 'en'; 509 $lang = 'en';
434 } else { 510 } else {
435 - $translateSl = Translate::translateSl($form->message); 511 + $translateSl = Translate::translateSl($form_message);
436 $lang = $translateSl['texts']['sl'] ?? 'en'; 512 $lang = $translateSl['texts']['sl'] ?? 'en';
437 } 513 }
438 514
@@ -440,40 +516,67 @@ class RelayInquiry extends Command @@ -440,40 +516,67 @@ class RelayInquiry extends Command
440 $message = Translate::tran($message, $lang); 516 $message = Translate::tran($message, $lang);
441 } 517 }
442 } 518 }
  519 + return [$message, $message_id, $lang??''];
  520 + }
443 521
444 - $this->output('获取转发设备信息');  
445 - // 客户端 头信息 来源  
446 - $device_port = $form->email ? '1' : '2'; //1 pc 2移动端  
447 - $user_agent = $form->email ? Arr::random($this->pc_ua) : Arr::random($this->mobile_ua);  
448 - $referrer = $this->getReferer($country_name, $lang);  
449 - $this->output('写入数据'); 522 + public function getUrls($is_v6, $domain, $re_website, $form, $task){
  523 + $this->output('转发对象:' . $domain);
  524 + $this->output('获取转发链接');
  525 + // v6:有邮箱推送主站,没有邮箱推送AMP站;v5:仅推送有邮箱到主站
  526 + $lang = '';
  527 + if ($is_v6) {
  528 + // 获取语种, 6.0是可以确定语种的
  529 + $project = Project::getProjectByDomain($domain);
  530 + if (empty($project)) {
  531 + $this->logChannel()->info('广告任务ID:' . $task['id'] . ', 转发对象:' . $re_website . '非v6链接,转发失败;', ['广告任务ID:' . $task['id'], '询盘ID:' . $form->id]);
  532 + return [[], $lang];
  533 + }
  534 + $lang = WebLanguage::getLangById($project->main_lang_id ?? 1)['short'];
450 535
451 - $pre = 0;  
452 - $start_time = time();  
453 - $seconds = rand(300, 3000); // 开始时间 从5-50分钟后开始  
454 - $exists = ReInquiryDetail::where('re_website', $domain)->where('email', $form->email)->first();  
455 - if($exists){  
456 - $this->output('转发站点邮件已存在');  
457 - continue; 536 + // 获取访问明细和着陆页
  537 + $product_url = $this->getLinksFromSitemap($re_website . 'product_sitemap.xml');
  538 + $product_cate_url = $this->getLinksFromSitemap($re_website . 'product_category_sitemap.xml');
  539 + $keywords_url = $this->getLinksFromSitemap($re_website . 'product_keywords_sitemap.xml');
  540 + $page_url = $this->getLinksFromSitemap($re_website . 'page_sitemap.xml');
  541 + } else {
  542 + if($form->email){
  543 + //通过sitemap拿访问页面
  544 + $product_url = $this->getLinksFromSitemap($re_website . 'sitemap_post.xml');
  545 + $product_cate_url = $this->getLinksFromSitemap($re_website . 'sitemap_category.xml');
  546 + $keywords_url = $this->getLinksFromSitemap($re_website . 'sitemap_post_tag.xml');
  547 + $page_url = $this->getLinksFromSitemap($re_website . 'sitemap_page.xml');
  548 + }else{
  549 + //m站先就往contact-us着陆
  550 + $product_url = $product_cate_url = $keywords_url = [];
  551 + $page_url = [$re_website . 'contact-us/'];
458 } 552 }
459 - // 写入推送详情  
460 - $re_detail = ReInquiryDetail::createInquiry($task['id'], $form->id, $domain, $country_name, $ip, $form->full_name, $form->email, $phone, $message, $message_id, $device_port,  
461 - $user_agent, $referrer, $urls, $is_v6, date('Y-m-d H:i:s', $start_time + $seconds));  
462 - foreach ($urls as $k=>$v){  
463 - $pre++;  
464 - $seconds += rand(3,10);  
465 - ReInquiryDetailLog::createInquiryLog($re_detail->id, ReInquiryDetailLog::TYPE_VISIT, $pre, $v, date('Y-m-d H:i:s', $start_time + $seconds));  
466 - // 最后一次访问询盘 加上询盘  
467 - if($k+1 >= count($urls)){  
468 - $seconds += rand(10,30);  
469 - $pre++;  
470 - ReInquiryDetailLog::createInquiryLog($re_detail->id, ReInquiryDetailLog::TYPE_INQUIRY, $pre, $v, date('Y-m-d H:i:s', $start_time + $seconds));  
471 } 553 }
  554 +
  555 + // 所有可用url
  556 + $urls = $inquiry_urls = [];
  557 + //入口url 首页30%,单页10%,聚合页60%
  558 + $type = getRandByRatio([30,10,60]);
  559 + $inlet = $re_website;
  560 + $type == 1 && $inlet = $page_url ? Arr::random($page_url) : $re_website;
  561 + $type == 2 && $inlet = $keywords_url ? Arr::random($keywords_url) : $re_website;
  562 + $urls[] = $inquiry_urls[] = $inlet;
  563 + $all_urls = array_merge($urls, $product_url, $product_cate_url, $keywords_url, $page_url);
  564 + $inquiry_urls = array_merge($urls, $product_cate_url, $keywords_url, $page_url);
  565 +
  566 + // 随机访问1-6个页面
  567 + $deep = rand(1,6);
  568 + if($deep > 2) {
  569 + $visit_urls = Arr::random($all_urls, rand(1, count($all_urls) > 4 ? 4 : count($all_urls)));
  570 + $urls = array_merge($urls, $visit_urls);
  571 + }
  572 + if($deep > 1) {
  573 + // 推送着落页只能是 首页、产品分类、单页面、聚合页
  574 + if (!in_array(end($urls), $inquiry_urls)) {
  575 + $urls[] = Arr::random($inquiry_urls);
472 } 576 }
473 } 577 }
474 - return true; 578 + return [$urls, $lang];
475 } 579 }
476 -  
477 /** 580 /**
478 * 获取待处理询盘表单 581 * 获取待处理询盘表单
479 * @param int $num 582 * @param int $num
@@ -494,7 +597,7 @@ class RelayInquiry extends Command @@ -494,7 +597,7 @@ class RelayInquiry extends Command
494 { 597 {
495 $cache_key = 'inquiry_ads_tasks'; 598 $cache_key = 'inquiry_ads_tasks';
496 $ads = Cache::get($cache_key, function () use ($cache_key) { 599 $ads = Cache::get($cache_key, function () use ($cache_key) {
497 - $ads = ReInquiryTask::where(['status' => ReInquiryTask::STATUS_OPEN])->get(['id', 'ad_id', 'num', 'target', 'is_replace_text', 'ai_param']); 600 + $ads = ReInquiryTask::where(['status' => ReInquiryTask::STATUS_OPEN])->get(['id', 'ad_id', 'num', 'target', 'is_replace_text', 'ai_param', 'shop_site', 'fob_pro']);
498 $array = []; 601 $array = [];
499 foreach ($ads as $key=>$val) { 602 foreach ($ads as $key=>$val) {
500 $ad_ids = explode(',', $val['ad_id']); 603 $ad_ids = explode(',', $val['ad_id']);
@@ -158,9 +158,37 @@ class postInquiry extends Command @@ -158,9 +158,37 @@ class postInquiry extends Command
158 } 158 }
159 159
160 public function inquiry(ReInquiryDetail $detail, ReInquiryDetailLog $log){ 160 public function inquiry(ReInquiryDetail $detail, ReInquiryDetailLog $log){
161 - $website = 'https://' . $detail['re_website'] . '/'; 161 + $res = false;
  162 + if ($detail['type'] == 1) {
162 // v6 163 // v6
163 - if($detail['is_v6']) { 164 + if ($detail['is_v6']) {
  165 + $res = $this->v6Inquiry($detail, $log);
  166 + } else {
  167 + $res = $this->v5Inquiry($detail, $log);
  168 + }
  169 + } elseif ($detail['type'] == 2) {
  170 + //商城询盘
  171 + $res = $this->ShopInquiry($detail, $log);
  172 + } elseif ($detail['type'] == 3) {
  173 + //Fob询盘
  174 + $res = $this->FobInquiry($detail, $log);
  175 + }
  176 +
  177 + if(!$res){
  178 + return false;
  179 + }
  180 +
  181 + $log->status = ReInquiryDetailLog::STATUS_SUCCESS;
  182 + $log->save();
  183 +
  184 + //统计
  185 + ReInquiryCount::addInquiryNum($detail['id'], $detail['re_website']);
  186 +
  187 + return true;
  188 + }
  189 +
  190 + public function v6Inquiry($detail, $log){
  191 + $website = 'https://' . $detail['re_website'] . '/';
164 $data = [ 192 $data = [
165 'name' => $detail['name'], 193 'name' => $detail['name'],
166 'phone' => $detail['phone'], 194 'phone' => $detail['phone'],
@@ -168,22 +196,23 @@ class postInquiry extends Command @@ -168,22 +196,23 @@ class postInquiry extends Command
168 'submit_ip' => $detail['ip'], 196 'submit_ip' => $detail['ip'],
169 'refer' => $log->url, 197 'refer' => $log->url,
170 ]; 198 ];
171 - if($detail->email){ 199 + if ($detail->email) {
172 $data['email'] = $detail->email; 200 $data['email'] = $detail->email;
173 - }else{ 201 + } else {
174 $data['__amp_source_origin'] = trim($website, '/'); 202 $data['__amp_source_origin'] = trim($website, '/');
175 } 203 }
176 -  
177 $res = Http::withoutVerifying()->withHeaders(['User-Agent' => $detail['user_agent']])->post($website . 'api/inquiryQd/', $data)->json(); 204 $res = Http::withoutVerifying()->withHeaders(['User-Agent' => $detail['user_agent']])->post($website . 'api/inquiryQd/', $data)->json();
178 - if(empty($res['code']) || $res['code'] != 200){ 205 + if (empty($res['code']) || $res['code'] != 200) {
179 $log->status = ReInquiryDetailLog::STATUS_FAIL; 206 $log->status = ReInquiryDetailLog::STATUS_FAIL;
180 $log->remark = mb_substr($res['message'] ?? '', 0, 200); 207 $log->remark = mb_substr($res['message'] ?? '', 0, 200);
181 $log->save(); 208 $log->save();
182 -  
183 Log::channel('inquiry_relay')->error('inquiry_relay v6 inquiry error', [$res, $website . 'api/inquiryQd/', $data]); 209 Log::channel('inquiry_relay')->error('inquiry_relay v6 inquiry error', [$res, $website . 'api/inquiryQd/', $data]);
184 return false; 210 return false;
185 } 211 }
186 - }else{ 212 + return true;
  213 + }
  214 +
  215 + public function v5Inquiry($detail, $log){
187 $data = [ 216 $data = [
188 'name' => $detail['name'], 217 'name' => $detail['name'],
189 'phone' => $detail['phone'], 218 'phone' => $detail['phone'],
@@ -199,11 +228,11 @@ class postInquiry extends Command @@ -199,11 +228,11 @@ class postInquiry extends Command
199 $result = Http::withoutVerifying()->post('https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data); 228 $result = Http::withoutVerifying()->post('https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data);
200 $res = $result->json(); 229 $res = $result->json();
201 //兼容接口返回格式 230 //兼容接口返回格式
202 - if(!empty($res['data'][0]['status'])){ 231 + if (!empty($res['data'][0]['status'])) {
203 $res['data'][0]['code'] = $res['data'][0]['status'] == 'success' ? 200 : 400; 232 $res['data'][0]['code'] = $res['data'][0]['status'] == 'success' ? 200 : 400;
204 !empty($res['data'][0]['msg']) && $res['message'] = $res['data'][0]['msg']; 233 !empty($res['data'][0]['msg']) && $res['message'] = $res['data'][0]['msg'];
205 } 234 }
206 - if(empty($res['data'][0]['code']) || !in_array($res['data'][0]['code'], [200,300])){ 235 + if (empty($res['data'][0]['code']) || !in_array($res['data'][0]['code'], [200, 300])) {
207 $log->status = ReInquiryDetailLog::STATUS_FAIL; 236 $log->status = ReInquiryDetailLog::STATUS_FAIL;
208 $log->remark = mb_substr($res['message'] ?? '', 0, 200); 237 $log->remark = mb_substr($res['message'] ?? '', 0, 200);
209 $log->save(); 238 $log->save();
@@ -211,16 +240,49 @@ class postInquiry extends Command @@ -211,16 +240,49 @@ class postInquiry extends Command
211 Log::channel('inquiry_relay')->error('inquiry_relay v4|v5 inquiry error', [$result->body(), 'https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data]); 240 Log::channel('inquiry_relay')->error('inquiry_relay v4|v5 inquiry error', [$result->body(), 'https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f', $data]);
212 return false; 241 return false;
213 } 242 }
  243 + return true;
214 } 244 }
215 - $log->status = ReInquiryDetailLog::STATUS_SUCCESS;  
216 - $log->save();  
217 245
218 - //统计  
219 - ReInquiryCount::addInquiryNum($detail['id'], $detail['re_website']); 246 + public function ShopInquiry($detail, $log){
  247 + $data = [
  248 + 'name' => $detail['name'],
  249 + 'email' => $detail['email'],
  250 + 'phone' => $detail['phone'],
  251 + 'message' => $detail['message'],
  252 + 'submit_ip' => $detail['ip'],
  253 + 'refer' => $log['url'],
  254 + ];
  255 + ksort($data);
  256 + $data['token'] = md5( json_encode($data, JSON_UNESCAPED_UNICODE ) . date("Y-m-d"));
  257 + $url = 'https://' . $detail['re_website'] . '/index.php?route=api/ai_inquiry/add';
  258 + $res = Http::withoutVerifying()->post($url, $data)->json();
  259 + if (empty($res['code']) || $res['code'] != 200) {
  260 + $log->status = ReInquiryDetailLog::STATUS_FAIL;
  261 + $log->remark = mb_substr($res['message'] ?? '', 0, 200);
  262 + $log->save();
220 263
221 - return true; 264 + Log::channel('inquiry_relay')->error('inquiry_relay shop inquiry error', [$res, $url, $data]);
  265 + return false;
  266 + }
222 } 267 }
223 268
  269 + public function FobInquiry($detail, $log){
  270 + $data = [
  271 + 'name' => $detail['name'],
  272 + 'email' => $detail['email'],
  273 + 'phone' => $detail['phone'],
  274 + 'post_id' => $log['url'],
  275 + ];
  276 + $res = Http::withoutVerifying()->post('https://fob.ai.cc/api/ad_to_scrm', $data)->json();
  277 + if (empty($res['code']) || $res['code'] != 200) {
  278 + $log->status = ReInquiryDetailLog::STATUS_FAIL;
  279 + $log->remark = mb_substr($res['message'] ?? '', 0, 200);
  280 + $log->save();
  281 +
  282 + Log::channel('inquiry_relay')->error('inquiry_relay fob inquiry error', [$res, 'https://fob.ai.cc/api/ad_to_scrm', $data]);
  283 + return false;
  284 + }
  285 + }
224 286
225 public function output($message) 287 public function output($message)
226 { 288 {
@@ -23,6 +23,7 @@ use App\Utils\HttpUtils; @@ -23,6 +23,7 @@ use App\Utils\HttpUtils;
23 use GuzzleHttp\Exception\GuzzleException; 23 use GuzzleHttp\Exception\GuzzleException;
24 use Illuminate\Http\Request; 24 use Illuminate\Http\Request;
25 use Illuminate\Support\Facades\DB; 25 use Illuminate\Support\Facades\DB;
  26 +use Illuminate\Support\Facades\Http;
26 27
27 /** 28 /**
28 * Class AdsController 29 * Class AdsController
@@ -126,7 +127,9 @@ class AdsController extends BaseController @@ -126,7 +127,9 @@ class AdsController extends BaseController
126 public function setRelaySite(Request $request) 127 public function setRelaySite(Request $request)
127 { 128 {
128 $id = intval($request->input('id', 0)); 129 $id = intval($request->input('id', 0));
129 - $target = $request->input('target'); 130 + $target = $request->input('target', []);
  131 + $shop_site = $request->input('shop_site', []);
  132 + $fob_pro = $request->input('fob_pro', []);
130 $task = ReInquiryTask::find($id); 133 $task = ReInquiryTask::find($id);
131 if(!$task){ 134 if(!$task){
132 return $this->response('广告不存在!', Code::USER_ERROR, []); 135 return $this->response('广告不存在!', Code::USER_ERROR, []);
@@ -153,15 +156,42 @@ class AdsController extends BaseController @@ -153,15 +156,42 @@ class AdsController extends BaseController
153 if($is_require_num > $task->num){ 156 if($is_require_num > $task->num){
154 return $this->response('必选渠道不能大于转发数量!', Code::USER_ERROR, []); 157 return $this->response('必选渠道不能大于转发数量!', Code::USER_ERROR, []);
155 } 158 }
156 -  
157 foreach ($target as $v){ 159 foreach ($target as $v){
158 ReInquiryCount::addInquiryNum($id, $v['url'], 0); 160 ReInquiryCount::addInquiryNum($id, $v['url'], 0);
159 } 161 }
  162 +
  163 + //商城
  164 + foreach ($shop_site as &$url) {
  165 + if (empty($url)) {
  166 + return $this->response('商城网站域名不能为空!', Code::USER_ERROR, []);
  167 + }
  168 + $url = trim(str_replace(['http://', 'https://'], '', $url), '/');
  169 + $res = Http::get($url . '/index.php?route=api/ai_inquiry/add')->json();
  170 + if (!$res) {
  171 + return $this->response($url . '不是商城网站!', Code::USER_ERROR, []);
  172 + }
  173 + ReInquiryCount::addInquiryNum($id, $url, 0, 2);
  174 + }
  175 + //超级项目
  176 + foreach ($fob_pro as &$postid) {
  177 + if (empty($postid)) {
  178 + return $this->response('项目ID不能为空!', Code::USER_ERROR, []);
  179 + }
  180 + ReInquiryCount::addInquiryNum($id, $postid, 0, 3);
  181 + }
  182 +
160 $task->target = json_encode($target); 183 $task->target = json_encode($target);
  184 + $task->shop_site = json_encode($shop_site);
  185 + $task->fob_pro = json_encode($fob_pro);
161 $task->save(); 186 $task->save();
162 return $this->response('success', Code::SUCCESS, []); 187 return $this->response('success', Code::SUCCESS, []);
163 } 188 }
164 189
  190 + public function fob_projects(){
  191 + $res = ReInquiryCount::getFobProjects();
  192 + return $this->response('success', Code::SUCCESS, $res);
  193 + }
  194 +
165 /** 195 /**
166 * 验证站点5.0还是6.0, 代理商信息 196 * 验证站点5.0还是6.0, 代理商信息
167 * @param Request $request 197 * @param Request $request
@@ -2,13 +2,16 @@ @@ -2,13 +2,16 @@
2 2
3 namespace App\Models\Inquiry; 3 namespace App\Models\Inquiry;
4 4
  5 +use App\Enums\Common\Code;
5 use App\Helper\Arr; 6 use App\Helper\Arr;
6 use App\Helper\QuanqiusouApi; 7 use App\Helper\QuanqiusouApi;
7 use App\Models\Base; 8 use App\Models\Base;
8 use App\Models\Domain\DomainInfo; 9 use App\Models\Domain\DomainInfo;
9 use App\Models\Project\Project; 10 use App\Models\Project\Project;
10 use App\Models\Task\TaskOwner; 11 use App\Models\Task\TaskOwner;
  12 +use App\Utils\HttpUtils;
11 use Illuminate\Database\Eloquent\Model; 13 use Illuminate\Database\Eloquent\Model;
  14 +use Illuminate\Support\Facades\Cache;
12 15
13 /** 16 /**
14 * Class ReInquiryCount 17 * Class ReInquiryCount
@@ -30,11 +33,12 @@ class ReInquiryCount extends Base @@ -30,11 +33,12 @@ class ReInquiryCount extends Base
30 * @author zbj 33 * @author zbj
31 * @date 2024/10/26 34 * @date 2024/10/26
32 */ 35 */
33 - public static function addInquiryNum($task_id, $domain, $num = 1) 36 + public static function addInquiryNum($task_id, $domain, $num = 1, $type = 1, $company = '')
34 { 37 {
35 $model = self::where('domain', $domain)->first(); 38 $model = self::where('domain', $domain)->first();
36 39
37 if (!$model) { 40 if (!$model) {
  41 + if($type == 1) {
38 //新增时获取公司名 42 //新增时获取公司名
39 $company = ''; 43 $company = '';
40 $domain_info = DomainInfo::where('domain', $domain)->first(); 44 $domain_info = DomainInfo::where('domain', $domain)->first();
@@ -46,10 +50,20 @@ class ReInquiryCount extends Base @@ -46,10 +50,20 @@ class ReInquiryCount extends Base
46 $company = $res['company_name']; 50 $company = $res['company_name'];
47 } 51 }
48 } 52 }
  53 + }
  54 + if($type == 2){
  55 + $company = $domain;
  56 + }
  57 + if($type == 3){
  58 + $fob_list = self::getFobProjects();
  59 + $fob = collect($fob_list)->where('postid', $domain)->first();
  60 + $company = $fob['company'] . ' - ' . $fob['plan'];
  61 + }
49 62
50 $model = new self(); 63 $model = new self();
51 $model->domain = $domain; 64 $model->domain = $domain;
52 $model->company = $company; 65 $model->company = $company;
  66 + $model->type = $type;
53 } 67 }
54 $model->task_ids = $model->task_ids + [$task_id]; 68 $model->task_ids = $model->task_ids + [$task_id];
55 $model->num = $model->num + $num; 69 $model->num = $model->num + $num;
@@ -78,4 +92,15 @@ class ReInquiryCount extends Base @@ -78,4 +92,15 @@ class ReInquiryCount extends Base
78 } 92 }
79 return $tasks; 93 return $tasks;
80 } 94 }
  95 +
  96 + public static function getFobProjects(){
  97 + $cache_key = 'GET_BIND_PROJECT_LIST';
  98 + $res = Cache::get($cache_key);
  99 + if(!$res){
  100 + $res = HttpUtils::get('https://fob.ai.cc/api/get_bind_project_list', []);
  101 + $res = json_decode($res, true)['data'] ?? [];
  102 + Cache::put($cache_key, $res, 120);
  103 + }
  104 + return $res;
  105 + }
81 } 106 }
@@ -67,7 +67,7 @@ class ReInquiryDetail extends Model @@ -67,7 +67,7 @@ class ReInquiryDetail extends Model
67 * @return ReInquiryDetail 67 * @return ReInquiryDetail
68 */ 68 */
69 public static function createInquiry($task_id, $form_id, $re_website, $country, $ip, $name, $email, $phone, $message, $text_id, $device_port, 69 public static function createInquiry($task_id, $form_id, $re_website, $country, $ip, $name, $email, $phone, $message, $text_id, $device_port,
70 - $user_agent, $referrer, $urls, $is_v6, $start_at, $status = self::STATUS_INIT) 70 + $user_agent, $referrer, $urls, $is_v6, $start_at, $status = self::STATUS_INIT, $type = 1)
71 { 71 {
72 $self = new self(); 72 $self = new self();
73 $self->task_id = $task_id; 73 $self->task_id = $task_id;
@@ -88,6 +88,7 @@ class ReInquiryDetail extends Model @@ -88,6 +88,7 @@ class ReInquiryDetail extends Model
88 $self->num = count($urls) + 1; 88 $self->num = count($urls) + 1;
89 $self->start_at = $start_at; 89 $self->start_at = $start_at;
90 $self->status = $status; 90 $self->status = $status;
  91 + $self->type = $type;
91 $self->save(); 92 $self->save();
92 return $self; 93 return $self;
93 } 94 }
@@ -105,6 +105,16 @@ How Much 写成 HM', @@ -105,6 +105,16 @@ How Much 写成 HM',
105 return $value; 105 return $value;
106 } 106 }
107 107
  108 + public function getShopSiteAttribute($value)
  109 + {
  110 + return $value ? json_decode($value, true) : [];
  111 + }
  112 +
  113 + public function getFobProAttribute($value)
  114 + {
  115 + return $value ? json_decode($value, true) : [];
  116 + }
  117 +
108 public function setAiParamAttribute($value) 118 public function setAiParamAttribute($value)
109 { 119 {
110 $this->attributes['ai_param'] = Arr::a2s($value); 120 $this->attributes['ai_param'] = Arr::a2s($value);
@@ -496,6 +496,7 @@ Route::middleware(['aloginauth'])->group(function () { @@ -496,6 +496,7 @@ Route::middleware(['aloginauth'])->group(function () {
496 Route::any('/fb_inquiry_chart', [Aside\Task\AdsController::class, 'fbInquiryChart'])->name('admin.fb_ads_inquiry_chart'); 496 Route::any('/fb_inquiry_chart', [Aside\Task\AdsController::class, 'fbInquiryChart'])->name('admin.fb_ads_inquiry_chart');
497 Route::any('/fb_relay_detail_list', [Aside\Task\AdsController::class, 'fbRelayDetail'])->name('admin.fb_ads_relay_detail_list'); 497 Route::any('/fb_relay_detail_list', [Aside\Task\AdsController::class, 'fbRelayDetail'])->name('admin.fb_ads_relay_detail_list');
498 Route::any('/fb_relay_count', [Aside\Task\AdsController::class, 'fbRelayCount'])->name('admin.fb_relay_count'); 498 Route::any('/fb_relay_count', [Aside\Task\AdsController::class, 'fbRelayCount'])->name('admin.fb_relay_count');
  499 + Route::any('/fob_projects', [Aside\Task\AdsController::class, 'fob_projects'])->name('admin.fob_projects');
499 }); 500 });
500 501
501 //统计所有项目相关 502 //统计所有项目相关