deal updated

This commit is contained in:
Thekindbull 2024-12-18 19:33:25 +08:00
parent f490c32bc0
commit c896647a35
10 changed files with 59 additions and 39 deletions

View File

@ -4,7 +4,7 @@
use Illuminate\Http\Request;
use App\Models\Deal;
use App\Models\Deal\Deal;
use App\Models\Agent\Agent;
use App\Models\City;

View File

@ -3,8 +3,8 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Deal;
use App\Models\Deal\Deal;
use App\Models\Deal\DealStatus;
class ConfirmClientFromBitrix extends Controller
{
@ -13,11 +13,11 @@ public function confirm(Request $request)
$deal = Deal::where('confirm_token', $request->hash)->first();
if ($request->is_unique == true)
{
$deal->is_unique = true;
$deal->status = DealStatus::UNIQUE;
}
else
{
$deal->is_unique = false;
$deal->is_unique = DealStatus::NOT_UNIQUE;
}
$deal->save();
return $deal->id;

View File

@ -8,7 +8,7 @@
use App\Models\Company\CompanyAdmin;
use App\Models\Agent\Agent;
use App\Models\Agent\AgentStatus;
use App\Models\Deal;
use App\Models\Deal\Deal;
class AgentsTable extends Component
{

View File

@ -7,7 +7,7 @@
use Livewire\WithoutUrlPagination;
use App\Models\Agent\Agent;
use App\Models\Deal;
use App\Models\Deal\Deal;
class ClientsTable extends Component
{

View File

@ -4,9 +4,9 @@
use Livewire\Component;
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\Status;
use App\Models\Agent\Agent;
use App\Models\Bitrix\SendClient;
@ -126,12 +126,13 @@ public function save()
'complex_id' => $this->client['complexId']
];
$data['confirm_token'] = $this->client['confirmToken'] = hash('sha256', json_encode($data));
if ($newDeal = Deal::create($data))
{
if ($bitrixId = $this->sendToBitrix($newDeal->id))
{
$newDeal->bitrix_id = $bitrixId;
$newDeal->status = 'MODERATION';
$newDeal->status = DealStatus::MODERATION;
$newDeal->save();
$this->result = $bitrixId;
return $this->status = self::SUCCESS;

View File

@ -9,7 +9,7 @@
use App\Models\Company\Company;
use App\Models\User;
use App\Models\Deal;
use App\Models\Deal\Deal;
class Agent extends Model
{

View File

@ -7,17 +7,20 @@
use App\Models\Company\Company;
class Details
{
{
use HasFactory;
public $details;
public function __construct(Company $company) {
public function __construct(Company $company)
{
$company;
if (!$company->details) {
if (!$company->details)
{
if ($company->type == 'SELFEMP')
{
$company->details = $this->emptyForSelfEmp();
$company->save();
};
}
;
if ($company->type == 'AGENCY')
{
$company->details = $this->emptyForAgency();
@ -27,7 +30,8 @@ public function __construct(Company $company) {
$this->details = $company->details;
}
private function emptyForSelfEmp() {
private function emptyForSelfEmp()
{
$data = [
'user' => [
'firstName' => '',
@ -51,7 +55,8 @@ private function emptyForSelfEmp() {
return $data;
}
private function emptyForAgency() {
private function emptyForAgency()
{
$data = [
'name' => '',
'fullName' => '',
@ -73,4 +78,4 @@ private function emptyForAgency() {
];
return $data;
}
}
}

View File

@ -1,12 +1,12 @@
<?php
namespace App\Models;
namespace App\Models\Deal;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Deal extends Model
{
{
use HasFactory;
protected $fillable = [
'client_id',
@ -17,11 +17,13 @@ class Deal extends Model
'confirm_token'
];
public function complex() {
public function complex()
{
return $this->belongsTo(\App\Models\Complex::class);
}
public function user() {
public function user()
{
return $this->belongsTo(\App\Models\User::class, 'client_id');
}
}
}

View 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';
}

View File

@ -5,20 +5,21 @@
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('deals', function (Blueprint $table) {
Schema::create('deals', function (Blueprint $table)
{
$table->id();
$table->foreignId('client_id')->references('id')->on('users');
$table->foreignId('complex_id')->references('id')->on('complexes')->onDelete('cascade');
$table->foreignId('agent_id')->references('id')->on('agents')->onDelete('cascade');
$table->string('bitrix_id')->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();
});
}
@ -30,4 +31,4 @@ public function down(): void
{
Schema::dropIfExists('clients');
}
};
};