diff --git a/app/Http/Controllers/Api/SystemController.php b/app/Http/Controllers/Api/SystemController.php index 640d0d0be..5445c9798 100755 --- a/app/Http/Controllers/Api/SystemController.php +++ b/app/Http/Controllers/Api/SystemController.php @@ -224,7 +224,7 @@ class SystemController extends AbstractController * * @apiParam {String} type * - get: 获取(默认) - * - save: 保存设置(参数:['open', 'time', 'advance', 'delay', 'edit', 'key']) + * - save: 保存设置(参数:['open', 'time', 'advance', 'delay', 'remindin', 'remindexceed', 'edit', 'key']) * @apiSuccess {Number} ret 返回状态码(1正确、0错误) * @apiSuccess {String} msg 返回信息(错误描述) * @apiSuccess {Object} data 返回数据 @@ -245,6 +245,8 @@ class SystemController extends AbstractController 'time', 'advance', 'delay', + 'remindin', + 'remindexceed', 'edit', 'key', ])) { @@ -268,6 +270,8 @@ class SystemController extends AbstractController $setting['time'] = $setting['time'] ? Base::json2array($setting['time']) : ['00:00', '23:59']; $setting['advance'] = intval($setting['advance']) ?: 120; $setting['delay'] = intval($setting['delay']) ?: 120; + $setting['remindin'] = intval($setting['remindin']) ?: 5; + $setting['remindexceed'] = intval($setting['remindexceed']) ?: 10; $setting['edit'] = $setting['edit'] ?: 'close'; $setting['cmd'] = "curl -sSL '" . Base::fillUrl("api/public/checkin/install?key={$setting['key']}") . "' | sh"; // diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index 87f66eed1..fd0afaebb 100755 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -8,6 +8,7 @@ use App\Module\Ihttp; use App\Module\RandomColor; use App\Tasks\AppPushTask; use App\Tasks\AutoArchivedTask; +use App\Tasks\CheckinRemindTask; use App\Tasks\DeleteBotMsgTask; use App\Tasks\DeleteTmpTask; use App\Tasks\EmailNoticeTask; @@ -194,6 +195,8 @@ class IndexController extends InvokeController Task::deliver(new DeleteBotMsgTask()); // 周期任务 Task::deliver(new LoopTask()); + // 签到提醒 + Task::deliver(new CheckinRemindTask()); // 获取笑话/心灵鸡汤 Task::deliver(new JokeSoupTask()); diff --git a/app/Tasks/CheckinRemindTask.php b/app/Tasks/CheckinRemindTask.php new file mode 100644 index 000000000..3474e2ea9 --- /dev/null +++ b/app/Tasks/CheckinRemindTask.php @@ -0,0 +1,90 @@ + 0) { + $timeRemindin = $timeStart - $remindin; + if ($timeRemindin <= Base::time() && Base::time() <= $timeStart) { + // 签到打卡提醒 + $this->remind('in'); + } + } + if ($remindexceed > 0) { + $timeRemindexceed = $timeStart + $remindexceed; + if ($timeRemindexceed <= Base::time() && Base::time() <= $timeRemindexceed + 300) { + // 签到缺卡提醒 + $this->remind('exceed'); + } + } + } + + public function end() + { + + } + + private function remind($type) + { + if (Cache::get("CheckinRemindTask:remind-" . $type) == date("Ymd")) { + return; + } + Cache::put("CheckinRemindTask:remind-" . $type, date("Ymd"), Carbon::now()->addDay()); + // + $botUser = User::botGetOrCreate('check-in'); + if (!$botUser) { + return; + } + // 提醒对象:在职、7天内有过签到数据 + User::whereNull('disable_at')->chunk(100, function ($users) use ($type, $botUser) { + /** @var User $user */ + foreach ($users as $user) { + if (UserCheckinRecord::whereUserid($user->userid)->whereDate(date("Y-m-d"))->exists()) { + continue; // 已打卡 + } + if (!UserCheckinRecord::whereUserid($user->userid)->where('created_at', '>', Carbon::now()->subDays(3))->exists()) { + continue; // 3天内没有打卡 + } + $dialog = WebSocketDialog::checkUserDialog($botUser, $user->userid); + if ($dialog) { + if ($type === 'exceed') { + $text = "

缺卡提醒:上班时间到了,你还没有打卡哦~

"; + } else { + $text = "

打卡提醒:快到上班时间了,别忘了打卡哦~

"; + } + WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => $text], $botUser->userid); + } + } + }); + } +} diff --git a/resources/assets/js/pages/manage/setting/components/SystemCheckin.vue b/resources/assets/js/pages/manage/setting/components/SystemCheckin.vue index 52cbd6722..e51795472 100644 --- a/resources/assets/js/pages/manage/setting/components/SystemCheckin.vue +++ b/resources/assets/js/pages/manage/setting/components/SystemCheckin.vue @@ -33,8 +33,21 @@ +
{{$L('签到前后时间收到消息通知')}}
+ +
+ + +
+
+ +
+ + +
+
+
{{$L('签到提醒对象:在职且3天内有签到过的成员')}}
-
{{$L('签到前后时间收到消息通知')}}