Authored by 郝肖肖

'潮流首页连接推百度资源位'

@@ -55,6 +55,12 @@ app.get('/goodsUrl', cseo.goodsUrl); @@ -55,6 +55,12 @@ app.get('/goodsUrl', cseo.goodsUrl);
55 // 逛详情-百度链接提交 55 // 逛详情-百度链接提交
56 app.get('/guangUrl', cseo.guangUrl); 56 app.get('/guangUrl', cseo.guangUrl);
57 57
  58 +// 潮流首页-百度链接提交
  59 +app.get('/yohoBoysUrl', cseo.yohoBoysUrl);
  60 +
  61 +// 潮流首页-百度链接提交
  62 +app.get('/yohoGirlsUrl', cseo.yohoGirlsUrl);
  63 +
58 app.listen(config.port, function() { 64 app.listen(config.port, function() {
59 logger.info(`yoho seo start : http://127.0.0.1:${config.port}`); 65 logger.info(`yoho seo start : http://127.0.0.1:${config.port}`);
60 }); 66 });
@@ -46,6 +46,18 @@ const guangUrl = (req, res) => { @@ -46,6 +46,18 @@ const guangUrl = (req, res) => {
46 }); 46 });
47 }; 47 };
48 48
  49 +const yohoBoysUrl = (req, res) => {
  50 + return req.ctx(BaiduLinkSubmit).yohoBoys(req.query).then(result => {
  51 + return res.json(result);
  52 + });
  53 +};
  54 +
  55 +const yohoGirlsUrl = (req, res) => {
  56 + return req.ctx(BaiduLinkSubmit).yohoGirls(req.query).then(result => {
  57 + return res.json(result);
  58 + });
  59 +};
  60 +
