264 lines
9.8 KiB
TypeScript
264 lines
9.8 KiB
TypeScript
import type { Context } from '../utils/handler.js'
|
|
import { guardMethod } from '../utils/method.js'
|
|
import { readJson } from '../utils/request.js'
|
|
import { withErrorBoundary } from '../utils/handler.js'
|
|
import {
|
|
afterSaleService,
|
|
type AfterSaleApplyInput,
|
|
type AfterSaleAuditInput,
|
|
type AfterSaleDetailInput,
|
|
type AfterSaleListInput,
|
|
type AfterSaleLogisticsInput
|
|
} from '../services/after-sale.service.js'
|
|
import { orderActionService } from '../services/order-action.service.js'
|
|
import { orderCreateService, type CheckoutGoods } from '../services/order-create.service.js'
|
|
import { orderListService } from '../services/order-list.service.js'
|
|
import { orderPushEventService, type OrderPushEventInput } from '../services/order-push-event.service.js'
|
|
import {
|
|
supplierOpenOrderService,
|
|
type SupplierOrderQueryRequest,
|
|
type SupplierReconciliationQueryRequest
|
|
} from '../services/supplier-open-order.service.js'
|
|
import { toHttpResponse } from './controller-response.js'
|
|
|
|
type OrderListRequest = {
|
|
supplierId?: string
|
|
userId?: string
|
|
orderId?: string
|
|
mainOrderId?: string
|
|
}
|
|
|
|
type OrderActionRequest = {
|
|
supplierId?: string
|
|
userId?: string
|
|
orderId?: string
|
|
mainOrderId?: string
|
|
deliveryStatus?: number
|
|
logisticsOrderId?: string
|
|
crrgBsnNm?: string
|
|
amount?: number
|
|
totalPrice?: number
|
|
wPayOrAPay?: number
|
|
pointsPrice?: number
|
|
}
|
|
|
|
type OrderCreateRequest = {
|
|
supplierId?: string
|
|
userId?: string
|
|
orderNo?: string
|
|
orderNumberId?: string
|
|
amount?: number
|
|
addressId?: string
|
|
remark?: string
|
|
goods?: CheckoutGoods[]
|
|
}
|
|
|
|
const centsToYuan = (value?: number) => Number((Number(value || 0) / 100).toFixed(2))
|
|
|
|
export const orderListController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
const body = await readJson<OrderListRequest>(request)
|
|
const supplierId = String(body.supplierId || '').trim()
|
|
const userId = String(body.userId || '').trim()
|
|
|
|
return toHttpResponse(await orderListService.listOrders(supplierId, userId))
|
|
})
|
|
|
|
export const orderCountController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
const body = await readJson<OrderListRequest>(request)
|
|
const supplierId = String(body.supplierId || '').trim()
|
|
const userId = String(body.userId || '').trim()
|
|
|
|
return toHttpResponse(await orderListService.countOrders(supplierId, userId))
|
|
})
|
|
|
|
export const orderDetailController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
const body = await readJson<OrderListRequest>(request)
|
|
const supplierId = String(body.supplierId || '').trim()
|
|
const userId = String(body.userId || '').trim()
|
|
const orderId = String(body.orderId || '').trim()
|
|
const mainOrderId = String(body.mainOrderId || '').trim()
|
|
|
|
return toHttpResponse(await orderListService.detailOrder(supplierId, userId, orderId, mainOrderId))
|
|
})
|
|
|
|
export const afterSaleApplyController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
return toHttpResponse(await afterSaleService.apply(await readJson<AfterSaleApplyInput>(request)))
|
|
})
|
|
|
|
export const afterSaleListController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
return toHttpResponse(await afterSaleService.list(await readJson<AfterSaleListInput>(request)))
|
|
})
|
|
|
|
export const afterSaleDetailController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
return toHttpResponse(await afterSaleService.detail(await readJson<AfterSaleDetailInput>(request)))
|
|
})
|
|
|
|
export const afterSaleAuditController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
return toHttpResponse(await afterSaleService.audit(await readJson<AfterSaleAuditInput>(request)))
|
|
})
|
|
|
|
export const afterSaleLogisticsController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
return toHttpResponse(await afterSaleService.updateLogistics(await readJson<AfterSaleLogisticsInput>(request)))
|
|
})
|
|
|
|
export const orderCreateController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
const body = await readJson<OrderCreateRequest>(request)
|
|
|
|
return toHttpResponse(await orderCreateService.createOrder({
|
|
supplierId: String(body.supplierId || '').trim(),
|
|
userId: String(body.userId || '').trim(),
|
|
orderNo: String(body.orderNo || '').trim(),
|
|
orderNumberId: body.orderNumberId,
|
|
amount: body.amount,
|
|
addressId: String(body.addressId || '').trim(),
|
|
remark: String(body.remark || '').trim(),
|
|
goods: Array.isArray(body.goods) ? body.goods : []
|
|
}))
|
|
})
|
|
|
|
export const orderCancelMainController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
const body = await readJson<OrderActionRequest>(request)
|
|
|
|
return toHttpResponse(await orderActionService.cancelPendingMain({
|
|
supplierId: String(body.supplierId || '').trim(),
|
|
userId: String(body.userId || '').trim(),
|
|
orderId: String(body.orderId || '').trim(),
|
|
mainOrderId: String(body.mainOrderId || body.orderId || '').trim()
|
|
}))
|
|
})
|
|
|
|
export const orderCancelPaidMainController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
const body = await readJson<OrderActionRequest>(request)
|
|
|
|
return toHttpResponse(await orderActionService.cancelPaidMain({
|
|
supplierId: String(body.supplierId || '').trim(),
|
|
userId: String(body.userId || '').trim(),
|
|
orderId: String(body.orderId || '').trim(),
|
|
mainOrderId: String(body.mainOrderId || body.orderId || '').trim()
|
|
}))
|
|
})
|
|
|
|
export const orderCancelSubController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
const body = await readJson<OrderActionRequest>(request)
|
|
|
|
return toHttpResponse(await orderActionService.cancelSub({
|
|
supplierId: String(body.supplierId || '').trim(),
|
|
userId: String(body.userId || '').trim(),
|
|
orderId: String(body.orderId || '').trim(),
|
|
mainOrderId: String(body.mainOrderId || '').trim()
|
|
}))
|
|
})
|
|
|
|
export const orderPayController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
const body = await readJson<OrderActionRequest>(request)
|
|
const totalPrice = Number(body.totalPrice ?? centsToYuan(body.amount))
|
|
|
|
return toHttpResponse(await orderActionService.payOrder({
|
|
supplierId: String(body.supplierId || '').trim(),
|
|
orderId: String(body.orderId || '').trim(),
|
|
totalPrice,
|
|
wPayOrAPay: Number(body.wPayOrAPay ?? 0),
|
|
pointsPrice: Number(body.pointsPrice ?? totalPrice)
|
|
}))
|
|
})
|
|
|
|
export const orderShipController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
const body = await readJson<OrderActionRequest>(request)
|
|
|
|
return toHttpResponse(await orderActionService.shipOrder({
|
|
supplierId: String(body.supplierId || '').trim(),
|
|
userId: String(body.userId || '').trim(),
|
|
orderId: String(body.orderId || body.mainOrderId || '').trim(),
|
|
deliveryStatus: Number(body.deliveryStatus || 1),
|
|
logisticsOrderId: String(body.logisticsOrderId || '').trim(),
|
|
crrgBsnNm: String(body.crrgBsnNm || '').trim()
|
|
}))
|
|
})
|
|
|
|
export const orderPushEventController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
const body = await readJson<OrderPushEventInput>(request)
|
|
|
|
return toHttpResponse(await orderPushEventService.pushEvent(body))
|
|
})
|
|
|
|
export const supplierOrderInfoController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
let body: SupplierOrderQueryRequest
|
|
try {
|
|
body = supplierOpenOrderService.parseBody(await readJson<SupplierOrderQueryRequest>(request))
|
|
} catch (error) {
|
|
return Response.json({
|
|
resultCode: 400,
|
|
message: error instanceof Error ? error.message : '请求参数解密失败',
|
|
orderInfo: []
|
|
})
|
|
}
|
|
|
|
return Response.json(await supplierOpenOrderService.queryOrderInfo(body))
|
|
})
|
|
|
|
export const supplierReconciliationInfoController = withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
let body: SupplierReconciliationQueryRequest
|
|
try {
|
|
body = supplierOpenOrderService.parseBody(await readJson<SupplierReconciliationQueryRequest>(request))
|
|
} catch (error) {
|
|
return Response.json({
|
|
resultCode: 400,
|
|
message: error instanceof Error ? error.message : '请求参数解密失败',
|
|
orderInfos: []
|
|
})
|
|
}
|
|
|
|
return Response.json(await supplierOpenOrderService.queryReconciliationInfo(body))
|
|
})
|