mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-23 03:50:56 +08:00
优化通知计数
This commit is contained in:
parent
a3cb6d757a
commit
d8c5a3d0a2
@ -198,4 +198,16 @@ class Notification extends Model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function afterCreate()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var $user User
|
||||||
|
*/
|
||||||
|
$user = User::findFirst($this->receiver_id);
|
||||||
|
|
||||||
|
$user->notice_count += 1;
|
||||||
|
|
||||||
|
$user->update();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -154,6 +154,13 @@ class User extends Model
|
|||||||
*/
|
*/
|
||||||
public $favorite_count = 0;
|
public $favorite_count = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通知数
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $notice_count = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会员期限
|
* 会员期限
|
||||||
*
|
*
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
namespace App\Services\Logic\User\Console;
|
namespace App\Services\Logic\User\Console;
|
||||||
|
|
||||||
use App\Repos\User as UserRepo;
|
|
||||||
use App\Services\Logic\Service as LogicService;
|
use App\Services\Logic\Service as LogicService;
|
||||||
|
|
||||||
class NotifyStats extends LogicService
|
class NotifyStats extends LogicService
|
||||||
@ -17,16 +16,7 @@ class NotifyStats extends LogicService
|
|||||||
{
|
{
|
||||||
$user = $this->getLoginUser();
|
$user = $this->getLoginUser();
|
||||||
|
|
||||||
$noticeCount = $this->getNoticeCount($user->id);
|
return ['notice_count' => $user->notice_count];
|
||||||
|
|
||||||
return ['notice_count' => $noticeCount];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getNoticeCount($userId)
|
|
||||||
{
|
|
||||||
$userRepo = new UserRepo();
|
|
||||||
|
|
||||||
return $userRepo->countUnreadNotifications($userId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ final class V20221021035953 extends AbstractMigration
|
|||||||
{
|
{
|
||||||
$this->alterPageTable();
|
$this->alterPageTable();
|
||||||
$this->alterHelpTable();
|
$this->alterHelpTable();
|
||||||
|
$this->alterUserTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function alterPageTable()
|
protected function alterPageTable()
|
||||||
@ -53,4 +54,22 @@ final class V20221021035953 extends AbstractMigration
|
|||||||
$table->save();
|
$table->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function alterUserTable()
|
||||||
|
{
|
||||||
|
$table = $this->table('kg_user');
|
||||||
|
|
||||||
|
if ($table->hasColumn('notice_count') == false) {
|
||||||
|
$table->addColumn('notice_count', 'integer', [
|
||||||
|
'null' => false,
|
||||||
|
'default' => '0',
|
||||||
|
'limit' => MysqlAdapter::INT_REGULAR,
|
||||||
|
'signed' => false,
|
||||||
|
'comment' => '通知数',
|
||||||
|
'after' => 'favorite_count',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$table->save();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ layui.use(['jquery', 'form', 'element', 'layer', 'helper'], function () {
|
|||||||
$token.attr('content', res.token);
|
$token.attr('content', res.token);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 300000);
|
}, 600000);
|
||||||
|
|
||||||
if (window.user.id > 0) {
|
if (window.user.id > 0) {
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
@ -60,7 +60,7 @@ layui.use(['jquery', 'form', 'element', 'layer', 'helper'], function () {
|
|||||||
$notifyDot.removeClass('layui-badge-dot');
|
$notifyDot.removeClass('layui-badge-dot');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 30000);
|
}, 60000);
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
$.post('/uc/online');
|
$.post('/uc/online');
|
||||||
}, 60000);
|
}, 60000);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user