mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 19:35:50 +00:00
项目相关通知忽略当前用户
This commit is contained in:
parent
867a46a791
commit
ce32d137fb
@ -7,6 +7,7 @@ use App\Module\Base;
|
|||||||
use App\Tasks\PushTask;
|
use App\Tasks\PushTask;
|
||||||
use Hhxsv5\LaravelS\Swoole\Task\Task;
|
use Hhxsv5\LaravelS\Swoole\Task\Task;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Project
|
* Class Project
|
||||||
@ -308,6 +309,7 @@ class Project extends AbstractModel
|
|||||||
$userid = $this->relationUserids();
|
$userid = $this->relationUserids();
|
||||||
}
|
}
|
||||||
$lists = [
|
$lists = [
|
||||||
|
'ignoreFd' => Request::header('fd'),
|
||||||
'userid' => $userid,
|
'userid' => $userid,
|
||||||
'msg' => [
|
'msg' => [
|
||||||
'type' => 'project',
|
'type' => 'project',
|
||||||
|
|||||||
@ -6,6 +6,7 @@ use App\Module\Base;
|
|||||||
use App\Tasks\PushTask;
|
use App\Tasks\PushTask;
|
||||||
use Hhxsv5\LaravelS\Swoole\Task\Task;
|
use Hhxsv5\LaravelS\Swoole\Task\Task;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ProjectColumn
|
* Class ProjectColumn
|
||||||
@ -117,6 +118,7 @@ class ProjectColumn extends AbstractModel
|
|||||||
$userid = $this->project->relationUserids();
|
$userid = $this->project->relationUserids();
|
||||||
}
|
}
|
||||||
$lists = [
|
$lists = [
|
||||||
|
'ignoreFd' => Request::header('fd'),
|
||||||
'userid' => $userid,
|
'userid' => $userid,
|
||||||
'msg' => [
|
'msg' => [
|
||||||
'type' => 'projectColumn',
|
'type' => 'projectColumn',
|
||||||
|
|||||||
@ -9,6 +9,7 @@ use Arr;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Hhxsv5\LaravelS\Swoole\Task\Task;
|
use Hhxsv5\LaravelS\Swoole\Task\Task;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ProjectTask
|
* Class ProjectTask
|
||||||
@ -638,6 +639,7 @@ class ProjectTask extends AbstractModel
|
|||||||
$userid = $this->project->relationUserids();
|
$userid = $this->project->relationUserids();
|
||||||
}
|
}
|
||||||
$lists = [
|
$lists = [
|
||||||
|
'ignoreFd' => Request::header('fd'),
|
||||||
'userid' => $userid,
|
'userid' => $userid,
|
||||||
'msg' => [
|
'msg' => [
|
||||||
'type' => 'projectTask',
|
'type' => 'projectTask',
|
||||||
|
|||||||
@ -45,7 +45,7 @@ class PushTask extends AbstractTask
|
|||||||
self::sendTmpMsgForUserid(intval(Base::leftDelete($this->params, "RETRY::")));
|
self::sendTmpMsgForUserid(intval(Base::leftDelete($this->params, "RETRY::")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is_array($this->params) && self::push($this->params, '', 1, $this->retryOffline);
|
is_array($this->params) && self::push($this->params, $this->retryOffline);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,7 +87,7 @@ class PushTask extends AbstractTask
|
|||||||
->chunk(100, function($list) use ($userid) {
|
->chunk(100, function($list) use ($userid) {
|
||||||
foreach ($list as $item) {
|
foreach ($list as $item) {
|
||||||
self::push([
|
self::push([
|
||||||
'tmp_msg_id' => $item->id,
|
'tmpMsgId' => $item->id,
|
||||||
'userid' => $userid,
|
'userid' => $userid,
|
||||||
'msg' => Base::json2array($item->msg),
|
'msg' => Base::json2array($item->msg),
|
||||||
]);
|
]);
|
||||||
@ -98,11 +98,11 @@ class PushTask extends AbstractTask
|
|||||||
/**
|
/**
|
||||||
* 推送消息
|
* 推送消息
|
||||||
* @param array $lists 消息列表
|
* @param array $lists 消息列表
|
||||||
* @param string|int $key 延迟推送key依据,留空立即推送(延迟推送时发给同一人同一种消息类型只发送最新的一条)
|
|
||||||
* @param int $delay 延迟推送时间,默认:1秒($key填写时有效)
|
|
||||||
* @param bool $retryOffline 如果会员不在线,等上线后继续发送
|
* @param bool $retryOffline 如果会员不在线,等上线后继续发送
|
||||||
|
* @param string $key 延迟推送key依据,留空立即推送(延迟推送时发给同一人同一种消息类型只发送最新的一条)
|
||||||
|
* @param int $delay 延迟推送时间,默认:1秒($key填写时有效)
|
||||||
*/
|
*/
|
||||||
public static function push(array $lists, $key = '', $delay = 1, $retryOffline = true)
|
public static function push(array $lists, $retryOffline = true, $key = null, $delay = 1)
|
||||||
{
|
{
|
||||||
if (!is_array($lists) || empty($lists)) {
|
if (!is_array($lists) || empty($lists)) {
|
||||||
return;
|
return;
|
||||||
@ -117,8 +117,9 @@ class PushTask extends AbstractTask
|
|||||||
}
|
}
|
||||||
$userid = $item['userid'];
|
$userid = $item['userid'];
|
||||||
$fd = $item['fd'];
|
$fd = $item['fd'];
|
||||||
|
$ignoreFd = $item['ignoreFd'];
|
||||||
$msg = $item['msg'];
|
$msg = $item['msg'];
|
||||||
$tmp_msg_id = intval($item['tmp_msg_id']);
|
$tmpMsgId = intval($item['tmpMsgId']);
|
||||||
if (!is_array($msg)) {
|
if (!is_array($msg)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -127,7 +128,7 @@ class PushTask extends AbstractTask
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// 发送对象
|
// 发送对象
|
||||||
$offline_user = [];
|
$offlineUser = [];
|
||||||
$array = [];
|
$array = [];
|
||||||
if ($fd) {
|
if ($fd) {
|
||||||
if (is_array($fd)) {
|
if (is_array($fd)) {
|
||||||
@ -145,34 +146,41 @@ class PushTask extends AbstractTask
|
|||||||
if ($row->isNotEmpty()) {
|
if ($row->isNotEmpty()) {
|
||||||
$array = array_merge($array, $row->toArray());
|
$array = array_merge($array, $row->toArray());
|
||||||
} else {
|
} else {
|
||||||
$offline_user[] = $uid;
|
$offlineUser[] = $uid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($ignoreFd) {
|
||||||
|
$ignoreFd = is_array($ignoreFd) ? $ignoreFd : [$ignoreFd];
|
||||||
|
}
|
||||||
// 开始发送
|
// 开始发送
|
||||||
foreach ($array as $fid) {
|
foreach ($array as $fid) {
|
||||||
if (empty($key)) {
|
if ($ignoreFd) {
|
||||||
try {
|
if (in_array($fid, $ignoreFd)) continue;
|
||||||
$swoole->push($fid, Base::array2json($msg));
|
|
||||||
$tmp_msg_id > 0 && WebSocketTmpMsg::whereId($tmp_msg_id)->update(['send' => 1]);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
if ($key) {
|
||||||
$key = "PUSH::" . $fid . ":" . $type . ":" . $key;
|
$key = "PUSH::" . $fid . ":" . $type . ":" . $key;
|
||||||
Cache::put($key, [
|
Cache::put($key, [
|
||||||
'fd' => $fid,
|
'fd' => $fid,
|
||||||
|
'ignoreFd' => $ignoreFd,
|
||||||
'msg' => $msg,
|
'msg' => $msg,
|
||||||
]);
|
]);
|
||||||
$task = new PushTask($key, $retryOffline);
|
$task = new PushTask($key, $retryOffline);
|
||||||
$task->delay($delay);
|
$task->delay($delay);
|
||||||
Task::deliver($task);
|
Task::deliver($task);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
$swoole->push($fid, Base::array2json($msg));
|
||||||
|
$tmpMsgId > 0 && WebSocketTmpMsg::whereId($tmpMsgId)->update(['send' => 1]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 记录不在线的
|
// 记录不在线的
|
||||||
if ($retryOffline && $tmp_msg_id == 0) {
|
if ($retryOffline && $tmpMsgId == 0) {
|
||||||
$offline_user = array_values(array_unique($offline_user));
|
$offlineUser = array_values(array_unique($offlineUser));
|
||||||
self::addTmpMsg($offline_user, $msg);
|
self::addTmpMsg($offlineUser, $msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user