plan7 selector - добавлена админка для сохранения api данных
This commit is contained in:
parent
46107da265
commit
37dd42e7ed
35
app/Modules/Admin/Http/Controllers/AdminPlan7Controller.php
Normal file
35
app/Modules/Admin/Http/Controllers/AdminPlan7Controller.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Main\Models\Complex;
|
||||
use Modules\Plan7\Models\ComplexPlan7;
|
||||
|
||||
class AdminPlan7Controller extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('admin::plan7.index', [
|
||||
'complexes' => Complex::orderBy('city_id')->get()
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(Request $request) {
|
||||
foreach ($request->plan7 as $complexId=>$plan7ApiData) {
|
||||
if ($plan7ApiData['token'] && $plan7ApiData['zk']) {
|
||||
ComplexPlan7::updateOrCreate([
|
||||
'complex_id' => $complexId,
|
||||
], [
|
||||
'complex_id' => $complexId,
|
||||
'token' => $plan7ApiData['token'],
|
||||
'zk' => $plan7ApiData['zk']
|
||||
]);
|
||||
} else {
|
||||
ComplexPlan7::where('complex_id', $complexId)->delete();
|
||||
}
|
||||
}
|
||||
return to_route('admin.plan7');
|
||||
}
|
||||
}
|
||||
@ -71,6 +71,7 @@
|
||||
Route::post('/admin/bitrix/agents/{agent}/set', [Modules\Admin\Http\Controllers\AdminBitrixController::class, 'setAgentId'])->name('admin.bitrix.agent.set');
|
||||
Route::get('/admin/bitrix/agents/{agent}/deals/sync', [Modules\Admin\Http\Controllers\AdminBitrixController::class, 'syncDeals'])->name('admin.bitrix.agent.deals.sync');
|
||||
|
||||
|
||||
Route::get('/admin/plan7', [Modules\Admin\Http\Controllers\AdminPlan7Controller::class, 'index'])->name('admin.plan7');
|
||||
Route::post('/admin/plan7/save', [Modules\Admin\Http\Controllers\AdminPlan7Controller::class, 'save'])->name('admin.plan7.save');
|
||||
|
||||
});
|
||||
@ -6,9 +6,9 @@
|
||||
Создайтие обработчики событий на стороне вашего Битрикс24 для указанных событий.
|
||||
</div>
|
||||
<form action="{{ route('admin.bitrix.webhooks.create') }}" method="post">
|
||||
@csrf
|
||||
@foreach ($webhooksEnumCases as $webhookEnum)
|
||||
<div class="row my-2 border-bottom">
|
||||
@csrf
|
||||
<div class="col-3 vstack">
|
||||
<span class="fw-bold">{{ $webhookEnum->name }}</span>
|
||||
<small>{{ __('admin.' . $webhookEnum->name) . ' webhook label' }}</small>
|
||||
|
||||
@ -42,6 +42,8 @@ class="nav-link d-flex align-items-center gap-2 fs-5 border rounded-4" href="#">
|
||||
</li>
|
||||
<li class="nav-item text-center m-2"><a class="nav-link d-flex align-items-center gap-2 fs-5 border rounded-4"
|
||||
href="{{ route('admin.bitrix') }}">Битрикс24</a></li>
|
||||
<li class="nav-item text-center m-2"><a class="nav-link d-flex align-items-center gap-2 fs-5 border rounded-4"
|
||||
href="{{ route('admin.plan7') }}">Plan7</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
33
app/Modules/Admin/Views/plan7/index.blade.php
Normal file
33
app/Modules/Admin/Views/plan7/index.blade.php
Normal file
@ -0,0 +1,33 @@
|
||||
@php($title = 'Интеграция Plan7')
|
||||
@extends('layouts.admin')
|
||||
@section('content')
|
||||
<div class="alert alert-primary" role="alert">
|
||||
Активируйте передачу данных в JSON для каталога отдельного ЖК на вкладке API и
|
||||
скопируйте полученные токен и идентфикатор жилого комплекса в соответствующиие поля ниже
|
||||
</div>
|
||||
<form action="{{ route('admin.plan7.save') }}" method="post">
|
||||
@csrf
|
||||
@foreach($complexes as $complex)
|
||||
<div class="row my-2 border-bottom">
|
||||
<div class="col-3 vstack">
|
||||
<span class="fw-bold">{{ $complex->name }}</span>
|
||||
</div>
|
||||
<div class="col-3 vstack">
|
||||
<span class="fw-bold">{{ $complex->city->name }}</span>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<input class="form-control" type="text" name="plan7[{{ $complex->id }}][zk]" placeholder="ID ЖК из Plan7"
|
||||
value="{{ $complex->getPlan7ApiData()?->zk }}">
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<input class="form-control" type="text" name="plan7[{{ $complex->id }}][token]" placeholder="API токен для ЖК из Plan7"
|
||||
value="{{ $complex->getPlan7ApiData()?->token }}">
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
<button type="submit" class="btn btn-primary mb-3">
|
||||
<i class="bi bi-save"></i> Сохранить
|
||||
</button>
|
||||
</form>
|
||||
@endsection
|
||||
@ -163,11 +163,13 @@ class="bi bi-plus-circle" viewBox="0 0 16 16">
|
||||
@enderror
|
||||
|
||||
</div>
|
||||
@if($complexId)
|
||||
@if($complexId && ComplexHasPlan7ApiData($complexId))
|
||||
<div class="p-2 bg-light border border-1 rounded-4 mb-3 bg-light">
|
||||
<label for="complexId">Помещение</label>
|
||||
<div>
|
||||
<livewire:plan7Selector />
|
||||
@livewire('plan7Selector', [
|
||||
'complexId' => $complexId
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@ -7,10 +7,12 @@
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
use Modules\Main\Models\City;
|
||||
use Modules\Plan7\Traits\Plan7;
|
||||
class Complex extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
use Plan7;
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'city_id'
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
<?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::create('complex_plan7', function (Blueprint $table)
|
||||
{
|
||||
$table->id();
|
||||
$table->foreignId('complex_id')->references('id')->on('complexes')->onDelete('cascade');
|
||||
$table->string('token');
|
||||
$table->integer('zk');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('complex_plan7');
|
||||
}
|
||||
};
|
||||
15
app/Modules/Plan7/Helpers/helper.php
Normal file
15
app/Modules/Plan7/Helpers/helper.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
use Modules\Main\Models\Complex;
|
||||
|
||||
|
||||
if (!function_exists('ComplexHasPlan7ApiData')) {
|
||||
function ComplexHasPlan7ApiData(Complex|int $complex)
|
||||
{
|
||||
if (is_int($complex) == 'int')
|
||||
$complex = Complex::find($complex);
|
||||
if ($complex->getPlan7ApiData()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -3,10 +3,12 @@
|
||||
namespace Modules\Plan7\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
use Modules\Main\Models\Complex;
|
||||
|
||||
class Plan7SelectorLivewire extends Component
|
||||
{
|
||||
public $mode = 'new';
|
||||
public $complexId;
|
||||
public $containerId;
|
||||
public $filter = [];
|
||||
|
||||
@ -16,14 +18,18 @@ class Plan7SelectorLivewire extends Component
|
||||
public $summary;
|
||||
public $room = false;
|
||||
public $objects = [];
|
||||
private $apiSummary = 'https://plan7.ru/catalog/exp/json/summary/?token=0754c5e6a3824322&zk=614';
|
||||
private $apiAll = 'https://plan7.ru/catalog/exp/json/?token=0754c5e6a3824322&zk=614';
|
||||
private $apiSummary;
|
||||
private $apiAll;
|
||||
public function mount($containerId = 'plan7__selector')
|
||||
{
|
||||
$this->containerId = $containerId;
|
||||
if ($plan7ApiData = Complex::find($this->complexId)->getPlan7ApiData()) {
|
||||
$this->apiSummary = 'https://plan7.ru/catalog/exp/json/summary/?token=' . $plan7ApiData->token . '&zk=' . $plan7ApiData->zk;
|
||||
$this->apiAll = 'https://plan7.ru/catalog/exp/json/?token=' . $plan7ApiData->token . '&zk=' . $plan7ApiData->zk;
|
||||
$this->getSummary();
|
||||
$this->getData();
|
||||
}
|
||||
}
|
||||
|
||||
private function getSummary() {
|
||||
$URL = $this->apiSummary;
|
||||
@ -74,8 +80,6 @@ public function resetFilter() {
|
||||
public function start() {
|
||||
$this->mode = 'select';
|
||||
$this->filter = [];
|
||||
//$this->room = false;
|
||||
$this->getData();
|
||||
}
|
||||
public function done() {
|
||||
$this->mode = 'selected';
|
||||
@ -115,29 +119,7 @@ public function render()
|
||||
];
|
||||
}
|
||||
}
|
||||
/*if (!$this->bs && !$this->room) {
|
||||
foreach ($this->allObjects['values']['bs'] as $key => $house) {
|
||||
$objs[] = [
|
||||
'mode' => 'bs',
|
||||
'id' => $house['id'],
|
||||
'name' => $house['name'],
|
||||
];
|
||||
}
|
||||
} elseif ($this->bs && !$this->room) {
|
||||
foreach ($this->allObjects['data'] as $key => $room) {
|
||||
if ($room['access'] != 0) {
|
||||
$room['mode'] = 'room';
|
||||
$objs[] = $room;
|
||||
}
|
||||
}
|
||||
} elseif ($this->bs && $this->room) {
|
||||
foreach ($this->allObjects['data'] as $key => $room) {
|
||||
if ($room['id'] == $this->room['id']) {
|
||||
$room['mode'] = 'room';
|
||||
$objs[] = $room;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return view('plan7::livewire.selector', [
|
||||
'objs' => $objs
|
||||
]);
|
||||
|
||||
14
app/Modules/Plan7/Models/ComplexPlan7.php
Normal file
14
app/Modules/Plan7/Models/ComplexPlan7.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Plan7\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
class ComplexPlan7 extends Model
|
||||
{
|
||||
protected $table = 'complex_plan7';
|
||||
|
||||
protected $fillable = [
|
||||
'complex_id',
|
||||
'token',
|
||||
'zk'
|
||||
];
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Plan7\Models;
|
||||
|
||||
|
||||
class Plan7Selector
|
||||
{
|
||||
|
||||
}
|
||||
@ -23,6 +23,7 @@ public function boot()
|
||||
$this->registerConfig();
|
||||
$this->registerComponent();
|
||||
$this->registerLivewire();
|
||||
$this->registerHelpers();
|
||||
}
|
||||
|
||||
protected function registerViews()
|
||||
@ -68,4 +69,12 @@ protected function registerComponent()
|
||||
{
|
||||
//Blade::component('document', \Modules\Plan7\Http\Components\DocumentComponent::class);
|
||||
}
|
||||
|
||||
protected function registerHelpers()
|
||||
{
|
||||
$files = glob(__DIR__ . '/../Helpers/' . "*.php");
|
||||
foreach ($files as $key => $file) {
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
app/Modules/Plan7/Traits/Plan7.php
Normal file
22
app/Modules/Plan7/Traits/Plan7.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Plan7\Traits;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Modules\Plan7\Models\ComplexPlan7;
|
||||
trait Plan7
|
||||
{
|
||||
public function getPlan7ApiData()
|
||||
{
|
||||
if ( $plan7 = ComplexPlan7::where('complex_id', $this->id)->first() ) {
|
||||
return $plan7;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
if($json['total_commits'] > 0)
|
||||
{
|
||||
//$result = shell_exec("cd /var/www/lk && git reset --hard HEAD && git pull && npm run build");
|
||||
$result = shell_exec("cd /var/www/lk && git reset --hard HEAD && git pull && npm run build && php artisan optimize:clear");
|
||||
$result = shell_exec("cd /var/www/lk && git reset --hard HEAD && git pull && php artisan migrate && npm run build && php artisan optimize:clear");
|
||||
echo "<p>$result</p>" ;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user