bug调整
This commit is contained in:
@@ -722,7 +722,7 @@ router.put('/:id/confirm', auth, async (req, res) => {
|
||||
|
||||
// 检查订单是否存在且属于当前用户
|
||||
const [orders] = await getDB().execute(
|
||||
'SELECT id, status FROM orders WHERE id = ? AND user_id = ?',
|
||||
'SELECT * FROM orders WHERE id = ? AND user_id = ?',
|
||||
[orderId, userId]
|
||||
);
|
||||
|
||||
@@ -736,6 +736,24 @@ router.put('/:id/confirm', auth, async (req, res) => {
|
||||
return res.status(400).json({ success: false, message: '只能确认已发货的订单' });
|
||||
}
|
||||
|
||||
// 佣金分配
|
||||
const [products] = await getDB().execute(
|
||||
'SELECT * FROM order_items WHERE order_id = ?',
|
||||
[orderId]
|
||||
);
|
||||
for (const product of products) {
|
||||
const [producersResult] = await getDB().execute(
|
||||
'SELECT * FROM products WHERE id = ?',
|
||||
[product.product_id]
|
||||
);
|
||||
if (producersResult[0].shop_name) {
|
||||
await getDB().execute(
|
||||
'UPDATE users SET income = income + ? WHERE id = ?',
|
||||
[producersResult[0].price * product.quantity, parseInt(producersResult[0].shop_name)]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新订单状态
|
||||
await getDB().execute(
|
||||
'UPDATE orders SET status = "completed", updated_at = NOW() WHERE id = ?',
|
||||
|
||||
@@ -104,7 +104,7 @@ const router = express.Router();
|
||||
// 商品管理路由
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
const { page = 1, limit = 10, search = '', category = '', status = '' } = req.query;
|
||||
const { page = 1, limit = 10, search = '', category = '', status = '', sort } = req.query;
|
||||
|
||||
// 确保参数为有效数字
|
||||
const pageNum = Math.max(1, parseInt(page) || 1);
|
||||
@@ -129,6 +129,21 @@ router.get('/', async (req, res) => {
|
||||
whereClause += ' AND status = "active"';
|
||||
}
|
||||
|
||||
switch (sort) {
|
||||
case 'price_desc':
|
||||
whereClause += ' ORDER BY sale_price DESC'
|
||||
break;
|
||||
case 'price_asc':
|
||||
whereClause += ' ORDER BY sale_price ASC'
|
||||
break;
|
||||
case 'sales_desc':
|
||||
whereClause += ' ORDER BY sales DESC'
|
||||
break;
|
||||
default:
|
||||
whereClause += ' ORDER BY created_at DESC'
|
||||
break;
|
||||
}
|
||||
|
||||
// 获取总数
|
||||
const countQuery = `SELECT COUNT(*) as total FROM products ${whereClause}`;
|
||||
const [countResult] = await getDB().execute(countQuery, params);
|
||||
@@ -139,13 +154,12 @@ router.get('/', async (req, res) => {
|
||||
SELECT id, name, rongdou_price, points_price, stock, image_url as image, description, status, payment_methods, created_at, updated_at, sales, images
|
||||
FROM products
|
||||
${whereClause}
|
||||
ORDER BY created_at DESC
|
||||
LIMIT ${limitNum} OFFSET ${offset}
|
||||
`;
|
||||
|
||||
// 确保参数数组正确传递
|
||||
const queryParams = [...params];
|
||||
console.log('Query params:', queryParams, 'Query:', query);
|
||||
// console.log('Query params:', queryParams, 'Query:', query);
|
||||
const [products] = await getDB().execute(query, queryParams);
|
||||
|
||||
products.forEach(item=>{
|
||||
|
||||
Reference in New Issue
Block a user