...
|
...
|
@@ -4,7 +4,7 @@ const ROOT_PATH = global.ROOT_PATH; |
|
|
const _ = require('lodash');
|
|
|
const redis = require(`${ROOT_PATH}/libs/redis`);
|
|
|
const YohoApiModel = require('./../interface/yoho-api');
|
|
|
|
|
|
const co = Promise.coroutine;
|
|
|
const rp = require('request-promise');
|
|
|
const senUrl = 'http://data.zz.baidu.com/urls?token=0lSAO4ZxEKsYopMG&site=';
|
|
|
|
...
|
...
|
@@ -46,17 +46,9 @@ class BaiduLinkSubmit extends global.yoho.BaseModel { |
|
|
|
|
|
// 提交商品详情URL
|
|
|
goodsUrl() {
|
|
|
let ids = [];
|
|
|
let message = '';
|
|
|
|
|
|
return this.yohoApiModel.bdPromotion().then(rdata => {
|
|
|
rdata = _.get(rdata, 'data', []);
|
|
|
ids = _.map(rdata, item => {
|
|
|
return `${item.erpProductId}`;
|
|
|
});
|
|
|
let that = this;
|
|
|
|
|
|
return redis.hmgetAsync('global:yoho:seo:linksubmit:goods', ids);
|
|
|
}).then(rdata => {
|
|
|
return co(function* () {
|
|
|
|
|
|
let products = {
|
|
|
pc: [],
|
...
|
...
|
@@ -64,14 +56,21 @@ class BaiduLinkSubmit extends global.yoho.BaseModel { |
|
|
pcUrl: 'https://www.yohobuy.com',
|
|
|
wapUrl: 'https://m.yohobuy.com'
|
|
|
};
|
|
|
let tids = [];
|
|
|
let rdata = _.get(yield that.yohoApiModel.bdPromotion(), 'data', []);
|
|
|
let ids = _.map(rdata, item => {
|
|
|
return `${item.erpProductId}`;
|
|
|
});
|
|
|
|
|
|
let artice = {
|
|
|
total: ids.length,
|
|
|
notAlready: 0
|
|
|
};
|
|
|
|
|
|
ids = _.difference(ids, rdata);// 去除已经推送的
|
|
|
ids = _.difference(ids, yield redis.hmgetAsync('global:yoho:seo:linksubmit:goods', ids));// 去除已经推送的
|
|
|
artice.notAlready = ids.length;
|
|
|
message = `获取${artice.total}条记录,未推送的有${artice.notAlready}条记录`;
|
|
|
|
|
|
let message = `获取${artice.total}条记录,未推送的有${artice.notAlready}条记录`;
|
|
|
|
|
|
if (artice.notAlready <= 0) {
|
|
|
return [
|
...
|
...
|
@@ -81,50 +80,40 @@ class BaiduLinkSubmit extends global.yoho.BaseModel { |
|
|
}
|
|
|
|
|
|
_.each(ids, val => {
|
|
|
tids.push(val, val);// mset做准备
|
|
|
|
|
|
products.pc.push(`${products.pcUrl}/product/${val}.html`);
|
|
|
products.wap.push(`${products.wapUrl}/product/${val}.html`);
|
|
|
});
|
|
|
|
|
|
return Promise.all([
|
|
|
this.sendUrl(products.pc, products.pcUrl),
|
|
|
this.sendUrl(products.wap, products.wapUrl)
|
|
|
rdata = yield Promise.all([
|
|
|
that.sendUrl(products.pc, products.pcUrl),
|
|
|
that.sendUrl(products.wap, products.wapUrl)
|
|
|
]);
|
|
|
}).then(rdata => {
|
|
|
|
|
|
if (rdata[0].code !== 200 || rdata[1].code !== 200) {
|
|
|
return rdata;
|
|
|
}
|
|
|
|
|
|
let tids = [];
|
|
|
yield redis.hmsetAsync('global:yoho:seo:linksubmit:goods', tids);
|
|
|
|
|
|
_.each(ids, id => {
|
|
|
tids.push(id, id);
|
|
|
});
|
|
|
ids = [];
|
|
|
tids = [];
|
|
|
|
|
|
return redis.hmsetAsync('global:yoho:seo:linksubmit:goods', tids).then(() => {
|
|
|
ids = [];
|
|
|
tids = [];
|
|
|
Object.assign(rdata[0], {message: message});
|
|
|
Object.assign(rdata[1], {message: message});
|
|
|
|
|
|
Object.assign(rdata[0], {message: message});
|
|
|
Object.assign(rdata[1], {message: message});
|
|
|
return rdata;
|
|
|
});
|
|
|
});
|
|
|
return rdata;
|
|
|
|
|
|
})();
|
|
|
}
|
|
|
|
|
|
// 提交逛详情URL
|
|
|
guangUrl() {
|
|
|
let ids = [];
|
|
|
let message = '';
|
|
|
|
|
|
return this.yohoApiModel.getLastArticleList().then(rdata => {
|
|
|
rdata = _.get(rdata, 'data.artList', []);
|
|
|
ids = _.map(rdata, item => {
|
|
|
return `${item.articleId}`;
|
|
|
});
|
|
|
let that = this;
|
|
|
|
|
|
return redis.hmgetAsync('global:yoho:seo:linksubmit:guang', ids);
|
|
|
}).then(rdata => {
|
|
|
return co(function* () {
|
|
|
|
|
|
let guangs = {
|
|
|
pc: [],
|
...
|
...
|
@@ -132,14 +121,20 @@ class BaiduLinkSubmit extends global.yoho.BaseModel { |
|
|
pcUrl: 'https://www.yohobuy.com',
|
|
|
wapUrl: 'https://m.yohobuy.com'
|
|
|
};
|
|
|
let tids = [];
|
|
|
let rdata = _.get(yield that.yohoApiModel.getLastArticleList(), 'data.artList', []);
|
|
|
let ids = _.map(rdata, item => {
|
|
|
return `${item.articleId}`;
|
|
|
});
|
|
|
let artice = {
|
|
|
total: ids.length,
|
|
|
notAlready: 0
|
|
|
};
|
|
|
|
|
|
ids = _.difference(ids, rdata);// 去除已经推送的
|
|
|
ids = _.difference(ids, yield redis.hmgetAsync('global:yoho:seo:linksubmit:guang', ids));// 去除已经推送的
|
|
|
artice.notAlready = ids.length;
|
|
|
message = `获取${artice.total}条记录,未推送的有${artice.notAlready}条记录`;
|
|
|
|
|
|
let message = `获取${artice.total}条记录,未推送的有${artice.notAlready}条记录`;
|
|
|
|
|
|
if (artice.notAlready <= 0) {
|
|
|
return [
|
...
|
...
|
@@ -148,38 +143,33 @@ class BaiduLinkSubmit extends global.yoho.BaseModel { |
|
|
];
|
|
|
}
|
|
|
|
|
|
|
|
|
_.each(ids, val => {
|
|
|
tids.push(val, val);// mset做准备
|
|
|
|
|
|
guangs.pc.push(`${guangs.pcUrl}/guang/${val}.html`);
|
|
|
guangs.wap.push(`${guangs.wapUrl}/guang/${val}.html`);
|
|
|
});
|
|
|
|
|
|
return Promise.all([
|
|
|
this.sendUrl(guangs.pc, guangs.pcUrl),
|
|
|
this.sendUrl(guangs.wap, guangs.wapUrl)
|
|
|
rdata = yield Promise.all([
|
|
|
that.sendUrl(guangs.pc, guangs.pcUrl),
|
|
|
that.sendUrl(guangs.wap, guangs.wapUrl)
|
|
|
]);
|
|
|
}).then(rdata => {
|
|
|
|
|
|
if (rdata[0].code !== 200 || rdata[1].code !== 200) {
|
|
|
return rdata;
|
|
|
}
|
|
|
|
|
|
let tids = [];
|
|
|
|
|
|
_.each(ids, id => {
|
|
|
tids.push(id, id);
|
|
|
});
|
|
|
yield redis.hmsetAsync('global:yoho:seo:linksubmit:guang', tids);
|
|
|
|
|
|
return redis.hmsetAsync('global:yoho:seo:linksubmit:guang', tids).then(() => {
|
|
|
ids = [];
|
|
|
tids = [];
|
|
|
ids = [];
|
|
|
tids = [];
|
|
|
|
|
|
Object.assign(rdata[0], {message: message});
|
|
|
Object.assign(rdata[1], {message: message});
|
|
|
Object.assign(rdata[0], {message: message});
|
|
|
Object.assign(rdata[1], {message: message});
|
|
|
|
|
|
return rdata;
|
|
|
});
|
|
|
});
|
|
|
return rdata;
|
|
|
})();
|
|
|
}
|
|
|
|
|
|
}
|
...
|
...
|
|