lazyphp / PESCMS-TEAM

The open source task management system
GNU General Public License v2.0
84 stars 36 forks source link

[已解决]任务逾期没有邮件提醒?[Solved]No email reminder for task overdue? #4

Closed qqzwc closed 4 years ago

qqzwc commented 4 years ago

您好,似乎只是新建任务和任务追加了说明等,会触发主页消息通知和邮件提醒。但是如果任务逾期了忘记执行,(即使已添加了Cron或任务计划),也不会自动发送邮件提醒对吗? 能否添加此功能?

qqzwc commented 4 years ago

建议(抱歉还没形成代码): 1.数据库中的pes_task中增加一列overdue_remind_date,记录此任务的上次逾期通知时间 2.PESCMS-TEAM\Model\Notice.php中的actionNoticeSend在检查完待发送通知后,增加一步,遍历一下pes_task中状态为逾期漏执行的(task_delete = 0 and task_mail =1 and task_complete_time = 0),且overdue_remind_date<今天的(避免当天多次发送重复邮件),对其发送邮件,并更新标记overdue_remind_date为今天

lazyphp commented 4 years ago

目前版本确实没有逾期通知。 后续我看看是以日报表,还是周报的形式汇报逾期的任务。

qqzwc commented 4 years ago

感谢您的回复。我想的是定时任务触发SendNotice.php的时候,Notice.php中的actionNoticeSend就直接检查是否有逾期并且今天还没通知的,就发送逾期通知给执行人,避免她忘记登系统忘掉这事儿了。软件在不断优化完善,你们辛苦了!

qqzwc commented 4 years ago

目前版本确实没有逾期通知。 后续我看看是以日报表,还是周报的形式汇报逾期的任务。

PHP新手小白一个,奉献一个自己的低质量很不规范的代码给恰好有相同需求的人 1.数据库中给pes_task增加一个int(11)的字段overdue_remind_time 2.手工修改\Model\Notice.php中的ActionNoticeSend函数,代码如下 public static function actionNoticeSend(){ $sendList = \Model\Content::listContent(['table' => 'send', 'condition' => 'send_time = 0']); if(!empty($sendList)){ foreach ($sendList as $value) { //@todo 目前仅有邮件发送,日后再慢慢完善其他通知方式 switch ($value['send_type']) { case '1': (new \Expand\Notice\Mail())->send($value); break; } } //发送成功,删除过去7天的待发送列表 \Core\Func\CoreFunc::db('send')->where('send_time > 0 AND send_time <= :send_time')->delete([ 'send_time' => time() - 86400 * 7 ]); }

//检查是否有逾期任务且今天尚未通知的,立刻发送邮件通知(不管是否设置了邮件通知)
$msql = new \Core\Db\Mysql();
//需要在pes_task中添加一个字段overdue_remind_time,数据类型为int(11),存放逾期邮件通知时间(避免当天重复发送通知)
$sql = 'SELECT task_id,task_title,user_mail from pes_task as t 
left join pes_user as u on t.task_project_id=u.user_id where task_delete = 0 
and t.task_status < 4 and t.task_complete_time = 0 and task_end_time < UNIX_TIMESTAMP()
AND (UNIX_TIMESTAMP() - overdue_remind_time)/86400 >= 1';
$res = $msql->getAll($sql);
$tm=time();
$homeurl=\Model\Content::findContent('option', 'domain', 'option_name')['value'];
$homeroot=$_SERVER['REQUEST_URI'];
$homefile=self::url('Team-Task-view', ['id' => '']);
$mailref=str_replace('Expand/Cli/SendNotice.phpDOCUMENT_ROOT','Public', $homeurl . $homeroot . $homefile);
foreach( $res as $rowdata )
{
    $email=array();
    $usermail=$rowdata['user_mail'];
    $task_title=$rowdata['task_title'];
    $send_content=$email['send_content'];
    $task_id=$rowdata['task_id'];
    $email['send_account']=$usermail;
    $email['send_title']="{$task_title}任务已超期";
    $email['send_content']="<a href=\"{$mailref}{$task_id}\">{$task_title}</a>任务已超期,请立即登录系统完成执行!";
    $email['send_id']=0;
    (new \Expand\Notice\Mail())->send($email);
    //标记为今天已发送过,避免重复发送
    $msql->query("update pes_task set overdue_remind_time={$tm} where task_id='{$task_id}'");
}

}