作者 lyh

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

@@ -8,9 +8,15 @@ @@ -8,9 +8,15 @@
8 8
9 namespace App\Console\Commands\Inquiry; 9 namespace App\Console\Commands\Inquiry;
10 10
  11 +use App\Helper\Arr;
  12 +use App\Helper\Common;
  13 +use App\Helper\Gpt;
11 use App\Helper\Translate; 14 use App\Helper\Translate;
12 use App\Helper\Validate; 15 use App\Helper\Validate;
  16 +use App\Http\Logic\Aside\Optimize\InquiryForwardLogic;
  17 +use App\Models\Ai\AiCommand;
13 use App\Models\Inquiry\InquiryInfo; 18 use App\Models\Inquiry\InquiryInfo;
  19 +use App\Models\Inquiry\InquiryRelayAi;
14 use App\Models\Project\InquiryFilterConfig; 20 use App\Models\Project\InquiryFilterConfig;
15 use App\Models\Project\Project; 21 use App\Models\Project\Project;
16 use App\Services\InquiryRelayService; 22 use App\Services\InquiryRelayService;
@@ -221,7 +227,59 @@ class SyncInquiryRelay extends Command @@ -221,7 +227,59 @@ class SyncInquiryRelay extends Command
221 $remark = $this->inquiryFilter($unique_sign, $country, $data['ip'], $data['message'], $data['refer'], $data['email'], $data['phone'], $data['name']); 227 $remark = $this->inquiryFilter($unique_sign, $country, $data['ip'], $data['message'], $data['refer'], $data['email'], $data['phone'], $data['name']);
222 $status = $remark ? InquiryInfo::STATUS_INVALID : InquiryInfo::STATUS_INIT; 228 $status = $remark ? InquiryInfo::STATUS_INVALID : InquiryInfo::STATUS_INIT;
223 229
224 - $model->createInquiry($data['name'], $data['phone'], $data['email'], $data['ip'], $country, $data['message'], $message_cn, $type, $data['time'], $data['refer'], $data['title'], $keywords, $message_sign, $data['origin_key'], $data['image'], $email_status, $phone_status, $unique_sign, $status, $remark); 230 + $form_id = $model->createInquiry($data['name'], $data['phone'], $data['email'], $data['ip'], $country, $data['message'], $message_cn, $type, $data['time'], $data['refer'], $data['title'], $keywords, $message_sign, $data['origin_key'], $data['image'], $email_status, $phone_status, $unique_sign, $status, $remark);
  231 +
  232 + if ($form_id && $status == InquiryInfo::STATUS_INIT) {
  233 + $inquiry_ai_info = InquiryRelayAi::where('form_id', $form_id)->first();
  234 + if (!$inquiry_ai_info) {
  235 + //AI匹配询盘关键词
  236 + $ai_info = AiCommand::select(['ai'])->where('key', 'inquiry_keyword_extract')->first();
  237 + if (!$ai_info) {
  238 + $this->output('AI重写指令[inquiry_keyword_extract]未配置');
  239 + return true;
  240 + }
  241 +
  242 + $ai_command = $ai_info['ai'];
  243 + $ai_command = str_replace('{title}', $data['title'], $ai_command);
  244 + $ai_command = str_replace('{keywords}', $keywords, $ai_command);
  245 + $ai_command = str_replace('{content}', $data['message'], $ai_command);
  246 + $ai_keyword = Common::deal_str(Gpt::instance()->openai_chat_qqs($ai_command));
  247 + if (!$ai_keyword) {
  248 + $this->output('询盘ID:' . $form_id . ',AI提取询盘关键词失败');
  249 + return true;
  250 + }
  251 +
  252 + //关键词查询项目着陆页
  253 + $inquiryForwardLogic = new InquiryForwardLogic();
  254 + $forward_list = $inquiryForwardLogic->searchKeywords($ai_keyword, 2, 3);
  255 + if (empty($forward_list)) {
  256 + $this->output('询盘ID:' . $form_id . ',根据关键词[' . $ai_keyword . ']查询项目着陆页为空');
  257 + return true;
  258 + }
  259 +
  260 + //重写询盘内容
  261 + $ai_message_list = [];
  262 + for ($i = 0; $i < count($forward_list); $i++) {
  263 + $message_re = $inquiryForwardLogic->aiRewrite($data['message'], $data['title'], $keywords);
  264 + if (isset($message_re['ai_message']) && $message_re['ai_message']) {
  265 + $ai_message_list[] = $message_re['ai_message'];
  266 + }
  267 + }
  268 + if (empty($ai_message_list)) {
  269 + $this->output('询盘ID:' . $form_id . ',AI重写询盘内容失败');
  270 + return true;
  271 + }
  272 +
  273 +
  274 + $inquiry_ai_info = new InquiryRelayAi();
  275 + $inquiry_ai_info->form_id = $form_id;
  276 + $inquiry_ai_info->keywords = $ai_keyword;
  277 + $inquiry_ai_info->forward_url = Arr::a2s($forward_list);
  278 + $inquiry_ai_info->message_ai = Arr::a2s($ai_message_list);
  279 + $inquiry_ai_info->save();
  280 + }
  281 + }
  282 +
