Files
WXProgram/miniprogram/services/orderService.ts
2025-10-19 23:38:54 +08:00

82 lines
2.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Order } from '../types';
import apiService from './apiService';
class OrderService {
/**
* 构造函数
*/
constructor() {
// 不再使用模拟数据
}
/**
* 获取所有待处理订单
*/
async getPendingOrders(): Promise<Order[]> {
return apiService.getPendingOrders();
}
/**
* 根据ID获取订单
*/
async getOrderById(id: number): Promise<Order | null> {
return apiService.getOrderById(id);
}
/**
* 指派订单给货运人员
* @param orderId 订单ID
* @param deliveryPersonId 货运人员ID
* @returns 指派结果包含success状态和可选消息
*/
async assignOrder(orderId: number, deliveryPersonId: number): Promise<{ success: boolean; message?: string }> {
// 真实环境中调用API
try {
return await apiService.assignOrder(orderId, deliveryPersonId);
} catch (error) {
console.error('指派订单失败:', error);
return { success: false, message: error instanceof Error ? error.message : '指派失败' };
}
}
/**
* 更新订单状态
*/
async updateOrderStatus(orderId: number, status: Order['status']): Promise<{ success: boolean; message?: string }> {
return apiService.updateOrderStatus(orderId, status).then(result => ({
success: result.success,
message: result.message || '状态更新成功'
}));
}
/**
* 创建新订单
*/
async createOrder(orderData: Omit<Order, 'id' | 'createTime'>): Promise<Order> {
return apiService.createOrder(orderData);
}
/**
* 获取货运人员的订单列表
*/
async getDeliveryPersonOrders(deliveryPersonId: number): Promise<Order[]> {
return apiService.getDeliveryPersonOrders(deliveryPersonId);
}
/**
* 删除订单
* @param orderId 订单ID
*/
async deleteOrder(orderId: number): Promise<{ success: boolean; message?: string }> {
try {
await apiService.deleteOrder(orderId);
return { success: true, message: '删除成功' };
} catch (error) {
console.error('删除订单失败:', error);
return { success: false, message: error instanceof Error ? error.message : '删除失败' };
}
}
}
export default new OrderService();