|
...
|
...
|
@@ -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);
|
...
|
...
|
|