добавлены трейты и таблицы для работы с plan7 и отправки в битрикс

This commit is contained in:
developer 2026-04-03 15:49:36 +08:00
parent d711d11760
commit 26f20033a3
6 changed files with 36 additions and 18 deletions

View File

@ -13,7 +13,7 @@ class SendDeal extends BitrixSender
public function __construct(Deal $deal)
{
$this->addDataItem('complexName', $deal->complex->name);
if ($plan7Data = $deal->plan7Data || $plan7Data = $deal->getPlan7Data()) {
if ($plan7Data = $deal->plan7_data) {
$this->addDataItem('plan7', $plan7Data);
}
}

View File

@ -211,17 +211,12 @@ public function back()
public function save()
{
$deal = new Deal();
$deal->complex_id = $this->complexId;
$deal->agent_id = $this->agentId;
if ($this->plan7Room) {
$deal->plan7Data = $this->plan7Room;
}
if (
!$deal = Deal::create([
'agent_id' => $this->agentId,
'complex_id' => $this->complexId,
'plan7_data' => ($this->plan7Room) ? json_encode($this->plan7Room) : null
])
)
{
@ -229,10 +224,6 @@ public function save()
return;
}
if ($this->plan7Room) {
$deal->setPlan7Data($this->plan7Room['id'], $this->plan7Room);
}
foreach ($this->contacts as $contact)
{
if (

View File

@ -12,20 +12,20 @@
use Modules\Main\Models\Complex;
use Modules\Main\Models\Agent\Agent;
use Modules\Bitrix\Traits\Bitrixable;
use Modules\Plan7\Traits\Plan7Deal;
use App\Notifications\Deal\DealCreated;
use App\Notifications\Deal\DealUnique;
use App\Notifications\Deal\DealNotUnique;
class Deal extends Model
{
use HasFactory, Notifiable, Bitrixable, Plan7Deal;
use HasFactory, Notifiable, Bitrixable;
protected $fillable = [
'complex_id',
'agent_id',
'bitrix_id',
'is_unique',
'confirm_token'
'confirm_token',
'plan7_data'
];
public function complex()
{

View File

@ -0,0 +1,28 @@
<?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('deals', function (Blueprint $table)
{
$table->text('plan7_data')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
}
};

View File

@ -8,12 +8,12 @@
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Modules\Plan7\Models\DealPlan7;
use Modules\Main\Models\Deal\Deal;
trait Plan7Deal
{
public $plan7Data;
protected $bitrixData = [];
public function setPlan7Data($id, $data)
{
$this->plan7Data = $data;
return DealPlan7::updateOrCreate(['deal_id' => $this->id], [
'plan7_id' => $id,
'data' => json_encode($data)
@ -22,7 +22,6 @@ public function setPlan7Data($id, $data)
public function getPlan7Data()
{
if ($plan7 = DealPlan7::where('deal_id', $this->id)->first()) {
$this->plan7Data = json_decode($plan7->data);
return $plan7->data;
}
return [];