temp.js
1.13 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
40
41
const {ProductRelationModel} = require('./models');
const lockup = require('node-lockup');
const sjApi = require('./libs/sj-api');
const _ = require('lodash');
const task = async result => {
if (result.third.du || result.third.sj.length) {
let sj = '';
const du = result.third.du ? `http://du.hupu.com/mdu/product/detail.html?id=${result.third.du.productId}&source=boutiqueRecommend` : '';
if (result.third.sj.length) {
const res = await sjApi(`source(__id:{in: ${JSON.stringify(result.third.sj)}}){data{}}`);
if (res.code === 0) {
sj = _.get(res, 'result.data', []).map(item => item.url).join('|');
} else {
console.log(res);
}
}
console.log(`${result.productId},${result.productCode},${_.trim(result.productName.replace(',', ','))},${du},${sj}`);
return true;
}
return false;
};
const locktask = lockup(task, 50);
let open = false;
let inx = 0;
ProductRelationModel.findAll().then((results) => {
results.forEach(async result => {
if (result.productId === 10000853) {
open = true;
}
if (open && inx < 300) {
locktask(result);
inx++;
}
});
});