合并分支 'akun' 到 'master'
Akun 查看合并请求 !2907
正在显示
1 个修改的文件
包含
70 行增加
和
0 行删除
| @@ -3,13 +3,19 @@ | @@ -3,13 +3,19 @@ | ||
| 3 | namespace App\Console\Commands\Test; | 3 | namespace App\Console\Commands\Test; |
| 4 | 4 | ||
| 5 | use App\Helper\Arr; | 5 | use App\Helper\Arr; |
| 6 | +use App\Helper\Common; | ||
| 7 | +use App\Helper\Gpt; | ||
| 8 | +use App\Http\Logic\Aside\Optimize\InquiryForwardLogic; | ||
| 6 | use App\Http\Logic\Bside\Product\CategoryLogic; | 9 | use App\Http\Logic\Bside\Product\CategoryLogic; |
| 10 | +use App\Models\Ai\AiCommand; | ||
| 7 | use App\Models\Com\Notify; | 11 | use App\Models\Com\Notify; |
| 8 | use App\Models\CustomModule\CustomModuleContent; | 12 | use App\Models\CustomModule\CustomModuleContent; |
| 9 | use App\Models\Devops\ServerConfig; | 13 | use App\Models\Devops\ServerConfig; |
| 10 | use App\Models\Devops\ServersIp; | 14 | use App\Models\Devops\ServersIp; |
| 11 | use App\Models\Domain\DomainCreateTask; | 15 | use App\Models\Domain\DomainCreateTask; |
| 12 | use App\Models\Domain\DomainInfo; | 16 | use App\Models\Domain\DomainInfo; |
| 17 | +use App\Models\Inquiry\InquiryInfo; | ||
| 18 | +use App\Models\Inquiry\InquiryRelayAi; | ||
| 13 | use App\Models\Product\Category; | 19 | use App\Models\Product\Category; |
| 14 | use App\Models\Product\CategoryRelated; | 20 | use App\Models\Product\CategoryRelated; |
| 15 | use App\Models\Product\Keyword; | 21 | use App\Models\Product\Keyword; |
| @@ -43,7 +49,71 @@ class Temp extends Command | @@ -43,7 +49,71 @@ class Temp extends Command | ||
| 43 | 49 | ||
| 44 | public function handle() | 50 | public function handle() |
| 45 | { | 51 | { |
| 52 | +// $this->inquiryAiCheck(17259, 27450); | ||
| 53 | + $this->inquiryAiCheck(17259, 17261); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public function inquiryAiCheck($start_id, $end_id) | ||
| 57 | + { | ||
| 58 | + //AI匹配询盘关键词 | ||
| 59 | + $ai_info = AiCommand::select(['ai'])->where('key', 'inquiry_keyword_extract')->first(); | ||
| 60 | + if (!$ai_info) { | ||
| 61 | + $this->output('AI重写指令[inquiry_keyword_extract]未配置'); | ||
| 62 | + return true; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + 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) { | ||
| 66 | + foreach ($inquiries as $inquiry) { | ||
| 67 | + $inquiry_ai_info = InquiryRelayAi::where('form_id', $inquiry['id'])->first(); | ||
| 68 | + if (!$inquiry_ai_info) { | ||
| 69 | + | ||
| 70 | + $ai_command = $ai_info['ai']; | ||
| 71 | + $ai_command = str_replace('{title}', $inquiry['url_title'], $ai_command); | ||
| 72 | + $ai_command = str_replace('{keywords}', $inquiry['url_keyword'], $ai_command); | ||
| 73 | + $ai_command = str_replace('{content}', $inquiry['message'], $ai_command); | ||
| 74 | + $ai_keyword = Common::deal_str(Gpt::instance()->openai_chat_qqs($ai_command)); | ||
| 75 | + if (!$ai_keyword) { | ||
| 76 | + $this->output('询盘ID:' . $inquiry['id'] . ',AI提取询盘关键词失败'); | ||
| 77 | + continue; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + //关键词查询项目着陆页:先精准匹配,没有数据再全文索引匹配 | ||
| 81 | + $inquiryForwardLogic = new InquiryForwardLogic(); | ||
| 82 | + $forward_list = $inquiryForwardLogic->searchKeywords($ai_keyword, 2, 3); | ||
| 83 | + if (empty($forward_list)) { | ||
| 84 | + $forward_list = $inquiryForwardLogic->searchKeywords($ai_keyword, 1, 3); | ||
| 85 | + if (empty($forward_list)) { | ||
| 86 | + $this->output('询盘ID:' . $inquiry['id'] . ',根据关键词[' . $ai_keyword . ']查询项目着陆页为空'); | ||
| 87 | + continue; | ||
| 88 | + } | ||
| 89 | + } | ||
| 46 | 90 | ||
| 91 | + //重写询盘内容 | ||
| 92 | + $ai_message_list = []; | ||
| 93 | + for ($i = 0; $i < count($forward_list); $i++) { | ||
| 94 | + $message_re = $inquiryForwardLogic->aiRewrite($inquiry['message'], $inquiry['url_title'], $inquiry['url_keyword']); | ||
| 95 | + if (isset($message_re['ai_message']) && $message_re['ai_message']) { | ||
| 96 | + $ai_message_list[] = $message_re['ai_message']; | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | + if (empty($ai_message_list)) { | ||
| 100 | + $this->output('询盘ID:' . $inquiry['id'] . ',AI重写询盘内容失败'); | ||
| 101 | + continue; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + $inquiry_ai_info = new InquiryRelayAi(); | ||
| 105 | + $inquiry_ai_info->form_id = $inquiry['id']; | ||
| 106 | + $inquiry_ai_info->keywords = $ai_keyword; | ||
| 107 | + $inquiry_ai_info->forward_url = Arr::a2s($forward_list); | ||
| 108 | + $inquiry_ai_info->message_ai = Arr::a2s($ai_message_list); | ||
| 109 | + $inquiry_ai_info->save(); | ||
| 110 | + | ||
| 111 | + $this->output('询盘ID:' . $inquiry['id'] . ',success'); | ||
| 112 | + } | ||
| 113 | + } | ||
| 114 | + }); | ||
| 115 | + | ||
| 116 | + return true; | ||
| 47 | } | 117 | } |
| 48 | 118 | ||
| 49 | /** | 119 | /** |
-
请 注册 或 登录 后发表评论