diff --git a/app/Modules/Bitrix/Models/SendDeal.php b/app/Modules/Bitrix/Models/SendDeal.php index c35b90c..8bc7449 100644 --- a/app/Modules/Bitrix/Models/SendDeal.php +++ b/app/Modules/Bitrix/Models/SendDeal.php @@ -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); } } diff --git a/app/Modules/Bitrix/Traits/Bitrixable.php b/app/Modules/Bitrix/Traits/Bitrixable.php index c9df95a..7a966e1 100644 --- a/app/Modules/Bitrix/Traits/Bitrixable.php +++ b/app/Modules/Bitrix/Traits/Bitrixable.php @@ -48,7 +48,7 @@ protected static function create(array $attributes = []) $model = new static(); $model->fill($attributes); $model->save(); - + try { $model->setBitrixId(); diff --git a/app/Modules/ClientCreateForm/Http/Livewire/ClientCreateLivewire.php b/app/Modules/ClientCreateForm/Http/Livewire/ClientCreateLivewire.php index 73ba369..8dece66 100644 --- a/app/Modules/ClientCreateForm/Http/Livewire/ClientCreateLivewire.php +++ b/app/Modules/ClientCreateForm/Http/Livewire/ClientCreateLivewire.php @@ -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 ( diff --git a/app/Modules/Main/Models/Deal/Deal.php b/app/Modules/Main/Models/Deal/Deal.php index 21ba850..2f67f93 100644 --- a/app/Modules/Main/Models/Deal/Deal.php +++ b/app/Modules/Main/Models/Deal/Deal.php @@ -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() { diff --git a/app/Modules/Plan7/Database/Migrations/2026_04_03_000003_add_plan7_field_to_deal_table.php b/app/Modules/Plan7/Database/Migrations/2026_04_03_000003_add_plan7_field_to_deal_table.php new file mode 100644 index 0000000..d1b9d6b --- /dev/null +++ b/app/Modules/Plan7/Database/Migrations/2026_04_03_000003_add_plan7_field_to_deal_table.php @@ -0,0 +1,28 @@ +text('plan7_data')->nullable(); + }); + + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + + } +}; diff --git a/app/Modules/Plan7/Traits/Plan7Deal.php b/app/Modules/Plan7/Traits/Plan7Deal.php index bd8820a..f427af3 100644 --- a/app/Modules/Plan7/Traits/Plan7Deal.php +++ b/app/Modules/Plan7/Traits/Plan7Deal.php @@ -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 [];