feat: add user notification center
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace app\adminapi\controller\notice;
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\notice\UserNoticeLists;
|
||||
use app\adminapi\validate\notice\UserNoticeValidate;
|
||||
use app\common\enum\notice\UserNoticeEnum;
|
||||
use app\common\model\notice\NoticeRecord;
|
||||
use app\common\service\notice\UserNoticeService;
|
||||
|
||||
/**
|
||||
* 站内消息管理。
|
||||
*/
|
||||
class UserNoticeController extends BaseAdminController
|
||||
{
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new UserNoticeLists());
|
||||
}
|
||||
|
||||
public function options()
|
||||
{
|
||||
return $this->data([
|
||||
'scene_options' => UserNoticeEnum::getOptions(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function send()
|
||||
{
|
||||
$params = (new UserNoticeValidate())->post()->goCheck('send');
|
||||
$scope = (string) $params['recipient_scope'];
|
||||
$userIds = $scope === 'specified'
|
||||
? array_values(array_unique(array_map('intval', $params['user_ids'])))
|
||||
: [];
|
||||
$sentCount = UserNoticeService::sendSystem(
|
||||
trim((string) $params['title']),
|
||||
trim((string) $params['content']),
|
||||
trim((string) ($params['target_url'] ?? '')),
|
||||
$userIds
|
||||
);
|
||||
|
||||
if ($sentCount === 0) {
|
||||
return $this->fail('没有可接收消息的启用用户');
|
||||
}
|
||||
|
||||
return $this->success("已发送给 {$sentCount} 位用户");
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$ids = $this->request->post('ids/a', []);
|
||||
$ids = array_values(array_unique(array_filter(array_map('intval', $ids))));
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择需要删除的消息');
|
||||
}
|
||||
|
||||
NoticeRecord::whereIn('id', $ids)
|
||||
->whereIn('scene_id', UserNoticeEnum::getSceneIds())
|
||||
->delete();
|
||||
|
||||
return $this->success('删除成功');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user