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