mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-30 22:24:55 +08:00
69 lines
1.7 KiB
PHP
69 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Listeners;
|
|
|
|
use App\Caches\ChapterCounter as CacheChapterCounter;
|
|
use App\Models\Chapter as ChapterModel;
|
|
use App\Services\Syncer\ChapterCounter as ChapterCounterSyncer;
|
|
use Phalcon\Events\Event;
|
|
|
|
class ChapterCounter extends Listener
|
|
{
|
|
|
|
protected $counter;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->counter = new CacheChapterCounter();
|
|
}
|
|
|
|
public function incrUserCount(Event $event, $source, ChapterModel $chapter)
|
|
{
|
|
$this->counter->hIncrBy($chapter->id, 'user_count');
|
|
|
|
$this->syncChapterCounter($chapter);
|
|
}
|
|
|
|
public function decrUserCount(Event $event, $source, ChapterModel $chapter)
|
|
{
|
|
$this->counter->hDecrBy($chapter->id, 'user_count');
|
|
|
|
$this->syncChapterCounter($chapter);
|
|
}
|
|
|
|
public function incrConsultCount(Event $event, $source, ChapterModel $chapter)
|
|
{
|
|
$this->counter->hIncrBy($chapter->id, 'consult_count');
|
|
|
|
$this->syncChapterCounter($chapter);
|
|
}
|
|
|
|
public function decrConsultCount(Event $event, $source, ChapterModel $chapter)
|
|
{
|
|
$this->counter->hDecrBy($chapter->id, 'consult_count');
|
|
|
|
$this->syncChapterCounter($chapter);
|
|
}
|
|
|
|
public function incrLikeCount(Event $event, $source, ChapterModel $chapter)
|
|
{
|
|
$this->counter->hIncrBy($chapter->id, 'like_count');
|
|
|
|
$this->syncChapterCounter($chapter);
|
|
}
|
|
|
|
public function decrLikeCount(Event $event, $source, ChapterModel $chapter)
|
|
{
|
|
$this->counter->hDecrBy($chapter->id, 'like_count');
|
|
|
|
$this->syncChapterCounter($chapter);
|
|
}
|
|
|
|
protected function syncChapterCounter(ChapterModel $chapter)
|
|
{
|
|
$syncer = new ChapterCounterSyncer();
|
|
|
|
$syncer->addItem($chapter->id);
|
|
}
|
|
|
|
} |