c366614fcd
Task 0.5+0.6: SalesAuthController (login 200/422/403, me, logout) + маршруты /api/sales/auth и зона данных. Порядок middleware admin-db ДО auth:sales. Тест SalesAuthTest 7/7, весь sales-набор 25/25. Logout инвалидирует токен (в тесте Auth::forgetGuards() — артефакт мульти-запросов; в бою каждый запрос свежий). Larastan baseline: Pest false-pos SalesAuthTest. Заодно pint-канон моделей/трейта/SalesModelsTest. Один эскейп на сессию. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
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 $assigned_at
|
|
* @property 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');
|
|
}
|
|
}
|