feat: 员工自助注册+审核流程

- 新增 registration_packages 表:管理员配置注册套餐(名称/角色)
- AuthController 新增 register() 和 registrationPackages() 公开接口
- UserController 新增 approve() / reject() 审核接口
- StoreController 新增 publicList() 公开门店列表
- 前端 /register 注册页:选门店→选岗位套餐→填信息→提交
- 前端 system/registration-packages:套餐 CRUD
- 用户管理页:待审核状态展示 + 通过/拒绝快捷操作
- 登录页底部加「申请注册」跳转链接
- 路由白名单加 /register
This commit is contained in:
li
2026-03-14 17:39:50 +08:00
parent 4a68855a88
commit ee2b1757d0
105 changed files with 7859 additions and 2469 deletions
@@ -4,8 +4,11 @@ namespace App\Http\Controllers\Admin\Office;
use App\Http\Controllers\Controller;
use App\Models\Office\Approval;
use App\Models\Office\ApprovalNode;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class ApprovalController extends Controller
{
@@ -21,16 +24,59 @@ class ApprovalController extends Controller
public function store(Request $request): JsonResponse
{
$validated = $request->validate([
'title' => 'required|string|max:255',
'template_id' => 'nullable|exists:approval_templates,id',
'form_data' => 'nullable|array',
'title' => 'required|string|max:255',
'template_id' => 'nullable|exists:approval_templates,id',
'form_data' => 'nullable|array',
'related_type' => 'nullable|string|max:50',
'related_id' => 'nullable|integer',
'related_id' => 'nullable|integer',
]);
$validated['applicant_id'] = auth()->id();
$validated['status'] = 0;
return $this->success(Approval::create($validated));
$validated['applicant_id'] = auth()->id();
$validated['status'] = 0;
$validated['current_node'] = 1;
$approval = null;
DB::transaction(function () use ($validated, &$approval) {
$approval = Approval::create($validated);
// 根据模板 flow_nodes 自动创建多级审批节点
if ($approval->template_id && $approval->template) {
$flowNodes = $approval->template->flow_nodes ?? [];
foreach ($flowNodes as $node) {
$level = $node['level'] ?? 1;
$role = $node['role'] ?? null;
$label = $node['label'] ?? "{$level}级审批";
// 按 role 找同门店下首个匹配用户
$approverId = null;
if ($role) {
$approverId = User::whereHas('roles', fn($q) => $q->where('slug', $role))
->where('store_id', $approval->store_id)
->value('id');
}
ApprovalNode::create([
'approval_id' => $approval->id,
'node_order' => $level,
'node_label' => $label,
'role' => $role,
'approver_id' => $approverId,
'action' => 0,
]);
}
} else {
// 无模板:创建单一审批节点
ApprovalNode::create([
'approval_id' => $approval->id,
'node_order' => 1,
'node_label' => '审批',
'action' => 0,
]);
}
});
return $this->success($approval->load(['template', 'applicant', 'nodes']));
}
public function show(Approval $approval): JsonResponse
@@ -44,7 +90,7 @@ class ApprovalController extends Controller
return $this->error('该审批已完结,无法修改', 40001);
}
$validated = $request->validate([
'title' => 'sometimes|string|max:255',
'title' => 'sometimes|string|max:255',
'form_data' => 'nullable|array',
]);
$approval->update($validated);
@@ -62,43 +108,28 @@ class ApprovalController extends Controller
return $this->success(null);
}
public function approve(Approval $approval): JsonResponse
public function approve(Request $request, Approval $approval): JsonResponse
{
if ($approval->status >= 2) {
return $this->error('该审批已完结', 40001);
}
$currentUser = auth()->user();
$userRoles = $currentUser->roles()->pluck('slug')->toArray();
// 当前节点匹配:approver_id 精确匹配 或 role 匹配当前用户角色
$node = $approval->nodes()
->where('approver_id', auth()->id())
->where('action', 0)
->where('node_order', $approval->current_node)
->where('action', 0)
->where(function ($q) use ($currentUser, $userRoles) {
$q->where('approver_id', $currentUser->id)
->orWhereIn('role', $userRoles)
->orWhereNull('approver_id'); // 无指定审批人时任何人可审
})
->first();
if (!$node) {
return $this->error('无待处理的审批节点', 40001);
}
$node->update(['action' => 1, 'acted_at' => now()]);
$pendingNodes = $approval->nodes()->where('action', 0)->exists();
if (!$pendingNodes) {
$approval->update(['status' => 2]);
} else {
$approval->update([
'status' => 1,
'current_node' => $approval->current_node + 1,
]);
}
return $this->success($approval->load('nodes'));
}
public function reject(Request $request, Approval $approval): JsonResponse
{
$node = $approval->nodes()
->where('approver_id', auth()->id())
->where('action', 0)
->where('node_order', $approval->current_node)
->first();
if (!$node) {
return $this->error('无待处理的审批节点', 40001);
return $this->error('无待处理的审批节点或您无权审批此节点', 40001);
}
$validated = $request->validate([
@@ -106,13 +137,67 @@ class ApprovalController extends Controller
]);
$node->update([
'action' => 2,
'comment' => $validated['comment'] ?? null,
'acted_at' => now(),
'action' => 1,
'approver_id' => $currentUser->id,
'comment' => $validated['comment'] ?? null,
'acted_at' => now(),
]);
$approval->update(['status' => 3]);
return $this->success($approval->load('nodes'));
// 检查是否还有下一节点
$hasNext = $approval->nodes()
->where('node_order', '>', $approval->current_node)
->where('action', 0)
->exists();
if ($hasNext) {
$approval->update([
'status' => 1, // 审批中
'current_node' => $approval->current_node + 1,
]);
} else {
$approval->update(['status' => 2]); // 已通过
}
return $this->success($approval->load(['nodes.approver']));
}
public function reject(Request $request, Approval $approval): JsonResponse
{
if ($approval->status >= 2) {
return $this->error('该审批已完结', 40001);
}
$currentUser = auth()->user();
$userRoles = $currentUser->roles()->pluck('slug')->toArray();
$node = $approval->nodes()
->where('node_order', $approval->current_node)
->where('action', 0)
->where(function ($q) use ($currentUser, $userRoles) {
$q->where('approver_id', $currentUser->id)
->orWhereIn('role', $userRoles)
->orWhereNull('approver_id');
})
->first();
if (!$node) {
return $this->error('无待处理的审批节点或您无权操作', 40001);
}
$validated = $request->validate([
'comment' => 'nullable|string|max:255',
]);
$node->update([
'action' => 2,
'approver_id' => $currentUser->id,
'comment' => $validated['comment'] ?? null,
'acted_at' => now(),
]);
$approval->update(['status' => 3]); // 已驳回
return $this->success($approval->load(['nodes.approver']));
}
public function withdraw(Approval $approval): JsonResponse
@@ -120,6 +205,9 @@ class ApprovalController extends Controller
if ($approval->status > 1) {
return $this->error('该审批已完结,无法撤回', 40001);
}
if ($approval->applicant_id !== auth()->id()) {
return $this->error('只能撤回自己发起的审批', 40001);
}
$approval->update(['status' => 4]);
return $this->success($approval);