feat: 新增电工APP订单相关功能及数据库扩展

为四类订单表(报修/安装/维保/勘察)新增人工费、材料费、距离、预计时长字段,新增订单池、我的订单、订单详情、接单、完成订单、收益汇总接口,新增数据库迁移脚本和演示数据,支撑电工APP订单管理闭环
This commit is contained in:
andyesfly committed 2026-10-04 09:26:59 +08:00
1 parent 7b6fe46d10
commit 91aa3c06f0
8 files changed
+764 -3

No files matched your search

+46 -1
View File
@@ -1,4 +1,4 @@
import { Controller, Get, Post, Put, Del, Inject, Body, Param } from "@midwayjs/core";
import { Controller, Get, Post, Put, Del, Inject, Body, Param, Query } from "@midwayjs/core";
import { Context } from "@midwayjs/koa";
import { WorkerAppService } from "../service/worker_app.service";
import {
@@ -72,6 +72,51 @@ export class WorkerAppController {
return this.workerAppService.listNotices(this.currentWorkerId());
}
// 订单池:静态路径必须声明在动态路径 /orders/:source/:id 之前
@Get("/orders/pool")
async orderPool() {
return this.workerAppService.orderPool();
}
// 我的订单(可按 status=pending|completed 过滤)
@Get("/orders")
async myOrders(@Query("status") status?: string) {
return this.workerAppService.myOrders(this.currentWorkerId(), status);
}
// 订单详情
@Get("/orders/:source/:id")
async orderDetail(@Param("source") source: string, @Param("id") id: string) {
if (!this.workerAppService.isValidSource(source)) {
return { code: 400, message: "不支持的订单来源" };
}
return this.workerAppService.orderDetail(this.currentWorkerId(), source, Number(id));
}
// 接单
@Post("/orders/:source/:id/grab")
async grabOrder(@Param("source") source: string, @Param("id") id: string) {
if (!this.workerAppService.isValidSource(source)) {
return { code: 400, message: "不支持的订单来源" };
}
return this.workerAppService.grabOrder(this.currentWorkerId(), source, Number(id));
}
// 完成订单
@Put("/orders/:source/:id/complete")
async completeOrder(@Param("source") source: string, @Param("id") id: string) {
if (!this.workerAppService.isValidSource(source)) {
return { code: 400, message: "不支持的订单来源" };
}
return this.workerAppService.completeOrder(this.currentWorkerId(), source, Number(id));
}
// 收益汇总
@Get("/earnings/summary")
async earningsSummary() {
return this.workerAppService.earningsSummary(this.currentWorkerId());
}
// 当前登录电工 ID(由 WorkerAuthMiddleware 写入)
private currentWorkerId(): number {
return this.ctx.state.worker?.workerId;