b7919910f1
- 新增 PROJECT_ISSUES.md 统一管理所有问题和解决方案 - 精简 CLAUDE.md,移除重复的问题记录部分 - 修复审批列表数据混乱问题(React 18 StrictMode + 状态管理) - 修复首次加载不显示数据问题(requestIdRef 清理时机) - 修复页码初始值错误(hasMore 默认值) - 修复后端响应序列化问题(Eloquent 模型转数组) - 添加审批人和抄送人重复校验 - 修复双 header 问题 - 调整申请页面 padding-bottom Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
123 lines
3.3 KiB
PHP
123 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace app\controller;
|
|
|
|
use app\service\ApprovalService;
|
|
use app\model\ApprovalOrder;
|
|
use Webman\Http\Request;
|
|
use Webman\Http\Response;
|
|
|
|
class ApprovalController extends BaseController
|
|
{
|
|
private ApprovalService $service;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->service = new ApprovalService();
|
|
}
|
|
|
|
/**
|
|
* 获取路由参数
|
|
*/
|
|
private function getRouteParam(Request $request, string $name, $default = null)
|
|
{
|
|
$route = $request->route;
|
|
if ($route && method_exists($route, 'param')) {
|
|
return $route->param($name) ?? $default;
|
|
}
|
|
return $default;
|
|
}
|
|
|
|
/**
|
|
* 获取审批列表
|
|
*/
|
|
public function list(Request $request): Response
|
|
{
|
|
$userId = $this->getUserId($request);
|
|
$type = $request->get('type', 'my');
|
|
$page = (int) $request->get('page', 1);
|
|
$pageSize = (int) $request->get('page_size', 20);
|
|
|
|
try {
|
|
$result = $this->service->getList($userId, $type, $page, $pageSize);
|
|
|
|
// 使用 json() 全局函数返回 JSON
|
|
return json([
|
|
'code' => 0,
|
|
'message' => 'success',
|
|
'data' => $result,
|
|
]);
|
|
} catch (\Exception $e) {
|
|
error_log("❌ Error in list controller: " . $e->getMessage() . "\n" . $e->getTraceAsString());
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取审批详情
|
|
*/
|
|
public function detail(Request $request): Response
|
|
{
|
|
$id = (int) $this->getRouteParam($request, 'id');
|
|
|
|
$approval = ApprovalOrder::with(['flow.nodes', 'applicant', 'records.approver'])
|
|
->findOrFail($id);
|
|
|
|
return $this->success($approval);
|
|
}
|
|
|
|
/**
|
|
* 审批通过
|
|
*/
|
|
public function approve(Request $request): Response
|
|
{
|
|
$userId = $this->getUserId($request);
|
|
$id = (int) $this->getRouteParam($request, 'id');
|
|
$data = $request->post();
|
|
$data = $data ?? [];
|
|
$comment = $data['comment'] ?? null;
|
|
|
|
try {
|
|
$approval = $this->service->approve($id, $userId, $comment);
|
|
return $this->success($approval, '已通过');
|
|
} catch (\Exception $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 审批拒绝
|
|
*/
|
|
public function reject(Request $request): Response
|
|
{
|
|
$userId = $this->getUserId($request);
|
|
$id = (int) $this->getRouteParam($request, 'id');
|
|
$data = $request->post();
|
|
$data = $data ?? [];
|
|
$comment = $data['comment'] ?? null;
|
|
|
|
try {
|
|
$approval = $this->service->reject($id, $userId, $comment);
|
|
return $this->success($approval, '已拒绝');
|
|
} catch (\Exception $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 撤销申请
|
|
*/
|
|
public function cancel(Request $request): Response
|
|
{
|
|
$userId = $this->getUserId($request);
|
|
$id = (int) $this->getRouteParam($request, 'id');
|
|
|
|
try {
|
|
$approval = $this->service->cancel($id, $userId);
|
|
return $this->success($approval, '已撤销');
|
|
} catch (\Exception $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
}
|