|
...
|
...
|
@@ -3,13 +3,19 @@ |
|
|
|
namespace App\Console\Commands\Test;
|
|
|
|
|
|
|
|
use App\Helper\Arr;
|
|
|
|
use App\Helper\Common;
|
|
|
|
use App\Helper\Gpt;
|
|
|
|
use App\Http\Logic\Aside\Optimize\InquiryForwardLogic;
|
|
|
|
use App\Http\Logic\Bside\Product\CategoryLogic;
|
|
|
|
use App\Models\Ai\AiCommand;
|
|
|
|
use App\Models\Com\Notify;
|
|
|
|
use App\Models\CustomModule\CustomModuleContent;
|
|
|
|
use App\Models\Devops\ServerConfig;
|
|
|
|
use App\Models\Devops\ServersIp;
|
|
|
|
use App\Models\Domain\DomainCreateTask;
|
|
|
|
use App\Models\Domain\DomainInfo;
|
|
|
|
use App\Models\Inquiry\InquiryInfo;
|
|
|
|
use App\Models\Inquiry\InquiryRelayAi;
|
|
|
|
use App\Models\Product\Category;
|
|
|
|
use App\Models\Product\CategoryRelated;
|
|
|
|
use App\Models\Product\Keyword;
|
|
...
|
...
|
@@ -43,7 +49,71 @@ class Temp extends Command |
|
|
|
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
// $this->inquiryAiCheck(17259, 27450);
|
|
|
|
$this->inquiryAiCheck(17259, 17261);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function inquiryAiCheck($start_id, $end_id)
|
|
|
|
{
|
|
|
|
//AI匹配询盘关键词
|
|
|
|
$ai_info = AiCommand::select(['ai'])->where('key', 'inquiry_keyword_extract')->first();
|
|
|
|
if (!$ai_info) {
|
|
|
|
$this->output('AI重写指令[inquiry_keyword_extract]未配置');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
InquiryInfo::select(['id', 'message', 'url_title', 'url_keyword'])->whereBetween('id', [$start_id, $end_id])->where('status', InquiryInfo::STATUS_INIT)->chunk(100, function ($inquiries) use ($ai_info) {
|
|
|
|
foreach ($inquiries as $inquiry) {
|
|
|
|
$inquiry_ai_info = InquiryRelayAi::where('form_id', $inquiry['id'])->first();
|
|
|
|
if (!$inquiry_ai_info) {
|
|
|
|
|
|
|
|
$ai_command = $ai_info['ai'];
|
|
|
|
$ai_command = str_replace('{title}', $inquiry['url_title'], $ai_command);
|
|
|
|
$ai_command = str_replace('{keywords}', $inquiry['url_keyword'], $ai_command);
|
|
|
|
$ai_command = str_replace('{content}', $inquiry['message'], $ai_command);
|
|
|
|
$ai_keyword = Common::deal_str(Gpt::instance()->openai_chat_qqs($ai_command));
|
|
|
|
if (!$ai_keyword) {
|
|
|
|
$this->output('询盘ID:' . $inquiry['id'] . ',AI提取询盘关键词失败');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//关键词查询项目着陆页:先精准匹配,没有数据再全文索引匹配
|
|
|
|
$inquiryForwardLogic = new InquiryForwardLogic();
|
|
|
|
$forward_list = $inquiryForwardLogic->searchKeywords($ai_keyword, 2, 3);
|
|
|
|
if (empty($forward_list)) {
|
|
|
|
$forward_list = $inquiryForwardLogic->searchKeywords($ai_keyword, 1, 3);
|
|
|
|
if (empty($forward_list)) {
|
|
|
|
$this->output('询盘ID:' . $inquiry['id'] . ',根据关键词[' . $ai_keyword . ']查询项目着陆页为空');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//重写询盘内容
|
|
|
|
$ai_message_list = [];
|
|
|
|
for ($i = 0; $i < count($forward_list); $i++) {
|
|
|
|
$message_re = $inquiryForwardLogic->aiRewrite($inquiry['message'], $inquiry['url_title'], $inquiry['url_keyword']);
|
|
|
|
if (isset($message_re['ai_message']) && $message_re['ai_message']) {
|
|
|
|
$ai_message_list[] = $message_re['ai_message'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (empty($ai_message_list)) {
|
|
|
|
$this->output('询盘ID:' . $inquiry['id'] . ',AI重写询盘内容失败');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$inquiry_ai_info = new InquiryRelayAi();
|
|
|
|
$inquiry_ai_info->form_id = $inquiry['id'];
|
|
|
|
$inquiry_ai_info->keywords = $ai_keyword;
|
|
|
|
$inquiry_ai_info->forward_url = Arr::a2s($forward_list);
|
|
|
|
$inquiry_ai_info->message_ai = Arr::a2s($ai_message_list);
|
|
|
|
$inquiry_ai_info->save();
|
|
|
|
|
|
|
|
$this->output('询盘ID:' . $inquiry['id'] . ',success');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
|