新增优惠券的选择
This commit is contained in:
@@ -1061,7 +1061,7 @@ router.post('/confirm-payment', auth, async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
await connection.beginTransaction();
|
await connection.beginTransaction();
|
||||||
|
|
||||||
const { orderId: order_id, addressId: address_id } = req.body;
|
const { orderId: order_id, addressId: address_id, couponRecordId } = req.body;
|
||||||
const userId = req.user.id;
|
const userId = req.user.id;
|
||||||
|
|
||||||
// 验证必填字段
|
// 验证必填字段
|
||||||
@@ -1090,7 +1090,7 @@ router.post('/confirm-payment', auth, async (req, res) => {
|
|||||||
|
|
||||||
// 解析支付方式
|
// 解析支付方式
|
||||||
let allPaymentMethods = [];
|
let allPaymentMethods = [];
|
||||||
console.log(typeof order.payment_methods_list);
|
// console.log(typeof order.payment_methods_list);
|
||||||
|
|
||||||
if (order.payment_methods_list) {
|
if (order.payment_methods_list) {
|
||||||
try {
|
try {
|
||||||
@@ -1222,6 +1222,14 @@ router.post('/confirm-payment', auth, async (req, res) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新优惠券记录
|
||||||
|
if (couponRecordId) {
|
||||||
|
await connection.execute(
|
||||||
|
'UPDATE coupon_use SET use_time = NOW(), order_id = ? WHERE id = ?',
|
||||||
|
[order_id, couponRecordId]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 更新订单状态和收货地址
|
// 更新订单状态和收货地址
|
||||||
const addressStr = JSON.stringify({
|
const addressStr = JSON.stringify({
|
||||||
recipient_name: address.receiver_name,
|
recipient_name: address.receiver_name,
|
||||||
@@ -1238,6 +1246,12 @@ router.post('/confirm-payment', auth, async (req, res) => {
|
|||||||
[addressStr, order_id]
|
[addressStr, order_id]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 减组合库存
|
||||||
|
// await connection.execute(
|
||||||
|
// 'UPDATE product_spec_combinations SET stock = stock - 1 WHERE id = ?',
|
||||||
|
// [order.product_combination_id]
|
||||||
|
// );
|
||||||
|
|
||||||
await connection.commit();
|
await connection.commit();
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ router.get('/', async (req, res) => {
|
|||||||
|
|
||||||
// 获取商品列表
|
// 获取商品列表
|
||||||
const query = `
|
const query = `
|
||||||
SELECT id, name, rongdou_price, points_price, stock, image_url as image, description, status, payment_methods, created_at, updated_at, sales
|
SELECT id, name, rongdou_price, points_price, stock, image_url as image, description, status, payment_methods, created_at, updated_at, sales, images
|
||||||
FROM products
|
FROM products
|
||||||
${whereClause}
|
${whereClause}
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
@@ -53,6 +53,7 @@ router.get('/', async (req, res) => {
|
|||||||
|
|
||||||
products.forEach(item=>{
|
products.forEach(item=>{
|
||||||
item.payment_methods = JSON.parse(item.payment_methods)
|
item.payment_methods = JSON.parse(item.payment_methods)
|
||||||
|
item.images = JSON.parse(item.images)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@@ -1018,7 +1019,6 @@ router.get('/:id/recommended', async (req, res) => {
|
|||||||
stock, image_url as image, description
|
stock, image_url as image, description
|
||||||
FROM products
|
FROM products
|
||||||
WHERE id NOT IN (${filteredRecommendProductIds.map(() => '?').join(',')})
|
WHERE id NOT IN (${filteredRecommendProductIds.map(() => '?').join(',')})
|
||||||
AND id != 3
|
|
||||||
ORDER BY RAND()
|
ORDER BY RAND()
|
||||||
LIMIT ${6 - recommendedProducts.length}
|
LIMIT ${6 - recommendedProducts.length}
|
||||||
`;
|
`;
|
||||||
|
|||||||
Reference in New Issue
Block a user