This commit is contained in:
董海洋
2026-05-26 09:18:48 +08:00
parent 12b582ec64
commit ff40282dc1
19 changed files with 703 additions and 8 deletions
+42
View File
@@ -0,0 +1,42 @@
const { query } = require('../config/database')
async function getPriceList(ctx) {
const orderId = ctx.params.orderId
const orders = await query('SELECT * FROM orders WHERE id = ?', [orderId])
if (orders.length === 0) {
ctx.body = { code: 404, message: '订单不存在' }
return
}
const order = orders[0]
let items = []
try {
const cartData = typeof order.cart === 'string' ? JSON.parse(order.cart) : order.cart
items = Array.isArray(cartData) ? cartData : (cartData.items || cartData.list || [])
} catch (e) {
items = []
}
ctx.body = {
code: 200,
data: {
orderNo: order.id,
createTime: order.created_at,
items: items.map(item => ({
name: item.name,
quantity: item.quantity || item.count || 1,
price: item.price || 0,
unit: item.unit || '件',
subtotal: (item.price || 0) * (item.quantity || item.count || 1)
})),
total: order.total_price,
remark: ''
}
}
}
module.exports = {
getPriceList
}