feat(sales): Eloquent-модели портала продаж

Task 0.2: SalesUser (Authenticatable + HasApiTokens, isHead), SalesTariff, SalesClientAssignment (snapshot тарифа), SalesAttachmentRequest, SalesPayout (append-only через триггер БД). Тест tests/Feature/Sales/SalesModelsTest.php — 9 passed. Разрешение хозяина: один эскейп на сессию.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Дмитрий
2026-06-30 12:08:52 +03:00
parent b0794fbef6
commit 9b91016f46
6 changed files with 531 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* Привязка «один менеджер один клиент» с snapshot тарифа.
*
* SaaS-level модель: без RLS. tenant_id UNIQUE один клиент всегда
* принадлежит не более чем одному менеджеру.
*
* tariff_params snapshot параметров тарифа на момент привязки
* (копируется из SalesTariff.params, не следует live изменениям тарифа).
*
* Timestamps: только created_at (нет updated_at без timestamps = false,
* задаём через $timestamps).
*
* Источник: db/migrations/2026_07_01_100000_create_sales_portal_tables.php
*
* @property int $id
* @property int $sales_user_id
* @property int $tenant_id
* @property int|null $tariff_id
* @property string|null $tariff_kind
* @property array<string,mixed> $tariff_params
* @property \Carbon\Carbon $assigned_at
* @property \Carbon\Carbon $created_at
*/
class SalesClientAssignment extends Model
{
public $timestamps = false;
protected $fillable = [
'sales_user_id',
'tenant_id',
'tariff_id',
'tariff_kind',
'tariff_params',
'assigned_at',
];
protected function casts(): array
{
return [
'tariff_params' => 'array',
'assigned_at' => 'datetime',
'created_at' => 'datetime',
];
}
/** @return BelongsTo<SalesUser, $this> */
public function salesUser(): BelongsTo
{
return $this->belongsTo(SalesUser::class, 'sales_user_id');
}
/** @return BelongsTo<SalesTariff, $this> */
public function tariff(): BelongsTo
{
return $this->belongsTo(SalesTariff::class, 'tariff_id');
}
/** @return BelongsTo<Tenant, $this> */
public function tenant(): BelongsTo
{
return $this->belongsTo(Tenant::class, 'tenant_id');
}
}