更改商品添加逻辑,新增分佣逻辑

This commit is contained in:
dzl
2025-10-22 17:26:40 +08:00
parent 6d579316b7
commit cb38e0fa3a
2 changed files with 93 additions and 5 deletions

View File

@@ -887,6 +887,30 @@ 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 = ?',
[product.product_id]
);
if (producersResult[0].shop_name) {
await db.execute(
'UPDATE users SET income = income + ? WHERE id = ?',
[1, parseInt(producersResult[0].shop_name)]
);
}
}
// await db.execute(
// 'UPDATE users SET income = income + ? WHERE id = ?',
// ['分佣金额', '收到分佣的用户id']
// );
}
await db.query('COMMIT');
res.json({ success: true, message: '订单状态已更新' });

View File

@@ -25,9 +25,10 @@ router.get('/', async (req, res) => {
if (status) {
whereClause += ' AND p.status = ?';
params.push(status);
} else {
whereClause += ' AND p.status = "active"';
}
}
// else {
// whereClause += ' AND p.status = "active"';
// }
if (shop_name) {
whereClause += ' AND p.shop_name = ?';
@@ -200,7 +201,7 @@ router.get('/:id', async (req, res) => {
image_url, images, videos, description, details, shop_name, shop_avatar,
payment_methods, sales, rating, status, created_at, updated_at
FROM products
WHERE id = ? AND status = 'active'
WHERE id = ?
`;
const [products] = await getDB().execute(query, [id]);
@@ -410,7 +411,8 @@ router.get('/:id', async (req, res) => {
SELECT * FROM users WHERE id = ?
`
const [user] = await getDB().execute(query, [parseInt(enhancedProduct.shop_name)])
enhancedProduct.shop_name = user[0].username
console.log(123, user, enhancedProduct.shop_name)
enhancedProduct.shop_name = user.length > 0 ? user[0].username : enhancedProduct.shop_name
}
res.json({
@@ -452,6 +454,68 @@ router.post('/', async (req, res) => {
`,`
WHERE name = ?
`]
const params = [name, price, stock]
if(description) {
query[0] += ', description = ?'
params.push(description)
}
if(points_price !== null) {
query[0] += ', points_price = ?'
params.push(points_price)
}
if(rongdou_price !== null) {
query[0] += ', rongdou_price = ?'
params.push(rongdou_price)
}
if(image_url) {
query[0] += ', image_url = ?'
params.push(image_url)
}
if(images.length > 0) {
query[0] += ', images = ?'
params.push(JSON.stringify(images))
}
if(videos.length > 0) {
query[0] += ', videos = ?'
params.push(JSON.stringify(videos))
}
if(details) {
query[0] += ', details = ?'
params.push(details)
}
if(shop_name) {
query[0] += ', shop_name = ?'
params.push(shop_name)
}
if(shop_avatar) {
query[0] += ', shop_avatar = ?'
params.push(shop_avatar)
}
if(payment_methods.length > 0) {
query[0] += ', payment_methods = ?'
params.push(JSON.stringify(payment_methods))
}
if(status) {
query[0] += ', status = ?'
params.push(status)
}
query[0] += ', updated_at = NOW()'
params.push('temp')
const [result] = await getDB().execute(query.join(' '), params)