225 return true; 283 return true;
226 } 284 }
227 285
@@ -152,7 +152,10 @@ class InquiryForwardController extends BaseController @@ -152,7 +152,10 @@ class InquiryForwardController extends BaseController
152 'type.required' => '搜索类型不能为空', 152 'type.required' => '搜索类型不能为空',
153 ]); 153 ]);
154 154
155 - $lists = $inquiryForwardLogic->searchKeywords(); 155 + $keywords = $this->param['keywords'];
  156 + $type = $this->param['type'];
  157 + $num = $this->param['num'] ?? 3;
  158 + $lists = $inquiryForwardLogic->searchKeywords($keywords, $type, $num);
156 $this->response('success', Code::SUCCESS, $lists); 159 $this->response('success', Code::SUCCESS, $lists);
157 } 160 }
158 161
@@ -172,7 +175,8 @@ class InquiryForwardController extends BaseController @@ -172,7 +175,8 @@ class InquiryForwardController extends BaseController
172 'message.required' => '需要重写的文案不能为空', 175 'message.required' => '需要重写的文案不能为空',
173 ]); 176 ]);
174 177
175 - $data = $inquiryForwardLogic->aiRewrite(); 178 + $message = $this->param['message'];
  179 + $data = $inquiryForwardLogic->aiRewrite($message);
176 $this->response('success', Code::SUCCESS, $data); 180 $this->response('success', Code::SUCCESS, $data);
177 } 181 }
178 182
@@ -846,6 +846,9 @@ class ProjectController extends BaseController @@ -846,6 +846,9 @@ class ProjectController extends BaseController
846 $domain_array = parse_url($domain_pro ? $domain_pro->domain : ''); 846 $domain_array = parse_url($domain_pro ? $domain_pro->domain : '');
847 $domain = $domain_array['host'] ?? $domain_array['path']; 847 $domain = $domain_array['host'] ?? $domain_array['path'];
848 } 848 }
  849 + $item['channel']['channel'] = Channel::where('id', $item['channel']['channel_id'])->value('title');
  850 + $item['channel']['zone'] = Zone::where('id', $item['channel']['zone_id'])->value('title');
  851 + $item['channel']['user'] = User::where('id', $item['channel']['user_id'])->value('name');
