|
...
|
...
|
@@ -197,7 +197,10 @@ class RelayInquiry extends Command |
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// 未设置对法对象
|
|
|
|
if (empty($ad_task['target'])) {
|
|
|
|
$target_num_arr = array_map(function ($item) {
|
|
|
|
return count($item['target']);
|
|
|
|
}, $ad_task);
|
|
|
|
if (!array_sum($target_num_arr)) {
|
|
|
|
$val->status = ReInquiryForm::STATUS_FORGO;
|
|
|
|
$val->remark = '广告任务转发对象为空!';
|
|
|
|
$val->save();
|
|
...
|
...
|
@@ -213,9 +216,14 @@ class RelayInquiry extends Command |
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$this->relayDetail($ad_task, $val);
|
|
|
|
$res = false;
|
|
|
|
foreach ($ad_task as $task){
|
|
|
|
$res += $this->relayDetail($task, $val);
|
|
|
|
}
|
|
|
|
$val->status = $res ? ReInquiryForm::STATUS_SUCCESS : ReInquiryForm::STATUS_FORGO;
|
|
|
|
$val->save();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->logChannel()->info('执行询盘错误:' . $e->getMessage());
|
|
|
|
$this->logChannel()->info('执行询盘错误:',[$e->getMessage(), $e->getFile(), $e->getLine()]);
|
|
|
|
$this->output('执行询盘错误:' . $e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
...
|
...
|
@@ -294,9 +302,7 @@ class RelayInquiry extends Command |
|
|
|
|
|
|
|
if (empty($random_data)) {
|
|
|
|
$this->logChannel()->info('当前任务未发现转发对象!', ['广告任务ID:' . $task['id'], '询盘ID:' . $form->id]);
|
|
|
|
$form->status = ReInquiryForm::STATUS_FORGO;
|
|
|
|
$form->remark = '当前任务未发现转发对象,广告ID: ' . $form->ad_id . '!';
|
|
|
|
$form->save();
|
|
|
|
$form->remark = $form->remark . '当前任务未发现转发对象,广告ID: ' . $form->ad_id . '!';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -385,12 +391,22 @@ class RelayInquiry extends Command |
|
|
|
//开启文案替换
|
|
|
|
if ($task['is_replace_text'] == 2) {
|
|
|
|
//AI生成
|
|
|
|
$message = $this->ai_send($task['ai_param'], $message);
|
|
|
|
if(!$message){
|
|
|
|
$this->output('AI文案生成失败');
|
|
|
|
continue;
|
|
|
|
$error = 0;
|
|
|
|
while ($error<3){
|
|
|
|
$message = $this->ai_send($task['ai_param'], $message);
|
|
|
|
if(!$message){
|
|
|
|
$this->output('AI文案生成失败');
|
|
|
|
$error++;
|
|
|
|
if($error==2){
|
|
|
|
$task['is_replace_text'] = 1;
|
|
|
|
$this->output('AI文案生成失败,使用文案库');
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif ($task['is_replace_text'] == 1 || strlen($message) <= 4) {
|
|
|
|
}
|
|
|
|
if ($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();
|
|
...
|
...
|
@@ -444,9 +460,6 @@ class RelayInquiry extends Command |
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$form->status = ReInquiryForm::STATUS_SUCCESS;
|
|
|
|
$form->save();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -468,12 +481,15 @@ class RelayInquiry extends Command |
|
|
|
*/
|
|
|
|
public function getAdTask($ad_id)
|
|
|
|
{
|
|
|
|
$cache_key = 'inquiry_ads_task';
|
|
|
|
$cache_key = 'inquiry_ads_tasks';
|
|
|
|
$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', 'ai_param']);
|
|
|
|
$array = [];
|
|
|
|
foreach ($ads as $key=>$val) {
|
|
|
|
$array[$val->ad_id] = $val;
|
|
|
|
$ad_ids = explode(',', $val['ad_id']);
|
|
|
|
foreach ($ad_ids as $ad_id){
|
|
|
|
$array[$ad_id][] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($array)
|
|
|
|
Cache::put($cache_key, $array, 60);
|
|
...
|
...
|
@@ -584,13 +600,15 @@ class RelayInquiry extends Command |
|
|
|
$lang = $translateSl['texts']['sl'] ?? 'en';
|
|
|
|
if ($lang == 'en' || Str::contains($lang, 'zh')) {
|
|
|
|
$language = '英文';
|
|
|
|
$lang = 'en';
|
|
|
|
}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('{language}', Arr::random(explode("\r\n", $language)), $ai_command);
|
|
|
|
$ai_command = str_replace('{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);
|
|
|
|
//中括号里的根据概率使用
|
|
...
|
...
|
@@ -609,8 +627,10 @@ class RelayInquiry extends Command |
|
|
|
}
|
|
|
|
|
|
|
|
$text = Gpt::instance()->openai_chat_qqs($ai_command);
|
|
|
|
if ($lang != 'en' && !Str::contains($lang, 'zh')) {
|
|
|
|
$text = Translate::tran($text, $lang);
|
|
|
|
}
|
|
|
|
$this->logChannel()->info("AI询盘文案", [$ai_command, $text]);
|
|
|
|
$text = Common::deal_keywords($text);
|
|
|
|
return Common::deal_str($text);
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|