chore: 移除已迁移的旧文件

This commit is contained in:
root
2026-02-27 18:01:32 +08:00
parent 4ceb5eac7e
commit c1e54d9457
11 changed files with 33 additions and 3089 deletions
-109
View File
@@ -1,109 +0,0 @@
<?php
namespace app\controller;
use app\service\FeishuNotificationService;
use Webman\Http\Request;
use Webman\Http\Response;
class TestController extends BaseController
{
/**
* 测试发送飞书通知
*/
public function testNotification(Request $request): Response
{
$userId = (int) ($request->get('user_id') ?? 1);
$orderId = (int) ($request->get('order_id') ?? 0);
$real = (int) ($request->get('real') ?? 0); // real=1 发送真实业务通知
try {
$notification = new FeishuNotificationService();
// 获取用户的company_id和feishu_app_id
$user = \app\model\User::find($userId);
if (!$user) {
return $this->error('用户不存在');
}
if (!$user->feishu_app_id) {
return $this->error('用户未绑定飞书应用');
}
$notification->setCompany($user->company_id);
$notification->setApp($user->feishu_app_id);
// 如果 real=1,发送真实业务通知
if ($real && $orderId) {
$order = \app\model\ApprovalOrder::find($orderId);
if (!$order) {
return $this->error('审批单不存在');
}
// 获取业务数据
$businessTrip = \app\model\BusinessTrip::find($order->business_id);
if (!$businessTrip) {
return $this->error('出差申请不存在');
}
// 构建真实业务内容
$detailUrl = "https://xsm.dev.hnxinyouhe.com/business-trip/detail/{$businessTrip->id}";
$content = "**出差原因**: {$businessTrip->reason}\n";
$content .= "**目的地**: {$businessTrip->destination}\n";
$content .= "**时间**: {$businessTrip->start_date} 至 {$businessTrip->end_date}";
$params = [
'user_id' => $userId,
'title' => '新的出差审批申请',
'applicant' => $businessTrip->user->name,
'type' => '出差申请',
'content' => $content,
'url' => $detailUrl,
'order_id' => $orderId,
];
$note = '真实业务通知(含审批按钮)';
} else {
// 发送测试消息
$params = [
'user_id' => $userId,
'title' => '测试审批通知',
'applicant' => '系统测试',
'type' => '测试申请',
'content' => '这是一条测试消息,用于验证飞书通知功能是否正常工作。如果看到"通过"和"拒绝"按钮,说明按钮功能正常。',
'url' => $orderId ? "https://xsm.dev.hnxinyouhe.com/approval/detail/{$orderId}" : 'https://xsm.dev.hnxinyouhe.com/dashboard',
];
// 如果提供了 order_id,添加审批按钮
if ($orderId) {
$params['order_id'] = $orderId;
}
$note = $orderId ? '测试消息(含审批按钮)' : '测试消息(不含审批按钮)';
}
// 发送消息
$result = $notification->sendApprovalNotification($params);
if ($result) {
// 获取用户在该应用下的feishu_user_id
$feishuUserId = $user->getFeishuUserId($user->feishu_app_id);
return $this->success([
'message' => '消息发送成功',
'user_id' => $userId,
'user_name' => $user->name,
'feishu_user_id' => $feishuUserId,
'feishu_app_id' => $user->feishu_app_id,
'has_order_id' => !empty($orderId),
'type' => $real ? '真实业务通知' : '测试消息',
'note' => $note,
]);
} else {
return $this->error('消息发送失败,请查看日志');
}
} catch (\Exception $e) {
return $this->error('测试失败: ' . $e->getMessage());
}
}
}
-529
View File
@@ -1,529 +0,0 @@
<?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";