|
...
|
...
|
@@ -7,7 +7,10 @@ |
|
|
|
*/
|
|
|
|
namespace App\Console\Commands\Inquiry;
|
|
|
|
|
|
|
|
use App\Helper\Common;
|
|
|
|
use App\Helper\Gpt;
|
|
|
|
use App\Helper\Translate;
|
|
|
|
use App\Models\Ai\AiCommand;
|
|
|
|
use App\Models\Inquiry\ReInquiryDetail;
|
|
|
|
use App\Models\Inquiry\ReInquiryDetailLog;
|
|
|
|
use App\Models\Inquiry\ReInquiryForm;
|
|
...
|
...
|
@@ -379,8 +382,17 @@ class RelayInquiry extends Command |
|
|
|
$this->output('转发内容');
|
|
|
|
$message = $form->message;
|
|
|
|
$message_id = 0;
|
|
|
|
//开启文案替换 配置替换或者字符少于4个,直接替换文案
|
|
|
|
if($task['is_replace_text'] || strlen($message) <= 4) {
|
|
|
|
//开启文案替换
|
|
|
|
if ($task['is_replace_text'] == 2) {
|
|
|
|
//AI生成
|
|
|
|
$message = $this->ai_send($task['ai_param'], $message);
|
|
|
|
if(!$message){
|
|
|
|
$this->output('AI文案生成失败');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} elseif ($task['is_replace_text'] == 1 || strlen($message) <= 4) {
|
|
|
|
//配置文案库替换或者字符少于4个,直接替换文案
|
|
|
|
|
|
|
|
$use_ids = ReInquiryDetail::where(['re_website' => $domain])->where('status', '<>', ReInquiryDetail::STATUS_FAIL)->pluck('text_id')->toArray();
|
|
|
|
$text = ReInquiryText::whereNotIn('id', $use_ids)->where('status', ReInquiryText::STATUS_USABLE)->inRandomOrder()->first();
|
|
|
|
$message = $text->content;
|
|
...
|
...
|
@@ -397,7 +409,7 @@ class RelayInquiry extends Command |
|
|
|
$lang = $translateSl['texts']['sl'] ?? 'en';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($lang != 'en' && Str::contains($lang, 'zh')) {
|
|
|
|
if ($lang != 'en' && !Str::contains($lang, 'zh')) {
|
|
|
|
$message = Translate::tran($message, $lang);
|
|
|
|
}
|
|
|
|
}
|
|
...
|
...
|
@@ -458,7 +470,7 @@ class RelayInquiry extends Command |
|
|
|
{
|
|
|
|
$cache_key = 'inquiry_ads_task';
|
|
|
|
$ads = Cache::get($cache_key, function () use ($cache_key) {
|
|
|
|
$ads = ReInquiryTask::where(['status' => ReInquiryTask::STATUS_OPEN])->get(['id', 'ad_id', 'num', 'target', 'is_replace_text']);
|
|
|
|
$ads = ReInquiryTask::where(['status' => ReInquiryTask::STATUS_OPEN])->get(['id', 'ad_id', 'num', 'target', 'is_replace_text', 'ai_param']);
|
|
|
|
$array = [];
|
|
|
|
foreach ($ads as $key=>$val) {
|
|
|
|
$array[$val->ad_id] = $val;
|
|
...
|
...
|
@@ -562,6 +574,46 @@ class RelayInquiry extends Command |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ai_send($ai_param, $incontent)
|
|
|
|
{
|
|
|
|
$ai_command = AiCommand::where('key', 'fb_inquiry_text')->value('ai');
|
|
|
|
if (!$ai_command) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
$translateSl = Translate::translateSl($incontent);
|
|
|
|
$lang = $translateSl['texts']['sl'] ?? 'en';
|
|
|
|
if ($lang == 'en' || Str::contains($lang, 'zh')) {
|
|
|
|
$language = '英文';
|
|
|
|
}else{
|
|
|
|
$language = Translate::getTls($lang);
|
|
|
|
}
|
|
|
|
$ai_command = str_replace('{mkeywords}', Arr::random(explode("\r\n", $ai_param['mkeywords'])), $ai_command);
|
|
|
|
$ai_command = str_replace('{incontent}', Arr::random(explode("\r\n", $incontent)), $ai_command);
|
|
|
|
$ai_command = str_replace('{characters}', Arr::random(explode("\r\n", $ai_param['characters'])), $ai_command);
|
|
|
|
$ai_command = str_replace('{language}', Arr::random(explode("\r\n", $language)), $ai_command);
|
|
|
|
$ai_command = str_replace('{inkeywords}', Arr::random(explode("\r\n", $ai_param['inkeywords'])), $ai_command);
|
|
|
|
$ai_command = str_replace('{suoxie}', Arr::random(explode("\r\n", $ai_param['suoxie'])), $ai_command);
|
|
|
|
//中括号里的根据概率使用
|
|
|
|
preg_match_all("/\[([^\]]+)\]/", $ai_command, $matches);
|
|
|
|
foreach ($matches[1] as $k => $match){
|
|
|
|
//按比例使用
|
|
|
|
$matche_arr = explode('|', $match);
|
|
|
|
$percentage = intval(trim($matche_arr[0], "%"));
|
|
|
|
if(rand(1,100) <= $percentage){
|
|
|
|
//使用
|
|
|
|
$ai_command = str_replace($matches[0][$k], $matche_arr[1], $ai_command);
|
|
|
|
}else{
|
|
|
|
//删除中括号
|
|
|
|
$ai_command = str_replace($matches[0][$k], '', $ai_command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$text = Gpt::instance()->openai_chat_qqs($ai_command);
|
|
|
|
$this->logChannel()->info("AI询盘文案", [$ai_command, $text]);
|
|
|
|
$text = Common::deal_keywords($text);
|
|
|
|
return Common::deal_str($text);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Psr\Log\LoggerInterface
|
|
|
|
*/
|
...
|
...
|
|