diff --git a/app/Http/Controllers/Api/PublicController.php b/app/Http/Controllers/Api/PublicController.php index f3cacea42..a04ac794d 100755 --- a/app/Http/Controllers/Api/PublicController.php +++ b/app/Http/Controllers/Api/PublicController.php @@ -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(); } diff --git a/app/Http/Controllers/Api/SystemController.php b/app/Http/Controllers/Api/SystemController.php index b7b064be5..bcf729247 100755 --- a/app/Http/Controllers/Api/SystemController.php +++ b/app/Http/Controllers/Api/SystemController.php @@ -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; } diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 3a4e80d52..4585aca11 100755 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -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); } } diff --git a/app/Models/UserCheckin.php b/app/Models/UserCheckinMac.php similarity index 81% rename from app/Models/UserCheckin.php rename to app/Models/UserCheckinMac.php index a9aa05d9f..c18789d42 100644 --- a/app/Models/UserCheckin.php +++ b/app/Models/UserCheckinMac.php @@ -6,7 +6,7 @@ namespace App\Models; use App\Module\Base; /** - * App\Models\UserCheckin + * App\Models\UserCheckinMac * * @property int $id * @property int|null $userid 会员id @@ -14,18 +14,18 @@ use App\Module\Base; * @property string|null $remark 备注 * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at - * @method static \Illuminate\Database\Eloquent\Builder|UserCheckin newModelQuery() - * @method static \Illuminate\Database\Eloquent\Builder|UserCheckin newQuery() - * @method static \Illuminate\Database\Eloquent\Builder|UserCheckin query() - * @method static \Illuminate\Database\Eloquent\Builder|UserCheckin whereCreatedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|UserCheckin whereId($value) - * @method static \Illuminate\Database\Eloquent\Builder|UserCheckin whereMac($value) - * @method static \Illuminate\Database\Eloquent\Builder|UserCheckin whereRemark($value) - * @method static \Illuminate\Database\Eloquent\Builder|UserCheckin whereUpdatedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|UserCheckin whereUserid($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserCheckinMac newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|UserCheckinMac newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|UserCheckinMac query() + * @method static \Illuminate\Database\Eloquent\Builder|UserCheckinMac whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserCheckinMac whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserCheckinMac whereMac($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserCheckinMac whereRemark($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserCheckinMac whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|UserCheckinMac whereUserid($value) * @mixin \Eloquent */ -class UserCheckin extends AbstractModel +class UserCheckinMac extends AbstractModel { /** * 保存mac地址 @@ -45,7 +45,7 @@ class UserCheckin extends AbstractModel 'remark' => $item['remark'] ]; } - $row = UserCheckin::updateInsert([ + $row = self::updateInsert([ 'userid' => $userid, 'mac' => $item['mac'] ], $update); @@ -54,7 +54,7 @@ class UserCheckin extends AbstractModel $list[] = $row; } } - UserCheckin::whereUserid($userid)->whereNotIn('id', $ids)->delete(); + self::whereUserid($userid)->whereNotIn('id', $ids)->delete(); // return Base::retSuccess('修改成功', $list); }); diff --git a/database/migrations/2022_12_11_214403_create_user_checkins_table.php b/database/migrations/2022_12_11_214403_create_user_checkin_macs_table.php similarity index 80% rename from database/migrations/2022_12_11_214403_create_user_checkins_table.php rename to database/migrations/2022_12_11_214403_create_user_checkin_macs_table.php index 8158e39ef..d27c57cf2 100644 --- a/database/migrations/2022_12_11_214403_create_user_checkins_table.php +++ b/database/migrations/2022_12_11_214403_create_user_checkin_macs_table.php @@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreateUserCheckinsTable extends Migration +class CreateUserCheckinMacsTable extends Migration { /** * Run the migrations. @@ -13,7 +13,7 @@ class CreateUserCheckinsTable extends Migration */ public function up() { - Schema::create('user_checkins', function (Blueprint $table) { + Schema::create('user_checkin_macs', function (Blueprint $table) { $table->bigIncrements('id'); $table->bigInteger('userid')->nullable()->default(0)->comment('会员id'); $table->string('mac', 100)->nullable()->default('')->comment('MAC地址'); @@ -29,6 +29,6 @@ class CreateUserCheckinsTable extends Migration */ public function down() { - Schema::dropIfExists('user_checkins'); + Schema::dropIfExists('user_checkin_macs'); } } diff --git a/resources/assets/js/pages/manage/components/TeamManagement.vue b/resources/assets/js/pages/manage/components/TeamManagement.vue index d94240b49..1ad5b44a8 100644 --- a/resources/assets/js/pages/manage/components/TeamManagement.vue +++ b/resources/assets/js/pages/manage/components/TeamManagement.vue @@ -91,7 +91,7 @@ -