新增返回实付总额
This commit is contained in:
@@ -77,7 +77,7 @@ router.get('/', auth, async (req, res) => {
|
||||
SELECT
|
||||
o.id, o.order_no, o.user_id, o.total_amount, o.total_points,
|
||||
o.status, o.address, o.created_at, o.updated_at,o.total_rongdou,
|
||||
u.username
|
||||
u.username, o.real_rongdou, o.real_points
|
||||
FROM orders o
|
||||
LEFT JOIN users u ON o.user_id = u.id
|
||||
${whereClause}
|
||||
@@ -114,7 +114,7 @@ router.get('/', auth, async (req, res) => {
|
||||
}
|
||||
|
||||
// 处理地址信息
|
||||
console.log(order.address,'order.address');
|
||||
// console.log(order.address,'order.address');
|
||||
|
||||
if (order.address) {
|
||||
try {
|
||||
@@ -344,7 +344,8 @@ router.get('/:id', auth, async (req, res) => {
|
||||
const query = `
|
||||
SELECT
|
||||
o.id, o.order_no, o.user_id, o.total_amount, o.total_points,
|
||||
o.status, o.address, o.created_at, o.updated_at,
|
||||
o.status, o.address, o.created_at, o.updated_at, o.total_rongdou,
|
||||
o.real_rongdou, o.real_points,
|
||||
u.username, u.phone
|
||||
FROM orders o
|
||||
LEFT JOIN users u ON o.user_id = u.id
|
||||
@@ -457,6 +458,10 @@ router.post('/create-from-cart', auth, async (req, res) => {
|
||||
`UPDATE product_spec_combinations SET stock = stock - ? WHERE id = ?`,
|
||||
[item.quantity, item.specification_id]
|
||||
);
|
||||
await db.execute(
|
||||
`UPDATE products SET stock = stock - ? WHERE id = ?`,
|
||||
[item.quantity, item.product_id]
|
||||
);
|
||||
}
|
||||
|
||||
// 验证商品状态和库存,计算总价和支付方式
|
||||
@@ -661,6 +666,11 @@ router.put('/:id/cancel', auth, async (req, res) => {
|
||||
'UPDATE product_spec_combinations SET stock = stock + ? WHERE id = ?',
|
||||
[orderDetails[0].quantity, orderDetails[0].spec_combination_id]
|
||||
);
|
||||
// 返还销售量
|
||||
await db.execute(
|
||||
'UPDATE products SET stock = stock + ? WHERE id = ?',
|
||||
[orderDetails[0].quantity, orderDetails[0].product_id]
|
||||
);
|
||||
|
||||
|
||||
// 更新订单状态
|
||||
@@ -746,6 +756,10 @@ router.put('/:id/confirm', auth, async (req, res) => {
|
||||
'SELECT * FROM products WHERE id = ?',
|
||||
[product.product_id]
|
||||
);
|
||||
await getDB().execute(
|
||||
'UPDATE products SET sales = sales + ? WHERE id = ?',
|
||||
[product.quantity, product.product_id]
|
||||
);
|
||||
if (producersResult[0].shop_name) {
|
||||
await getDB().execute(
|
||||
'UPDATE users SET income = income + ? WHERE id = ?',
|
||||
@@ -1115,7 +1129,7 @@ router.post('/confirm-payment', auth, async (req, res) => {
|
||||
try {
|
||||
await connection.beginTransaction();
|
||||
|
||||
const { orderId: order_id, addressId: address_id, couponRecordId, paymentMethod } = req.body;
|
||||
const { orderId: order_id, addressId: address_id, couponRecordId, paymentMethod, beansAmount, pointsAmount } = req.body;
|
||||
const userId = req.user.id;
|
||||
|
||||
// 验证必填字段
|
||||
@@ -1389,6 +1403,20 @@ router.post('/confirm-payment', auth, async (req, res) => {
|
||||
);
|
||||
}
|
||||
|
||||
if (beansAmount > 0) {
|
||||
await connection.execute(
|
||||
'UPDATE orders SET real_rongdou = ? WHERE id = ?',
|
||||
[beansAmount, order_id]
|
||||
);
|
||||
}
|
||||
|
||||
if (pointsAmount > 0) {
|
||||
await connection.execute(
|
||||
'UPDATE orders SET real_points = ? WHERE id = ?',
|
||||
[pointsAmount, order_id]
|
||||
);
|
||||
}
|
||||
|
||||
// 更新订单状态和收货地址
|
||||
const addressStr = JSON.stringify({
|
||||
recipient_name: address.receiver_name,
|
||||
|
||||
Reference in New Issue
Block a user