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

This commit is contained in:
developer 2026-04-03 15:30:43 +08:00
parent d9366946c4
commit d711d11760
4 changed files with 13 additions and 2 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->getPlan7Data()) {
if ($plan7Data = $deal->plan7Data || $plan7Data = $deal->getPlan7Data()) {
$this->addDataItem('plan7', $plan7Data);
}
}

View File

@ -48,6 +48,7 @@ protected static function create(array $attributes = [])
$model = new static();
$model->fill($attributes);
$model->save();
try
{
$model->setBitrixId();

View File

@ -211,7 +211,14 @@ 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,

View File

@ -10,8 +10,10 @@
use Modules\Plan7\Models\DealPlan7;
trait Plan7Deal
{
public $plan7Data;
public function setPlan7Data($id, $data)
{
$this->plan7Data = $data;
return DealPlan7::updateOrCreate(['deal_id' => $this->id], [
'plan7_id' => $id,
'data' => json_encode($data)
@ -20,6 +22,7 @@ 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 [];