CaiWuXiTong/resources/views/business/pages/other/log-statistics.blade.php

732 lines
30 KiB
PHP

<div class="log-statistics-page" data-log-statistics>
<style>
.log-statistics-page {
display: grid;
gap: 1rem;
padding: 1rem;
color: var(--vip-content-ink, #171717);
font-size: 0.8125rem;
}
.log-statistics-note {
display: flex;
align-items: flex-start;
gap: 0.65rem;
padding: 0.85rem 1rem;
border: 1px solid var(--vip-border, #D8D2C7);
border-radius: 8px;
background: var(--vip-surface, #fff);
}
.log-statistics-note .material-icons-outlined {
color: var(--vip-content-accent-dark, #856632);
font-size: 1.15rem;
}
.log-statistics-note strong {
display: block;
font-size: 0.8125rem;
font-weight: 600;
}
.log-statistics-note span {
display: block;
margin-top: 0.15rem;
color: var(--vip-content-muted, #595959);
font-size: 0.75rem;
line-height: 1.65;
}
.log-statistics-penalty-rule {
display: flex;
align-items: flex-start;
gap: 0.75rem;
padding: 0.9rem 1rem;
border: 1px solid var(--vip-content-accent, #B9954F);
border-left-width: 4px;
border-radius: 8px;
background: var(--vip-content-accent-soft, #F7F0DE);
}
.log-statistics-penalty-rule .material-icons-outlined {
flex: 0 0 auto;
color: var(--vip-content-accent-dark, #856632);
font-size: 1.2rem;
}
.log-statistics-penalty-rule strong {
display: block;
margin-bottom: 0.15rem;
color: var(--vip-content-ink, #171717);
font-size: 0.78rem;
font-weight: 600;
}
.log-statistics-penalty-rule span {
display: block;
color: var(--vip-content-muted, #595959);
font-size: 0.75rem;
line-height: 1.7;
}
.log-statistics-alert {
display: flex;
align-items: flex-start;
gap: 0.65rem;
padding: 0.85rem 1rem;
border: 1px solid rgba(184, 0, 0, 0.3);
border-radius: 8px;
background: rgba(184, 0, 0, 0.04);
color: var(--vip-danger, #B80000);
font-size: 0.75rem;
line-height: 1.7;
}
.log-statistics-alert a {
color: var(--vip-content-accent-dark, #856632);
font-weight: 600;
}
.log-statistics-filters {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 0.65rem;
padding: 0.85rem 1rem;
border: 1px solid var(--vip-border, #D8D2C7);
border-radius: 8px;
background: var(--vip-surface, #fff);
}
.log-statistics-field {
display: grid;
gap: 0.3rem;
color: var(--vip-content-muted, #595959);
font-size: 0.75rem;
}
.log-statistics-field input {
min-height: 2rem;
padding: 0 0.6rem;
border: 1px solid var(--vip-border, #D8D2C7);
border-radius: 6px;
background: var(--vip-surface, #fff);
color: var(--vip-content-ink, #171717);
font: inherit;
}
.log-statistics-button {
display: inline-flex;
min-height: 2rem;
align-items: center;
justify-content: center;
padding: 0 0.8rem;
border: 1px solid var(--vip-border, #D8D2C7);
border-radius: 6px;
background: var(--vip-surface, #fff);
color: var(--vip-content-accent-dark, #856632);
font: inherit;
font-size: 0.75rem;
font-weight: 600;
text-decoration: none;
cursor: pointer;
}
.log-statistics-button--primary {
border-color: var(--vip-content-accent-dark, #856632);
background: var(--vip-content-accent-dark, #856632);
color: var(--vip-surface, #fff);
}
.log-statistics-cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
gap: 0.65rem;
}
.log-statistics-card {
display: grid;
gap: 0.3rem;
padding: 0.9rem 1rem;
border: 1px solid var(--vip-border, #D8D2C7);
border-radius: 8px;
background: var(--vip-surface, #fff);
}
.log-statistics-card.is-link {
width: 100%;
color: inherit;
font: inherit;
text-align: left;
text-decoration: none;
transition: border-color 150ms ease, background 150ms ease;
}
.log-statistics-card.is-link:hover,
.log-statistics-card.is-link:focus-visible {
border-color: var(--vip-content-accent, #B9954F);
background: var(--vip-content-accent-soft, #F7F0DE);
outline: none;
}
.log-statistics-card span {
color: var(--vip-content-muted, #595959);
font-size: 0.6875rem;
}
.log-statistics-card strong {
font-size: 1.15rem;
font-weight: 600;
font-variant-numeric: tabular-nums;
}
.log-statistics-card a {
color: inherit;
text-decoration: none;
}
.log-statistics-card__hint {
color: var(--vip-content-accent-dark, #856632) !important;
font-size: 0.625rem !important;
font-weight: 600;
}
.log-statistics-dialog {
width: min(72rem, calc(100vw - 2rem));
max-height: calc(100vh - 4rem);
padding: 0;
overflow: hidden;
border: 1px solid var(--vip-border, #D8D2C7);
border-radius: 12px;
background: var(--vip-surface, #fff);
color: var(--vip-content-ink, #171717);
box-shadow: 0 16px 40px rgba(23, 23, 23, 0.2);
}
.log-statistics-dialog:not([open]) {
display: none;
}
.log-statistics-dialog::backdrop {
background: rgba(23, 23, 23, 0.42);
}
.log-statistics-dialog__head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 1rem;
padding: 0.9rem 1rem;
border-bottom: 1px solid var(--vip-border, #D8D2C7);
background: var(--vip-content-accent-soft, #F7F0DE);
}
.log-statistics-dialog__head strong {
display: block;
font-size: 0.82rem;
font-weight: 600;
}
.log-statistics-dialog__head span {
display: block;
margin-top: 0.2rem;
color: var(--vip-content-muted, #595959);
font-size: 0.6875rem;
}
.log-statistics-dialog__close {
min-height: 1.8rem;
padding: 0 0.65rem;
border: 1px solid var(--vip-border, #D8D2C7);
border-radius: 5px;
background: var(--vip-surface, #fff);
color: var(--vip-content-accent-dark, #856632);
font: inherit;
font-size: 0.6875rem;
font-weight: 600;
cursor: pointer;
}
.log-statistics-dialog .log-statistics-table-wrap {
max-height: min(60vh, 32rem);
}
.log-statistics-panel {
overflow: hidden;
border: 1px solid var(--vip-border, #D8D2C7);
border-radius: 8px;
background: var(--vip-surface, #fff);
scroll-margin-top: 5rem;
}
.log-statistics-panel__head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
padding: 0.75rem 1rem;
border-bottom: 1px solid var(--vip-border, #D8D2C7);
background: var(--vip-content-accent-soft, #F7F0DE);
}
.log-statistics-panel__head strong {
font-size: 0.78rem;
font-weight: 600;
}
.log-statistics-panel__head span {
color: var(--vip-content-muted, #595959);
font-size: 0.6875rem;
}
.log-statistics-detail-actions {
display: inline-flex;
align-items: center;
gap: 0.75rem;
}
.log-statistics-collapse {
display: inline-flex;
min-height: 1.75rem;
align-items: center;
gap: 0.25rem;
padding: 0 0.55rem;
border: 1px solid var(--vip-border, #D8D2C7);
border-radius: 5px;
background: var(--vip-surface, #fff);
color: var(--vip-content-accent-dark, #856632);
font-size: 0.6875rem;
font-weight: 600;
text-decoration: none;
}
.log-statistics-table-wrap {
overflow: auto;
max-height: 28rem;
}
.log-statistics-table {
width: 100%;
min-width: 54rem;
border-collapse: collapse;
font-size: 0.75rem;
}
.log-statistics-table th,
.log-statistics-table td {
padding: 0.55rem 0.7rem;
border-right: 1px solid var(--vip-border, #D8D2C7);
border-bottom: 1px solid var(--vip-border, #D8D2C7);
text-align: left;
white-space: nowrap;
}
.log-statistics-table th {
position: sticky;
top: 0;
z-index: 1;
background: #fffaf0;
font-weight: 600;
}
.log-statistics-table .is-number {
text-align: right;
font-variant-numeric: tabular-nums;
}
.log-statistics-table a {
color: var(--vip-content-accent-dark, #856632);
font-weight: 600;
text-decoration: none;
}
.log-statistics-table tr.is-selected td {
background: var(--vip-content-accent-soft, #F7F0DE);
}
.log-statistics-table .is-wrapped {
min-width: 18rem;
white-space: normal;
line-height: 1.6;
}
.log-statistics-empty {
padding: 2rem 1rem;
color: var(--vip-content-muted, #595959);
text-align: center;
}
.log-statistics-state {
display: inline-flex;
align-items: center;
gap: 0.25rem;
font-weight: 600;
}
.log-statistics-state.is-succeeded { color: var(--vip-success, #53793E); }
.log-statistics-state.is-failed { color: var(--vip-danger, #B80000); }
.log-statistics-state.is-pending,
.log-statistics-state.is-syncing,
.log-statistics-state.is-unavailable { color: var(--vip-warning, #935F07); }
</style>
<div class="log-statistics-note">
<span class="material-icons-outlined" aria-hidden="true">schedule</span>
<div>
<strong>钉钉 {{ $worklogTemplateName }} · 次日 12:00 截止</strong>
<span>统计日当天提交的日志,以及次日 12:00 前补交的日志,统一计入统计日;每日中午 12:00 后提交归入下一统计日。同一提交人同一统计日有多篇日志时,只按最早一篇计入日志条数和明细。下一统计日中午后提交、且该成员目标统计日确需提交日志但没有按时日志的记录,会显示为目标统计日的超时日志;排班休息、请假等免提交日期不统计。</span>
</div>
</div>
<div class="log-statistics-penalty-rule" data-worklog-penalty-rule>
<span class="material-icons-outlined" aria-hidden="true">rule</span>
<div>
<strong>日志漏写扣分规则</strong>
<span>第 1 次漏写扣 10 分,第 2 次扣 20 分,第 3 次扣 40 分,之后每次在上一次基础上翻倍并累计。只统计已经超过“次日 12:00”截止时间,且公司排班标记为工作日、又没有请假或休息记录的日期;公司双休日的加班打卡不需要写日志,不扣分。</span>
</div>
</div>
@if ($worklogState['permission_required'])
<div class="log-statistics-alert" role="alert">
<span class="material-icons-outlined" aria-hidden="true">key_off</span>
<div>
钉钉日志接口尚未授权,需要应用权限 <strong>qyapi_report_query</strong>。
@if ($worklogState['permission_apply_url'])
<a href="{{ $worklogState['permission_apply_url'] }}" target="_blank" rel="noopener">前往钉钉开通</a>
@endif
开通后系统会自动重试同步。
</div>
</div>
@elseif ($worklogState['state'] === 'failed')
<div class="log-statistics-alert" role="alert">
<span class="material-icons-outlined" aria-hidden="true">error_outline</span>
<div>日志同步失败,当前展示最近成功数据。错误代码:{{ $worklogState['error_code'] ?: '未知错误' }}</div>
</div>
@endif
<form class="log-statistics-filters" method="GET" action="{{ route('business.pages.show', ['section' => 'other', 'page' => 'log-statistics']) }}">
<label class="log-statistics-field">
<span>开始日期</span>
<input type="date" name="from" value="{{ $worklogFilters['from'] }}">
</label>
<label class="log-statistics-field">
<span>结束日期</span>
<input type="date" name="to" value="{{ $worklogFilters['to'] }}">
</label>
<button class="log-statistics-button log-statistics-button--primary" type="submit">查询</button>
<a class="log-statistics-button" href="{{ route('business.pages.show', ['section' => 'other', 'page' => 'log-statistics']) }}">重置</a>
<span class="log-statistics-state is-{{ $worklogState['state'] }}">
<span class="material-icons-outlined" aria-hidden="true">sync</span>
@switch($worklogState['state'])
@case('succeeded') 已同步 @break
@case('syncing') 同步中 @break
@case('failed') 同步异常 @break
@case('unavailable') 镜像未建立 @break
@default 等待首次同步
@endswitch
@if ($worklogState['last_succeeded_at'])
· 最近成功 {{ $worklogState['last_succeeded_at'] }}
@endif
</span>
</form>
@php
$currentDetailsUrl = route('business.pages.show', [
'section' => 'other',
'page' => 'log-statistics',
'from' => $worklogFilters['from'],
'to' => $worklogFilters['to'],
'date' => $worklogCurrent['statistics_date'],
'details' => 1,
]) . '#worklog-detail';
$hasWorklogPenalty = $worklogPenaltyError !== null || $worklogPenalty['members'] !== [];
@endphp
<div class="log-statistics-cards">
@if ($hasWorklogPenalty)
<button class="log-statistics-card is-link" type="button" title="点击查看扣分明细"
data-worklog-penalty-open aria-haspopup="dialog" aria-controls="worklog-penalty-dialog">
<span>{{ $worklogPenalty['start_date'] ?: '2026-11-04' }} 起扣分合计</span>
<strong>{{ $worklogPenalty['total_points_formatted'] }}</strong>
<span class="log-statistics-card__hint">点击查看扣分明细</span>
</button>
@else
<div class="log-statistics-card">
<span>{{ $worklogPenalty['start_date'] ?: '2026-11-04' }} 起扣分合计</span>
<strong>{{ $worklogPenalty['total_points_formatted'] }}</strong>
</div>
@endif
<a class="log-statistics-card is-link" href="{{ $currentDetailsUrl }}" title="点击查看提交人明细">
<span>{{ $worklogCurrent['statistics_date'] }} 提交人数</span>
<strong>{{ number_format((int) $worklogCurrent['submitter_count']) }}</strong>
<span class="log-statistics-card__hint">点击查看提交人</span>
</a>
<a class="log-statistics-card is-link" href="{{ $currentDetailsUrl }}" title="点击查看日志明细">
<span>{{ $worklogCurrent['statistics_date'] }} 日志条数</span>
<strong>{{ number_format((int) $worklogCurrent['submission_count']) }}</strong>
<span class="log-statistics-card__hint">点击查看日志明细</span>
</a>
<div class="log-statistics-card">
<span>当前统计日截止时间</span>
<strong>{{ $worklogCutoffAt }}</strong>
</div>
<a class="log-statistics-card is-link" href="#worklog-summary" title="点击查看每日统计">
<span>查询范围日志总数</span>
<strong>{{ number_format((int) $worklogTotalSubmissions) }}</strong>
</a>
</div>
<section id="worklog-summary" class="log-statistics-panel" aria-label="每日日志提交统计">
<div class="log-statistics-panel__head">
<strong>每日日志提交统计</strong>
<span>{{ $worklogFilters['from'] }} 至 {{ $worklogFilters['to'] }}</span>
</div>
@if ($worklogDaily === [])
<div class="log-statistics-empty">当前时间范围暂无日志提交数据。</div>
@else
<div class="log-statistics-table-wrap">
<table class="log-statistics-table">
<thead>
<tr>
<th>统计日期</th>
<th>截止时间</th>
<th>提交人数</th>
<th>日志条数</th>
<th>超时日志数量</th>
<th>首次提交</th>
<th>最后提交</th>
</tr>
</thead>
<tbody>
@foreach ($worklogDaily as $day)
@php
$isSelected = $worklogFilters['date'] === $day['statistics_date'];
$deadline = \Illuminate\Support\Carbon::parse($day['statistics_date'])->addDay()->setTime(12, 0);
$detailUrl = route('business.pages.show', [
'section' => 'other',
'page' => 'log-statistics',
'from' => $worklogFilters['from'],
'to' => $worklogFilters['to'],
'date' => $day['statistics_date'],
'details' => 1,
]) . '#worklog-detail';
$lateDetailUrl = route('business.pages.show', [
'section' => 'other',
'page' => 'log-statistics',
'from' => $worklogFilters['from'],
'to' => $worklogFilters['to'],
'date' => $day['statistics_date'],
'late' => 1,
]) . '#worklog-late-detail';
@endphp
<tr @class(['is-selected' => $isSelected])>
<td>
<a href="{{ $detailUrl }}">{{ $day['statistics_date'] }}</a>
</td>
<td>{{ $deadline->format('Y-m-d H:i:s') }}</td>
<td class="is-number">
<a href="{{ $detailUrl }}" title="查看 {{ $day['statistics_date'] }} 提交人姓名">{{ number_format((int) $day['submitter_count']) }}</a>
</td>
<td class="is-number">
<a href="{{ $detailUrl }}" title="查看 {{ $day['statistics_date'] }} 日志明细">{{ number_format((int) $day['submission_count']) }}</a>
</td>
<td class="is-number">
@if ((int) $day['late_submission_count'] > 0)
<a href="{{ $lateDetailUrl }}" title="查看 {{ $day['statistics_date'] }} 超时日志明细">{{ number_format((int) $day['late_submission_count']) }}</a>
@else
0
@endif
</td>
<td>{{ $day['first_submitted_at'] ?: '-' }}</td>
<td>{{ $day['last_submitted_at'] ?: '-' }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
</section>
@if ($worklogShowDetails)
<section id="worklog-detail" class="log-statistics-panel" aria-label="日志提交明细">
<div class="log-statistics-panel__head">
<strong>日志提交明细</strong>
<div class="log-statistics-detail-actions">
<span>{{ $worklogFilters['date'] }}</span>
<a class="log-statistics-collapse" href="{{ route('business.pages.show', [
'section' => 'other',
'page' => 'log-statistics',
'from' => $worklogFilters['from'],
'to' => $worklogFilters['to'],
'date' => $worklogFilters['date'],
]) }}#worklog-summary">
<span class="material-icons-outlined" aria-hidden="true">expand_less</span>
收起明细
</a>
</div>
</div>
@if ($worklogSubmissions === [])
<div class="log-statistics-empty">所选统计日暂无提交记录。</div>
@else
<div class="log-statistics-table-wrap">
<table class="log-statistics-table">
<thead>
<tr>
<th>提交人</th>
<th>提交时间</th>
<th>日志模板</th>
<th>日志ID</th>
</tr>
</thead>
<tbody>
@foreach ($worklogSubmissions as $submission)
<tr>
<td>{{ $submission['creator_name'] ?: ($submission['creator_userid'] ?: '未知提交人') }}</td>
<td>{{ $submission['submitted_at'] }}</td>
<td>{{ $submission['template_name'] ?: $worklogTemplateName }}</td>
<td>{{ $submission['report_id'] }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
</section>
@endif
@if ($worklogShowLateDetails)
<section id="worklog-late-detail" class="log-statistics-panel" aria-label="超时日志明细">
<div class="log-statistics-panel__head">
<div>
<strong>超时日志明细</strong>
<span>解释为什么当日没有按时日志,但稍后能看到提交记录</span>
</div>
<div class="log-statistics-detail-actions">
<span>{{ $worklogFilters['date'] }}</span>
<a class="log-statistics-collapse" href="{{ route('business.pages.show', [
'section' => 'other',
'page' => 'log-statistics',
'from' => $worklogFilters['from'],
'to' => $worklogFilters['to'],
'date' => $worklogFilters['date'],
]) }}#worklog-summary">
<span class="material-icons-outlined" aria-hidden="true">expand_less</span>
收起明细
</a>
</div>
</div>
@if ($worklogLateSubmissions === [])
<div class="log-statistics-empty">所选统计日暂无超时日志记录。</div>
@else
<div class="log-statistics-table-wrap">
<table class="log-statistics-table" data-worklog-late-detail>
<thead>
<tr>
<th>提交人</th>
<th>漏写统计日</th>
<th>截止时间</th>
<th>实际提交时间</th>
<th>超时时长</th>
<th>判定说明</th>
<th>日志模板</th>
<th>日志ID</th>
</tr>
</thead>
<tbody>
@foreach ($worklogLateSubmissions as $submission)
<tr>
<td>{{ $submission['creator_name'] ?: ($submission['creator_userid'] ?: '未知提交人') }}</td>
<td>{{ $submission['late_for_date'] }}</td>
<td>{{ $submission['deadline_at'] }}</td>
<td>{{ $submission['submitted_at'] }}</td>
<td>{{ $submission['late_duration'] }}</td>
<td class="is-wrapped">{{ $submission['reason'] }}</td>
<td>{{ $submission['template_name'] ?: $worklogTemplateName }}</td>
<td>{{ $submission['report_id'] }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
</section>
@endif
@if ($hasWorklogPenalty)
<dialog id="worklog-penalty-dialog" class="log-statistics-dialog" aria-labelledby="worklog-penalty-title"
aria-modal="true" data-worklog-penalty>
<div class="log-statistics-dialog__head">
<div>
<strong id="worklog-penalty-title">日志漏写扣分统计</strong>
<span>
@if ($worklogPenalty['start_date'])
{{ $worklogPenalty['start_date'] }} 至 {{ $worklogPenalty['end_date'] }} · 合计 {{ $worklogPenalty['total_points_formatted'] }} 分
@else
暂无已截止统计日
@endif
</span>
</div>
<button type="button" class="log-statistics-dialog__close" data-worklog-dialog-close>关闭</button>
</div>
@if ($worklogPenaltyError)
<div class="log-statistics-empty">{{ $worklogPenaltyError }}</div>
@else
<div class="log-statistics-table-wrap">
<table class="log-statistics-table">
<thead>
<tr>
<th>姓名</th>
<th>漏写次数</th>
<th>漏写日期</th>
<th>扣分计算</th>
<th>累计扣分</th>
</tr>
</thead>
<tbody>
@foreach ($worklogPenalty['members'] as $penalty)
<tr>
<td>{{ $penalty['name'] }}</td>
<td class="is-number">{{ number_format((int) $penalty['missed_count']) }}</td>
<td class="is-wrapped">{{ implode('、', $penalty['missed_dates']) }}</td>
<td class="is-wrapped">{{ $penalty['penalty_formula'] }}</td>
<td class="is-number"><strong>{{ $penalty['penalty_points_formatted'] }}</strong></td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
</dialog>
@endif
<script>
(function () {
var trigger = document.querySelector('[data-worklog-penalty-open]');
var dialog = document.getElementById('worklog-penalty-dialog');
if (!trigger || !dialog) { return; }
trigger.addEventListener('click', function () {
if (dialog.open) { return; }
if (typeof dialog.showModal === 'function') {
dialog.showModal();
} else {
dialog.setAttribute('open', '');
}
});
dialog.querySelectorAll('[data-worklog-dialog-close]').forEach(function (button) {
button.addEventListener('click', function () {
if (typeof dialog.close === 'function') {
dialog.close();
} else {
dialog.removeAttribute('open');
}
});
});
dialog.addEventListener('click', function (event) {
if (event.target === dialog && typeof dialog.close === 'function') {
dialog.close();
}
});
})();
</script>
</div>