fix of contracts

This commit is contained in:
Thekindbull 2025-08-04 01:04:03 +08:00
parent b400487e0c
commit 043653df9c
11 changed files with 105 additions and 43 deletions

View File

@ -27,7 +27,8 @@ public function __invoke(Deal $deal, Request $request)
'date' => $request->date,//дата ДДУ 'date' => $request->date,//дата ДДУ
'reg_date' => $request->reg_date,//Дата регистрации ДДУ 'reg_date' => $request->reg_date,//Дата регистрации ДДУ
'payment_type' => $request->payment_type,//Вид оплаты 'payment_type' => $request->payment_type,//Вид оплаты
'plan7_id' => $request->plan7_id 'plan7_id' => $request->plan7_id,
'base64_image' => $request->plan_image
] ]
); );
$agent = $deal->agent; $agent = $deal->agent;

View File

@ -38,6 +38,7 @@ public function setAgentId(Request $request, Agent $agent)
} }
public function syncDeals(Agent $agent) public function syncDeals(Agent $agent)
{ {
$importedCount = 0;
$url = 'https://b24alfa.pro/channels/lk/getDealsOfContact?id=' . $agent->bitrixId(); $url = 'https://b24alfa.pro/channels/lk/getDealsOfContact?id=' . $agent->bitrixId();
$data = file_get_contents($url); $data = file_get_contents($url);
$deals = json_decode($data, true); $deals = json_decode($data, true);
@ -51,7 +52,7 @@ public function syncDeals(Agent $agent)
//Загрузка контактов //Загрузка контактов
if ($deal['contacts'][0]['phone']) if ($deal['contacts'][0]['phone'])
{ {
$client = User::createOrFirst( $client = User::firstOrCreate(
['phone' => $deal['contacts'][0]['phone']], ['phone' => $deal['contacts'][0]['phone']],
[ [
'name' => $deal['contacts'][0]['name'], 'name' => $deal['contacts'][0]['name'],
@ -60,7 +61,7 @@ public function syncDeals(Agent $agent)
); );
} }
; ;
$dealItem = false; $dealItem = false; //собственный, не из битрикса
$bitrixId = BitrixId::where('bx_id', $deal['deal']['deal_id']) $bitrixId = BitrixId::where('bx_id', $deal['deal']['deal_id'])
->where('bitrixable_type', Deal::class); ->where('bitrixable_type', Deal::class);
//Загрузка сделок //Загрузка сделок
@ -80,19 +81,24 @@ public function syncDeals(Agent $agent)
$dealItem = Deal::find($bitrixId->bitrixable_id); $dealItem = Deal::find($bitrixId->bitrixable_id);
} }
; ;
$inDeal = $deal['deal']; $inDeal = $deal['deal'];//входящие данные по сделке
$contract = Contract::updateOrCreate( if ($dealItem)
['deal_id' => $dealItem->id], {
[ $importedCount++;
'price' => $inDeal['price'], $contract = Contract::updateOrCreate(
'square' => $inDeal['square'], ['deal_id' => $dealItem->id],
'floor' => $inDeal['floor'], [
'room' => $inDeal['room'], 'price' => $inDeal['price'],
'plan7_id' => $inDeal['plan7_id'] 'square' => $inDeal['square'],
] 'floor' => $inDeal['floor'],
); 'room' => $inDeal['room'],
$this->sendDealToBitrix($dealItem); 'plan7_id' => $inDeal['plan7_id']
]
);
$this->sendDealToBitrix($dealItem);
}
} }
return back()->with('success', 'Импортировано ' . $importedCount . ' сделок');
} }
function sendDealToBitrix(Deal $deal) function sendDealToBitrix(Deal $deal)

View File

@ -34,4 +34,19 @@ public function setBitrixId($id): bool
} }
return false; return false;
} }
protected static function booted()
{
static::deleted(function ($bitrixableItem)
{
$this->bitrixable()->delete();
});
static::forceDeleted(function ($bitrixableItem)
{
$this->bitrixable()->delete();
});
}
} }

View File

@ -11,9 +11,9 @@
*/ */
public function up(): void public function up(): void
{ {
Schema::create('contracts', function (Blueprint $table) { Schema::table('client_contract', function (Blueprint $table)
$table->id(); {
$table->timestamps(); $table->longText('base64_image')->nullable(); // Or not nullable if required
}); });
} }
@ -22,6 +22,6 @@ public function up(): void
*/ */
public function down(): void public function down(): void
{ {
Schema::dropIfExists('contracts'); //Schema::dropIfExists('contracts');
} }
}; };

View File

