Commit 9097fac0 by 杨树贤

判断通知开关

parent f7f2c0c3
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace App\Tasks; namespace App\Tasks;
use Common\Model\RedisModel;
use Hhxsv5\LaravelS\Swoole\Task\Task; use Hhxsv5\LaravelS\Swoole\Task\Task;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
...@@ -10,35 +11,37 @@ class SendNoticeTask extends Task ...@@ -10,35 +11,37 @@ class SendNoticeTask extends Task
private $data; private $data;
private $PushTask = false; private $PushTask = false;
private $TaskNum; private $TaskNum;
public function __construct($keyword, $data, $toUser, $TaskNum=1, $is_ignore=0)
public function __construct($keyword, $data, $toUser, $TaskNum = 1, $is_ignore = 0)
{ {
if (is_array($data)) { if (is_array($data)) {
$data = json_encode($data); $data = json_encode($data);
} }
$this->data = [ $this->data = [
'data' => $data, 'data' => $data,
'touser'=> $toUser, 'touser' => $toUser,
'is_ignore' => $is_ignore, 'is_ignore' => $is_ignore,
'keyword' => $keyword 'keyword' => $keyword,
]; ];
$this->TaskNum = $TaskNum; $this->TaskNum = $TaskNum;
} }
// 处理任务的逻辑,运行在Task进程中,不能投递任务 // 处理任务的逻辑,运行在Task进程中,不能投递任务
public function handle() public function handle()
{ {
// return true; $switches = $this->getNotificationSwitches($this->data['touser']);
$time = date('H'); if ($switches['sys_msg'] == 0) {//不发通知时段处理
if (20 < $time || $time < 9) {//不发通知时段处理
return true; return true;
} }
try { try {
$Url = config('website.IC_AUTH_API').'/hprose/HttpSendMsg'; $Url = config('website.IC_AUTH_API') . '/hprose/HttpSendMsg';
$res = json_decode(reportCurl($Url, $this->data, true, ['MsgToken:fg368hjk4567wtbk8']), true); $res = json_decode(reportCurl($Url, $this->data, true, ['MsgToken:fg368hjk4567wtbk8']), true);
if (!isset($res['errcode']) || $res['errcode'] !== 0) { if (!isset($res['errcode']) || $res['errcode'] !== 0) {
ErrorLog(ErrorCode(001, 9), '消息系统消息发送失败'); ErrorLog(ErrorCode(001, 9), '消息系统消息发送失败');
$this->PushTask = true; $this->PushTask = true;
} }
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
SendErrMsg($e); SendErrMsg($e);
...@@ -51,7 +54,7 @@ class SendNoticeTask extends Task ...@@ -51,7 +54,7 @@ class SendNoticeTask extends Task
{ {
//消息推送失败,任务重试,第一次为4分钟后,第二次为10分钟后,第三次为18分钟后 //消息推送失败,任务重试,第一次为4分钟后,第二次为10分钟后,第三次为18分钟后
if ($this->PushTask === true && $this->TaskNum < 4) { if ($this->PushTask === true && $this->TaskNum < 4) {
$this->TaskNum ++; $this->TaskNum++;
$task = new SendNoticeTask( $task = new SendNoticeTask(
$this->data['keyword'], $this->data['keyword'],
$this->data['data'], $this->data['data'],
...@@ -59,8 +62,21 @@ class SendNoticeTask extends Task ...@@ -59,8 +62,21 @@ class SendNoticeTask extends Task
$this->TaskNum, $this->TaskNum,
$this->data['is_ignore'] $this->data['is_ignore']
); );
$task -> delay(60*2*$this->TaskNum); $task->delay(60 * 2 * $this->TaskNum);
Task::deliver($task); Task::deliver($task);
} }
} }
//获取通知开关,目前只有系统通知被用到
private function getNotificationSwitches($userId)
{
$redis = new RedisModel();
$user = json_decode($redis->hget('ic_user', $userId), true);
$result = [];
//不存在代表是不可以接受通知的
$result ['sys_msg'] = array_get($user, 'sys_msg', 0);
$result ['activity_msg'] = array_get($user, 'activity_msg', 0);
return $result;
}
} }
common @ 6a492b76
Subproject commit 8428774c731bbcd89366d7d698daf57579f0b53b Subproject commit 6a492b76f3938205ed9d94cd12b81d66feea657d
2930 18312
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment