接口更改
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
const express = require('express');
|
||||
const { getDB } = require('../database');
|
||||
const { auth, adminAuth } = require('../middleware/auth');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -8,7 +7,7 @@ const router = express.Router();
|
||||
|
||||
|
||||
// 获取订单列表
|
||||
router.get('/', auth, async (req, res) => {
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
const { page = 1, limit = 10, search = '', orderNumber = '', username = '', status = '', startDate = '', endDate = '' } = req.query;
|
||||
|
||||
@@ -18,7 +17,7 @@ router.get('/', auth, async (req, res) => {
|
||||
const pageNum = parseInt(page) || 1;
|
||||
const limitNum = parseInt(limit) || 10;
|
||||
const offset = (pageNum - 1) * limitNum;
|
||||
const isAdmin = req.user.role === 'admin';
|
||||
const isAdmin = true;
|
||||
|
||||
let whereClause = 'WHERE 1=1';
|
||||
const params = [];
|
||||
@@ -141,7 +140,7 @@ router.get('/', auth, async (req, res) => {
|
||||
});
|
||||
|
||||
|
||||
router.post('/confirm', auth, async (req, res) => {
|
||||
router.post('/confirm', async (req, res) => {
|
||||
const connection = await getDB().getConnection();
|
||||
|
||||
try {
|
||||
@@ -265,7 +264,7 @@ router.get('/', auth, async (req, res) => {
|
||||
});
|
||||
|
||||
|
||||
router.get('/pre-order/:id', auth, async (req, res) => {
|
||||
router.get('/pre-order/:id', async (req, res) => {
|
||||
try {
|
||||
const preOrderId = req.params.id;
|
||||
const userId = req.user.id;
|
||||
@@ -327,7 +326,7 @@ router.get('/', auth, async (req, res) => {
|
||||
});
|
||||
|
||||
|
||||
router.get('/:id', auth, async (req, res) => {
|
||||
router.get('/:id', async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const isAdmin = req.user.role === 'admin';
|
||||
@@ -408,7 +407,7 @@ router.get('/:id', auth, async (req, res) => {
|
||||
});
|
||||
|
||||
// 创建预订单
|
||||
router.post('/create-from-cart', auth, async (req, res) => {
|
||||
router.post('/create-from-cart', async (req, res) => {
|
||||
const db = getDB();
|
||||
await db.query('START TRANSACTION');
|
||||
|
||||
@@ -590,7 +589,7 @@ router.post('/create-from-cart', auth, async (req, res) => {
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
router.put('/:id/cancel', auth, async (req, res) => {
|
||||
router.put('/:id/cancel', async (req, res) => {
|
||||
const db = getDB();
|
||||
await db.query('START TRANSACTION');
|
||||
|
||||
@@ -682,7 +681,7 @@ router.put('/:id/cancel', auth, async (req, res) => {
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
router.put('/:id/confirm', auth, async (req, res) => {
|
||||
router.put('/:id/confirm', async (req, res) => {
|
||||
try {
|
||||
const orderId = req.params.id;
|
||||
const userId = req.user.id;
|
||||
@@ -767,7 +766,7 @@ router.put('/:id/confirm', auth, async (req, res) => {
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
router.put('/:id/status', auth, adminAuth, async (req, res) => {
|
||||
router.put('/:id/status', async (req, res) => {
|
||||
const db = getDB();
|
||||
await db.query('START TRANSACTION');
|
||||
|
||||
@@ -914,7 +913,7 @@ router.put('/:id/status', auth, adminAuth, async (req, res) => {
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
router.get('/pending-payment/:id', auth, async (req, res) => {
|
||||
router.get('/pending-payment/:id', async (req, res) => {
|
||||
try {
|
||||
const preOrderId = req.params.id;
|
||||
const userId = req.user.id;
|
||||
@@ -1055,7 +1054,7 @@ router.get('/pending-payment/:id', auth, async (req, res) => {
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
router.post('/confirm-payment', auth, async (req, res) => {
|
||||
router.post('/confirm-payment', async (req, res) => {
|
||||
const connection = await getDB().getConnection();
|
||||
|
||||
try {
|
||||
@@ -1304,7 +1303,7 @@ router.post('/confirm-payment', auth, async (req, res) => {
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
router.get('/stats', auth, adminAuth, async (req, res) => {
|
||||
router.get('/stats', async (req, res) => {
|
||||
try {
|
||||
// 总订单数
|
||||
const [totalOrders] = await getDB().execute('SELECT COUNT(*) as count FROM orders');
|
||||
|
||||
Reference in New Issue
Block a user