report.js
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const {mysqlPool} = require('./mysql');
module.exports = async(data) => {
let dataId = 0;
const {productId, sizeId, price, time} = data;
try {
const updateRows = await mysqlPool.update('UPDATE `channel_sku_compare` SET `channel_price` = :channelPrice, `update_time` = :updateTime WHERE `product_id` = :productId AND `size_id` = :sizeId', {
channelPrice: price,
updateTime: time,
productId,
sizeId
});
if (!updateRows) {
return Promise.reject(new Error(`更新channel_sku_compare表失败 ${JSON.stringify(data)}`));
}
const insertId = await mysqlPool.insert('INSERT INTO `channel_sku_compare_record` (`product_id`, `size_id`, `channel_price`, `create_time`, `sku`) VALUES (:productId, :sizeId, :channelPrice, :createTime, 0)', {
productId,
sizeId,
channelPrice: price,
createTime: time
});
if (!insertId) {
return Promise.reject(new Error(`插入channel_sku_compare_record表失败 ${JSON.stringify(data)}`));
} else {
return Promise.resolve({
price,
sizeId,
productId,
dataId
});
}
} catch (error) {
return Promise.reject(new Error(`更新channel_sku_compare表错误: ${JSON.stringify(data)}, ${error.message}`));
}
};