mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-17 19:23:26 +00:00
feat: 上班打卡新增每日开心
This commit is contained in:
parent
ec2d9b1ca5
commit
fff929d2b8
@ -129,7 +129,17 @@ class PublicController extends AbstractController
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
if ($checkins && $botUser = User::botGetOrCreate('check-in')) {
|
if ($checkins && $botUser = User::botGetOrCreate('check-in')) {
|
||||||
$sendMsg = function($type, UserCheckinMac $checkin) use ($botUser, $nowDate) {
|
$getJoke = function() {
|
||||||
|
$jokes = Base::json2array(Cache::get("JokeTask:rands"));
|
||||||
|
if ($jokes) {
|
||||||
|
$jokev = $jokes[array_rand($jokes)];
|
||||||
|
if ($jokev) {
|
||||||
|
return $jokev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
$sendMsg = function($type, UserCheckinMac $checkin) use ($getJoke, $botUser, $nowDate) {
|
||||||
$cacheKey = "Checkin::sendMsg-{$nowDate}-{$type}:" . $checkin->userid;
|
$cacheKey = "Checkin::sendMsg-{$nowDate}-{$type}:" . $checkin->userid;
|
||||||
if (Cache::get($cacheKey) === "yes") {
|
if (Cache::get($cacheKey) === "yes") {
|
||||||
return;
|
return;
|
||||||
@ -141,7 +151,11 @@ class PublicController extends AbstractController
|
|||||||
$hi = date("H:i");
|
$hi = date("H:i");
|
||||||
$pre = $type == "up" ? "上班" : "下班";
|
$pre = $type == "up" ? "上班" : "下班";
|
||||||
$remark = $checkin->remark ? " ({$checkin->remark})": "";
|
$remark = $checkin->remark ? " ({$checkin->remark})": "";
|
||||||
$text = "{$pre}打卡成功,打卡时间: {$hi} {$remark}";
|
$text = "<p>{$pre}打卡成功,打卡时间: {$hi} {$remark}</p>";
|
||||||
|
$joke = $getJoke();
|
||||||
|
if ($joke) {
|
||||||
|
$text = "<pre>{$text}<p>----------</p><p>每日开心:{$joke}。</p></pre>";
|
||||||
|
}
|
||||||
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => $text], $botUser->userid);
|
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => $text], $botUser->userid);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -10,6 +10,7 @@ use App\Tasks\AppPushTask;
|
|||||||
use App\Tasks\AutoArchivedTask;
|
use App\Tasks\AutoArchivedTask;
|
||||||
use App\Tasks\DeleteTmpTask;
|
use App\Tasks\DeleteTmpTask;
|
||||||
use App\Tasks\EmailNoticeTask;
|
use App\Tasks\EmailNoticeTask;
|
||||||
|
use App\Tasks\JokeTask;
|
||||||
use App\Tasks\LoopTask;
|
use App\Tasks\LoopTask;
|
||||||
use Arr;
|
use Arr;
|
||||||
use Cache;
|
use Cache;
|
||||||
@ -190,6 +191,8 @@ class IndexController extends InvokeController
|
|||||||
Task::deliver(new DeleteTmpTask('tmp', 24));
|
Task::deliver(new DeleteTmpTask('tmp', 24));
|
||||||
// 周期任务
|
// 周期任务
|
||||||
Task::deliver(new LoopTask());
|
Task::deliver(new LoopTask());
|
||||||
|
// 获取笑话
|
||||||
|
Task::deliver(new JokeTask());
|
||||||
|
|
||||||
return "success";
|
return "success";
|
||||||
}
|
}
|
||||||
|
|||||||
51
app/Tasks/JokeTask.php
Normal file
51
app/Tasks/JokeTask.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tasks;
|
||||||
|
|
||||||
|
use App\Module\Base;
|
||||||
|
use App\Module\Ihttp;
|
||||||
|
use Cache;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
@error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取笑话大全
|
||||||
|
*
|
||||||
|
* 每日小时采集1次
|
||||||
|
*/
|
||||||
|
class JokeTask extends AbstractTask
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function start()
|
||||||
|
{
|
||||||
|
if (Cache::get("JokeTask:lastYmdH") == date("YmdH")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Cache::put("JokeTask:lastYmdH", date("YmdH"), Carbon::now()->addDay());
|
||||||
|
//
|
||||||
|
$array = [];
|
||||||
|
for ($i = 0; $i < 10; $i++) {
|
||||||
|
$res = Ihttp::ihttp_get("https://api.vvhan.com/api/joke?type=json"); // 备用 https://api.ghser.com/xiaohua?type=json
|
||||||
|
if (Base::isError($res)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$data = Base::json2array($res['data']);
|
||||||
|
if ($data['success'] !== true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$array[] = $data['joke'];
|
||||||
|
}
|
||||||
|
Cache::forever("JokeTask:rands", Base::array2json($array));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function end()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user