- добавил авто-создание токенов в табл bx_id
- убрал политику на создание организации
This commit is contained in:
parent
14675465c4
commit
4a9f232723
@ -27,10 +27,6 @@ public function complex()
|
||||
{
|
||||
return $this->belongsTo(Complex::class);
|
||||
}
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'client_id');
|
||||
}
|
||||
public function agent()
|
||||
{
|
||||
return $this->belongsTo(Agent::class, 'agent_id');
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('bx_ids', function (Blueprint $table)
|
||||
{
|
||||
$table->string('token')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('bx_ids');
|
||||
}
|
||||
};
|
||||
@ -13,6 +13,11 @@ class ContractUpdateController
|
||||
{
|
||||
public function __invoke(Deal $deal, Request $request)
|
||||
{
|
||||
$companyToken = $deal->agent->company->secret;
|
||||
if ($request->token != $companyToken)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$status =
|
||||
Contract::updateOrCreate(
|
||||
['deal_id' => $deal->id],
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
use Modules\Main\Models\Deal\Deal;
|
||||
use Modules\Main\Models\Deal\Client;
|
||||
@ -35,56 +36,49 @@ protected static function booted()
|
||||
{
|
||||
return;
|
||||
}
|
||||
$object = false;
|
||||
$sender = new BitrixSender();
|
||||
switch ( $bitrixId->bitrixable_type )
|
||||
{
|
||||
case Deal::class:
|
||||
$deal = Deal::findOrFail($bitrixId->bitrixable_id);
|
||||
$sender = new SendDeal($deal);
|
||||
$result = $sender->send();
|
||||
if ($result == true)
|
||||
{
|
||||
$id = $sender->resultData['id'];
|
||||
$bitrixId->bx_id = $id;
|
||||
return;
|
||||
}
|
||||
$object = $deal;
|
||||
break;
|
||||
case Agent::class:
|
||||
$agent = Agent::findOrFail($bitrixId->bitrixable_id);
|
||||
$sender = new SendAgent($agent);
|
||||
$result = $sender->send();
|
||||
if ($result == true)
|
||||
{
|
||||
$id = $sender->resultData['id'];
|
||||
$bitrixId->bx_id = $id;
|
||||
return;
|
||||
};
|
||||
break;
|
||||
case DealClients::class:
|
||||
$dealClient = DealClients::findOrFail($bitrixId->bitrixable_id);
|
||||
$client = $dealClient->client;
|
||||
$sender = new SendClient($client);
|
||||
$result = $sender->send();
|
||||
if ($result)
|
||||
{
|
||||
$id = $sender->resultData['id'];
|
||||
$bitrixId->bx_id = $id;
|
||||
$bitrixId->bitrixable_type = Client::class;
|
||||
$bitrixId->bitrixable_id = $client->id;
|
||||
return;
|
||||
};
|
||||
$bitrixId->bitrixable_type = Client::class;
|
||||
$bitrixId->bitrixable_id = $client->id;
|
||||
$object = $client;
|
||||
break;
|
||||
case Company::class:
|
||||
$company = Company::findOrFail($bitrixId->bitrixable_id);
|
||||
$sender = new SendCompany($company);
|
||||
$result = $sender->send();
|
||||
if ($result == true)
|
||||
{
|
||||
$id = $sender->resultData['id'];
|
||||
$bitrixId->bx_id = $id;
|
||||
return;
|
||||
};
|
||||
$object = $company;
|
||||
break;
|
||||
}
|
||||
if ($sender)
|
||||
{
|
||||
$bitrixId->token = Hash::make(json_encode([$object]));
|
||||
$sender->setCallbackUrl(
|
||||
route('api.company.confirm', [
|
||||
'token' => $bitrixId->token
|
||||
])
|
||||
);
|
||||
$result = $sender->send();
|
||||
if ($result)
|
||||
{
|
||||
$id = $sender->resultData['id'];
|
||||
$bitrixId->bx_id = $id;
|
||||
return;
|
||||
};
|
||||
}
|
||||
throw new \Exception('Error of bitrix identifier getter for ' . $bitrixId->bitrixable_type . ' with id ' . $bitrixId->bitrixable_id);
|
||||
});
|
||||
static::created(function (BitrixId $bitrixId)
|
||||
|
||||
@ -8,13 +8,17 @@
|
||||
|
||||
class BitrixSender
|
||||
{
|
||||
private $callbackUrl = false;
|
||||
protected $data;
|
||||
public $resultData;
|
||||
public function __construct(array $data)
|
||||
public function __construct()
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
}
|
||||
public function setCallbackUrl($callbackUrl)
|
||||
{
|
||||
$this->callbackUrl = $callbackUrl;
|
||||
}
|
||||
protected function getUrl()
|
||||
{
|
||||
$webhookEnumItem = false;
|
||||
@ -51,6 +55,10 @@ protected function getUrl()
|
||||
}
|
||||
public function send()
|
||||
{
|
||||
if ($this->callbackUrl)
|
||||
{
|
||||
$this->data['callbackUrl'] = $this->callbackUrl;
|
||||
}
|
||||
$postdata = http_build_query(
|
||||
$this->data
|
||||
);
|
||||
|
||||
@ -16,11 +16,6 @@ class CreateCompanyController extends Controller
|
||||
*/
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
if ($request->user()->cannot('create', Company::class))
|
||||
{
|
||||
abort(403, 'Unauthorized action');
|
||||
}
|
||||
|
||||
$company = false;
|
||||
$request->enum('type', CompanyType::class);
|
||||
$validated = $request->validate([
|
||||
|
||||
Loading…
Reference in New Issue
Block a user