fix! Обновление статуса сделки из битрикса в ЛК после переработки модуля
This commit is contained in:
parent
59bdd07bc0
commit
474c97d4e8
@ -5,74 +5,74 @@
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
use App\Models\Deal\Deal;
|
use Modules\Main\Models\Deal\Deal;
|
||||||
use App\Models\Deal\DealStatus;
|
use Modules\Main\Models\Deal\DealStatus;
|
||||||
use App\Notifications\UniqueContact;
|
use App\Notifications\UniqueContact;
|
||||||
use App\Notifications\NotUniqueContact;
|
use App\Notifications\NotUniqueContact;
|
||||||
use App\Notifications\Deal\DealUnique;
|
use App\Notifications\Deal\DealUnique;
|
||||||
use App\Notifications\Deal\DealNotUnique;
|
use App\Notifications\Deal\DealNotUnique;
|
||||||
|
|
||||||
|
use Modules\Bitrix\Models\BitrixId;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class BitrixApiController extends Controller
|
class BitrixApiController extends Controller
|
||||||
{
|
{
|
||||||
public const ACTION_CONFIRM_DEAL = 'confirm_deal';
|
public const ACTION_CONFIRM_DEAL = 'confirm_deal';
|
||||||
public const ACTION_UPDATE_CONTRACT = 'update_contract';
|
public const ACTION_UPDATE_CONTRACT = 'update_contract';
|
||||||
public const ACTION_CONFIRM_COMPANY = 'confirm_company';
|
public const ACTION_CONFIRM_COMPANY = 'confirm_company';
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
switch ( $request->action )
|
if (!$bxId = BitrixId::where('token', $request->token)->first()) {
|
||||||
{
|
return false;
|
||||||
case $this::ACTION_CONFIRM_DEAL:
|
};
|
||||||
$deal = Deal::where('confirm_token', $request->token)->first();
|
$object = $bxId->bitrixable;
|
||||||
$this->confirmDeal($deal, $request);
|
switch ($request->action) {
|
||||||
break;
|
case $this::ACTION_CONFIRM_DEAL:
|
||||||
case $this::ACTION_UPDATE_CONTRACT:
|
$this->confirmDeal($object, $request);
|
||||||
$deal = Deal::where('confirm_token', $request->token)->first();
|
break;
|
||||||
$this->updateContract($deal, $request);
|
case $this::ACTION_UPDATE_CONTRACT:
|
||||||
break;
|
$this->updateContract($object, $request);
|
||||||
case $this::ACTION_CONFIRM_COMPANY:
|
break;
|
||||||
$this->confirmCompany($request);
|
case $this::ACTION_CONFIRM_COMPANY:
|
||||||
break;
|
$this->confirmCompany($request, $object);
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function confirmCompany(Request $request)
|
public function confirmCompany(Request $request, $company)
|
||||||
{
|
{
|
||||||
$confirmer = new ConfirmCompanyController;
|
$confirmer = new ConfirmCompanyController;
|
||||||
$confirmer($request);
|
$confirmer($request, $company);
|
||||||
}
|
}
|
||||||
public function confirmDeal(Deal $deal, Request $request)
|
public function confirmDeal(Deal $deal, Request $request)
|
||||||
{
|
{
|
||||||
$agent = $deal->agent;
|
$agent = $deal->agent;
|
||||||
if ((bool) $request->is_unique == true)
|
$request->is_unique = json_decode($request->is_unique, true);
|
||||||
{
|
if ($request->is_unique == true) {
|
||||||
$deal->status = DealStatus::UNIQUE;
|
$deal->status = DealStatus::UNIQUE;
|
||||||
$agent->user->notify(new UniqueContact($deal));
|
$agent->user->notify(new UniqueContact($deal));
|
||||||
$deal->notify(new DealUnique());
|
$deal->notify(new DealUnique());
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$deal->status = DealStatus::NOT_UNIQUE;
|
$deal->status = DealStatus::NOT_UNIQUE;
|
||||||
$agent->user->notify(new NotUniqueContact($deal));
|
$agent->user->notify(new NotUniqueContact($deal));
|
||||||
$deal->notify(new DealNotUnique());
|
$deal->notify(new DealNotUnique());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$agent->bitrixId())
|
if (!$agent->bitrixId()) {
|
||||||
{
|
|
||||||
$agent->setBitrixId($request->agent_id);
|
$agent->setBitrixId($request->agent_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::build([
|
Log::build([
|
||||||
'driver' => 'single',
|
'driver' => 'single',
|
||||||
'path' => storage_path('logs/bitrix.log'),
|
'path' => storage_path('logs/bitrix.log'),
|
||||||
])->error(
|
])->error(
|
||||||
json_encode(
|
json_encode(
|
||||||
[
|
[
|
||||||
'is_unique' => $request->is_unique,
|
'is_unique' => $request->is_unique,
|
||||||
'deal' => $deal->id,
|
'deal' => $deal->id,
|
||||||
'status' => $deal->status
|
'status' => $deal->status
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@ -20,9 +20,8 @@ class ConfirmCompanyController extends Controller
|
|||||||
* @param $reqest['status'] - new|accepted|declined
|
* @param $reqest['status'] - new|accepted|declined
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function __invoke(Request $request)
|
public function __invoke(Request $request, Company $company)
|
||||||
{
|
{
|
||||||
$company = Company::find($request->company_id);
|
|
||||||
if ($company->secret == $request->token)
|
if ($company->secret == $request->token)
|
||||||
{
|
{
|
||||||
$company->status = $request->status;
|
$company->status = $request->status;
|
||||||
|
|||||||
@ -67,7 +67,7 @@ protected static function booted()
|
|||||||
{
|
{
|
||||||
$bitrixId->token = Hash::make(json_encode([$object]));
|
$bitrixId->token = Hash::make(json_encode([$object]));
|
||||||
$sender->setCallbackUrl(
|
$sender->setCallbackUrl(
|
||||||
route('api.company.confirm', [
|
route('api.bx.action', [
|
||||||
'token' => $bitrixId->token
|
'token' => $bitrixId->token
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|||||||
@ -8,17 +8,21 @@
|
|||||||
|
|
||||||
class BitrixSender
|
class BitrixSender
|
||||||
{
|
{
|
||||||
private $callbackUrl = false;
|
protected $callbackUrl = false;
|
||||||
protected $data;
|
protected $data;
|
||||||
public $resultData;
|
public $resultData;
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
$this->data = [];
|
||||||
}
|
}
|
||||||
public function setCallbackUrl($callbackUrl)
|
public function setCallbackUrl($callbackUrl)
|
||||||
{
|
{
|
||||||
$this->callbackUrl = $callbackUrl;
|
$this->callbackUrl = $callbackUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addDataItem($key, $value) {
|
||||||
|
$this->data[$key] = $value;
|
||||||
|
}
|
||||||
protected function getUrl()
|
protected function getUrl()
|
||||||
{
|
{
|
||||||
$webhookEnumItem = false;
|
$webhookEnumItem = false;
|
||||||
|
|||||||
@ -12,9 +12,7 @@ class SendAgent extends BitrixSender
|
|||||||
use HasFactory;
|
use HasFactory;
|
||||||
public function __construct(Agent $agent)
|
public function __construct(Agent $agent)
|
||||||
{
|
{
|
||||||
$this->data = [
|
$this->addDataItem('name', $agent->user->name);
|
||||||
'name' => $agent->user->name,
|
$this->addDataItem('phones', [$agent->user->phone]);
|
||||||
'phones' => [$agent->user->phone],
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,9 +12,7 @@ class SendClient extends BitrixSender
|
|||||||
use HasFactory;
|
use HasFactory;
|
||||||
public function __construct(Client $client)
|
public function __construct(Client $client)
|
||||||
{
|
{
|
||||||
$this->data = [
|
$this->addDataItem('name', $client->name);
|
||||||
'name' => $client->name,
|
$this->addDataItem('phones', $client->phone);
|
||||||
'phones' => [$client->phone],
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,16 +11,10 @@ class SendCompany extends BitrixSender
|
|||||||
use HasFactory;
|
use HasFactory;
|
||||||
public function __construct(Company $company)
|
public function __construct(Company $company)
|
||||||
{
|
{
|
||||||
$this->data = [
|
$this->addDataItem('name', $company->name);
|
||||||
'name' => $company->name,
|
$this->addDataItem('inn', $company->inn);
|
||||||
'inn' => $company->inn,
|
$this->addDataItem('email', $company->email);
|
||||||
'email' => $company->email,
|
$this->addDataItem('phone', $company->phone);
|
||||||
'phone' => $company->phone,
|
$this->addDataItem('address', $company->legal_address);
|
||||||
'address' => $company->legal_address,
|
|
||||||
'callbackUrl' => route('api.company.confirm', [
|
|
||||||
'token' => $company->secret
|
|
||||||
])
|
|
||||||
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,9 +12,6 @@ class SendDeal extends BitrixSender
|
|||||||
use HasFactory;
|
use HasFactory;
|
||||||
public function __construct(Deal $deal)
|
public function __construct(Deal $deal)
|
||||||
{
|
{
|
||||||
$this->data = [
|
$this->addDataItem('complexName', $deal->complex->name);
|
||||||
'token' => $deal->confirm_token,
|
|
||||||
'complexName' => $deal->complex->name
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,8 +20,10 @@ protected function registerWebRoutes()
|
|||||||
//Set Default Controllers Namespace
|
//Set Default Controllers Namespace
|
||||||
->namespace('Modules\\Bitrix\\Http\\Controllers')
|
->namespace('Modules\\Bitrix\\Http\\Controllers')
|
||||||
->group(app_path('Modules/Bitrix/Routes/web.php'));
|
->group(app_path('Modules/Bitrix/Routes/web.php'));
|
||||||
|
|
||||||
Route::middleware('api')
|
Route::middleware('api')
|
||||||
->prefix('api')
|
->namespace('Modules\\Bitrix\\Http\\Controllers')
|
||||||
->group(base_path('Modules/Bitrix/Routes/api.php'));
|
->prefix('api/bx')
|
||||||
|
->group(app_path('Modules/Bitrix/Routes/api.php'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -21,4 +21,5 @@
|
|||||||
return $request->user();
|
return $request->user();
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get('/action', [BitrixApiController::class, 'index']);
|
Route::post('/action', [BitrixApiController::class, 'index'])->name('api.bx.action');
|
||||||
|
Route::get('/action', [BitrixApiController::class, 'index']);
|
||||||
@ -7,8 +7,8 @@
|
|||||||
use Illuminate\Notifications\Messages\MailMessage;
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
use Illuminate\Notifications\Notification;
|
use Illuminate\Notifications\Notification;
|
||||||
|
|
||||||
use App\Models\Deal\Deal;
|
use Modules\Main\Models\Deal\Deal;
|
||||||
use App\Models\Deal\DealStatus;
|
use Modules\Main\Models\Deal\DealStatus;
|
||||||
|
|
||||||
class NotUniqueContact extends Notification
|
class NotUniqueContact extends Notification
|
||||||
{
|
{
|
||||||
@ -54,9 +54,12 @@ public function toMail(object $notifiable): MailMessage
|
|||||||
*/
|
*/
|
||||||
public function toArray(object $notifiable): array
|
public function toArray(object $notifiable): array
|
||||||
{
|
{
|
||||||
|
$clientsNames = $this->deal->clients->pluck('name')->toArray();
|
||||||
return [
|
return [
|
||||||
'deal' => $this->deal->id,
|
'deal' => $this->deal->id,
|
||||||
'text' => __('notifications.' . get_class($this), ['contact' => $this->deal->user->name])
|
'text' => __('notifications.' . get_class($this), [
|
||||||
|
'contact' => implode(', ', $clientsNames)
|
||||||
|
])
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,8 +7,8 @@
|
|||||||
use Illuminate\Notifications\Messages\MailMessage;
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
use Illuminate\Notifications\Notification;
|
use Illuminate\Notifications\Notification;
|
||||||
|
|
||||||
use App\Models\Deal\Deal;
|
use Modules\Main\Models\Deal\Deal;
|
||||||
use App\Models\Deal\DealStatus;
|
use Modules\Main\Models\Deal\DealStatus;
|
||||||
|
|
||||||
class UniqueContact extends Notification
|
class UniqueContact extends Notification
|
||||||
{
|
{
|
||||||
@ -54,9 +54,13 @@ public function toMail(object $notifiable): MailMessage
|
|||||||
*/
|
*/
|
||||||
public function toArray(object $notifiable): array
|
public function toArray(object $notifiable): array
|
||||||
{
|
{
|
||||||
|
$clientsNames = $this->deal->clients->pluck('name')->toArray();
|
||||||
return [
|
return [
|
||||||
'deal' => $this->deal->id,
|
'deal' => $this->deal->id,
|
||||||
'text' => __('notifications.' . get_class($this), ['contact' => $this->deal->user->name])
|
'text' => __('notifications.' . get_class($this),
|
||||||
|
[
|
||||||
|
'contact' => implode(', ', $clientsNames)
|
||||||
|
])
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,9 +24,3 @@
|
|||||||
return $request->user();
|
return $request->user();
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::post('/client', [BitrixApiController::class, 'index'])->name('api.client');
|
|
||||||
Route::post('/company/confirm', [BitrixApiController::class, 'index'])->name('api.company.confirm');
|
|
||||||
|
|
||||||
|
|
||||||
//Route::post('/client/confirm', [ConfirmClientFromBitrix::class, 'confirm'])->name('deal.confirm');
|
|
||||||
//Route::post('/client/{$deal}/contract', CoController::class)->name('company.status.update');
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user