no message

This commit is contained in:
kuaifan 2022-05-06 12:14:11 +08:00
parent 44b46c396b
commit b3286c8f74
8 changed files with 71 additions and 133 deletions

View File

@ -45,6 +45,16 @@ cd dootask
./cmd port 2222
```
### Change App Url
```bash
# This URL only affects the email reply.
./cmd url {Your domain url}
# example:
./cmd url https://domain.com
```
### Stop server
```bash

View File

@ -45,6 +45,16 @@ cd dootask
./cmd port 2222
```
### 更换URL
```bash
# 此地址仅影响邮件回复功能
./cmd url {域名地址}
# 例如:
./cmd url https://domain.com
```
### 停止服务
```bash

View File

@ -247,6 +247,7 @@ class WebSocketDialogMsg extends AbstractModel
*/
public static function formatMsg($text, $dialog_id)
{
@ini_set("pcre.backtrack_limit", 999999999);
// 图片 [:IMAGE:className:width:height:src:alt:]
preg_match_all("/<img\s+src=\"data:image\/(png|jpg|jpeg|gif);base64,(.*?)\"(.*?)>(<\/img>)*/s", $text, $matchs);
foreach ($matchs[2] as $key => $base64) {

View File

@ -69,7 +69,7 @@ class EmailNoticeTask extends AbstractTask
Carbon::now()->subMinutes($userMinute + 10),
Carbon::now()->subMinutes($userMinute)
])->chunkById(100, function ($rows) {
$this->unreadMsgEmail($rows);
$this->unreadMsgEmail($rows, "user");
});
}
if ($groupMinute > 0) {
@ -82,7 +82,7 @@ class EmailNoticeTask extends AbstractTask
Carbon::now()->subMinutes($groupMinute + 10),
Carbon::now()->subMinutes($groupMinute)
])->chunkById(100, function ($rows) {
$this->unreadMsgEmail($rows);
$this->unreadMsgEmail($rows, "group");
});
}
}
@ -152,10 +152,11 @@ class EmailNoticeTask extends AbstractTask
/**
* 未读消息通知
* @param \Illuminate\Database\Eloquent\Collection|EmailNoticeTask[] $rows
* @param $rows
* @param $dialogType
* @return void
*/
private function unreadMsgEmail($rows)
private function unreadMsgEmail($rows, $dialogType)
{
$array = $rows->groupBy('r_userid');
foreach ($array as $userid => $data) {
@ -170,32 +171,40 @@ class EmailNoticeTask extends AbstractTask
continue;
}
$setting = Base::setting('emailSetting');
$subject = env('APP_NAME') . " 未读消息提醒(" . count($data) . "条)";
$msgType = $dialogType === "group" ? "群聊" : "个人";
$subject = env('APP_NAME') . " 未读{$msgType}消息提醒(" . count($data) . "条)";
$content = view('email.unread', [
'type' => 'head',
'nickname' => $user->nickname,
'msgType' => $msgType,
'count' => count($data),
]);
$lists = $data->groupBy('dialog_id');
/** @var WebSocketDialogMsg[] $items */
foreach ($lists as $items) {
$dialogId = 0;
$dialogName = null;
foreach ($items as $item) {
$item->userInfo = User::userid2basic($item->userid);
$item->preview = $item->previewMsg(true);
if (empty($dialogId)) {
$dialogId = $item->dialog_id;
}
if ($dialogName === null) {
switch ($item->dialog_type) {
case "user":
$dialogName = $item->userInfo['nickname'];
break;
case "group":
$dialogName = $item->webSocketDialog?->name;
break;
if ($dialogType === "user" && $item->userInfo) {
if ($item->userInfo->profession) {
$dialogName = $item->userInfo->nickname . " ({$item->userInfo->profession})";
} else {
$dialogName = $item->userInfo->nickname;
}
} else {
$dialogName = $item->webSocketDialog?->name;
}
}
}
$content .= view('email.unread', [
'type' => 'content',
'dialogUrl' => config("app.url") . "/manage/messenger/{$dialogId}",
'dialogName' => $dialogName,
'unread' => count($items),
'items' => $items,

View File

@ -1,116 +0,0 @@
<?php
namespace App\Tasks;
use App\Models\ProjectTask;
use App\Models\ProjectTaskMailLog;
use App\Models\User;
use App\Module\Base;
use Carbon\Carbon;
use Guanguans\Notify\Factory;
use Guanguans\Notify\Messages\EmailMessage;
@error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
class OverdueRemindEmailTask extends AbstractTask
{
public function __construct()
{
//
}
public function start()
{
$setting = Base::setting('emailSetting');
if ($setting['notice'] === 'open') {
$hours = floatval($setting['task_remind_hours']);
$hours2 = floatval($setting['task_remind_hours2']);
if ($hours > 0) {
ProjectTask::whereNull('complete_at')
->whereNull('archived_at')
->whereBetween("end_at", [
Carbon::now()->addMinutes($hours * 60),
Carbon::now()->addMinutes($hours * 60 + 10)
])->chunkById(100, function ($tasks) {
/** @var ProjectTask $task */
foreach ($tasks as $task) {
$this->overdueBeforeAfterEmail($task, true);
}
});
}
if ($hours2 > 0) {
ProjectTask::whereNull('complete_at')
->whereNull('archived_at')
->whereBetween("end_at", [
Carbon::now()->subMinutes($hours2 * 60 + 10),
Carbon::now()->subMinutes($hours2 * 60)
])->chunkById(100, function ($tasks) {
/** @var ProjectTask $task */
foreach ($tasks as $task) {
$this->overdueBeforeAfterEmail($task, false);
}
});
}
}
}
/**
* 过期前、超期后提醒
* @param ProjectTask $task
* @param $isBefore
* @return void
*/
private function overdueBeforeAfterEmail(ProjectTask $task, $isBefore)
{
$userids = $task->taskUser->where('owner', 1)->pluck('userid')->toArray();
if (empty($userids)) {
return;
}
$users = User::whereIn('userid', $userids)->get();
if (empty($users)) {
return;
}
$setting = Base::setting('emailSetting');
$hours = floatval($setting['task_remind_hours']);
$hours2 = floatval($setting['task_remind_hours2']);
/** @var User $user */
foreach ($users as $user) {
$data = [
'type' => $isBefore ? 1 : 2,
'userid' => $user->userid,
'task_id' => $task->id,
];
$emailLog = ProjectTaskMailLog::where($data)->first();
if ($emailLog) {
continue;
}
try {
if (!Base::isEmail($user->email)) {
throw new \Exception("User email '{$user->email}' address error");
}
if ($isBefore) {
$subject = env('APP_NAME') . " 任务提醒";
$content = "<p>{$user->nickname} 您好:</p><p>您有一个任务【{$task->name}】还有{$hours}小时即将超时,请及时处理。</p>";
} else {
$subject = env('APP_NAME') . " 任务过期提醒";
$content = "<p>{$user->nickname} 您好:</p><p>您的任务【{$task->name}】已经超时{$hours2}小时,请及时处理。</p>";
}
Factory::mailer()
->setDsn("smtp://{$setting['account']}:{$setting['password']}@{$setting['smtp_server']}:{$setting['port']}?verify_peer=0")
->setMessage(EmailMessage::create()
->from(env('APP_NAME', 'Task') . " <{$setting['account']}>")
->to($user->email)
->subject($subject)
->html($content))
->send();
$data['is_send'] = 1;
} catch (\Exception $e) {
$data['send_error'] = $e->getMessage();
}
$data['email'] = $user->email;
ProjectTaskMailLog::createInstance($data)->save();
}
}
}

12
cmd
View File

@ -358,6 +358,18 @@ if [ $# -gt 0 ]; then
$COMPOSE up -d
echo -e "${OK} ${GreenBG} 修改成功 ${Font}"
echo -e "地址: http://${GreenBG}127.0.0.1:$(env_get APP_PORT)${Font}"
elif [[ "$1" == "url" ]]; then
shift 1
env_set APP_URL "$1"
supervisorctl_restart php
echo -e "${OK} ${GreenBG} 修改成功 ${Font}"
elif [[ "$1" == "env" ]]; then
shift 1
if [ -n "$1" ]; then
env_set $1 "$2"
fi
supervisorctl_restart php
echo -e "${OK} ${GreenBG} 修改成功 ${Font}"
elif [[ "$1" == "repassword" ]]; then
shift 1
run_exec mariadb "sh /etc/mysql/repassword.sh \"$@\""

View File

@ -1041,7 +1041,7 @@ cli_server.color = On
[Pcre]
; PCRE library backtracking limit.
; http://php.net/pcre.backtrack-limit
pcre.backtrack_limit=10000000
;pcre.backtrack_limit=100000
; PCRE library recursion limit.
; Please note that if you set this value to a high number you may consume all

View File

@ -4,7 +4,7 @@
<tr style="box-sizing:border-box;padding:0;vertical-align:top;text-align:left">
<td style="box-sizing:border-box;word-break:break-word;border-collapse:collapse;padding:0 0 10px;vertical-align:top;text-align:left;color:#202020;font-weight:normal;margin:0;line-height:19px;font-size:14px">
<p>{{ $nickname }} 您好:</p>
<p>您有({{ $count }})条未读消息,请及时处理。</p>
<p>您有({{ $count }})条未读{{ $msgType }}消息,请及时处理。</p>
<hr style='box-sizing:border-box;color:#d9d9d9;background-color:#d9d9d9;height:1px;border:none;margin-top:32px'>
</td>
</tr>
@ -15,7 +15,7 @@
<tbody>
<tr style="box-sizing:border-box;padding:0;vertical-align:top;text-align:left">
<td style="box-sizing:border-box;word-break:break-word;border-collapse:collapse;padding:0 0 10px;vertical-align:top;text-align:left;color:#202020;font-weight:normal;margin:0;line-height:19px;font-size:14px">
<h2 style="box-sizing:border-box;color:#202020;font-weight:normal;padding:0 0 8px 0;margin:0;text-align:left;line-height:1.3;word-break:normal;font-size:26px">
<h2 style="box-sizing:border-box;color:#202020;font-weight:normal;padding:0 0 8px 0;margin:0;text-align:left;line-height:1.3;word-break:normal;font-size:24px">
{{ $dialogName }}
</h2>
<h4 style="box-sizing:border-box;color:#202020;font-weight:normal;padding:0;margin:0;text-align:left;line-height:1.3;word-break:normal;font-size:18px">
@ -27,11 +27,11 @@
<tbody>
<tr style="box-sizing:border-box;padding:0;vertical-align:top;text-align:left">
<td style="box-sizing:border-box;word-break:break-word;border-collapse:collapse;vertical-align:middle;text-align:left;padding: 0 10px 10px 0;min-width:24px;color:#202020;font-weight:normal;margin:0;line-height:19px;font-size:14px;border-radius:4px">
<img data-imagetype="External" src="{{$item->userInfo["userimg"]}}" style="box-sizing:border-box;outline:none;text-decoration:none;width:24px;max-width:100%;float:left;clear:both;display:block;border-radius:4px;height:24px">
<img data-imagetype="External" src="{{$item->userInfo?->userimg}}" style="box-sizing:border-box;outline:none;text-decoration:none;width:24px;max-width:100%;float:left;clear:both;display:block;border-radius:4px;height:24px">
</td>
<td style="box-sizing:border-box;word-break:break-word;border-collapse:collapse;padding:0 0 10px;vertical-align:middle;text-align:left;color:#202020;font-weight:normal;margin:0;line-height:19px;font-size:14px">
<strong style="box-sizing:border-box">
{{$item->userInfo["nickname"]}}
{{$item->userInfo?->nickname}}
</strong>
</td>
</tr>
@ -45,6 +45,18 @@
</tbody>
</table>
@endforeach
@if (!empty($dialogUrl))
<br style="box-sizing:border-box">
<table style="box-sizing:border-box; border-spacing:0; border-collapse:collapse; padding:0; vertical-align:top; text-align:left">
<tbody>
<tr style="box-sizing:border-box; padding:0; vertical-align:top; text-align:left">
<td style="box-sizing:border-box; word-break:break-word; border-collapse:collapse; padding:0 0 10px; vertical-align:top; text-align:left; color:#202020; font-weight:normal; margin:0; line-height:19px; font-size:14px">
<a style="text-decoration:none; box-sizing:border-box; color:white; background-color:#46bc99; padding:8px 16px; border-radius:4px; font-size:10px; text-transform:uppercase; font-weight:bold" href="{{ $dialogUrl }}" target="_blank">回复消息</a>
</td>
</tr>
</tbody>
</table>
@endif
<br style="box-sizing:border-box">
<hr style="box-sizing:border-box;color:#d9d9d9;background-color:#d9d9d9;height:1px;border:none">
<br style="box-sizing:border-box">