新增翻页相关功能
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const express = require('express');
|
||||
const { getDB } = require('../database');
|
||||
const { log } = require('winston');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -328,17 +329,18 @@ router.get('/', async (req, res) => {
|
||||
|
||||
router.get('/:id', async (req, res) => {
|
||||
try {
|
||||
console.log(1234,req.query)
|
||||
const { id } = req.params;
|
||||
const isAdmin = req.user.role === 'admin';
|
||||
// const isAdmin = req.user.role === 'admin';
|
||||
|
||||
let whereClause = 'WHERE o.id = ?';
|
||||
const params = [id];
|
||||
|
||||
// 非管理员只能查看自己的订单
|
||||
if (!isAdmin) {
|
||||
whereClause += ' AND o.user_id = ?';
|
||||
params.push(req.user.id);
|
||||
}
|
||||
// if (!isAdmin) {
|
||||
// whereClause += ' AND o.user_id = ?';
|
||||
// params.push(req.user.id);
|
||||
// }
|
||||
|
||||
const query = `
|
||||
SELECT
|
||||
@@ -774,6 +776,8 @@ router.put('/:id/status', async (req, res) => {
|
||||
|
||||
const orderId = req.params.id;
|
||||
const { status } = req.body;
|
||||
const deliveryCode = req.body.logistics_no;
|
||||
const logisticsCompany = req.body.logistics_company;
|
||||
|
||||
const validStatuses = ['pending', 'shipped', 'completed', 'cancelled'];
|
||||
if (!validStatuses.includes(status)) {
|
||||
@@ -828,10 +832,17 @@ router.put('/:id/status', async (req, res) => {
|
||||
}
|
||||
|
||||
// 更新订单状态
|
||||
await db.execute(
|
||||
'UPDATE orders SET status = ?, updated_at = NOW() WHERE id = ?',
|
||||
[status, orderId]
|
||||
);
|
||||
if (status === 'shipped') {
|
||||
await db.execute(
|
||||
'UPDATE orders SET status = ?, delivery_code = ?, logistics_company = ?, updated_at = NOW() WHERE id = ?',
|
||||
[status, deliveryCode, logisticsCompany, orderId]
|
||||
);
|
||||
} else {
|
||||
await db.execute(
|
||||
'UPDATE orders SET status = ?, updated_at = NOW() WHERE id = ?',
|
||||
[status, orderId]
|
||||
);
|
||||
}
|
||||
|
||||
await db.query('COMMIT');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user