обновлен механизм подсчета вознаграждения

This commit is contained in:
Thekindbull 2025-08-19 09:12:40 +08:00
parent aa802811f1
commit 33e61ac20d
5 changed files with 54 additions and 3 deletions

View File

@ -70,7 +70,7 @@ public function syncDeals(Agent $agent)
{
$dealItem = Deal::create([
'client_id' => $client->id,
'complex_id' => 1,
'complex_id' => $inDeal->complex_id,
'agent_id' => $agent->id,
'status' => DealStatus::UNIQUE,
]);

View File

@ -41,7 +41,12 @@
</td>
<td class="align-middle">
<?php
$contract->reward = $contract->reward ? $contract->reward : 0;
$agent = $contract->deal->agent;
$agentPaymentable = $agent->getPaymentable($contract->deal->complex);
$rewardPercent = $agentPaymentable->getPaymentablePercent();
$price = $contract->price;
$contract->reward = ($price * $rewardPercent) / 100;
//$contract->reward = $contract->reward ? $contract->reward : 0;
$reward = Number::forHumans($contract->reward, precision: 2);
$reward = str_replace('million', 'млн', $reward);
$reward = str_replace('thousand', 'тыс', $reward);

View File

@ -0,0 +1,17 @@
<?php
namespace Modules\Payment\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Agent\Agent;
class AgentPayment
{
private $agent;
public function __construct(Agent $agent)
{
}
}

View File

@ -4,7 +4,9 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Agent\Agent;
use App\Models\Company\Company;
use App\Models\Complex;
class Payment extends Model
{
use HasFactory;
@ -14,4 +16,30 @@ class Payment extends Model
'complex_id',
'value'
];
public function getPaymentablePercent()
{
//наследуется
if ((int) $this->value == -1)
{
if ($this->paymentable_type == 'Company')
{
return false;
}
if ($this->paymentable_type == 'Agent')
{
$agent = Agent::find($this->paymentable_id);
$company = $agent->company;
$parentPaymentable = $company->getPaymentable(Complex::find($this->complex_id));
return $parentPaymentable->getPaymentablePercent();
}
}
//не установлено
if ($this->value == null)
{
return false;
}
return $this->value;
}
}

View File

@ -46,6 +46,7 @@ public function getPaymentable(Complex $complex)
return false;
}
public function setPayment(Complex $complex, $value)
{
$paymentable = $this->getPaymentable($complex);