新增原价以及佣金

This commit is contained in:
dzl
2025-10-23 17:27:55 +08:00
parent cb38e0fa3a
commit 9eea43e92e
3 changed files with 36 additions and 8 deletions

View File

@@ -887,12 +887,12 @@ router.put('/:id/status', async (req, res) => {
);
}
// 分佣金额分配
if (status === 'completed') {
const [products] = await getDB().execute(
'SELECT * FROM order_items WHERE order_id = ?',
[orderId]
);
let producers = []
for (const product of products) {
const [producersResult] = await db.execute(
'SELECT * FROM products WHERE id = ?',
@@ -901,7 +901,7 @@ router.put('/:id/status', async (req, res) => {
if (producersResult[0].shop_name) {
await db.execute(
'UPDATE users SET income = income + ? WHERE id = ?',
[1, parseInt(producersResult[0].shop_name)]
[producersResult[0].price * product.quantity, parseInt(producersResult[0].shop_name)]
);
}
}

View File

@@ -58,7 +58,7 @@ router.get('/', async (req, res) => {
SELECT DISTINCT
p.id, p.name, p.rongdou_price, p.points_price, p.stock,
p.image_url as image, p.description, p.status, p.payment_methods,
p.created_at, p.updated_at, p.sales, p.shop_name
p.created_at, p.updated_at, p.sales, p.shop_name, p.sale_price
FROM products p
${joinClause}
${whereClause}
@@ -431,7 +431,7 @@ router.post('/', async (req, res) => {
const {
name, description, price, points_price, rongdou_price = 0, stock, category = [],
image_url, images = [], videos = [], details, status = 'active',
shop_name, shop_avatar, payment_methods = ['points', 'rongdou', 'points_rongdou'], attributes = []
shop_name, shop_avatar, payment_methods = ['points', 'rongdou', 'points_rongdou'], attributes = [], sale_price
} = req.body;
if (!name || !price || stock === undefined) {
@@ -511,6 +511,12 @@ router.post('/', async (req, res) => {
params.push(status)
}
if(sale_price !== null) {
query[0] += ', sale_price = ?'
params.push(sale_price)
console.log(12345,sale_price)
}
query[0] += ', updated_at = NOW()'
params.push('temp')
@@ -580,7 +586,7 @@ router.put('/:id', async (req, res) => {
const {
name, description, price, points_price, rongdou_price, stock, category, level,
image_url, images, videos, details, status, shop_name, shop_avatar, payment_methods,
specifications, attributes
specifications, attributes, sale_price
} = req.body;
// 检查商品是否存在
@@ -667,6 +673,12 @@ router.put('/:id', async (req, res) => {
updateValues.push(status);
}
if (sale_price !== null) {
updateFields.push('sale_price = ?');
updateValues.push(sale_price);
console.log(12345,sale_price)
}
if (updateFields.length === 0) {
return res.status(400).json({ message: '没有要更新的字段' });
}

View File

@@ -34,7 +34,7 @@ router.get('/', async (req, res) => {
// 获取商品列表
const query = `
SELECT id, user_id, amount, status, time
SELECT id, user_id, amount, status, time, pass_time
FROM withdrawal
${whereClause}
ORDER BY time DESC
@@ -43,12 +43,20 @@ router.get('/', async (req, res) => {
// 确保参数数组正确传递
const queryParams = [...params];
console.log('Query params:', queryParams, 'Query:', query);
// console.log('Query params:', queryParams, 'Query:', query);
const [withdrawals] = await getDB().execute(query, queryParams);
let income = 0;
if (user_id) {
const [userIncome] = await getDB().execute(`
SELECT income FROM users WHERE id = ?
`, [user_id]);
income = userIncome[0].income;
}
res.json({
success: true,
data: {
withdrawals,
income,
pagination: {
page: pageNum,
limit: limitNum,
@@ -68,13 +76,21 @@ router.post('/:id/approve', async (req, res) => {
const { id } = req.params;
const query = `
UPDATE withdrawal
SET status = 'success'
SET status = 'success', pass_time = NOW()
WHERE id = ?
`;
const queryParams = [id];
const [result] = await getDB().execute(query, queryParams);
if (result.affectedRows === 0) {
return res.status(404).json({ success: false, message: '提现记录不存在' });
} else {
const [withdrawal] = await getDB().execute(`
SELECT amount, user_id FROM withdrawal WHERE id = ?
`, [id]);
// console.log(withdrawal);
await getDB().execute(`
UPDATE users SET income = income - ? WHERE id = ?
`, [withdrawal[0].amount, withdrawal[0].user_id]);
}
res.json({
success: true,