@ -16,4 +16,18 @@ public function index()
'status' => 'all' 'status' => 'all'
]); ]);
} }
public function delete(Contract $contract)
{
$deal = $contract->deal();
if ($contract->delete())
{
if ($deal->delete())
{
return back()->with('success', 'Договор был успешно удален из базы данных');
}
}
return back()->withErrors('Не удалось корректно удалить договор и сделку. Попробуйте позже.');
}
} }

View File

@ -25,7 +25,8 @@ class Contract extends Model
'date',//дата ДДУ 'date',//дата ДДУ
'reg_date',//Дата регистрации ДДУ 'reg_date',//Дата регистрации ДДУ
'payment_type',//Вид оплаты 'payment_type',//Вид оплаты
'plan7_id'//ид помещения из plan7 'plan7_id',//ид помещения из plan7
'base64_image'
]; ];
public function deal() public function deal()

View File

@ -3,9 +3,30 @@
class ContractStatus class ContractStatus
{ {
const NEW = 'NEW'; const NEW = 'NEW';
const TREATY = 'TREATY'; //переговоры const TREATY = 'TREATY'; //Выплачено
const RESERVATION = 'RESERVATION'; //бронь const RESERVATION = 'RESERVATION'; //бронь
const SUCCESS = "SUCCESS"; const SUCCESS = "SUCCESS";
const DECLINE = "DECLINE"; const DECLINE = "DECLINE";
}
public static function getName($status)
{
return __('contracts.status_' . $status);
}
public static function getHtmlColor($status)
{
switch ( $status )
{
case self::NEW:
return '#ccc';
case self::RESERVATION:
return '#4fb5e5';
case self::TREATY:
return '#e3e54f';
case self::SUCCESS:
return '#4fe576';
case self::DECLINE:
return '#eb612c';
}
return '#ccc';
}
}

View File

@ -6,4 +6,6 @@
Route::middleware(['auth'])->group(function () Route::middleware(['auth'])->group(function ()
{ {
Route::get('/contracts', [ContractsController::class, 'index'])->name('contracts'); Route::get('/contracts', [ContractsController::class, 'index'])->name('contracts');
Route::post('/contracts/{contract}/delete', [ContractsController::class, 'delete'])->name('contract.delete');
}); });

View File

@ -1,4 +1,4 @@
@php($statuses = App\Models\Deal\ContractStatus::class) @php($statuses = Modules\Contracts\Models\ContractStatus::class)
<div> <div>
<div class="fs-5 bg-light p-0 m-0 border border-1 rounded-4 py-3"> <div class="fs-5 bg-light p-0 m-0 border border-1 rounded-4 py-3">
<table class="table m-0"> <table class="table m-0">
@ -51,8 +51,8 @@
{!! $reward !!} {!! $reward !!}
</td> </td>
<td> <td>
<div class="py-1 px-3 border rounded rounded-5" <div class="py-1 px-3 border rounded rounded-5 text-center"
style="background-color:{{ $statuses::getColor($contract->status) }}"> style="background-color:{{ $statuses::getHtmlColor($contract->status) }}">
{{ $statuses::getName($contract->status) }} {{ $statuses::getName($contract->status) }}
</div> </div>
</td> </td>
@ -65,10 +65,11 @@
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" <a class="dropdown-item"
href="{{ route('contract', ['contract' => $contract->id]) }}">Детали</a> href="{{ route('contract', ['contract' => $contract->id]) }}">Детали</a>
<!--<form method="post" action=""> <form method="post"
action="{{ route('contract.delete', ['contract' => $contract]) }}">
@csrf @csrf
<button class="dropdown-item" type="submit">Удалить</button> <button class="dropdown-item" type="submit">Удалить</button>
</form>--> </form>
</div> </div>
</div> </div>
</td> </td>

View File

@ -2,8 +2,8 @@
return [ return [
'status_NEW' => 'Новый', 'status_NEW' => 'Новый',
'status_TREATY' => 'Выплачено', 'status_TREATY' => 'Выплачено',
'status_RESERVATION' => 'Забронировано', 'status_RESERVATION' => 'Бронь',
'status_SUSSCESS' => 'Успех', 'status_SUCCESS' => 'Успех',
'status_DECLINE' => 'Отклонен' 'status_DECLINE' => 'Отклонен'
]; ];

View File

