145 lines
10 KiB
PHP

<x-layouts.admin>
<x-slot name="title">钉钉账号绑定</x-slot>
<x-slot name="content">
<div class="my-6">
@include('system_settings.partials.navigation')
<div class="mb-5 rounded-xl border border-[#D8D2C7] bg-[#F7F0DE] px-4 py-3 text-sm text-[#595959]">
钉钉登录不会自动注册账号。只有企业内在职人员与现有启用财务账号唯一匹配时才会自动绑定;其他申请需管理员确认。
</div>
@if ($errors->any())
<div class="mb-5 rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700">
@foreach ($errors->all() as $error)<p>{{ $error }}</p>@endforeach
</div>
@endif
@php
$statusLabels = ['pending' => '待处理', 'approved' => '已绑定', 'rejected' => '已拒绝', 'revoked' => '已解绑'];
$eventLabels = [
'binding_pending' => '提交绑定申请',
'binding_auto_approved' => '自动绑定',
'binding_admin_approved' => '管理员绑定',
'binding_rejected' => '拒绝绑定',
'binding_revoked' => '解除绑定',
'login_success' => '钉钉登录成功',
'login_denied' => '钉钉登录拒绝',
];
@endphp
<section class="mb-6 rounded-xl border border-[#D8D2C7] bg-white p-4">
<h2 class="mb-3 text-sm font-semibold text-[#171717]">待处理与历史申请</h2>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-[#D8D2C7] text-sm">
<thead class="bg-[#F7F0DE] text-left text-[#595959]">
<tr>
<th class="px-4 py-3">钉钉用户</th>
<th class="px-4 py-3">企业资料</th>
<th class="px-4 py-3">状态</th>
<th class="px-4 py-3">最近尝试</th>
<th class="px-4 py-3 text-right">处理</th>
</tr>
</thead>
<tbody class="divide-y divide-[#D8D2C7]">
@forelse ($bindingRequests as $bindingRequest)
<tr>
<td class="px-4 py-3 font-semibold text-[#171717]">{{ $bindingRequest->nickname ?: '未提供姓名' }}</td>
<td class="px-4 py-3 text-[#595959]">
<div>{{ $bindingRequest->email_hint ?: '无企业邮箱' }}</div>
<div>{{ $bindingRequest->mobile_hint ?: '无手机号' }}</div>
</td>
<td class="px-4 py-3">
<span @class([
'rounded-full px-2.5 py-1 text-xs font-semibold',
'bg-amber-50 text-[#935F07]' => $bindingRequest->status === 'pending',
'bg-green-50 text-[#53793E]' => $bindingRequest->status === 'approved',
'bg-red-50 text-[#B80000]' => in_array($bindingRequest->status, ['rejected', 'revoked'], true),
])>{{ $statusLabels[$bindingRequest->status] ?? $bindingRequest->status }}</span>
</td>
<td class="px-4 py-3 text-[#595959]">{{ optional($bindingRequest->last_attempted_at)->format('Y-m-d H:i:s') ?: '-' }}</td>
<td class="px-4 py-3 text-right">
@if ($bindingRequest->status !== 'approved')
<form method="POST" action="{{ route('system-settings.dingtalk-bindings.approve', $bindingRequest->id) }}" class="inline-flex items-center gap-2">
@csrf
<select name="user_id" required class="h-9 rounded-lg border border-[#D8D2C7] bg-white px-2 text-sm text-[#171717] focus:border-[#856632] focus:ring-[#856632]/20">
<option value="">选择财务账号</option>
@foreach ($eligibleUsers as $eligibleUser)
<option value="{{ $eligibleUser->id }}">{{ $eligibleUser->name }} · {{ $eligibleUser->email }}</option>
@endforeach
</select>
<button type="submit" class="h-9 rounded-lg bg-[#856632] px-3 text-sm font-semibold text-white hover:bg-[#6A5129]">绑定</button>
</form>
<form method="POST" action="{{ route('system-settings.dingtalk-bindings.reject', $bindingRequest->id) }}" class="ml-2 inline" onsubmit="return confirm('确定拒绝该钉钉绑定申请吗?')">
@csrf
<button type="submit" class="text-sm font-semibold text-[#B80000] hover:underline">拒绝</button>
</form>
@else
<span class="text-[#595959]">{{ $bindingRequest->matchedUser?->email ?: '已处理' }}</span>
@endif
</td>
</tr>
@empty
<tr><td colspan="5" class="px-4 py-10 text-center text-[#595959]">暂无钉钉绑定申请。</td></tr>
@endforelse
</tbody>
</table>
</div>
</section>
<section class="mb-6 rounded-xl border border-[#D8D2C7] bg-white p-4">
<h2 class="mb-3 text-sm font-semibold text-[#171717]">已绑定账号</h2>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-[#D8D2C7] text-sm">
<thead class="bg-[#F7F0DE] text-left text-[#595959]">
<tr><th class="px-4 py-3">财务账号</th><th class="px-4 py-3">钉钉用户</th><th class="px-4 py-3">绑定时间</th><th class="px-4 py-3 text-right">操作</th></tr>
</thead>
<tbody class="divide-y divide-[#D8D2C7]">
@forelse ($identities as $identity)
<tr>
<td class="px-4 py-3"><strong class="text-[#171717]">{{ $identity->user?->name }}</strong><div class="text-[#595959]">{{ $identity->user?->email }}</div></td>
<td class="px-4 py-3 text-[#595959]">{{ $identity->nickname ?: '企业员工' }}</td>
<td class="px-4 py-3 text-[#595959]">{{ optional($identity->bound_at)->format('Y-m-d H:i:s') ?: '-' }}</td>
<td class="px-4 py-3 text-right">
<form method="POST" action="{{ route('system-settings.dingtalk-bindings.destroy', $identity->id) }}" class="inline" onsubmit="return confirm('解除后该用户将不能继续使用钉钉登录,确定继续吗?')">
@csrf
@method('DELETE')
<button type="submit" class="text-sm font-semibold text-[#B80000] hover:underline">解除绑定</button>
</form>
</td>
</tr>
@empty
<tr><td colspan="4" class="px-4 py-10 text-center text-[#595959]">暂无已绑定账号。</td></tr>
@endforelse
</tbody>
</table>
</div>
</section>
<section class="rounded-xl border border-[#D8D2C7] bg-white p-4">
<h2 class="mb-3 text-sm font-semibold text-[#171717]">最近审计记录</h2>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-[#D8D2C7] text-sm">
<thead class="bg-[#F7F0DE] text-left text-[#595959]">
<tr><th class="px-4 py-3">时间</th><th class="px-4 py-3">事件</th><th class="px-4 py-3">财务账号</th><th class="px-4 py-3">操作人</th><th class="px-4 py-3">结果</th></tr>
</thead>
<tbody class="divide-y divide-[#D8D2C7]">
@forelse ($audits as $audit)
<tr>
<td class="px-4 py-3 text-[#595959]">{{ optional($audit->created_at)->format('Y-m-d H:i:s') }}</td>
<td class="px-4 py-3 text-[#171717]">{{ $eventLabels[$audit->event] ?? $audit->event }}</td>
<td class="px-4 py-3 text-[#595959]">{{ $audit->user?->email ?: '-' }}</td>
<td class="px-4 py-3 text-[#595959]">{{ $audit->actor?->email ?: '系统' }}</td>
<td class="px-4 py-3 text-[#595959]">{{ $audit->outcome }}</td>
</tr>
@empty
<tr><td colspan="5" class="px-4 py-10 text-center text-[#595959]">暂无审计记录。</td></tr>
@endforelse
</tbody>
</table>
</div>
</section>
</div>
</x-slot>
</x-layouts.admin>