spider-normal-sell-task.js 1.24 KB
const priceCompare = require('../utils/price-compare');
const { queryNormalSellProductRelations } = require('../libs/ufo-product-api');
const ddAlert = require('../libs/dingding-alert');
const { logger } = require('../libs/logger');
module.exports = async(time) => {
  let myDate = new Date();

  // 分页获取周几就取第几页 周日取第七页
  let pageNo = myDate.getDay() || 7;
  let pageSize = 2000;

  // 获取要比价是skn对比关系
  let productRelationsArr = {};
  let sknsData = [];
  try {
    // 获取所有要比价的商品对应关系
    const productRelations = await queryNormalSellProductRelations({
      pageNo,
      pageSize,
      status: 1,
      productSign : 2
    });
    if (productRelations) {
      productRelationsArr = JSON.parse(productRelations).data.records;
    }
    productRelationsArr.forEach(relations => {
      sknsData.push({'productId' : relations.channelProductId, 'yhId': relations.productId});
    });
  }catch(error) {
    logger.error(`[正常商品比价]`+error);
    ddAlert(`监控提醒 : pop服务接口 queryChannelProductRelationsPages 异常,请查看! @15101660386 `, 'bjSpider');
    return false;
  }
  //进行比价
  priceCompare(time, sknsData, `正常商品比价 页码:${pageNo}`);
}