@ -37,20 +37,20 @@ class="bi bi-arrow-right" viewBox="0 0 16 16">
</div> </div>
<div class="col-3 text-end"> <div class="col-3 text-end">
<!--<a href="" class="btn border-1 border-secondary-subtle text-secondary rounded-4 p-3"> <!--<a href="" class="btn border-1 border-secondary-subtle text-secondary rounded-4 p-3">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor"
class="bi bi-trash3" viewBox="0 0 16 16"> class="bi bi-trash3" viewBox="0 0 16 16">
<path <path
d="M6.5 1h3a.5.5 0 0 1 .5.5v1H6v-1a.5.5 0 0 1 .5-.5M11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3A1.5 1.5 0 0 0 5 1.5v1H1.5a.5.5 0 0 0 0 1h.538l.853 10.66A2 2 0 0 0 4.885 16h6.23a2 2 0 0 0 1.994-1.84l.853-10.66h.538a.5.5 0 0 0 0-1zm1.958 1-.846 10.58a1 1 0 0 1-.997.92h-6.23a1 1 0 0 1-.997-.92L3.042 3.5zm-7.487 1a.5.5 0 0 1 .528.47l.5 8.5a.5.5 0 0 1-.998.06L5 5.03a.5.5 0 0 1 .47-.53Zm5.058 0a.5.5 0 0 1 .47.53l-.5 8.5a.5.5 0 1 1-.998-.06l.5-8.5a.5.5 0 0 1 .528-.47M8 4.5a.5.5 0 0 1 .5.5v8.5a.5.5 0 0 1-1 0V5a.5.5 0 0 1 .5-.5" /> d="M6.5 1h3a.5.5 0 0 1 .5.5v1H6v-1a.5.5 0 0 1 .5-.5M11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3A1.5 1.5 0 0 0 5 1.5v1H1.5a.5.5 0 0 0 0 1h.538l.853 10.66A2 2 0 0 0 4.885 16h6.23a2 2 0 0 0 1.994-1.84l.853-10.66h.538a.5.5 0 0 0 0-1zm1.958 1-.846 10.58a1 1 0 0 1-.997.92h-6.23a1 1 0 0 1-.997-.92L3.042 3.5zm-7.487 1a.5.5 0 0 1 .528.47l.5 8.5a.5.5 0 0 1-.998.06L5 5.03a.5.5 0 0 1 .47-.53Zm5.058 0a.5.5 0 0 1 .47.53l-.5 8.5a.5.5 0 1 1-.998-.06l.5-8.5a.5.5 0 0 1 .528-.47M8 4.5a.5.5 0 0 1 .5.5v8.5a.5.5 0 0 1-1 0V5a.5.5 0 0 1 .5-.5" />
</svg> </svg>
</a> </a>
<a href="" class="btn border-1 border-secondary-subtle text-secondary rounded-4 p-3"> <a href="" class="btn border-1 border-secondary-subtle text-secondary rounded-4 p-3">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor"
class="bi bi-pen" viewBox="0 0 16 16"> class="bi bi-pen" viewBox="0 0 16 16">
<path <path
d="m13.498.795.149-.149a1.207 1.207 0 1 1 1.707 1.708l-.149.148a1.5 1.5 0 0 1-.059 2.059L4.854 14.854a.5.5 0 0 1-.233.131l-4 1a.5.5 0 0 1-.606-.606l1-4a.5.5 0 0 1 .131-.232l9.642-9.642a.5.5 0 0 0-.642.056L6.854 4.854a.5.5 0 1 1-.708-.708L9.44.854A1.5 1.5 0 0 1 11.5.796a1.5 1.5 0 0 1 1.998-.001m-.644.766a.5.5 0 0 0-.707 0L1.95 11.756l-.764 3.057 3.057-.764L14.44 3.854a.5.5 0 0 0 0-.708z" /> d="m13.498.795.149-.149a1.207 1.207 0 1 1 1.707 1.708l-.149.148a1.5 1.5 0 0 1-.059 2.059L4.854 14.854a.5.5 0 0 1-.233.131l-4 1a.5.5 0 0 1-.606-.606l1-4a.5.5 0 0 1 .131-.232l9.642-9.642a.5.5 0 0 0-.642.056L6.854 4.854a.5.5 0 1 1-.708-.708L9.44.854A1.5 1.5 0 0 1 11.5.796a1.5 1.5 0 0 1 1.998-.001m-.644.766a.5.5 0 0 0-.707 0L1.95 11.756l-.764 3.057 3.057-.764L14.44 3.854a.5.5 0 0 0 0-.708z" />
</svg> </svg>
</a>--> </a>-->
</div> </div>
</div> </div>
<!--Основная часть--> <!--Основная часть-->
@ -107,7 +107,8 @@ class="bi bi-pen" viewBox="0 0 16 16">
</div> </div>
</div> </div>
<div class="col col-lg-4 p-3"> <div class="col col-lg-4 p-3">
<div class="rounded-4 h-100 w-100" style="background-color:#ebeef5"></div> <div class="rounded-4 h-100 w-100" style="background-color:#ebeef5"
data-base64="{{ $contract->base64_image }}"></div>
</div> </div>
</div> </div>
</div> </div>