deal updated
This commit is contained in:
parent
f490c32bc0
commit
c896647a35
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
use App\Models\Deal;
|
use App\Models\Deal\Deal;
|
||||||
use App\Models\Agent\Agent;
|
use App\Models\Agent\Agent;
|
||||||
use App\Models\City;
|
use App\Models\City;
|
||||||
|
|
||||||
|
|||||||
@ -3,8 +3,8 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\Deal\Deal;
|
||||||
use App\Models\Deal;
|
use App\Models\Deal\DealStatus;
|
||||||
|
|
||||||
class ConfirmClientFromBitrix extends Controller
|
class ConfirmClientFromBitrix extends Controller
|
||||||
{
|
{
|
||||||
@ -13,11 +13,11 @@ public function confirm(Request $request)
|
|||||||
$deal = Deal::where('confirm_token', $request->hash)->first();
|
$deal = Deal::where('confirm_token', $request->hash)->first();
|
||||||
if ($request->is_unique == true)
|
if ($request->is_unique == true)
|
||||||
{
|
{
|
||||||
$deal->is_unique = true;
|
$deal->status = DealStatus::UNIQUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$deal->is_unique = false;
|
$deal->is_unique = DealStatus::NOT_UNIQUE;
|
||||||
}
|
}
|
||||||
$deal->save();
|
$deal->save();
|
||||||
return $deal->id;
|
return $deal->id;
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
use App\Models\Company\CompanyAdmin;
|
use App\Models\Company\CompanyAdmin;
|
||||||
use App\Models\Agent\Agent;
|
use App\Models\Agent\Agent;
|
||||||
use App\Models\Agent\AgentStatus;
|
use App\Models\Agent\AgentStatus;
|
||||||
use App\Models\Deal;
|
use App\Models\Deal\Deal;
|
||||||
|
|
||||||
class AgentsTable extends Component
|
class AgentsTable extends Component
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
use Livewire\WithoutUrlPagination;
|
use Livewire\WithoutUrlPagination;
|
||||||
|
|
||||||
use App\Models\Agent\Agent;
|
use App\Models\Agent\Agent;
|
||||||
use App\Models\Deal;
|
use App\Models\Deal\Deal;
|
||||||
|
|
||||||
class ClientsTable extends Component
|
class ClientsTable extends Component
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,9 +4,9 @@
|
|||||||
|
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Deal;
|
use App\Models\Deal\Deal;
|
||||||
|
use App\Models\Deal\DealStatus;
|
||||||
use App\Models\Complex;
|
use App\Models\Complex;
|
||||||
use App\Models\Status;
|
|
||||||
use App\Models\Agent\Agent;
|
use App\Models\Agent\Agent;
|
||||||
use App\Models\Bitrix\SendClient;
|
use App\Models\Bitrix\SendClient;
|
||||||
|
|
||||||
@ -126,12 +126,13 @@ public function save()
|
|||||||
'complex_id' => $this->client['complexId']
|
'complex_id' => $this->client['complexId']
|
||||||
];
|
];
|
||||||
$data['confirm_token'] = $this->client['confirmToken'] = hash('sha256', json_encode($data));
|
$data['confirm_token'] = $this->client['confirmToken'] = hash('sha256', json_encode($data));
|
||||||
|
|
||||||
if ($newDeal = Deal::create($data))
|
if ($newDeal = Deal::create($data))
|
||||||
{
|
{
|
||||||
if ($bitrixId = $this->sendToBitrix($newDeal->id))
|
if ($bitrixId = $this->sendToBitrix($newDeal->id))
|
||||||
{
|
{
|
||||||
$newDeal->bitrix_id = $bitrixId;
|
$newDeal->bitrix_id = $bitrixId;
|
||||||
$newDeal->status = 'MODERATION';
|
$newDeal->status = DealStatus::MODERATION;
|
||||||
$newDeal->save();
|
$newDeal->save();
|
||||||
$this->result = $bitrixId;
|
$this->result = $bitrixId;
|
||||||
return $this->status = self::SUCCESS;
|
return $this->status = self::SUCCESS;
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
use App\Models\Company\Company;
|
use App\Models\Company\Company;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Deal;
|
use App\Models\Deal\Deal;
|
||||||
|
|
||||||
class Agent extends Model
|
class Agent extends Model
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,27 +7,31 @@
|
|||||||
use App\Models\Company\Company;
|
use App\Models\Company\Company;
|
||||||
|
|
||||||
class Details
|
class Details
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
public $details;
|
public $details;
|
||||||
public function __construct(Company $company) {
|
public function __construct(Company $company)
|
||||||
|
{
|
||||||
$company;
|
$company;
|
||||||
if (!$company->details) {
|
if (!$company->details)
|
||||||
if ($company->type == 'SELFEMP')
|
|
||||||
{
|
{
|
||||||
|
if ($company->type == 'SELFEMP')
|
||||||
|
{
|
||||||
$company->details = $this->emptyForSelfEmp();
|
$company->details = $this->emptyForSelfEmp();
|
||||||
$company->save();
|
$company->save();
|
||||||
};
|
}
|
||||||
|
;
|
||||||
if ($company->type == 'AGENCY')
|
if ($company->type == 'AGENCY')
|
||||||
{
|
{
|
||||||
$company->details = $this->emptyForAgency();
|
$company->details = $this->emptyForAgency();
|
||||||
$company->save();
|
$company->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$this->details = $company->details;
|
$this->details = $company->details;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function emptyForSelfEmp() {
|
private function emptyForSelfEmp()
|
||||||
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'user' => [
|
'user' => [
|
||||||
'firstName' => '',
|
'firstName' => '',
|
||||||
@ -49,9 +53,10 @@ private function emptyForSelfEmp() {
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function emptyForAgency() {
|
private function emptyForAgency()
|
||||||
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'name' => '',
|
'name' => '',
|
||||||
'fullName' => '',
|
'fullName' => '',
|
||||||
@ -72,5 +77,5 @@ private function emptyForAgency() {
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
return $data;
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models\Deal;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Deal extends Model
|
class Deal extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'client_id',
|
'client_id',
|
||||||
'complex_id',
|
'complex_id',
|
||||||
'agent_id',
|
'agent_id',
|
||||||
'bitrix_id',
|
'bitrix_id',
|
||||||
@ -17,11 +17,13 @@ class Deal extends Model
|
|||||||
'confirm_token'
|
'confirm_token'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function complex() {
|
public function complex()
|
||||||
|
{
|
||||||
return $this->belongsTo(\App\Models\Complex::class);
|
return $this->belongsTo(\App\Models\Complex::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function user() {
|
public function user()
|
||||||
|
{
|
||||||
return $this->belongsTo(\App\Models\User::class, 'client_id');
|
return $this->belongsTo(\App\Models\User::class, 'client_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
11
app/Models/Deal/DealStatus.php
Normal file
11
app/Models/Deal/DealStatus.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Deal;
|
||||||
|
|
||||||
|
final class DealStatus
|
||||||
|
{
|
||||||
|
public const NEW = 'NEW';
|
||||||
|
public const MODERATION = 'MODERATION';
|
||||||
|
public const UNIQUE = 'UNIQUE';
|
||||||
|
public const NOT_UNIQUE = 'NOT UNIQUE';
|
||||||
|
}
|
||||||
@ -5,29 +5,30 @@
|
|||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*/
|
*/
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
Schema::create('deals', function (Blueprint $table) {
|
Schema::create('deals', function (Blueprint $table)
|
||||||
|
{
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('client_id')->references('id')->on('users');
|
$table->foreignId('client_id')->references('id')->on('users');
|
||||||
$table->foreignId('complex_id')->references('id')->on('complexes')->onDelete('cascade');
|
$table->foreignId('complex_id')->references('id')->on('complexes')->onDelete('cascade');
|
||||||
$table->foreignId('agent_id')->references('id')->on('agents')->onDelete('cascade');
|
$table->foreignId('agent_id')->references('id')->on('agents')->onDelete('cascade');
|
||||||
$table->string('bitrix_id')->nullable();
|
$table->string('bitrix_id')->nullable();
|
||||||
$table->string('confirm_token')->nullable();
|
$table->string('confirm_token')->nullable();
|
||||||
$table->enum('status',['NEW','MODERATION','UNIQUE','NOT UNIQUE'])->default('NEW');
|
$table->enum('status', ['NEW', 'MODERATION', 'UNIQUE', 'NOT UNIQUE'])->default('NEW');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverse the migrations.
|
* Reverse the migrations.
|
||||||
*/
|
*/
|
||||||
public function down(): void
|
public function down(): void
|
||||||
{
|
{
|
||||||
Schema::dropIfExists('clients');
|
Schema::dropIfExists('clients');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user