49 const setTask = (req, res) => { 61 const setTask = (req, res) => {
50 return req.ctx(SeoIndexModel).setTask(req.query).then(result => { 62 return req.ctx(SeoIndexModel).setTask(req.query).then(result => {
51 return res.json(result); 63 return res.json(result);
@@ -86,6 +98,8 @@ module.exports = { @@ -86,6 +98,8 @@ module.exports = {
86 siteMapXml, 98 siteMapXml,
87 goodsUrl, 99 goodsUrl,
88 guangUrl, 100 guangUrl,
  101 + yohoBoysUrl,
  102 + yohoGirlsUrl,
89 setTask, 103 setTask,
90 delTask, 104 delTask,
91 demoXsd, 105 demoXsd,
@@ -24,11 +24,11 @@ class BaiduLinkSubmit extends global.yoho.BaseModel { @@ -24,11 +24,11 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
24 let siteType = ''; 24 let siteType = '';
25 25
26 if (type === 'mip') { 26 if (type === 'mip') {
27 - siteType = 'MIP'; 27 + siteType = 'MIP: ';
28 } else if (site.indexOf('www.yohobuy') > -1) { 28 } else if (site.indexOf('www.yohobuy') > -1) {
29 - siteType = 'PC'; 29 + siteType = 'PC: ';
30 } else if (site.indexOf('m.yohobuy') > -1) { 30 } else if (site.indexOf('m.yohobuy') > -1) {
31 - siteType = 'WAP'; 31 + siteType = 'WAP: ';
32 } 32 }
33 33
34 if (!site) { 34 if (!site) {
@@ -41,7 +41,7 @@ class BaiduLinkSubmit extends global.yoho.BaseModel { @@ -41,7 +41,7 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
41 41
42 return rp({ 42 return rp({
43 method: 'POST', 43 method: 'POST',
44 - uri: `${senUrl}`, 44 + uri: senUrl,
45 qs: { 45 qs: {
46 token: '0lSAO4ZxEKsYopMG', 46 token: '0lSAO4ZxEKsYopMG',
47 site: site, 47 site: site,
@@ -58,7 +58,7 @@ class BaiduLinkSubmit extends global.yoho.BaseModel { @@ -58,7 +58,7 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
58 58
59 return Object.assign({ 59 return Object.assign({
60 code: 200, 60 code: 200,
61 - message: `${siteType} 当天剩余${result.remain || result.remain_mip}条可推送到百度资源平台,本次成功推送${result.success || result.success_mip}条。` // eslint-disable-line 61 + message: `${siteType}当天剩余${result.remain || result.remain_mip}条可推送到百度资源平台,本次成功推送${result.success || result.success_mip}条。` // eslint-disable-line
62 }, result); 62 }, result);
63 }).catch(e => { 63 }).catch(e => {
64 console.log(e.message); 64 console.log(e.message);
@@ -130,7 +130,6 @@ class BaiduLinkSubmit extends global.yoho.BaseModel { @@ -130,7 +130,6 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
130 130
131 // 提交逛详情URL 131 // 提交逛详情URL
132 guangUrl() { 132 guangUrl() {
133 -  
134 let that = this; 133 let that = this;
135 134
136 return co(function* () { 135 return co(function* () {
@@ -194,6 +193,140 @@ class BaiduLinkSubmit extends global.yoho.BaseModel { @@ -194,6 +193,140 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
194 })(); 193 })();
195 } 194 }
196 195
  196 + _getYohoNewsLink(url) {
  197 + return rp({
  198 + method: 'GET',
  199 + uri: url,
  200 + qs: {},
  201 + qsStringifyOptions: {
  202 + encode: false
  203 + },
  204 + timeout: 8 * 1000,
  205 + json: true,
  206 + gzip: true
  207 + }).then(result => {
  208 + return {
  209 + code: 200,
  210 + data: result,
  211 + message: 'success'
  212 + };
  213 + }).catch(e => {
  214 + console.log(`_getYohoNewsLink: err: ${e.message}`);
  215 + return {code: e.statusCode || 400, data: [], message: e.message};
  216 + });
  217 + }
  218 + // 潮流boys
  219 + yohoBoys() {
  220 + let that = this;
  221 +
  222 + return co(function* () {
  223 + let initData = {
  224 + pc: [],
  225 + pcUrl: 'http://www.yohoboys.com',
  226 + };
  227 +
  228 + let rdata = _.get(yield that._getYohoNewsLink(
  229 + `${initData.pcUrl}/channel/ajax/tab?channel=100&page=1`
  230 + ), 'data', []);
  231 + let tlinks = [];
  232 + let links = _.map(rdata, item => {
  233 + return _.get(item, 'content.url', '').replace(/http:|https:/, '');
  234 + });
  235 +
  236 + let artice = {
  237 + total: links.length,
  238 + notAlready: 0
  239 + };
  240 +
  241 + links = _.difference(links, yield redis.hmgetAsync('global:yoho:seo:linksubmit:newsBoys', links));// 去除已经推送的
  242 + artice.notAlready = links.length;
  243 +
  244 + if (artice.notAlready <= 0) {
  245 + let message = `获取${artice.total}条记录,未推送0条,成功推送0条。`;
  246 +
  247 + return {code: 201, data: [], message: message};
  248 + }
  249 +
  250 + _.each(links, val => {
  251 + if (_.isEmpty(val)) {
  252 + return true;
  253 + }
  254 +
  255 + tlinks.push(val, val);// mset做准备
  256 +
  257 + initData.pc.push(`http:${val}`);
  258 + });
  259 +
  260 + rdata = yield that.sendUrl(initData.pc, initData.pcUrl);
  261 +
  262 + if (_.get(rdata, 'code', 400) !== 200) {
  263 + return rdata;
  264 + }
  265 +
  266 + yield redis.hmsetAsync('global:yoho:seo:linksubmit:newsBoys', tlinks);
  267 +
  268 + links = [];
  269 + tlinks = [];
  270 +
  271 + return rdata;
  272 + })();
  273 + }
  274 + // 潮流girls
  275 + yohoGirls() {
  276 + let that = this;
  277 +
  278 + return co(function* () {
  279 + let initData = {
  280 + pc: [],
  281 + pcUrl: 'http://www.yohogirls.com',
  282 + };
  283 +
  284 + let rdata = _.get(yield that._getYohoNewsLink(
  285 + `${initData.pcUrl}/channel/ajax/getRecoms?channel=1&page=1`
  286 + ), 'data', []);
  287 + let tlinks = [];
  288 + let links = _.map(rdata, item => {
  289 + return _.get(item, 'link', '').replace(/http:|https:/, '');
  290 + });
  291 + let artice = {
  292 + total: links.length,
  293 + notAlready: 0
  294 + };
  295 +
  296 + links = _.difference(links, yield redis.hmgetAsync('global:yoho:seo:linksubmit:newsGirls', links));// 去除已经推送的
  297 + artice.notAlready = links.length;
  298 +
  299 + if (artice.notAlready <= 0) {
  300 + let message = `获取${artice.total}条记录,未推送0条,成功推送0条。`;
  301 +
  302 + return {code: 201, data: [], message: message};
  303 + }
  304 +
  305 + _.each(links, val => {
  306 + if (_.isEmpty(val)) {
  307 + return true;
  308 + }
  309 +
  310 + tlinks.push(val, val);// mset做准备
  311 +
  312 + initData.pc.push(`http:${val}`);
  313 + });
  314 +
  315 + rdata = yield that.sendUrl(initData.pc, initData.pcUrl);
  316 +
  317 + if (_.get(rdata, 'code', 400) !== 200) {
  318 + return rdata;
  319 + }
  320 +
  321 + yield redis.hmsetAsync('global:yoho:seo:linksubmit:newsGirls', tlinks);
  322 +
  323 + links = [];
  324 + tlinks = [];
  325 +
  326 + return rdata;
  327 + })();
  328 + }
  329 +
197 } 330 }
198 331
199 module.exports = BaiduLinkSubmit; 332 module.exports = BaiduLinkSubmit;
@@ -69,7 +69,7 @@ class SeoIndexModel extends global.yoho.BaseModel { @@ -69,7 +69,7 @@ class SeoIndexModel extends global.yoho.BaseModel {
69 _.each(item.goods_list.slice(0, 5), goods => { 69 _.each(item.goods_list.slice(0, 5), goods => {
70 contentUrl = goods.images_url || contentUrl; 70 contentUrl = goods.images_url || contentUrl;
71 71
72 - if (contentUrl === '') { 72 + if (_.isEmpty(contentUrl)) {
73 return true; 73 return true;
74 } 74 }
75 75