perf: 完善签到功能
This commit is contained in:
@@ -2,12 +2,9 @@
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Models\User;
|
||||
use App\Models\UserCheckin;
|
||||
use App\Models\UserCheckinMac;
|
||||
use App\Models\UserCheckinRecord;
|
||||
use App\Module\Base;
|
||||
use Carbon\Carbon;
|
||||
use Request;
|
||||
|
||||
/**
|
||||
@@ -94,10 +91,10 @@ class PublicController extends AbstractController
|
||||
$macs = explode(",", $mac);
|
||||
foreach ($macs as $item) {
|
||||
$item = strtoupper($item);
|
||||
if (Base::isMac($item) && $userCheckin = UserCheckin::whereMac($item)->first()) {
|
||||
if (Base::isMac($item) && $UserCheckinMac = UserCheckinMac::whereMac($item)->first()) {
|
||||
UserCheckinRecord::createInstance([
|
||||
'userid' => $userCheckin->userid,
|
||||
'mac' => $userCheckin->mac,
|
||||
'userid' => $UserCheckinMac->userid,
|
||||
'mac' => $UserCheckinMac->mac,
|
||||
'time' => $time,
|
||||
])->save();
|
||||
}
|
||||
|
||||
@@ -848,53 +848,66 @@ class SystemController extends AbstractController
|
||||
$headings[] = '成员名称';
|
||||
$headings[] = '成员邮箱';
|
||||
$headings[] = '签到日期';
|
||||
$headings[] = '签到时间1';
|
||||
$headings[] = '签到时间2';
|
||||
$headings[] = '签到班次';
|
||||
$headings[] = '首次签到时间';
|
||||
$headings[] = '首次签到结果';
|
||||
$headings[] = '最后签到时间';
|
||||
$headings[] = '最后签到结果';
|
||||
//
|
||||
$sheets = [];
|
||||
$start = Carbon::parse($date[0])->startOfDay();
|
||||
$end = Carbon::parse($date[1])->endOfDay();
|
||||
$startD = Carbon::parse($date[0])->startOfDay();
|
||||
$endD = Carbon::parse($date[1])->endOfDay();
|
||||
$users = User::whereIn('userid', $userid)->take(20)->get();
|
||||
/** @var User $user */
|
||||
foreach ($users as $user) {
|
||||
$records = UserCheckinRecord::whereUserid($user->userid)->whereBetween("created_at", [$start, $end])->orderBy('id')->get();
|
||||
$records = UserCheckinRecord::whereUserid($user->userid)->whereBetween("created_at", [$startD, $endD])->orderBy('id')->get();
|
||||
//
|
||||
$styles = ["A1:I1" => ["font" => ["bold" => true]]];
|
||||
$datas = [];
|
||||
$styles = [];
|
||||
$startT = $start->timestamp;
|
||||
$endT = $end->timestamp;
|
||||
$startT = $startD->timestamp;
|
||||
$endT = $endD->timestamp;
|
||||
$index = 1;
|
||||
while ($startT < $endT) {
|
||||
$index++;
|
||||
$first = $records->whereBetween("created_at", [Carbon::parse($startT), Carbon::parse($startT + $secondStart)])->first();
|
||||
$last = $records->whereBetween("created_at", [Carbon::parse($startT + $secondEnd), Carbon::parse($startT + 86400)])->last();
|
||||
$first = $first ? Carbon::parse($first->created_at)->timestamp : 0;
|
||||
$last = $last ? Carbon::parse($last->created_at)->timestamp : 0;
|
||||
if (empty($first) || $first > $startT + $secondStart) {
|
||||
$styles["E{$index}"] = [
|
||||
'font' => [
|
||||
'color' => [
|
||||
'rgb' => 'ff0000'
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
if (empty($last) || $last < $startT + $secondEnd) {
|
||||
$styles["F{$index}"] = [
|
||||
'font' => [
|
||||
'color' => [
|
||||
'rgb' => 'ff0000'
|
||||
]
|
||||
],
|
||||
];
|
||||
$firstBetween = [Carbon::createFromTimestamp($startT), Carbon::createFromTimestamp($startT + $secondEnd - 1)];
|
||||
$lastBetween = [Carbon::createFromTimestamp($startT + $secondStart + 1), Carbon::createFromTimestamp($startT + 86400)];
|
||||
$firstRecord = $records->whereBetween("created_at", $firstBetween)->first();
|
||||
$lastRecord = $records->whereBetween("created_at", $lastBetween)->last();
|
||||
$firstTimestamp = $firstRecord ? Carbon::parse($firstRecord->created_at)->timestamp : 0;
|
||||
$lastTimestamp = $lastRecord ? Carbon::parse($lastRecord->created_at)->timestamp : 0;
|
||||
if (Base::time() < $startT) {
|
||||
$firstResult = "-";
|
||||
$lastResult = "-";
|
||||
} else {
|
||||
$firstResult = "正常";
|
||||
$lastResult = "正常";
|
||||
if (empty($firstTimestamp)) {
|
||||
$firstResult = "缺卡";
|
||||
$styles["G{$index}"] = ["font" => ["color" => ["rgb" => "ff0000"]]];
|
||||
} elseif ($firstTimestamp > $startT + $secondStart) {
|
||||
$firstResult = "迟到";
|
||||
$styles["G{$index}"] = ["font" => ["color" => ["rgb" => "436FF6"]]];
|
||||
}
|
||||
if (empty($lastTimestamp)) {
|
||||
$lastResult = "缺卡";
|
||||
$styles["I{$index}"] = ["font" => ["color" => ["rgb" => "ff0000"]]];
|
||||
} elseif ($lastTimestamp < $startT + $secondEnd) {
|
||||
$lastResult = "早退";
|
||||
$styles["I{$index}"] = ["font" => ["color" => ["rgb" => "436FF6"]]];
|
||||
}
|
||||
}
|
||||
$firstTimestamp = $firstTimestamp ? date("H:i", $firstTimestamp) : "-";
|
||||
$lastTimestamp = $lastTimestamp ? date("H:i", $lastTimestamp) : "-";
|
||||
$datas[] = [
|
||||
$user->userid,
|
||||
$user->nickname,
|
||||
$user->email,
|
||||
date("Y-m-d", $startT),
|
||||
$first ? date("H:i", $first) : '-',
|
||||
$last ? date("H:i", $last) : '-',
|
||||
implode("-", $time),
|
||||
$firstTimestamp,
|
||||
$firstResult,
|
||||
$lastTimestamp,
|
||||
$lastResult,
|
||||
];
|
||||
$startT += 86400;
|
||||
}
|
||||
|
||||
@@ -7,12 +7,11 @@ use App\Models\Meeting;
|
||||
use App\Models\Project;
|
||||
use App\Models\UmengAlias;
|
||||
use App\Models\User;
|
||||
use App\Models\UserCheckin;
|
||||
use App\Models\UserCheckinMac;
|
||||
use App\Models\UserDelete;
|
||||
use App\Models\UserDepartment;
|
||||
use App\Models\UserEmailVerification;
|
||||
use App\Models\UserTransfer;
|
||||
use App\Models\WebSocket;
|
||||
use App\Models\WebSocketDialog;
|
||||
use App\Models\WebSocketDialogMsg;
|
||||
use App\Module\AgoraIO\AgoraTokenGenerator;
|
||||
@@ -506,13 +505,13 @@ class UsersController extends AbstractController
|
||||
* - no: 未认证
|
||||
* - 其他值: 全部(默认)
|
||||
* - keys.department 部门ID(0表示默认部门,不赋值获取所有部门)
|
||||
* - keys.checkin_mac 签到mac地址
|
||||
* - keys.checkin_mac 签到mac地址(get_checkin_mac=1时有效)
|
||||
*
|
||||
* @apiParam {Number} [checkin_mac] 获取签到mac地址
|
||||
* @apiParam {Number} [get_checkin_mac] 获取签到mac地址
|
||||
* - 0: 不获取(默认)
|
||||
* - 1: 获取
|
||||
* @apiParam {Number} [page] 当前页,默认:1
|
||||
* @apiParam {Number} [pagesize] 每页显示数量,默认:20,最大:50
|
||||
* @apiParam {Number} [page] 当前页,默认:1
|
||||
* @apiParam {Number} [pagesize] 每页显示数量,默认:20,最大:50
|
||||
*
|
||||
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||
@@ -525,6 +524,7 @@ class UsersController extends AbstractController
|
||||
$builder = User::select(['*', 'nickname as nickname_original']);
|
||||
//
|
||||
$keys = Request::input('keys');
|
||||
$getCheckinMac = intval(Request::input('get_checkin_mac')) === 1;
|
||||
if (is_array($keys)) {
|
||||
if ($keys['key']) {
|
||||
if (str_contains($keys['key'], "@")) {
|
||||
@@ -577,9 +577,9 @@ class UsersController extends AbstractController
|
||||
$builder->where("department", "like", "%,{$keys['department']},%");
|
||||
}
|
||||
}
|
||||
if (isset($keys['checkin_mac'])) {
|
||||
if ($getCheckinMac && isset($keys['checkin_mac'])) {
|
||||
$builder->whereIn('userid', function ($query) use ($keys) {
|
||||
$query->select('userid')->from('user_checkins')->where("mac", "like", "%{$keys['checkin_mac']}%");
|
||||
$query->select('userid')->from('user_checkin_macs')->where("mac", "like", "%{$keys['checkin_mac']}%");
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@@ -587,9 +587,9 @@ class UsersController extends AbstractController
|
||||
}
|
||||
$list = $builder->orderByDesc('userid')->paginate(Base::getPaginate(50, 20));
|
||||
//
|
||||
if (intval(Request::input('checkin_mac')) === 1) {
|
||||
if ($getCheckinMac) {
|
||||
$list->transform(function (User $user) {
|
||||
$user->checkin_macs = UserCheckin::whereUserid($user->userid)->orderBy('id')->pluck('mac');
|
||||
$user->checkin_macs = UserCheckinMac::whereUserid($user->userid)->orderBy('id')->pluck('mac');
|
||||
return $user;
|
||||
});
|
||||
}
|
||||
@@ -666,7 +666,7 @@ class UsersController extends AbstractController
|
||||
];
|
||||
}
|
||||
}
|
||||
return UserCheckin::saveMac($userInfo->userid, $array);
|
||||
return UserCheckinMac::saveMac($userInfo->userid, $array);
|
||||
|
||||
case 'department':
|
||||
if (!is_array($data['department'])) {
|
||||
@@ -1336,7 +1336,7 @@ class UsersController extends AbstractController
|
||||
{
|
||||
$user = User::auth();
|
||||
//
|
||||
$list = UserCheckin::whereUserid($user->userid)->orderBy('id')->get();
|
||||
$list = UserCheckinMac::whereUserid($user->userid)->orderBy('id')->get();
|
||||
//
|
||||
return Base::retSuccess('success', $list);
|
||||
}
|
||||
@@ -1386,6 +1386,6 @@ class UsersController extends AbstractController
|
||||
return Base::retError('最多只能添加3个MAC地址');
|
||||
}
|
||||
//
|
||||
return UserCheckin::saveMac($user->userid, $array);
|
||||
return UserCheckinMac::saveMac($user->userid, $array);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user