Initial commit: X-Server Mobile enterprise tool system
- Frontend: React 18 + TypeScript + Vite + Ant Design Mobile - Backend: PHP 8.5 + Webman 2.x + MySQL + Redis - i18n support: Chinese, English, Russian, Spanish, French - Approval workflow engine - Docker development environment - Feishu integration Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Service\ApprovalService;
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
|
||||
class ApprovalController extends BaseController
|
||||
{
|
||||
private ApprovalService $approvalService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->approvalService = new ApprovalService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取审批列表
|
||||
*/
|
||||
public function list(Request $request): Response
|
||||
{
|
||||
$type = $request->input('type', 'my');
|
||||
$page = (int) $request->input('page', 1);
|
||||
$pageSize = (int) $request->input('page_size', 20);
|
||||
|
||||
$userId = $this->getUserId($request);
|
||||
|
||||
if (!$userId) {
|
||||
return $this->error('用户未登录', 401);
|
||||
}
|
||||
|
||||
$result = $this->approvalService->getList($userId, $type, $page, $pageSize);
|
||||
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取审批详情
|
||||
*/
|
||||
public function detail(Request $request): Response
|
||||
{
|
||||
$id = $request->route('id');
|
||||
|
||||
$order = \App\Model\ApprovalOrder::with(['flow', 'applicant', 'records.approver'])
|
||||
->findOrFail($id);
|
||||
|
||||
return $this->success($order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交审批
|
||||
*/
|
||||
public function submit(Request $request): Response
|
||||
{
|
||||
$data = $request->all();
|
||||
$userId = $this->getUserId($request);
|
||||
|
||||
if (!$userId) {
|
||||
return $this->error('用户未登录', 401);
|
||||
}
|
||||
|
||||
$data['applicant_id'] = $userId;
|
||||
|
||||
try {
|
||||
$order = $this->approvalService->submit($data);
|
||||
return $this->success($order);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 审批通过
|
||||
*/
|
||||
public function approve(Request $request): Response
|
||||
{
|
||||
$id = $request->route('id');
|
||||
$comment = $request->post('comment');
|
||||
$userId = $this->getUserId($request);
|
||||
|
||||
if (!$userId) {
|
||||
return $this->error('用户未登录', 401);
|
||||
}
|
||||
|
||||
try {
|
||||
$order = $this->approvalService->approve((int) $id, $userId, $comment);
|
||||
return $this->success($order);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 审批拒绝
|
||||
*/
|
||||
public function reject(Request $request): Response
|
||||
{
|
||||
$id = $request->route('id');
|
||||
$comment = $request->post('comment');
|
||||
$userId = $this->getUserId($request);
|
||||
|
||||
if (!$userId) {
|
||||
return $this->error('用户未登录', 401);
|
||||
}
|
||||
|
||||
try {
|
||||
$order = $this->approvalService->reject((int) $id, $userId, $comment);
|
||||
return $this->success($order);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销申请
|
||||
*/
|
||||
public function cancel(Request $request): Response
|
||||
{
|
||||
$id = $request->route('id');
|
||||
$userId = $this->getUserId($request);
|
||||
|
||||
if (!$userId) {
|
||||
return $this->error('用户未登录', 401);
|
||||
}
|
||||
|
||||
try {
|
||||
$order = $this->approvalService->cancel((int) $id, $userId);
|
||||
return $this->success($order);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user