04953b22dc
- 新增通用审批列表页面(我发起的/待我审批/我已审批) - 新增通用审批详情页面(支持审批通过/拒绝操作) - 修复审批列表过滤逻辑("我已审批"只显示已完成订单) - 修复登录页面未设置 Zustand store 的问题 - 修复 User 类型定义(id 改为 number 类型) - 修复草稿恢复时的日期转换问题 - 创建测试数据脚本(test_data.php) - 安装 webman 官方依赖包(database, redis, pagination 等) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
113 lines
2.9 KiB
PHP
113 lines
2.9 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);
|
|
|
|
$result = $this->service->getList($userId, $type, $page, $pageSize);
|
|
|
|
return $this->success($result);
|
|
}
|
|
|
|
/**
|
|
* 获取审批详情
|
|
*/
|
|
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());
|
|
}
|
|
}
|
|
}
|