e-scooter-rental-system/server/add-data.js

56 lines
2.4 KiB
JavaScript

const http = require('http');
function postData(path, data) {
return new Promise((resolve, reject) => {
const postData = JSON.stringify(data);
const options = {
hostname: 'localhost',
port: 3000,
path: path,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
}
};
const req = http.request(options, (res) => {
let data = '';
res.on('data', (chunk) => data += chunk);
res.on('end', () => resolve(JSON.parse(data)));
});
req.on('error', reject);
req.write(postData);
req.end();
});
}
async function main() {
// 客服投诉
await postData('/api/complaints', { complaintId: 'COMP001', type: '服务态度', content: '客户投诉店员态度不好', handler: '张三', status: '待处理' });
console.log('✅ 投诉1');
await postData('/api/complaints', { complaintId: 'COMP002', type: '车辆问题', content: '电动车电量不足', handler: '李四', status: '处理中' });
console.log('✅ 投诉2');
await postData('/api/complaints', { complaintId: 'COMP003', type: '费用问题', content: '费用计算有误', handler: '王五', status: '已解决' });
console.log('✅ 投诉3');
// 审批
await postData('/api/approvals', { approvalId: 'APPR001', type: '订单退款', title: '客户申请退款', applicant: '张三', status: '待审批' });
console.log('✅ 审批1');
await postData('/api/approvals', { approvalId: 'APPR002', type: '车辆报废', title: '旧车报废申请', applicant: '李四', status: '已通过' });
console.log('✅ 审批2');
await postData('/api/approvals', { approvalId: 'APPR003', type: '押金退还', title: '押金退还审批', applicant: '王五', status: '待审批' });
console.log('✅ 审批3');
// 打款
await postData('/api/payments', { paymentId: 'PAY001', type: '退款', amount: 200, method: '微信', account: 'wx123456', status: '待打款' });
console.log('✅ 打款1');
await postData('/api/payments', { paymentId: 'PAY002', type: '押金退还', amount: 500, method: '支付宝', account: 'ali@xx.com', status: '已打款' });
console.log('✅ 打款2');
await postData('/api/payments', { paymentId: 'PAY003', type: '分成', amount: 300, method: '银行卡', account: '6222xxx1234', status: '打款中' });
console.log('✅ 打款3');
console.log('🎉 完成!');
}
main().catch(console.error);