Authored by 陈峰

update hige rate

... ... @@ -2,22 +2,24 @@ const {mysqlPool} = require('./mysql');
module.exports = async(data) => {
let dataId = 0;
const {productId, sizeId, price, time} = data;
const {productId, sizeId, price, time, highRate} = 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', {
const updateRows = await mysqlPool.update('UPDATE `channel_sku_compare` SET `channel_price` = :channelPrice, `update_time` = :updateTime, `high_rate` = :highRate WHERE `product_id` = :productId AND `size_id` = :sizeId', {
channelPrice: price,
updateTime: time,
productId,
sizeId
sizeId,
highRate: highRate || 0.05
});
if (!updateRows) {
const insertRow = await mysqlPool.insert('INSERT `channel_sku_compare` (`product_id`, `sku`, `size_id`,`channel_price`, `low_rate`, `high_rate`, `channel_average_price`, `update_time`, `status`) SELECT `product_id`,`id`,`size_id`, :channelPrice, 0.05, 0.05, 0.00, :updateTime, 0 FROM `storage` WHERE `product_id` = :productId AND `size_id` = :sizeId', {
const insertRow = await mysqlPool.insert('INSERT `channel_sku_compare` (`product_id`, `sku`, `size_id`,`channel_price`, `low_rate`, `high_rate`, `channel_average_price`, `update_time`, `status`) SELECT `product_id`,`id`,`size_id`, :channelPrice, 0.05, :highRate, 0.00, :updateTime, 0 FROM `storage` WHERE `product_id` = :productId AND `size_id` = :sizeId', {
channelPrice: price,
updateTime: time,
productId,
sizeId
sizeId,
highRate: highRate || 0.05
});
if (!insertRow) {
... ...
... ... @@ -61,6 +61,7 @@ const spiderBuyers = async(productId, lsId = 0, page = 0, trys = 0, tid) => {
let lastId;
let tryLogic = false;
let list = [];
console.log(JSON.stringify(result))
if (result.status === 200) {
let skip = false;
lastId = result.data.lastId;
... ... @@ -74,9 +75,9 @@ const spiderBuyers = async(productId, lsId = 0, page = 0, trys = 0, tid) => {
if (!time.isBefore(startTime)) {
mysql.insert('INSERT INTO `' + config.table + '` (`productId`, `nickName`, `icon`, `time`, `size`, `soldNum`, `price`) VALUES (:productId, :nickName, :icon, :time, :size, :soldNum, :price)', {
productId: productId,
nickName: info.buyer.userName,
icon: info.buyer.icon,
size: info.item.size,
nickName: info.userName,
icon: info.avatar,
size: info.sizeDesc,
time: time.format('YYYY-MM-DD HH:mm:ss'),
soldNum: products[productId].count,
price: products[productId].price,
... ... @@ -141,6 +142,7 @@ const start = async({inx, tid}) => {
try {
await spiderBuyers(productId, 0, 0, 0, tid);
} catch (error) {
console.log(error)
logger.info('error', error);
}
... ...
... ... @@ -2,6 +2,7 @@ const _ = require('lodash');
const spider = require('../libs/spider');
const report = require('../libs/report');
const sknsData = require('../data/skns.json');
const legoData = require('../data/lego.json');
const {mysqlPool} = require('../libs/mysql');
const {logger} = require('../libs/logger');
... ... @@ -32,6 +33,7 @@ module.exports = async(time) => {
const yhProduct = duProducts.find(p => _.get(p, 'third.du.productId') === detail.productId);
const hrtime = process.hrtime();
const timestamp = parseInt(Date.now() / 1000, 10) * 1000000000;
const inSkns = sknsData.some(s => s.yhId === yhProduct.productId);
sizeList.forEach(s => {
if (_.isPlainObject(s.item) && s.item.price > 0) {
... ... @@ -49,15 +51,18 @@ module.exports = async(time) => {
if (!find) {
return logger.error(`[spider-task]爬取尺码对应关系未找到: ${JSON.stringify(s)}`);
}
const highRate = inSkns ? 0.05 : 0.2;
report({
productId: yhProduct.productId,
sizeId: find.sizeId,
price: s.item.price / 100,
highRate,
time
}).then(() => {
const reportTime = timestamp + process.hrtime(hrtime)[1];
logger.info(`[spider-task]更新sku价格成功记录, duId:${detail.productId}, yhId: ${yhProduct.productId}, sizeId: ${find.sizeId}, time: ${time}`);
logger.info(`[spider-task]更新sku价格成功记录, duId:${detail.productId}, yhId: ${yhProduct.productId}, sizeId: ${find.sizeId}, time: ${time}, highRate: ${highRate}`);
sendMessage(1, reportTime);
}).catch(error => {
logger.error(error.message);
... ...
... ... @@ -72,16 +72,18 @@ module.exports = async(time) => {
if (!find) {
return logger.error(`[spider-task]爬取尺码对应关系未找到: ${JSON.stringify(s)}`);
}
const highRate = 0.05;
report({
productId: yhProduct.yhId,
sizeId: find.sizeId,
price: s.item.price / 100,
highRate,
time
}).then(() => {
const reportTime = timestamp + process.hrtime(hrtime)[1];
logger.info(`[spider-task]更新sku价格成功记录, duId:${detail.productId}, yhId: ${yhProduct.yhId}, sizeId: ${find.sizeId}, time: ${time}`);
logger.info(`[spider-task]更新sku价格成功记录, duId:${detail.productId}, yhId: ${yhProduct.yhId}, sizeId: ${find.sizeId}, time: ${time}, highRate: ${highRate}`);
sendMessage(1, reportTime);
}).catch(error => {
logger.error(error.message);
... ...