feat: 完善审批功能
- 新增通用审批列表页面(我发起的/待我审批/我已审批) - 新增通用审批详情页面(支持审批通过/拒绝操作) - 修复审批列表过滤逻辑("我已审批"只显示已完成订单) - 修复登录页面未设置 Zustand store 的问题 - 修复 User 类型定义(id 改为 number 类型) - 修复草稿恢复时的日期转换问题 - 创建测试数据脚本(test_data.php) - 安装 webman 官方依赖包(database, redis, pagination 等) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -50,7 +50,7 @@ class ApprovalController extends BaseController
|
||||
{
|
||||
$id = (int) $this->getRouteParam($request, 'id');
|
||||
|
||||
$approval = ApprovalOrder::with(['flow', 'applicant', 'records'])
|
||||
$approval = ApprovalOrder::with(['flow.nodes', 'applicant', 'records.approver'])
|
||||
->findOrFail($id);
|
||||
|
||||
return $this->success($approval);
|
||||
|
||||
@@ -190,13 +190,15 @@ class ApprovalService
|
||||
$query->whereIn('id', $pendingOrderIds);
|
||||
break;
|
||||
case 'approved':
|
||||
// 获取用户已审批的订单
|
||||
// 获取用户已审批的订单(只显示已完成的:approved、rejected、cancelled)
|
||||
$approvedOrderIds = ApprovalRecord::where('approver_id', $userId)
|
||||
->where('action', '!=', ApprovalRecord::ACTION_SUBMIT)
|
||||
->whereIn('action', [ApprovalRecord::ACTION_APPROVE, ApprovalRecord::ACTION_REJECT])
|
||||
->pluck('order_id')
|
||||
->unique()
|
||||
->toArray();
|
||||
$query->whereIn('id', $approvedOrderIds);
|
||||
$query->whereIn('id', $approvedOrderIds)
|
||||
->whereIn('status', [ApprovalOrder::STATUS_APPROVED, ApprovalOrder::STATUS_REJECTED, ApprovalOrder::STATUS_CANCELLED]);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -161,7 +161,8 @@ class BusinessTripService
|
||||
*/
|
||||
public function getList(int $userId, string $type = 'my', int $page = 1, int $pageSize = 20): array
|
||||
{
|
||||
$query = BusinessTrip::with(['user', 'itineraries', 'approvalOrder']);
|
||||
// 先不加 approvalOrder 关系,避免 PHP 8.5 兼容性问题
|
||||
$query = BusinessTrip::with(['user', 'itineraries']);
|
||||
|
||||
switch ($type) {
|
||||
case 'my':
|
||||
|
||||
@@ -7,11 +7,14 @@
|
||||
"workerman/webman": "^2.0",
|
||||
"workerman/webman-framework": "^2.0",
|
||||
"illuminate/database": "^10.0",
|
||||
"illuminate/pagination": "^10.0",
|
||||
"illuminate/pagination": "^10.49",
|
||||
"illuminate/redis": "^10.0",
|
||||
"illuminate/events": "^10.0",
|
||||
"illuminate/events": "^10.49",
|
||||
"firebase/php-jwt": "^6.10",
|
||||
"vlucas/phpdotenv": "^5.6"
|
||||
"vlucas/phpdotenv": "^5.6",
|
||||
"webman/database": "^2.1",
|
||||
"symfony/var-dumper": "^8.0",
|
||||
"webman/redis": "^2.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.5",
|
||||
|
||||
Generated
+1460
-1
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
require_once __DIR__ . '/support/bootstrap.php';
|
||||
|
||||
use support\Db;
|
||||
|
||||
$userId1 = 1; // 李佳博
|
||||
$userId2 = 2; // 闫继光
|
||||
$userId3 = 3; // 孟启
|
||||
|
||||
// 获取出差审批流程
|
||||
$flow = Db::table('approval_flow')->where('business_type', 'business_trip')->where('status', 1)->first();
|
||||
|
||||
if (!$flow) {
|
||||
echo "Error: No approval flow found\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
echo "Creating test data...\n";
|
||||
|
||||
// 1. 创建用户2提交的申请(让用户1审批)
|
||||
$trip1 = Db::table('business_trip')->insertGetId([
|
||||
'user_id' => $userId2,
|
||||
'reason' => '北京技术交流',
|
||||
'start_date' => '2026-03-15',
|
||||
'end_date' => '2026-03-17',
|
||||
'destination' => '北京',
|
||||
'estimated_cost' => 5000,
|
||||
'status' => 'pending',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
Db::table('business_trip_itinerary')->insert([
|
||||
'business_trip_id' => $trip1,
|
||||
'start_time' => '2026-03-15 08:00:00',
|
||||
'end_time' => '2026-03-17 18:00:00',
|
||||
'departure' => '郑州',
|
||||
'destination' => '北京',
|
||||
'transport' => '高铁',
|
||||
'trip_type' => 'roundtrip',
|
||||
'remark' => '参加技术交流会议',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
$order1 = Db::table('approval_order')->insertGetId([
|
||||
'business_type' => 'business_trip',
|
||||
'business_id' => $trip1,
|
||||
'title' => '出差申请 - 闫继光',
|
||||
'applicant_id' => $userId2,
|
||||
'status' => 'pending',
|
||||
'current_nodes' => json_encode([1]),
|
||||
'flow_id' => $flow->id,
|
||||
'form_data' => json_encode(['reason' => '北京技术交流', 'approvers' => [$userId1]]),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
Db::table('business_trip')->where('id', $trip1)->update(['approval_order_id' => $order1]);
|
||||
|
||||
Db::table('approval_record')->insert([
|
||||
'order_id' => $order1,
|
||||
'node_id' => 1,
|
||||
'node_type' => 'single_approve',
|
||||
'approver_id' => $userId2,
|
||||
'action' => 'submit',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
echo "Created trip for user 2 (闫继光), order_id: $order1\n";
|
||||
|
||||
// 2. 创建用户3提交的申请(让用户1审批)
|
||||
$trip2 = Db::table('business_trip')->insertGetId([
|
||||
'user_id' => $userId3,
|
||||
'reason' => '上海客户拜访',
|
||||
'start_date' => '2026-03-20',
|
||||
'end_date' => '2026-03-21',
|
||||
'destination' => '上海',
|
||||
'estimated_cost' => 3000,
|
||||
'status' => 'pending',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
Db::table('business_trip_itinerary')->insert([
|
||||
'business_trip_id' => $trip2,
|
||||
'start_time' => '2026-03-20 08:00:00',
|
||||
'end_time' => '2026-03-21 18:00:00',
|
||||
'departure' => '郑州',
|
||||
'destination' => '上海',
|
||||
'transport' => '高铁',
|
||||
'trip_type' => 'roundtrip',
|
||||
'remark' => '拜访重要客户',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
$order2 = Db::table('approval_order')->insertGetId([
|
||||
'business_type' => 'business_trip',
|
||||
'business_id' => $trip2,
|
||||
'title' => '出差申请 - 孟启',
|
||||
'applicant_id' => $userId3,
|
||||
'status' => 'pending',
|
||||
'current_nodes' => json_encode([1]),
|
||||
'flow_id' => $flow->id,
|
||||
'form_data' => json_encode(['reason' => '上海客户拜访', 'approvers' => [$userId1]]),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
Db::table('business_trip')->where('id', $trip2)->update(['approval_order_id' => $order2]);
|
||||
|
||||
Db::table('approval_record')->insert([
|
||||
'order_id' => $order2,
|
||||
'node_id' => 1,
|
||||
'node_type' => 'single_approve',
|
||||
'approver_id' => $userId3,
|
||||
'action' => 'submit',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
echo "Created trip for user 3 (孟启), order_id: $order2\n";
|
||||
|
||||
// 3. 创建一个已通过的申请(用户1审批的)
|
||||
$trip3 = Db::table('business_trip')->insertGetId([
|
||||
'user_id' => $userId2,
|
||||
'reason' => '广州展会',
|
||||
'start_date' => '2026-03-10',
|
||||
'end_date' => '2026-03-12',
|
||||
'destination' => '广州',
|
||||
'estimated_cost' => 8000,
|
||||
'status' => 'approved',
|
||||
'created_at' => date('Y-m-d H:i:s', strtotime('-2 days')),
|
||||
'updated_at' => date('Y-m-d H:i:s', strtotime('-1 day')),
|
||||
]);
|
||||
|
||||
Db::table('business_trip_itinerary')->insert([
|
||||
'business_trip_id' => $trip3,
|
||||
'start_time' => '2026-03-10 08:00:00',
|
||||
'end_time' => '2026-03-12 18:00:00',
|
||||
'departure' => '郑州',
|
||||
'destination' => '广州',
|
||||
'transport' => '飞机',
|
||||
'trip_type' => 'roundtrip',
|
||||
'remark' => '参加行业展会',
|
||||
'created_at' => date('Y-m-d H:i:s', strtotime('-2 days')),
|
||||
'updated_at' => date('Y-m-d H:i:s', strtotime('-2 days')),
|
||||
]);
|
||||
|
||||
$order3 = Db::table('approval_order')->insertGetId([
|
||||
'business_type' => 'business_trip',
|
||||
'business_id' => $trip3,
|
||||
'title' => '出差申请 - 闫继光',
|
||||
'applicant_id' => $userId2,
|
||||
'status' => 'approved',
|
||||
'current_nodes' => json_encode([]),
|
||||
'flow_id' => $flow->id,
|
||||
'form_data' => json_encode(['reason' => '广州展会', 'approvers' => [$userId1]]),
|
||||
'created_at' => date('Y-m-d H:i:s', strtotime('-2 days')),
|
||||
'updated_at' => date('Y-m-d H:i:s', strtotime('-1 day')),
|
||||
]);
|
||||
|
||||
Db::table('business_trip')->where('id', $trip3)->update(['approval_order_id' => $order3]);
|
||||
|
||||
Db::table('approval_record')->insert([
|
||||
'order_id' => $order3,
|
||||
'node_id' => 1,
|
||||
'node_type' => 'single_approve',
|
||||
'approver_id' => $userId2,
|
||||
'action' => 'submit',
|
||||
'created_at' => date('Y-m-d H:i:s', strtotime('-2 days')),
|
||||
'updated_at' => date('Y-m-d H:i:s', strtotime('-2 days')),
|
||||
]);
|
||||
|
||||
Db::table('approval_record')->insert([
|
||||
'order_id' => $order3,
|
||||
'node_id' => 1,
|
||||
'node_type' => 'single_approve',
|
||||
'approver_id' => $userId1,
|
||||
'action' => 'approve',
|
||||
'comment' => '同意',
|
||||
'created_at' => date('Y-m-d H:i:s', strtotime('-1 day')),
|
||||
'updated_at' => date('Y-m-d H:i:s', strtotime('-1 day')),
|
||||
]);
|
||||
|
||||
echo "Created approved trip, order_id: $order3\n";
|
||||
|
||||
// 4. 创建一个已拒绝的申请
|
||||
$trip4 = Db::table('business_trip')->insertGetId([
|
||||
'user_id' => $userId3,
|
||||
'reason' => '深圳培训',
|
||||
'start_date' => '2026-03-05',
|
||||
'end_date' => '2026-03-06',
|
||||
'destination' => '深圳',
|
||||
'estimated_cost' => 2000,
|
||||
'status' => 'rejected',
|
||||
'created_at' => date('Y-m-d H:i:s', strtotime('-3 days')),
|
||||
'updated_at' => date('Y-m-d H:i:s', strtotime('-2 days')),
|
||||
]);
|
||||
|
||||
Db::table('business_trip_itinerary')->insert([
|
||||
'business_trip_id' => $trip4,
|
||||
'start_time' => '2026-03-05 08:00:00',
|
||||
'end_time' => '2026-03-06 18:00:00',
|
||||
'departure' => '郑州',
|
||||
'destination' => '深圳',
|
||||
'transport' => '高铁',
|
||||
'trip_type' => 'roundtrip',
|
||||
'remark' => '参加产品培训',
|
||||
'created_at' => date('Y-m-d H:i:s', strtotime('-3 days')),
|
||||
'updated_at' => date('Y-m-d H:i:s', strtotime('-3 days')),
|
||||
]);
|
||||
|
||||
$order4 = Db::table('approval_order')->insertGetId([
|
||||
'business_type' => 'business_trip',
|
||||
'business_id' => $trip4,
|
||||
'title' => '出差申请 - 孟启',
|
||||
'applicant_id' => $userId3,
|
||||
'status' => 'rejected',
|
||||
'current_nodes' => json_encode([]),
|
||||
'flow_id' => $flow->id,
|
||||
'form_data' => json_encode(['reason' => '深圳培训', 'approvers' => [$userId1]]),
|
||||
'created_at' => date('Y-m-d H:i:s', strtotime('-3 days')),
|
||||
'updated_at' => date('Y-m-d H:i:s', strtotime('-2 days')),
|
||||
]);
|
||||
|
||||
Db::table('business_trip')->where('id', $trip4)->update(['approval_order_id' => $order4]);
|
||||
|
||||
Db::table('approval_record')->insert([
|
||||
'order_id' => $order4,
|
||||
'node_id' => 1,
|
||||
'node_type' => 'single_approve',
|
||||
'approver_id' => $userId3,
|
||||
'action' => 'submit',
|
||||
'created_at' => date('Y-m-d H:i:s', strtotime('-3 days')),
|
||||
'updated_at' => date('Y-m-d H:i:s', strtotime('-3 days')),
|
||||
]);
|
||||
|
||||
Db::table('approval_record')->insert([
|
||||
'order_id' => $order4,
|
||||
'node_id' => 1,
|
||||
'node_type' => 'single_approve',
|
||||
'approver_id' => $userId1,
|
||||
'action' => 'reject',
|
||||
'comment' => '预算不足,暂不批准',
|
||||
'created_at' => date('Y-m-d H:i:s', strtotime('-2 days')),
|
||||
'updated_at' => date('Y-m-d H:i:s', strtotime('-2 days')),
|
||||
]);
|
||||
|
||||
echo "Created rejected trip, order_id: $order4\n";
|
||||
|
||||
// 5. 更新现有订单4的审批节点,让用户1成为审批人
|
||||
Db::table('approval_order')->where('id', 4)->update([
|
||||
'form_data' => json_encode(['reason' => '11', 'approvers' => [$userId1]]),
|
||||
]);
|
||||
|
||||
echo "Updated order 4 to make user 1 the approver\n";
|
||||
|
||||
echo "\n=== Test data created successfully ===\n";
|
||||
Reference in New Issue
Block a user