mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-13 12:02:51 +00:00
perf: 优化签到错误提示
This commit is contained in:
parent
02d6dcd592
commit
e7fcb47e81
@ -103,9 +103,7 @@ class PublicController extends AbstractController
|
|||||||
return 'key error';
|
return 'key error';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($error = UserBot::checkinBotCheckin($mac, $time, $alreadyTip)) {
|
UserBot::checkinBotCheckin($mac, $time, $alreadyTip);
|
||||||
return $error;
|
|
||||||
}
|
|
||||||
return 'success';
|
return 'success';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -211,9 +211,7 @@ class UserBot extends AbstractModel
|
|||||||
if (!in_array('manual', $setting['modes'])) {
|
if (!in_array('manual', $setting['modes'])) {
|
||||||
return '暂未开放手动签到。';
|
return '暂未开放手动签到。';
|
||||||
}
|
}
|
||||||
if ($error = UserBot::checkinBotCheckin('manual-' . $userid, Timer::time(), true)) {
|
UserBot::checkinBotCheckin('manual-' . $userid, Timer::time(), true);
|
||||||
return $error;
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
} elseif ($command === 'locat-checkin') {
|
} elseif ($command === 'locat-checkin') {
|
||||||
$setting = Base::setting('checkinSetting');
|
$setting = Base::setting('checkinSetting');
|
||||||
@ -231,9 +229,7 @@ class UserBot extends AbstractModel
|
|||||||
} else {
|
} else {
|
||||||
return '错误的定位签到。';
|
return '错误的定位签到。';
|
||||||
}
|
}
|
||||||
if ($error = UserBot::checkinBotCheckin('locat-' . $userid, Timer::time(), true)) {
|
UserBot::checkinBotCheckin('locat-' . $userid, Timer::time(), true);
|
||||||
return $error;
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return Extranet::checkinBotQuickMsg($command);
|
return Extranet::checkinBotQuickMsg($command);
|
||||||
@ -247,7 +243,6 @@ class UserBot extends AbstractModel
|
|||||||
* - 支持:mac地址、(manual|locat|face|checkin)-userid
|
* - 支持:mac地址、(manual|locat|face|checkin)-userid
|
||||||
* @param $time
|
* @param $time
|
||||||
* @param bool $alreadyTip 签到过是否提示
|
* @param bool $alreadyTip 签到过是否提示
|
||||||
* @return string|null 返回string表示错误信息,返回null表示签到成功
|
|
||||||
*/
|
*/
|
||||||
public static function checkinBotCheckin($mac, $time, $alreadyTip = false)
|
public static function checkinBotCheckin($mac, $time, $alreadyTip = false)
|
||||||
{
|
{
|
||||||
@ -263,18 +258,20 @@ class UserBot extends AbstractModel
|
|||||||
$timeEnd = strtotime("{$nowDate} {$times[1]}");
|
$timeEnd = strtotime("{$nowDate} {$times[1]}");
|
||||||
$timeAdvance = max($timeStart - $advance, strtotime($nowDate));
|
$timeAdvance = max($timeStart - $advance, strtotime($nowDate));
|
||||||
$timeDelay = min($timeEnd + $delay, strtotime("{$nowDate} 23:59:59"));
|
$timeDelay = min($timeEnd + $delay, strtotime("{$nowDate} 23:59:59"));
|
||||||
|
$errorTime = false;
|
||||||
if (Timer::time() < $timeAdvance || $timeDelay < Timer::time()) {
|
if (Timer::time() < $timeAdvance || $timeDelay < Timer::time()) {
|
||||||
return "不在有效时间内,有效时间为:" . date("H:i", $timeAdvance) . "-" . date("H:i", $timeDelay);
|
$errorTime = "不在有效时间内,有效时间为:" . date("H:i", $timeAdvance) . "-" . date("H:i", $timeDelay);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
$macs = explode(",", $mac);
|
$macs = explode(",", $mac);
|
||||||
$checkins = [];
|
$checkins = [];
|
||||||
|
$array = [];
|
||||||
foreach ($macs as $mac) {
|
foreach ($macs as $mac) {
|
||||||
$mac = strtoupper($mac);
|
$mac = strtoupper($mac);
|
||||||
$array = [];
|
|
||||||
if (Base::isMac($mac)) {
|
if (Base::isMac($mac)) {
|
||||||
|
// 路由器签到
|
||||||
if ($UserCheckinMac = UserCheckinMac::whereMac($mac)->first()) {
|
if ($UserCheckinMac = UserCheckinMac::whereMac($mac)->first()) {
|
||||||
$array = [
|
$array[] = [
|
||||||
'userid' => $UserCheckinMac->userid,
|
'userid' => $UserCheckinMac->userid,
|
||||||
'mac' => $UserCheckinMac->mac,
|
'mac' => $UserCheckinMac->mac,
|
||||||
'date' => $nowDate,
|
'date' => $nowDate,
|
||||||
@ -285,6 +282,7 @@ class UserBot extends AbstractModel
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
} elseif (preg_match('/^(manual|locat|face|checkin)-(\d+)$/i', $mac, $match)) {
|
} elseif (preg_match('/^(manual|locat|face|checkin)-(\d+)$/i', $mac, $match)) {
|
||||||
|
// 机器签到、手动签到、定位签到
|
||||||
$type = str_replace('checkin', 'face', strtolower($match[1]));
|
$type = str_replace('checkin', 'face', strtolower($match[1]));
|
||||||
$mac = intval($match[2]);
|
$mac = intval($match[2]);
|
||||||
$remark = match ($type) {
|
$remark = match ($type) {
|
||||||
@ -294,7 +292,7 @@ class UserBot extends AbstractModel
|
|||||||
default => '',
|
default => '',
|
||||||
};
|
};
|
||||||
if ($UserInfo = User::whereUserid($mac)->whereBot(0)->first()) {
|
if ($UserInfo = User::whereUserid($mac)->whereBot(0)->first()) {
|
||||||
$array = [
|
$array[] = [
|
||||||
'userid' => $UserInfo->userid,
|
'userid' => $UserInfo->userid,
|
||||||
'mac' => '00:00:00:00:00:00',
|
'mac' => '00:00:00:00:00:00',
|
||||||
'date' => $nowDate,
|
'date' => $nowDate,
|
||||||
@ -304,13 +302,13 @@ class UserBot extends AbstractModel
|
|||||||
'remark' => $remark,
|
'remark' => $remark,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if ($array) {
|
}
|
||||||
$record = UserCheckinRecord::where($array)->first();
|
if (!$errorTime) {
|
||||||
|
foreach ($array as $item) {
|
||||||
|
$record = UserCheckinRecord::where($item)->first();
|
||||||
if (empty($record)) {
|
if (empty($record)) {
|
||||||
$record = UserCheckinRecord::createInstance($array);
|
$record = UserCheckinRecord::createInstance($item);
|
||||||
}
|
}
|
||||||
$record->times = Base::array2json(array_merge($record->times, [$nowTime]));
|
$record->times = Base::array2json(array_merge($record->times, [$nowTime]));
|
||||||
$record->report_time = $time;
|
$record->report_time = $time;
|
||||||
@ -332,11 +330,28 @@ class UserBot extends AbstractModel
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
$sendMsg = function($type, $checkin) use ($alreadyTip, $getJokeSoup, $botUser, $nowDate) {
|
$sendMsg = function($type, $checkin) use ($errorTime, $alreadyTip, $getJokeSoup, $botUser, $nowDate) {
|
||||||
|
$dialog = WebSocketDialog::checkUserDialog($botUser, $checkin['userid']);
|
||||||
|
if (!$dialog) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 判断错误
|
||||||
|
if ($errorTime) {
|
||||||
|
if ($alreadyTip) {
|
||||||
|
$text = $errorTime;
|
||||||
|
$text .= $checkin['remark'] ? " ({$checkin['remark']})": "";
|
||||||
|
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
|
||||||
|
'type' => 'content',
|
||||||
|
'content' => $text,
|
||||||
|
], $botUser->userid, false, false, true);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 判断已打卡
|
||||||
$cacheKey = "Checkin::sendMsg-{$nowDate}-{$type}:" . $checkin['userid'];
|
$cacheKey = "Checkin::sendMsg-{$nowDate}-{$type}:" . $checkin['userid'];
|
||||||
$typeContent = $type == "up" ? "上班" : "下班";
|
$typeContent = $type == "up" ? "上班" : "下班";
|
||||||
if (Cache::get($cacheKey) === "yes") {
|
if (Cache::get($cacheKey) === "yes") {
|
||||||
if ($alreadyTip && $dialog = WebSocketDialog::checkUserDialog($botUser, $checkin['userid'])) {
|
if ($alreadyTip) {
|
||||||
$text = "今日已{$typeContent}打卡,无需重复打卡。";
|
$text = "今日已{$typeContent}打卡,无需重复打卡。";
|
||||||
$text .= $checkin['remark'] ? " ({$checkin['remark']})": "";
|
$text .= $checkin['remark'] ? " ({$checkin['remark']})": "";
|
||||||
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
|
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
|
||||||
@ -347,8 +362,7 @@ class UserBot extends AbstractModel
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Cache::put($cacheKey, "yes", Carbon::now()->addDay());
|
Cache::put($cacheKey, "yes", Carbon::now()->addDay());
|
||||||
//
|
// 打卡成功
|
||||||
if ($dialog = WebSocketDialog::checkUserDialog($botUser, $checkin['userid'])) {
|
|
||||||
$hi = date("H:i");
|
$hi = date("H:i");
|
||||||
$remark = $checkin['remark'] ? " ({$checkin['remark']})": "";
|
$remark = $checkin['remark'] ? " ({$checkin['remark']})": "";
|
||||||
$subcontent = $getJokeSoup($type, $checkin['userid']);
|
$subcontent = $getJokeSoup($type, $checkin['userid']);
|
||||||
@ -366,7 +380,6 @@ class UserBot extends AbstractModel
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
], $botUser->userid, false, false, $type != "up");
|
], $botUser->userid, false, false, $type != "up");
|
||||||
}
|
|
||||||
};
|
};
|
||||||
if ($timeAdvance <= Timer::time() && Timer::time() < $timeEnd) {
|
if ($timeAdvance <= Timer::time() && Timer::time() < $timeEnd) {
|
||||||
// 上班打卡通知(从最早打卡时间 到 下班打卡时间)
|
// 上班打卡通知(从最早打卡时间 到 下班打卡时间)
|
||||||
@ -381,7 +394,6 @@ class UserBot extends AbstractModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user