3ebbbefb8d
1. 审批详情显示修复
- 新增 ApprovalService::getDetail() 方法
- 从 form_data 获取用户实际选择的审批人和抄送人
- 返回每个节点的 actual_approvers 和 approver_statuses
- 修复详情页显示默认审批人而非实际审批人的问题
2. 飞书消息emoji编码修复
- 修复 content 字段格式:应为 card 对象JSON字符串,不是 {"card":{...}}
- 使用 JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
- 新增 HttpClient::httpPostJson() 方法处理预编码字段
- 修复消息发送错误码 200621
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
125 lines
3.3 KiB
PHP
125 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');
|
|
|
|
try {
|
|
$detail = $this->service->getDetail($id);
|
|
return $this->success($detail);
|
|
} catch (\Exception $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 审批通过
|
|
*/
|
|
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());
|
|
}
|
|
}
|
|
}
|