作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into master-server

@@ -7,7 +7,10 @@ @@ -7,7 +7,10 @@
7 */ 7 */
8 namespace App\Console\Commands\Inquiry; 8 namespace App\Console\Commands\Inquiry;
9 9
  10 +use App\Helper\Common;
  11 +use App\Helper\Gpt;
10 use App\Helper\Translate; 12 use App\Helper\Translate;
  13 +use App\Models\Ai\AiCommand;
11 use App\Models\Inquiry\ReInquiryDetail; 14 use App\Models\Inquiry\ReInquiryDetail;
12 use App\Models\Inquiry\ReInquiryDetailLog; 15 use App\Models\Inquiry\ReInquiryDetailLog;
13 use App\Models\Inquiry\ReInquiryForm; 16 use App\Models\Inquiry\ReInquiryForm;
@@ -379,8 +382,17 @@ class RelayInquiry extends Command @@ -379,8 +382,17 @@ class RelayInquiry extends Command
379 $this->output('转发内容'); 382 $this->output('转发内容');
380 $message = $form->message; 383 $message = $form->message;
381 $message_id = 0; 384 $message_id = 0;
382 - //开启文案替换 配置替换或者字符少于4个,直接替换文案  
383 - if($task['is_replace_text'] || strlen($message) <= 4) { 385 + //开启文案替换
  386 + if ($task['is_replace_text'] == 2) {
  387 + //AI生成
  388 + $message = $this->ai_send($task['ai_param'], $message);
  389 + if(!$message){
  390 + $this->output('AI文案生成失败');
  391 + continue;
  392 + }
  393 + } elseif ($task['is_replace_text'] == 1 || strlen($message) <= 4) {
  394 + //配置文案库替换或者字符少于4个,直接替换文案
  395 +
384 $use_ids = ReInquiryDetail::where(['re_website' => $domain])->where('status', '<>', ReInquiryDetail::STATUS_FAIL)->pluck('text_id')->toArray(); 396 $use_ids = ReInquiryDetail::where(['re_website' => $domain])->where('status', '<>', ReInquiryDetail::STATUS_FAIL)->pluck('text_id')->toArray();
385 $text = ReInquiryText::whereNotIn('id', $use_ids)->where('status', ReInquiryText::STATUS_USABLE)->inRandomOrder()->first(); 397 $text = ReInquiryText::whereNotIn('id', $use_ids)->where('status', ReInquiryText::STATUS_USABLE)->inRandomOrder()->first();
386 $message = $text->content; 398 $message = $text->content;
@@ -397,7 +409,7 @@ class RelayInquiry extends Command @@ -397,7 +409,7 @@ class RelayInquiry extends Command
397 $lang = $translateSl['texts']['sl'] ?? 'en'; 409 $lang = $translateSl['texts']['sl'] ?? 'en';
398 } 410 }
399 411
400 - if ($lang != 'en' && Str::contains($lang, 'zh')) { 412 + if ($lang != 'en' && !Str::contains($lang, 'zh')) {
401 $message = Translate::tran($message, $lang); 413 $message = Translate::tran($message, $lang);
402 } 414 }
403 } 415 }
@@ -458,7 +470,7 @@ class RelayInquiry extends Command @@ -458,7 +470,7 @@ class RelayInquiry extends Command
458 { 470 {
459 $cache_key = 'inquiry_ads_task'; 471 $cache_key = 'inquiry_ads_task';
460 $ads = Cache::get($cache_key, function () use ($cache_key) { 472 $ads = Cache::get($cache_key, function () use ($cache_key) {
461 - $ads = ReInquiryTask::where(['status' => ReInquiryTask::STATUS_OPEN])->get(['id', 'ad_id', 'num', 'target', 'is_replace_text']); 473 + $ads = ReInquiryTask::where(['status' => ReInquiryTask::STATUS_OPEN])->get(['id', 'ad_id', 'num', 'target', 'is_replace_text', 'ai_param']);
462 $array = []; 474 $array = [];
463 foreach ($ads as $key=>$val) { 475 foreach ($ads as $key=>$val) {
464 $array[$val->ad_id] = $val; 476 $array[$val->ad_id] = $val;
@@ -562,6 +574,46 @@ class RelayInquiry extends Command @@ -562,6 +574,46 @@ class RelayInquiry extends Command
562 } 574 }
563 } 575 }
564 576
  577 + public function ai_send($ai_param, $incontent)
  578 + {
  579 + $ai_command = AiCommand::where('key', 'fb_inquiry_text')->value('ai');
  580 + if (!$ai_command) {
  581 + return '';
  582 + }
  583 + $translateSl = Translate::translateSl($incontent);
  584 + $lang = $translateSl['texts']['sl'] ?? 'en';
  585 + if ($lang == 'en' || Str::contains($lang, 'zh')) {
  586 + $language = '英文';
  587 + }else{
  588 + $language = Translate::getTls($lang);
  589 + }
  590 + $ai_command = str_replace('{mkeywords}', Arr::random(explode("\r\n", $ai_param['mkeywords'])), $ai_command);
  591 + $ai_command = str_replace('{incontent}', Arr::random(explode("\r\n", $incontent)), $ai_command);
  592 + $ai_command = str_replace('{characters}', Arr::random(explode("\r\n", $ai_param['characters'])), $ai_command);
  593 + $ai_command = str_replace('{language}', Arr::random(explode("\r\n", $language)), $ai_command);
  594 + $ai_command = str_replace('{inkeywords}', Arr::random(explode("\r\n", $ai_param['inkeywords'])), $ai_command);
  595 + $ai_command = str_replace('{suoxie}', Arr::random(explode("\r\n", $ai_param['suoxie'])), $ai_command);
  596 + //中括号里的根据概率使用
  597 + preg_match_all("/\[([^\]]+)\]/", $ai_command, $matches);
  598 + foreach ($matches[1] as $k => $match){
  599 + //按比例使用
  600 + $matche_arr = explode('|', $match);
  601 + $percentage = intval(trim($matche_arr[0], "%"));
  602 + if(rand(1,100) <= $percentage){
  603 + //使用
  604 + $ai_command = str_replace($matches[0][$k], $matche_arr[1], $ai_command);
  605 + }else{
  606 + //删除中括号
  607 + $ai_command = str_replace($matches[0][$k], '', $ai_command);
  608 + }
  609 + }
  610 +
  611 + $text = Gpt::instance()->openai_chat_qqs($ai_command);
  612 + $this->logChannel()->info("AI询盘文案", [$ai_command, $text]);
  613 + $text = Common::deal_keywords($text);
  614 + return Common::deal_str($text);
  615 + }
  616 +
565 /** 617 /**
566 * @return \Psr\Log\LoggerInterface 618 * @return \Psr\Log\LoggerInterface
567 */ 619 */
@@ -126,14 +126,18 @@ class NoticeController extends BaseController @@ -126,14 +126,18 @@ class NoticeController extends BaseController
126 return $this->error('other_domain参数必须为数组'); 126 return $this->error('other_domain参数必须为数组');
127 } 127 }
128 128
129 - $origin_array = parse_url($origin_domain);  
130 - $origin_domain = $origin_array['host'] ?? ''; 129 + if(strpos($origin_domain,'http') !== false){
  130 + $origin_array = parse_url($origin_domain);
  131 + $origin_domain = $origin_array['host'] ?? '';
  132 + }
131 if (empty($origin_domain)) { 133 if (empty($origin_domain)) {
132 return $this->error('origin_domain参数不能为空'); 134 return $this->error('origin_domain参数不能为空');
133 } 135 }
134 136
135 - $target_array = parse_url($target_domain);  
136 - $target_domain = $target_array['host'] ?? ''; 137 + if(strpos($target_domain,'http') !== false){
  138 + $target_array = parse_url($target_domain);
  139 + $target_domain = $target_array['host'] ?? '';
  140 + }
137 if (empty($target_domain)) { 141 if (empty($target_domain)) {
138 return $this->error('target_domain参数不能为空'); 142 return $this->error('target_domain参数不能为空');
139 } 143 }