作者 lyh

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

... ... @@ -8,9 +8,15 @@
namespace App\Console\Commands\Inquiry;
use App\Helper\Arr;
use App\Helper\Common;
use App\Helper\Gpt;
use App\Helper\Translate;
use App\Helper\Validate;
use App\Http\Logic\Aside\Optimize\InquiryForwardLogic;
use App\Models\Ai\AiCommand;
use App\Models\Inquiry\InquiryInfo;
use App\Models\Inquiry\InquiryRelayAi;
use App\Models\Project\InquiryFilterConfig;
use App\Models\Project\Project;
use App\Services\InquiryRelayService;
... ... @@ -221,7 +227,59 @@ class SyncInquiryRelay extends Command
$remark = $this->inquiryFilter($unique_sign, $country, $data['ip'], $data['message'], $data['refer'], $data['email'], $data['phone'], $data['name']);
$status = $remark ? InquiryInfo::STATUS_INVALID : InquiryInfo::STATUS_INIT;
$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);
$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);
if ($form_id && $status == InquiryInfo::STATUS_INIT) {
$inquiry_ai_info = InquiryRelayAi::where('form_id', $form_id)->first();
if (!$inquiry_ai_info) {
//AI匹配询盘关键词
$ai_info = AiCommand::select(['ai'])->where('key', 'inquiry_keyword_extract')->first();
if (!$ai_info) {
$this->output('AI重写指令[inquiry_keyword_extract]未配置');
return true;
}
$ai_command = $ai_info['ai'];
$ai_command = str_replace('{title}', $data['title'], $ai_command);
$ai_command = str_replace('{keywords}', $keywords, $ai_command);
$ai_command = str_replace('{content}', $data['message'], $ai_command);
$ai_keyword = Common::deal_str(Gpt::instance()->openai_chat_qqs($ai_command));
if (!$ai_keyword) {
$this->output('询盘ID:' . $form_id . ',AI提取询盘关键词失败');
return true;
}
//关键词查询项目着陆页
$inquiryForwardLogic = new InquiryForwardLogic();
$forward_list = $inquiryForwardLogic->searchKeywords($ai_keyword, 2, 3);
if (empty($forward_list)) {
$this->output('询盘ID:' . $form_id . ',根据关键词[' . $ai_keyword . ']查询项目着陆页为空');
return true;
}
//重写询盘内容
$ai_message_list = [];
for ($i = 0; $i < count($forward_list); $i++) {
$message_re = $inquiryForwardLogic->aiRewrite($data['message'], $data['title'], $keywords);
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:' . $form_id . ',AI重写询盘内容失败');
return true;
}
$inquiry_ai_info = new InquiryRelayAi();
$inquiry_ai_info->form_id = $form_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();
}
}
return true;
}
... ...
... ... @@ -152,7 +152,10 @@ class InquiryForwardController extends BaseController
'type.required' => '搜索类型不能为空',
]);
$lists = $inquiryForwardLogic->searchKeywords();
$keywords = $this->param['keywords'];
$type = $this->param['type'];
$num = $this->param['num'] ?? 3;
$lists = $inquiryForwardLogic->searchKeywords($keywords, $type, $num);
$this->response('success', Code::SUCCESS, $lists);
}
... ... @@ -172,7 +175,8 @@ class InquiryForwardController extends BaseController
'message.required' => '需要重写的文案不能为空',
]);
$data = $inquiryForwardLogic->aiRewrite();
$message = $this->param['message'];
$data = $inquiryForwardLogic->aiRewrite($message);
$this->response('success', Code::SUCCESS, $data);
}
... ...
... ... @@ -846,6 +846,9 @@ class ProjectController extends BaseController
$domain_array = parse_url($domain_pro ? $domain_pro->domain : '');
$domain = $domain_array['host'] ?? $domain_array['path'];
}
$item['channel']['channel'] = Channel::where('id', $item['channel']['channel_id'])->value('title');
$item['channel']['zone'] = Zone::where('id', $item['channel']['zone_id'])->value('title');
$item['channel']['user'] = User::where('id', $item['channel']['user_id'])->value('name');
$manageHr = new ManageHr();
$param = [
"id" => $item['id'],
... ...
... ... @@ -11,6 +11,7 @@ use App\Models\Inquiry\AreaTimezone;
use App\Models\Inquiry\InquiryInfo;
use App\Models\Inquiry\InquiryProject;
use App\Models\Inquiry\InquiryProjectRoute;
use App\Models\Inquiry\InquiryRelayAi;
use App\Models\Inquiry\InquiryRelayDetail;
use App\Models\Inquiry\InquiryRelayDetailLog;
use Illuminate\Support\Arr;
... ... @@ -102,6 +103,21 @@ class InquiryForwardLogic extends BaseLogic
if ($info === false) {
$this->fail('获取询盘详情失败');
}
$keywords_ai = '';
$forward_url_ai = [];
$message_ai = [];
$inquiry_ai_model = new InquiryRelayAi();
$ai_info = $inquiry_ai_model->read(['form_id' => $this->param['id']], ['keywords', 'forward_url', 'message_ai']);
if ($ai_info) {
$keywords_ai = $ai_info['keywords'];
$forward_url_ai = json_decode($ai_info['forward_url'], true);
$message_ai = json_decode($ai_info['message_ai'], true);
}
$info['keywords_ai'] = $keywords_ai;
$info['forward_url_ai'] = $forward_url_ai;
$info['message_ai'] = $message_ai;
return $this->success($info);
}
... ... @@ -240,22 +256,24 @@ class InquiryForwardLogic extends BaseLogic
/**
* 关键词查询项目着陆页
* @param $keywords
* @param $type
* @param $num
* @return int|mixed
* @author Akun
* @date 2025/02/26 17:13
*/
public function searchKeywords()
public function searchKeywords($keywords, $type, $num)
{
$num = $this->param['num'] ?? 3;
$model = new InquiryProjectRoute();
// if ($this->param['type'] == 1) {
// //使用全文索引搜索
// $routeQuery = $model->select(['project_id', 'route'])->whereRaw("MATCH(title) AGAINST(? IN BOOLEAN MODE)", [$this->param['keywords']]);
// } else {
if ($type == 1) {
//使用全文索引搜索
$routeQuery = $model->select(['project_id', 'route'])->whereRaw("MATCH(title) AGAINST(? IN BOOLEAN MODE)", [$keywords]);
} else {
//使用like查询
$routeQuery = $model->select(['project_id', 'route'])->where('title', 'like', '%' . $this->param['keywords'] . '%');
// }
$routeQuery = $model->select(['project_id', 'route'])->where('title', 'like', '%' . $keywords . '%');
}
$re_route = $routeQuery->inRandomOrder()->take(100)->get()->toArray();
... ... @@ -309,22 +327,29 @@ class InquiryForwardLogic extends BaseLogic
/**
* AI重写询盘文案
* @param $in_content
* @param $title
* @param $keywords
* @return array
* @throws \App\Exceptions\AsideGlobalException
* @throws \App\Exceptions\BsideGlobalException
* @author Akun
* @date 2025/02/27 10:40
*/
public function aiRewrite()
public function aiRewrite($in_content, $title = '', $keywords = '')
{
$ai_info = AiCommand::select(['ai', 'not_use_probability'])->where('key', 'inquiry_text_rewrite')->first();
if ($title && $keywords) {
$command_key = 'inquiry_text_rewrite_v2';
} else {
$command_key = 'inquiry_text_rewrite';
}
$ai_info = AiCommand::select(['ai', 'not_use_probability'])->where('key', $command_key)->first();
if (!$ai_info) {
$this->fail('AI重写指令未配置');
}
$ai_command = $ai_info['ai'];
$not_use_probability = $ai_info['not_use_probability'];
$in_content = $this->param['message'];
// 当原始询盘内容长度大于15个字符, 60%几率直接发送原始内容。
if (strlen($in_content) >= 15) {
... ... @@ -340,6 +365,10 @@ class InquiryForwardLogic extends BaseLogic
$lang = 'en';
}
if ($title && $keywords) {
$ai_command = str_replace('{title}', $title, $ai_command);
$ai_command = str_replace('{keywords}', $keywords, $ai_command);
}
$ai_command = str_replace('{incontent}', Arr::random(explode("\r\n", $in_content)), $ai_command);
$text = Gpt::instance()->openai_chat_qqs($ai_command);
... ...
... ... @@ -119,7 +119,7 @@ class InquiryInfo extends Base
$self->status = $status;
$self->remark = $remark;
$self->save();
return true;
return $self->id;
} catch (\Exception $e) {
return false;
}
... ...
<?php
namespace App\Models\Inquiry;
use App\Models\Base;
class InquiryRelayAi extends Base
{
protected $table = 'gl_inquiry_relay_ai';
}
... ...