Authored by 陈峰

价格曲线

... ... @@ -8,6 +8,7 @@ const {logger} = require('../../libs/logger');
const spiderSj = require('./spider/shenjian');
const spiderDu = require('./spider/du');
const spiderUfo = require('./spider/ufo');
const {getSpecialSizeProducts, getSize} = require('../../utils');
const mergePrice = (prices, scales) => {
let mp = 0;
... ... @@ -89,7 +90,7 @@ const report = async(product, time) => {
return results.filter(r => r).length;
};
const task = async({product, now, sizeRelation}) => {
const task = async({product, now, sizeRelation, isSpecialSize}) => {
try {
const results = await Promise.all([
spiderUfo(product.third.ufo),
... ... @@ -102,7 +103,12 @@ const task = async({product, now, sizeRelation}) => {
du: _.get(results[2], 'skus', []),
});
const skus = _.map(Object.keys(skusGroups), size => {
if (sizeRelation[size]) {
const find = getSize(size, sizeRelation, isSpecialSize);
if (isSpecialSize) {
console.log(`=================>price-day-task yhId: ${product.productId}, size: ${size} => ${find.relationSize || size}, ${find.sizeId}`);
}
if (find) {
const price = calcPrice(skusGroups[size]);
logger.info(`[price-day-task] skusGroups: ${product.productId}, ${size} ${JSON.stringify(skusGroups[size])}, price: ${price}`);
... ... @@ -111,7 +117,7 @@ const task = async({product, now, sizeRelation}) => {
return {
size,
price,
sizeId: _.get(sizeRelation[size], 'sizeId', 0)
sizeId: _.get(find, 'sizeId', 0)
};
}
}
... ... @@ -139,6 +145,8 @@ module.exports = async() => {
logger.info(`[price-day-task] dayTask, exists createtime price: ${now}`);
return;
}
const specialSizeProducts = await getSpecialSizeProducts();
const sizeData = await mysqlPool.query('select `size_name`,min(`id`) as id from `size` where `size_name` <> \'-\' group by `size_name`');
const sizeRelation = {};
... ... @@ -153,7 +161,8 @@ module.exports = async() => {
let insertTotal = 0;
products.forEach(async(product, inx) => {
const inserted = await lockTask({product, now, sizeRelation});
const isSpecialSize = Boolean(specialSizeProducts[product.productId]);
const inserted = await lockTask({product, now, sizeRelation, isSpecialSize});
insertTotal += inserted;
if (inx >= products.length - 1) {
... ...
... ... @@ -55,7 +55,7 @@ module.exports = async(time) => {
return logger.error(`[spider-task]爬取尺码对应关系未找到: ${JSON.stringify(s)}`);
}
if (isSpecialSize) {
console.log(`=================>yhId: ${yhProduct.yhId}, duId: ${detail.productId} size: ${s.size} => ${find.relationSize || s.size}, ${find.sizeId}`);
console.log(`=================>spider-all-task yhId: ${yhProduct.yhId}, duId: ${detail.productId} size: ${s.size} => ${find.relationSize || s.size}, ${find.sizeId}`);
}
const highRate = inSkns ? 0.02 : 0.05;
... ...
... ... @@ -77,7 +77,7 @@ module.exports = async(time) => {
return logger.error(`[spider-task]爬取尺码对应关系未找到: ${JSON.stringify(s)}`);
}
if (isSpecialSize) {
console.log(`=================>yhId: ${yhProduct.yhId}, duId: ${detail.productId} size: ${s.size} => ${find.relationSize || s.size}, ${find.sizeId}`);
console.log(`=================>spider-task yhId: ${yhProduct.yhId}, duId: ${detail.productId} size: ${s.size} => ${find.relationSize || s.size}, ${find.sizeId}`);
}
const highRate = 0.02;
... ...