chuan 4 weeks ago
parent
commit
1b7495f5f1
  1. 12
      app/admin/controller/Notice.php
  2. 6
      app/home/controller/Notice.php
  3. 2
      app/home/route/app.php
  4. 28
      app/home/service/NoticeService.php
  5. 7
      app/model/PusherLogModel.php

12
app/admin/controller/Notice.php

@ -3,6 +3,7 @@
namespace app\admin\controller;
use app\admin\service\NoticeService;
use app\model\PusherLogModel;
class Notice extends AdminBaseController
{
@ -48,15 +49,26 @@ class Notice extends AdminBaseController
// 将用户ID构建为数组
$explodeUser = explode(',', $param['users']);
$buildUserArr = [];
$insertData = [];
foreach ($explodeUser as $uid) {
if (is_numeric($uid)) {
$buildUserArr[] = strval($uid);
} else {
$buildUserArr[] = $uid;
}
$insertData[] = [
'user_id' => $uid,
'title' => $param['title'],
'content' => $param['body'],
];
}
// 发送通知
$res = (new \app\utility\Pusher())->publishToUsers($buildUserArr, $param['title'], $param['body']);
// 保存每个用户推送的消息内容
if (!empty($insertData)) {
PusherLogModel::insertAll($insertData);
}
return json([
'code' => 0,
'message' => 'ok',

6
app/home/controller/Notice.php

@ -11,4 +11,10 @@ class Notice extends HomeBaseController
$returnData = (new NoticeService())->generateToken($this->request->param());
return json($returnData);
}
public function pusherLog()
{
$returnData = (new NoticeService())->pusherLog($this->request->param(), $this->request->userId);
return json($returnData);
}
}

2
app/home/route/app.php

@ -184,6 +184,8 @@ Route::group('/',function (){
})->middleware(\app\home\middleware\RepeatOperateMiddleware::class);
Route::post('notice/pusher_log', 'Notice/pusherLog');
// 新增实名认证
Route::post('user_verify/detail', 'UserVerify/detail');

28
app/home/service/NoticeService.php

@ -1,6 +1,7 @@
<?php
namespace app\home\service;
use app\model\PusherLogModel;
use app\model\UserModel;
class NoticeService extends BaseHomeService
@ -27,4 +28,31 @@ class NoticeService extends BaseHomeService
return $this->toData('500', lang('system_busy'), [$exception->getMessage(), $exception->getTrace()]);
}
}
public function pusherLog($param, $userId): array
{
try {
if (empty($param['page']) || !is_numeric($param['page'])) {
return $this->toData('400', lang('parameter_error'));
}
if (empty($param['limit']) || !is_numeric($param['limit'])) {
return $this->toData('400', lang('parameter_error'));
}
// 获取pusher推送记录
$list = PusherLogModel::where(['user_id'=>$userId])->order('id', 'desc')->paginate([
'list_rows' => $param['limit'],
'page' => $param['page'],
]);
return $this->toData('0', 'successful', [
'list' => $list->items(),
'total' => $list->total(),
'page' => $list->currentPage(),
'last_page' => $list->lastPage(),
'user_id' => $userId,
]);
} catch (\Exception $exception) {
return $this->toData('500', lang('system_busy'), [$exception->getMessage(), $exception->getTrace()]);
}
}
}

7
app/model/PusherLogModel.php

@ -0,0 +1,7 @@
<?php
namespace app\model;
class PusherLogModel extends BaseModel
{
protected $name = 'pusher_log';
}
Loading…
Cancel
Save