Files
root 4ceb5eac7e chore: 重组项目文件结构,文档和部署文件归档
文件结构优化:
- docs/ 归档所有项目文档(PROJECT.md, PROJECT_ISSUES.md 等)
- deploy/ 归档所有部署相关文件(docker-compose.prod.yml, nginx 配置等)
- scripts/ 归档脚本文件(deploy.sh, rollback.sh)
- tests/ 归档测试文件(test_data.php)

更新引用路径:
- CLAUDE.md 更新文档路径引用
- 部署文档更新配置文件路径引用

清理文件:
- 移除非必要的测试文件(TestController, 测试脚本等)
- 移除重复/错误的目录

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-27 18:01:17 +08:00

530 lines
19 KiB
PHP

<?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";
// 首先删除现有的测试数据(只保留测试数据,id > 10)
echo "Cleaning up old test data...\n";
Db::table('approval_record')->where('order_id', '>', 10)->delete();
Db::table('business_trip_itinerary')->whereIn('business_trip_id', function($q) {
$q->select('id')->from('business_trip')->where('id', '>', 10);
})->delete();
Db::table('business_trip')->where('id', '>', 10)->delete();
Db::table('approval_order')->where('id', '>', 10)->delete();
echo "Cleanup completed.\n";
// ========== 用户1(李佳博)发起的订单 ==========
// 1. 审批中 - 用户1发起的,等待用户2审批
$trip1 = Db::table('business_trip')->insertGetId([
'user_id' => $userId1,
'reason' => '杭州客户洽谈',
'start_date' => '2026-03-25',
'end_date' => '2026-03-26',
'destination' => '杭州',
'estimated_cost' => 3000,
'status' => 'pending',
'created_at' => date('Y-m-d H:i:s', strtotime('-1 hour')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-1 hour')),
]);
Db::table('business_trip_itinerary')->insert([
'business_trip_id' => $trip1,
'start_time' => '2026-03-25 08:00:00',
'end_time' => '2026-03-26 18:00:00',
'departure' => '郑州',
'destination' => '杭州',
'transport' => '高铁',
'trip_type' => 'roundtrip',
'remark' => '洽谈业务合作',
'created_at' => date('Y-m-d H:i:s', strtotime('-1 hour')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-1 hour')),
]);
$order1 = Db::table('approval_order')->insertGetId([
'business_type' => 'business_trip',
'business_id' => $trip1,
'title' => '出差申请 - 杭州客户洽谈',
'applicant_id' => $userId1,
'status' => 'pending',
'current_nodes' => json_encode([2]), // 节点2是抄送人-孟启(作为审批人)
'flow_id' => $flow->id,
'form_data' => json_encode(['reason' => '杭州客户洽谈', 'approvers' => [$userId2]]),
'created_at' => date('Y-m-d H:i:s', strtotime('-1 hour')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-1 hour')),
]);
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' => $userId1,
'action' => 'submit',
'created_at' => date('Y-m-d H:i:s', strtotime('-1 hour')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-1 hour')),
]);
echo "Order $order1: 审批中 - 杭州客户洽谈(用户1发起)\n";
// 2. 已通过 - 用户1发起的,已被批准
$trip2 = Db::table('business_trip')->insertGetId([
'user_id' => $userId1,
'reason' => '南京技术调研',
'start_date' => '2026-03-28',
'end_date' => '2026-03-29',
'destination' => '南京',
'estimated_cost' => 2500,
'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' => $trip2,
'start_time' => '2026-03-28 08:00:00',
'end_time' => '2026-03-29 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')),
]);
$order2 = Db::table('approval_order')->insertGetId([
'business_type' => 'business_trip',
'business_id' => $trip2,
'title' => '出差申请 - 南京技术调研',
'applicant_id' => $userId1,
'status' => 'approved',
'current_nodes' => json_encode([]),
'flow_id' => $flow->id,
'form_data' => json_encode(['reason' => '南京技术调研', 'approvers' => [$userId2]]),
'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', $trip2)->update(['approval_order_id' => $order2]);
Db::table('approval_record')->insert([
'order_id' => $order2,
'node_id' => 1,
'node_type' => 'single_approve',
'approver_id' => $userId1,
'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' => $order2,
'node_id' => 1,
'node_type' => 'single_approve',
'approver_id' => $userId2,
'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 "Order $order2: 已通过 - 南京技术调研(用户1发起)\n";
// 3. 已拒绝 - 用户1发起的,已被拒绝
$trip3 = Db::table('business_trip')->insertGetId([
'user_id' => $userId1,
'reason' => '成都展会参观',
'start_date' => '2026-04-01',
'end_date' => '2026-04-03',
'destination' => '成都',
'estimated_cost' => 6000,
'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' => $trip3,
'start_time' => '2026-04-01 08:00:00',
'end_time' => '2026-04-03 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')),
]);
$order3 = Db::table('approval_order')->insertGetId([
'business_type' => 'business_trip',
'business_id' => $trip3,
'title' => '出差申请 - 成都展会参观',
'applicant_id' => $userId1,
'status' => 'rejected',
'current_nodes' => json_encode([]),
'flow_id' => $flow->id,
'form_data' => json_encode(['reason' => '成都展会参观', 'approvers' => [$userId2]]),
'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', $trip3)->update(['approval_order_id' => $order3]);
Db::table('approval_record')->insert([
'order_id' => $order3,
'node_id' => 1,
'node_type' => 'single_approve',
'approver_id' => $userId1,
'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' => $order3,
'node_id' => 1,
'node_type' => 'single_approve',
'approver_id' => $userId2,
'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 "Order $order3: 已拒绝 - 成都展会参观(用户1发起)\n";
// 4. 已撤回 - 用户1发起后自行撤回
$trip4 = Db::table('business_trip')->insertGetId([
'user_id' => $userId1,
'reason' => '西安供应商考察',
'start_date' => '2026-04-05',
'end_date' => '2026-04-06',
'destination' => '西安',
'estimated_cost' => 3500,
'status' => 'cancelled',
'created_at' => date('Y-m-d H:i:s', strtotime('-4 days')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-3 days')),
]);
Db::table('business_trip_itinerary')->insert([
'business_trip_id' => $trip4,
'start_time' => '2026-04-05 08:00:00',
'end_time' => '2026-04-06 18:00:00',
'departure' => '郑州',
'destination' => '西安',
'transport' => '高铁',
'trip_type' => 'roundtrip',
'remark' => '考察供应商',
'created_at' => date('Y-m-d H:i:s', strtotime('-4 days')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-4 days')),
]);
$order4 = Db::table('approval_order')->insertGetId([
'business_type' => 'business_trip',
'business_id' => $trip4,
'title' => '出差申请 - 西安供应商考察',
'applicant_id' => $userId1,
'status' => 'cancelled',
'current_nodes' => json_encode([]),
'flow_id' => $flow->id,
'form_data' => json_encode(['reason' => '西安供应商考察', 'approvers' => [$userId2]]),
'created_at' => date('Y-m-d H:i:s', strtotime('-4 days')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-3 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' => $userId1,
'action' => 'submit',
'created_at' => date('Y-m-d H:i:s', strtotime('-4 days')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-4 days')),
]);
Db::table('approval_record')->insert([
'order_id' => $order4,
'node_id' => 0,
'node_type' => 'cancel',
'approver_id' => $userId1,
'action' => 'cancel',
'comment' => '申请人撤销',
'created_at' => date('Y-m-d H:i:s', strtotime('-3 days')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-3 days')),
]);
echo "Order $order4: 已撤回 - 西安供应商考察(用户1发起)\n";
// ========== 其他用户发起,待用户1审批的订单 ==========
// 5. 待用户1审批 - 用户2发起
$trip5 = Db::table('business_trip')->insertGetId([
'user_id' => $userId2,
'reason' => '北京技术交流',
'start_date' => '2026-03-20',
'end_date' => '2026-03-22',
'destination' => '北京',
'estimated_cost' => 5000,
'status' => 'pending',
'created_at' => date('Y-m-d H:i:s', strtotime('-5 hours')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-5 hours')),
]);
Db::table('business_trip_itinerary')->insert([
'business_trip_id' => $trip5,
'start_time' => '2026-03-20 08:00:00',
'end_time' => '2026-03-22 18:00:00',
'departure' => '郑州',
'destination' => '北京',
'transport' => '高铁',
'trip_type' => 'roundtrip',
'remark' => '参加技术交流会议',
'created_at' => date('Y-m-d H:i:s', strtotime('-5 hours')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-5 hours')),
]);
$order5 = Db::table('approval_order')->insertGetId([
'business_type' => 'business_trip',
'business_id' => $trip5,
'title' => '出差申请 - 北京技术交流',
'applicant_id' => $userId2,
'status' => 'pending',
'current_nodes' => json_encode([1]), // 节点1是主管审批,审批人是用户1
'flow_id' => $flow->id,
'form_data' => json_encode(['reason' => '北京技术交流', 'approvers' => [$userId1]]),
'created_at' => date('Y-m-d H:i:s', strtotime('-5 hours')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-5 hours')),
]);
Db::table('business_trip')->where('id', $trip5)->update(['approval_order_id' => $order5]);
Db::table('approval_record')->insert([
'order_id' => $order5,
'node_id' => 1,
'node_type' => 'single_approve',
'approver_id' => $userId2,
'action' => 'submit',
'created_at' => date('Y-m-d H:i:s', strtotime('-5 hours')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-5 hours')),
]);
echo "Order $order5: 待审批 - 北京技术交流(用户2发起,用户1审批)\n";
// 6. 待用户1审批 - 用户3发起
$trip6 = Db::table('business_trip')->insertGetId([
'user_id' => $userId3,
'reason' => '上海客户拜访',
'start_date' => '2026-03-18',
'end_date' => '2026-03-19',
'destination' => '上海',
'estimated_cost' => 4000,
'status' => 'pending',
'created_at' => date('Y-m-d H:i:s', strtotime('-3 hours')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-3 hours')),
]);
Db::table('business_trip_itinerary')->insert([
'business_trip_id' => $trip6,
'start_time' => '2026-03-18 08:00:00',
'end_time' => '2026-03-19 18:00:00',
'departure' => '郑州',
'destination' => '上海',
'transport' => '高铁',
'trip_type' => 'roundtrip',
'remark' => '拜访重要客户',
'created_at' => date('Y-m-d H:i:s', strtotime('-3 hours')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-3 hours')),
]);
$order6 = Db::table('approval_order')->insertGetId([
'business_type' => 'business_trip',
'business_id' => $trip6,
'title' => '出差申请 - 上海客户拜访',
'applicant_id' => $userId3,
'status' => 'pending',
'current_nodes' => json_encode([1]), // 节点1是主管审批,审批人是用户1
'flow_id' => $flow->id,
'form_data' => json_encode(['reason' => '上海客户拜访', 'approvers' => [$userId1]]),
'created_at' => date('Y-m-d H:i:s', strtotime('-3 hours')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-3 hours')),
]);
Db::table('business_trip')->where('id', $trip6)->update(['approval_order_id' => $order6]);
Db::table('approval_record')->insert([
'order_id' => $order6,
'node_id' => 1,
'node_type' => 'single_approve',
'approver_id' => $userId3,
'action' => 'submit',
'created_at' => date('Y-m-d H:i:s', strtotime('-3 hours')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-3 hours')),
]);
echo "Order $order6: 待审批 - 上海客户拜访(用户3发起,用户1审批)\n";
// ========== 用户1已审批的订单(已通过/已拒绝) ==========
// 7. 用户1已审批(已通过)- 用户2发起
$trip7 = 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('-7 days')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-6 days')),
]);
Db::table('business_trip_itinerary')->insert([
'business_trip_id' => $trip7,
'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('-7 days')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-7 days')),
]);
$order7 = Db::table('approval_order')->insertGetId([
'business_type' => 'business_trip',
'business_id' => $trip7,
'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('-7 days')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-6 days')),
]);
Db::table('business_trip')->where('id', $trip7)->update(['approval_order_id' => $order7]);
Db::table('approval_record')->insert([
'order_id' => $order7,
'node_id' => 1,
'node_type' => 'single_approve',
'approver_id' => $userId2,
'action' => 'submit',
'created_at' => date('Y-m-d H:i:s', strtotime('-7 days')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-7 days')),
]);
Db::table('approval_record')->insert([
'order_id' => $order7,
'node_id' => 1,
'node_type' => 'single_approve',
'approver_id' => $userId1,
'action' => 'approve',
'comment' => '同意参加展会,注意控制预算',
'created_at' => date('Y-m-d H:i:s', strtotime('-6 days')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-6 days')),
]);
echo "Order $order7: 已通过 - 广州展会(用户1已审批)\n";
// 8. 用户1已审批(已拒绝)- 用户3发起
$trip8 = 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('-10 days')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-9 days')),
]);
Db::table('business_trip_itinerary')->insert([
'business_trip_id' => $trip8,
'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('-10 days')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-10 days')),
]);
$order8 = Db::table('approval_order')->insertGetId([
'business_type' => 'business_trip',
'business_id' => $trip8,
'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('-10 days')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-9 days')),
]);
Db::table('business_trip')->where('id', $trip8)->update(['approval_order_id' => $order8]);
Db::table('approval_record')->insert([
'order_id' => $order8,
'node_id' => 1,
'node_type' => 'single_approve',
'approver_id' => $userId3,
'action' => 'submit',
'created_at' => date('Y-m-d H:i:s', strtotime('-10 days')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-10 days')),
]);
Db::table('approval_record')->insert([
'order_id' => $order8,
'node_id' => 1,
'node_type' => 'single_approve',
'approver_id' => $userId1,
'action' => 'reject',
'comment' => '工作繁忙,暂不安排培训',
'created_at' => date('Y-m-d H:i:s', strtotime('-9 days')),
'updated_at' => date('Y-m-d H:i:s', strtotime('-9 days')),
]);
echo "Order $order8: 已拒绝 - 深圳培训(用户1已审批)\n";
echo "\n========== 数据汇总 ==========\n";
echo "用户1(李佳博)发起的订单:\n";
echo " - 订单$order1: 审批中(杭州客户洽谈)\n";
echo " - 订单$order2: 已通过(南京技术调研)\n";
echo " - 订单$order3: 已拒绝(成都展会参观)\n";
echo " - 订单$order4: 已撤回(西安供应商考察)\n";
echo "\n待用户1审批的订单:\n";
echo " - 订单$order5: 闫继光 - 北京技术交流\n";
echo " - 订单$order6: 孟启 - 上海客户拜访\n";
echo "\n用户1已审批的订单:\n";
echo " - 订单$order7: 已通过 - 闫继光(广州展会)\n";
echo " - 订单$order8: 已拒绝 - 孟启(深圳培训)\n";
echo "\n=== 测试数据创建完成 ===\n";