Commit 9097fac0 by 杨树贤

判断通知开关

parent f7f2c0c3
......@@ -2,6 +2,7 @@
namespace App\Tasks;
use Common\Model\RedisModel;
use Hhxsv5\LaravelS\Swoole\Task\Task;
use Illuminate\Support\Facades\Log;
......@@ -10,35 +11,37 @@ class SendNoticeTask extends Task
private $data;
private $PushTask = false;
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)) {
$data = json_encode($data);
}
$this->data = [
'data' => $data,
'touser'=> $toUser,
'touser' => $toUser,
'is_ignore' => $is_ignore,
'keyword' => $keyword
'keyword' => $keyword,
];
$this->TaskNum = $TaskNum;
}
// 处理任务的逻辑,运行在Task进程中,不能投递任务
public function handle()
{
// return true;
$time = date('H');
if (20 < $time || $time < 9) {//不发通知时段处理
$switches = $this->getNotificationSwitches($this->data['touser']);
if ($switches['sys_msg'] == 0) {//不发通知时段处理
return true;
}
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);
if (!isset($res['errcode']) || $res['errcode'] !== 0) {
ErrorLog(ErrorCode(001, 9), '消息系统消息发送失败');
$this->PushTask = true;
}
return true;
} catch (\Exception $e) {
SendErrMsg($e);
......@@ -51,7 +54,7 @@ class SendNoticeTask extends Task
{
//消息推送失败,任务重试,第一次为4分钟后,第二次为10分钟后,第三次为18分钟后
if ($this->PushTask === true && $this->TaskNum < 4) {
$this->TaskNum ++;
$this->TaskNum++;
$task = new SendNoticeTask(
$this->data['keyword'],
$this->data['data'],
......@@ -59,8 +62,21 @@ class SendNoticeTask extends Task
$this->TaskNum,
$this->data['is_ignore']
);
$task -> delay(60*2*$this->TaskNum);
$task->delay(60 * 2 * $this->TaskNum);
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
\ No newline at end of file
18312
\ 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