正在显示
3 个修改的文件
包含
60 行增加
和
1 行删除
| @@ -129,4 +129,24 @@ class InquiryForwardController extends BaseController | @@ -129,4 +129,24 @@ class InquiryForwardController extends BaseController | ||
| 129 | $lists = $inquiryForwardLogic->searchKeywords(); | 129 | $lists = $inquiryForwardLogic->searchKeywords(); |
| 130 | $this->response('success', Code::SUCCESS, $lists); | 130 | $this->response('success', Code::SUCCESS, $lists); |
| 131 | } | 131 | } |
| 132 | + | ||
| 133 | + /** | ||
| 134 | + * AI重写询盘文案 | ||
| 135 | + * @param InquiryForwardLogic $inquiryForwardLogic | ||
| 136 | + * @throws \App\Exceptions\AsideGlobalException | ||
| 137 | + * @throws \App\Exceptions\BsideGlobalException | ||
| 138 | + * @author Akun | ||
| 139 | + * @date 2025/02/27 10:40 | ||
| 140 | + */ | ||
| 141 | + public function aiRewriteInquiry(InquiryForwardLogic $inquiryForwardLogic) | ||
| 142 | + { | ||
| 143 | + $this->request->validate([ | ||
| 144 | + 'message' => 'required', | ||
| 145 | + ], [ | ||
| 146 | + 'message.required' => '需要重写的文案不能为空', | ||
| 147 | + ]); | ||
| 148 | + | ||
| 149 | + $data = $inquiryForwardLogic->aiRewrite(); | ||
| 150 | + $this->response('success', Code::SUCCESS, $data); | ||
| 151 | + } | ||
| 132 | } | 152 | } |
| @@ -2,13 +2,19 @@ | @@ -2,13 +2,19 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Http\Logic\Aside\Optimize; | 3 | namespace App\Http\Logic\Aside\Optimize; |
| 4 | 4 | ||
| 5 | +use App\Helper\Common; | ||
| 6 | +use App\Helper\Gpt; | ||
| 7 | +use App\Helper\Translate; | ||
| 5 | use App\Http\Logic\Aside\BaseLogic; | 8 | use App\Http\Logic\Aside\BaseLogic; |
| 9 | +use App\Models\Ai\AiCommand; | ||
| 6 | use App\Models\Inquiry\InquiryInfo; | 10 | use App\Models\Inquiry\InquiryInfo; |
| 7 | use App\Models\Inquiry\InquiryProject; | 11 | use App\Models\Inquiry\InquiryProject; |
| 8 | use App\Models\Inquiry\InquiryProjectRoute; | 12 | use App\Models\Inquiry\InquiryProjectRoute; |
| 9 | use App\Models\Inquiry\InquiryRelayDetail; | 13 | use App\Models\Inquiry\InquiryRelayDetail; |
| 14 | +use Illuminate\Support\Arr; | ||
| 10 | use Illuminate\Support\Facades\DB; | 15 | use Illuminate\Support\Facades\DB; |
| 11 | use Illuminate\Support\Facades\Log; | 16 | use Illuminate\Support\Facades\Log; |
| 17 | +use Illuminate\Support\Str; | ||
| 12 | 18 | ||
| 13 | /** | 19 | /** |
| 14 | * @remark :询盘中心 | 20 | * @remark :询盘中心 |
| @@ -200,6 +206,38 @@ class InquiryForwardLogic extends BaseLogic | @@ -200,6 +206,38 @@ class InquiryForwardLogic extends BaseLogic | ||
| 200 | } | 206 | } |
| 201 | } | 207 | } |
| 202 | 208 | ||
| 203 | - return array_slice($lists, 0, $num, true); | 209 | + return $this->success(array_slice($lists, 0, $num, true)); |
| 210 | + } | ||
| 211 | + | ||
| 212 | + /** | ||
| 213 | + * AI重写询盘文案 | ||
| 214 | + * @return array | ||
| 215 | + * @throws \App\Exceptions\AsideGlobalException | ||
| 216 | + * @throws \App\Exceptions\BsideGlobalException | ||
| 217 | + * @author Akun | ||
| 218 | + * @date 2025/02/27 10:40 | ||
| 219 | + */ | ||
| 220 | + public function aiRewrite() | ||
| 221 | + { | ||
| 222 | + $ai_command = AiCommand::where('key', ' inquiry_text_rewrite')->value('ai'); | ||
| 223 | + if (!$ai_command) { | ||
| 224 | + $this->fail('AI重写指令未配置'); | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + $in_content = $this->param['message']; | ||
| 228 | + $translateSl = Translate::translateSl($in_content); | ||
| 229 | + $lang = $translateSl['texts']['sl'] ?? 'en'; | ||
| 230 | + if ($lang == 'en' || $lang == 'ja' || $lang == 'ko' || Str::contains($lang, 'zh')) { | ||
| 231 | + $lang = 'en'; | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + $ai_command = str_replace('{incontent}', Arr::random(explode("\r\n", $in_content)), $ai_command); | ||
| 235 | + | ||
| 236 | + $text = Gpt::instance()->openai_chat_qqs($ai_command); | ||
| 237 | + if ($lang != 'en' && !Str::contains($lang, 'zh')) { | ||
| 238 | + $text = Translate::tran($text, $lang); | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + return $this->success(['ai_message' => Common::deal_str($text)]); | ||
| 204 | } | 242 | } |
| 205 | } | 243 | } |
| @@ -347,6 +347,7 @@ Route::middleware(['aloginauth'])->group(function () { | @@ -347,6 +347,7 @@ Route::middleware(['aloginauth'])->group(function () { | ||
| 347 | Route::any('/forwardInquiry', [Aside\Optimize\InquiryForwardController::class, 'forwardInquiry'])->name('admin.inquiry_forward_forwardInquiry'); | 347 | Route::any('/forwardInquiry', [Aside\Optimize\InquiryForwardController::class, 'forwardInquiry'])->name('admin.inquiry_forward_forwardInquiry'); |
| 348 | Route::any('/getInquiryIp', [Aside\Optimize\InquiryForwardController::class, 'getInquiryIp'])->name('admin.inquiry_forward_getInquiryIp'); | 348 | Route::any('/getInquiryIp', [Aside\Optimize\InquiryForwardController::class, 'getInquiryIp'])->name('admin.inquiry_forward_getInquiryIp'); |
| 349 | Route::any('/searchInquiryKeywords', [Aside\Optimize\InquiryForwardController::class, 'searchInquiryKeywords'])->name('admin.inquiry_forward_searchInquiryKeywords'); | 349 | Route::any('/searchInquiryKeywords', [Aside\Optimize\InquiryForwardController::class, 'searchInquiryKeywords'])->name('admin.inquiry_forward_searchInquiryKeywords'); |
| 350 | + Route::any('/aiRewriteInquiry', [Aside\Optimize\InquiryForwardController::class, 'aiRewriteInquiry'])->name('admin.inquiry_forward_aiRewriteInquiry'); | ||
| 350 | }); | 351 | }); |
| 351 | 352 | ||
| 352 | Route::prefix('custom_module')->group(function () { | 353 | Route::prefix('custom_module')->group(function () { |
-
请 注册 或 登录 后发表评论