849 $manageHr = new ManageHr(); 852 $manageHr = new ManageHr();
850 $param = [ 853 $param = [
851 "id" => $item['id'], 854 "id" => $item['id'],
@@ -11,6 +11,7 @@ use App\Models\Inquiry\AreaTimezone; @@ -11,6 +11,7 @@ use App\Models\Inquiry\AreaTimezone;
11 use App\Models\Inquiry\InquiryInfo; 11 use App\Models\Inquiry\InquiryInfo;
12 use App\Models\Inquiry\InquiryProject; 12 use App\Models\Inquiry\InquiryProject;
13 use App\Models\Inquiry\InquiryProjectRoute; 13 use App\Models\Inquiry\InquiryProjectRoute;
  14 +use App\Models\Inquiry\InquiryRelayAi;
14 use App\Models\Inquiry\InquiryRelayDetail; 15 use App\Models\Inquiry\InquiryRelayDetail;
15 use App\Models\Inquiry\InquiryRelayDetailLog; 16 use App\Models\Inquiry\InquiryRelayDetailLog;
16 use Illuminate\Support\Arr; 17 use Illuminate\Support\Arr;
@@ -102,6 +103,21 @@ class InquiryForwardLogic extends BaseLogic @@ -102,6 +103,21 @@ class InquiryForwardLogic extends BaseLogic
102 if ($info === false) { 103 if ($info === false) {
103 $this->fail('获取询盘详情失败'); 104 $this->fail('获取询盘详情失败');
104 } 105 }
  106 +
  107 + $keywords_ai = '';
  108 + $forward_url_ai = [];
  109 + $message_ai = [];
  110 + $inquiry_ai_model = new InquiryRelayAi();
  111 + $ai_info = $inquiry_ai_model->read(['form_id' => $this->param['id']], ['keywords', 'forward_url', 'message_ai']);
  112 + if ($ai_info) {
  113 + $keywords_ai = $ai_info['keywords'];
  114 + $forward_url_ai = json_decode($ai_info['forward_url'], true);
  115 + $message_ai = json_decode($ai_info['message_ai'], true);
  116 + }
  117 + $info['keywords_ai'] = $keywords_ai;
  118 + $info['forward_url_ai'] = $forward_url_ai;
  119 + $info['message_ai'] = $message_ai;
  120 +
105 return $this->success($info); 121 return $this->success($info);
106 } 122 }
107 123
@@ -240,22 +256,24 @@ class InquiryForwardLogic extends BaseLogic @@ -240,22 +256,24 @@ class InquiryForwardLogic extends BaseLogic
240 256
241 /** 257 /**
242 * 关键词查询项目着陆页 258 * 关键词查询项目着陆页
  259 + * @param $keywords
  260 + * @param $type
  261 + * @param $num
243 * @return int|mixed 262 * @return int|mixed
244 * @author Akun 263 * @author Akun
245 * @date 2025/02/26 17:13 264 * @date 2025/02/26 17:13
246 */ 265 */
247 - public function searchKeywords() 266 + public function searchKeywords($keywords, $type, $num)
248 { 267 {
249 - $num = $this->param['num'] ?? 3;  
250 268
251 $model = new InquiryProjectRoute(); 269 $model = new InquiryProjectRoute();
252 -// if ($this->param['type'] == 1) {  
253 -// //使用全文索引搜索  
254 -// $routeQuery = $model->select(['project_id', 'route'])->whereRaw("MATCH(title) AGAINST(? IN BOOLEAN MODE)", [$this->param['keywords']]);  
255 -// } else { 270 + if ($type == 1) {
  271 + //使用全文索引搜索
  272 + $routeQuery = $model->select(['project_id', 'route'])->whereRaw("MATCH(title) AGAINST(? IN BOOLEAN MODE)", [$keywords]);
  273 + } else {
256 //使用like查询 274 //使用like查询
257 - $routeQuery = $model->select(['project_id', 'route'])->where('title', 'like', '%' . $this->param['keywords'] . '%');  
258 -// } 275 + $routeQuery = $model->select(['project_id', 'route'])->where('title', 'like', '%' . $keywords . '%');
  276 + }
259 277
260 $re_route = $routeQuery->inRandomOrder()->take(100)->get()->toArray(); 278 $re_route = $routeQuery->inRandomOrder()->take(100)->get()->toArray();
261 279
@@ -309,22 +327,29 @@ class InquiryForwardLogic extends BaseLogic @@ -309,22 +327,29 @@ class InquiryForwardLogic extends BaseLogic
309 327
310 /** 328 /**
311 * AI重写询盘文案 329 * AI重写询盘文案
  330 + * @param $in_content
  331 + * @param $title
  332 + * @param $keywords
312 * @return array 333 * @return array
313 * @throws \App\Exceptions\AsideGlobalException 334 * @throws \App\Exceptions\AsideGlobalException
314 * @throws \App\Exceptions\BsideGlobalException 335 * @throws \App\Exceptions\BsideGlobalException
315 * @author Akun 336 * @author Akun
316 * @date 2025/02/27 10:40 337 * @date 2025/02/27 10:40
317 */ 338 */
318 - public function aiRewrite() 339 + public function aiRewrite($in_content, $title = '', $keywords = '')
319 { 340 {
320 - $ai_info = AiCommand::select(['ai', 'not_use_probability'])->where('key', 'inquiry_text_rewrite')->first(); 341 + if ($title && $keywords) {
  342 + $command_key = 'inquiry_text_rewrite_v2';
  343 + } else {
  344 + $command_key = 'inquiry_text_rewrite';
  345 + }
  346 + $ai_info = AiCommand::select(['ai', 'not_use_probability'])->where('key', $command_key)->first();
321 if (!$ai_info) { 347 if (!$ai_info) {
322 $this->fail('AI重写指令未配置'); 348 $this->fail('AI重写指令未配置');
323 } 349 }
324 350
325 $ai_command = $ai_info['ai']; 351 $ai_command = $ai_info['ai'];
326 $not_use_probability = $ai_info['not_use_probability']; 352 $not_use_probability = $ai_info['not_use_probability'];
327 - $in_content = $this->param['message'];  
328 353
329 // 当原始询盘内容长度大于15个字符, 60%几率直接发送原始内容。 354 // 当原始询盘内容长度大于15个字符, 60%几率直接发送原始内容。
330 if (strlen($in_content) >= 15) { 355 if (strlen($in_content) >= 15) {
@@ -340,6 +365,10 @@ class InquiryForwardLogic extends BaseLogic @@ -340,6 +365,10 @@ class InquiryForwardLogic extends BaseLogic
340 $lang = 'en'; 365 $lang = 'en';
341 } 366 }
342 367
  368 + if ($title && $keywords) {
  369 + $ai_command = str_replace('{title}', $title, $ai_command);
  370 + $ai_command = str_replace('{keywords}', $keywords, $ai_command);
  371 + }
343 $ai_command = str_replace('{incontent}', Arr::random(explode("\r\n", $in_content)), $ai_command); 372 $ai_command = str_replace('{incontent}', Arr::random(explode("\r\n", $in_content)), $ai_command);
344 373
345 $text = Gpt::instance()->openai_chat_qqs($ai_command); 374 $text = Gpt::instance()->openai_chat_qqs($ai_command);
@@ -119,7 +119,7 @@ class InquiryInfo extends Base @@ -119,7 +119,7 @@ class InquiryInfo extends Base
119 $self->status = $status; 119 $self->status = $status;
120 $self->remark = $remark; 120 $self->remark = $remark;
121 $self->save(); 121 $self->save();
122 - return true; 122 + return $self->id;
123 } catch (\Exception $e) { 123 } catch (\Exception $e) {
124 return false; 124 return false;
125 } 125 }
  1 +<?php
  2 +
  3 +namespace App\Models\Inquiry;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class InquiryRelayAi extends Base
  8 +{
  9 + protected $table = 'gl_inquiry_relay_ai';
  10 +}