582f454a5a
- 将后端目录名从大写改为小写 (Controller->controller 等) - 将命名空间从 App\ 改为 app\ (符合 webman 官方规范) - 移除不必要的 bootstrap 目录 - 完善出差审批业务功能: - 添加删除草稿功能 - 添加审批操作功能(同意/拒绝) - 完善审批详情页,显示审批人和审批记录 - 前端优化: - 调整列表页行高 - 隐藏底部导航栏 - 仪表盘只显示3个快捷入口 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
100 lines
2.5 KiB
PHP
100 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace app\controller;
|
|
|
|
use app\service\ApprovalService;
|
|
use Webman\Http\Request;
|
|
use Webman\Http\Response;
|
|
|
|
class ApprovalController extends BaseController
|
|
{
|
|
private ApprovalService $service;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->service = new ApprovalService();
|
|
}
|
|
|
|
/**
|
|
* 获取审批列表
|
|
*/
|
|
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) $request->route('id');
|
|
|
|
$approval = \App\Model\ApprovalOrder::with(['flow', 'applicant', 'records'])
|
|
->findOrFail($id);
|
|
|
|
return $this->success($approval);
|
|
}
|
|
|
|
/**
|
|
* 审批通过
|
|
*/
|
|
public function approve(Request $request): Response
|
|
{
|
|
$userId = $this->getUserId($request);
|
|
$id = (int) $request->route('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) $request->route('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) $request->route('id');
|
|
|
|
try {
|
|
$approval = $this->service->cancel($id, $userId);
|
|
return $this->success($approval, '已撤销');
|
|
} catch (\Exception $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
}
|