add CRM module start

This commit is contained in:
root
2026-01-15 07:09:36 +03:00
parent b14f293a45
commit b810a17649
40 changed files with 3807 additions and 14 deletions
+66
View File
@@ -0,0 +1,66 @@
<?php
namespace App\Modules\CRM\Models;
use CodeIgniter\Model;
use App\Models\Traits\TenantScopedModel;
class ContactModel extends Model
{
use TenantScopedModel;
protected $table = 'contacts';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = \App\Modules\CRM\Entities\Contact::class;
protected $useSoftDeletes = true;
protected $allowedFields = [
'organization_id',
'customer_id',
'name',
'email',
'phone',
'position',
'is_primary',
'notes',
];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
/**
* Получить контакты клиента
*/
public function getContactsForCustomer(int $customerId): array
{
return $this->where('customer_id', $customerId)->findAll();
}
/**
* Получить основной контакт клиента
*/
public function getPrimaryContact(int $customerId): ?object
{
return $this->where('customer_id', $customerId)
->where('is_primary', true)
->first();
}
/**
* Получить список контактов для выпадающего списка
*/
public function getContactsList(int $organizationId): array
{
$contacts = $this->where('organization_id', $organizationId)
->orderBy('name', 'ASC')
->findAll();
$list = [];
foreach ($contacts as $contact) {
$list[$contact->id] = $contact->name . ($contact->email ? " ({$contact->email})" : '');
}
return $list;
}
}