mirror of
https://gh.wpcy.net/https://github.com/hayBIT/freescout2ant.git
synced 2026-07-15 17:25:56 +08:00
Move all business logic from AmeiseController into CrmService: - getCrmUsers/getFSUsers: remove duplicates from controller, keep in CrmService (now return data arrays instead of HTTP responses) - Contract transformation: extract to CrmService::getContractsWithDetails() - Archive orchestration: extract to CrmService::archiveConversationFromRequest() - DB queries: extract to CrmService::getArchivedContracts() - ArchiveThreadsJob: use CrmService instead of direct sub-service instantiation Controller now only handles HTTP request/response, delegating all logic to CrmService. https://claude.ai/code/session_01Lbqz1JQAYAwFk6EamodxHU
67 lines
1.9 KiB
PHP
67 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Modules\AmeiseModule\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Routing\Controller;
|
|
use Modules\AmeiseModule\Services\CrmService;
|
|
|
|
class AmeiseController extends Controller
|
|
{
|
|
protected $crmService;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->middleware(function ($request, $next) {
|
|
$this->crmService = new CrmService('', auth()->user()->id);
|
|
return $next($request);
|
|
});
|
|
}
|
|
|
|
public function refreshToken()
|
|
{
|
|
$crmService = new CrmService('', auth()->user()->id);
|
|
$crmService->getAccessToken();
|
|
return response()->json(['status' => 'ok']);
|
|
}
|
|
|
|
/**
|
|
* @return Response Crm ajax controller.
|
|
*/
|
|
public function ajax(Request $request)
|
|
{
|
|
$inputs = $request->all();
|
|
switch ($request->action) {
|
|
case 'crm_users_search':
|
|
$results = [];
|
|
if (!empty($inputs['new_conversation'])) {
|
|
$results = $this->crmService->getFSUsers($inputs);
|
|
}
|
|
$result = $this->crmService->getCrmUsers($inputs, $results);
|
|
return response()->json($result);
|
|
break;
|
|
|
|
case 'get_contract':
|
|
$result = $this->crmService->getContractsWithDetails($request->input('client_id'));
|
|
return response()->json($result);
|
|
break;
|
|
|
|
case 'crm_conversation_archive':
|
|
$this->crmService->archiveConversationFromRequest($inputs, auth()->user()->id);
|
|
return response()->json(['status' => true]);
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function getContracts($id)
|
|
{
|
|
$archives = $this->crmService->getArchivedContracts($id);
|
|
if (!$archives) {
|
|
return '';
|
|
}
|
|
return view('ameise::partials.contracts', [
|
|
'archives' => $archives,
|
|
])->render();
|
|
}
|
|
}
|