start tasks module

This commit is contained in:
root
2026-01-23 08:48:06 +03:00
parent 283b9132a0
commit 725c62a179
22 changed files with 2489 additions and 6 deletions
+55 -4
View File
@@ -4,6 +4,7 @@ namespace App\Modules\CRM\Services;
use App\Modules\CRM\Models\DealModel;
use App\Modules\CRM\Models\DealStageModel;
use CodeIgniter\Events\Events;
class DealService
{
@@ -23,7 +24,18 @@ class DealService
{
$data['created_by'] = $userId;
return $this->dealModel->insert($data);
$dealId = $this->dealModel->insert($data);
if ($dealId) {
$deal = $this->dealModel->find($dealId);
Events::trigger('deal.created', [
'deal_id' => $dealId,
'deal' => $deal,
'user_id' => $userId,
]);
}
return $dealId;
}
/**
@@ -36,7 +48,20 @@ class DealService
return false;
}
return $this->dealModel->update($dealId, $data);
$result = $this->dealModel->update($dealId, $data);
if ($result) {
$newDeal = $this->dealModel->find($dealId);
Events::trigger('deal.updated', [
'deal_id' => $dealId,
'old_deal' => $oldDeal,
'new_deal' => $newDeal,
'changes' => $data,
'user_id' => $userId,
]);
}
return $result;
}
/**
@@ -54,7 +79,23 @@ class DealService
return false;
}
return $this->dealModel->update($dealId, ['stage_id' => $newStageId]);
$oldStageId = $deal['stage_id'];
$result = $this->dealModel->update($dealId, ['stage_id' => $newStageId]);
if ($result) {
$updatedDeal = $this->dealModel->find($dealId);
Events::trigger('deal.stage_changed', [
'deal_id' => $dealId,
'deal' => $updatedDeal,
'old_stage_id' => $oldStageId,
'new_stage_id' => $newStageId,
'old_stage' => $this->stageModel->find($oldStageId),
'new_stage' => $newStage,
'user_id' => $userId,
]);
}
return $result;
}
/**
@@ -67,7 +108,17 @@ class DealService
return false;
}
return $this->dealModel->delete($dealId);
$result = $this->dealModel->delete($dealId);
if ($result) {
Events::trigger('deal.deleted', [
'deal_id' => $dealId,
'deal' => $deal,
'user_id' => $userId,
]);
}
return $result;
}
/**