增加后台消息通知管理
This commit is contained in:
@@ -2,11 +2,13 @@
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\logic\MessageNotificationsLogic;
|
||||
use app\common\validate\MessageNotificationsValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\MessageNotifications;
|
||||
use app\common\model\User;
|
||||
use support\Db;
|
||||
use support\Request;
|
||||
|
||||
class MessageNotificationsService
|
||||
{
|
||||
@@ -31,6 +33,78 @@ class MessageNotificationsService
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
$config['order']['id'] = 'desc';
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
public function serviceDestroy(Request $request)
|
||||
{
|
||||
$config = $this->buildQueryConfig($request, 'destroy');
|
||||
$deleted = (new MessageNotificationsLogic())->logicDeleteBy($config);
|
||||
return $this->postProcess('Destroy', $deleted);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加前置处理
|
||||
*/
|
||||
public function servicePush(Request $request, $data)
|
||||
{
|
||||
$pushData = [
|
||||
'sender_id' => $request->user->uid,
|
||||
'sender_type' => 'admin',
|
||||
'title' => $data['title'],
|
||||
'content' => $data['content'],
|
||||
'scene' => 1,
|
||||
'recipient' => $data['recipient'],
|
||||
'push_method' => 1
|
||||
];
|
||||
$msgId = (new MessageNotificationsService())->pushNotice($pushData);
|
||||
return ['msg_id' => $msgId];
|
||||
}
|
||||
|
||||
public function afterServiceList($data)
|
||||
{
|
||||
$data->each(function (&$item) {
|
||||
$temp = explode(',', $item->recipient);
|
||||
$item->recipient_list = User::whereIn('id', $temp)->pluck('name')->toArray();
|
||||
$item->scene_name = MessageNotifications::SCENE[$item->scene];
|
||||
$item->push_method_name = MessageNotifications::PUSH_METHOD[$item->push_method];
|
||||
});
|
||||
unset($item);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function afterServiceShow($data)
|
||||
{
|
||||
$temp = explode(',', $data->recipient);
|
||||
$data->recipient_list = User::whereIn('id', $temp)->pluck('name')->toArray();
|
||||
$data->scene_name = MessageNotifications::SCENE[$data->scene];
|
||||
$data->push_method_name = MessageNotifications::PUSH_METHOD[$data->push_method];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一条消息
|
||||
@@ -45,6 +119,7 @@ class MessageNotificationsService
|
||||
'content' => $data['content'],
|
||||
'scene' => $data['scene'],
|
||||
'recipient' => $data['recipient'],
|
||||
'push_method' => $data['push_method'],
|
||||
'created_at' => time(),
|
||||
]);
|
||||
|
||||
@@ -116,6 +191,7 @@ class MessageNotificationsService
|
||||
'content' => $data['content'],
|
||||
'scene' => $data['scene'],
|
||||
'recipient' => $data['recipient'] ? implode(',', $data['recipient']) : '',
|
||||
'push_method' => $data['push_method'],
|
||||
]);
|
||||
|
||||
// 写用户状态
|
||||
|
||||
Reference in New Issue
Block a user