Authored by OF1706

guang ctx

@@ -31,13 +31,15 @@ exports.index = (req, res, next) => { @@ -31,13 +31,15 @@ exports.index = (req, res, next) => {
31 let isHotDegrade = _.get(req.app.locals.pc, 'guang.removeHotTag', false); 31 let isHotDegrade = _.get(req.app.locals.pc, 'guang.removeHotTag', false);
32 let isAdDegrade = _.get(req.app.locals.pc, 'guang.removeAd', false); 32 let isAdDegrade = _.get(req.app.locals.pc, 'guang.removeAd', false);
33 33
  34 + const reqCtx = req.ctx(guangModel);
  35 +
34 Promise.all([ 36 Promise.all([
35 - req.ctx(guangModel).getBanner(channel),  
36 - req.ctx(guangModel).getCategory(type, channel),  
37 - req.ctx(guangModel).getArticleList(gender, type, uid, udid, page, '', '', pageSize, channel, true),  
38 - req.ctx(guangModel).getHotTags(page, pageSize, channel, isHotDegrade),  
39 - req.ctx(guangModel).getAds(channel, isAdDegrade),  
40 - req.ctx(guangModel).getRecoArticles(gender, 1, 10, channel), 37 + reqCtx.getBanner(channel),
  38 + reqCtx.getCategory(type, channel),
  39 + reqCtx.getArticleList(gender, type, uid, udid, page, '', '', pageSize, channel, true),
  40 + reqCtx.getHotTags(page, pageSize, channel, isHotDegrade),
  41 + reqCtx.getAds(channel, isAdDegrade),
  42 + reqCtx.getRecoArticles(gender, 1, 10, channel),
41 headerModel.requestHeaderData(channel) 43 headerModel.requestHeaderData(channel)
42 ]).then(ret => { 44 ]).then(ret => {
43 45
@@ -265,15 +265,6 @@ module.exports = class extends global.yoho.BaseModel { @@ -265,15 +265,6 @@ module.exports = class extends global.yoho.BaseModel {
265 client_type: 'web' 265 client_type: 'web'
266 }; 266 };
267 267
268 - let options = {  
269 - url: 'guang/api/v2/article/getList',  
270 - data: param,  
271 - param: {  
272 - cache: useCache ? 300 : false  
273 - },  
274 - api: global.yoho.ServiceAPI  
275 - };  
276 -  
277 if (sortId) { 268 if (sortId) {
278 param.sort_id = sortId; 269 param.sort_id = sortId;
279 } 270 }
@@ -290,7 +281,15 @@ module.exports = class extends global.yoho.BaseModel { @@ -290,7 +281,15 @@ module.exports = class extends global.yoho.BaseModel {
290 param.limit = limit; 281 param.limit = limit;
291 } 282 }
292 283
293 - return this.get(options).then(res => { 284 + return this.get({
  285 + url: 'guang/api/v2/article/getList',
  286 + data: param,
  287 + param: {
  288 + cache: useCache ? 300 : false
  289 + },
  290 + api: global.yoho.ServiceAPI
  291 +
  292 + }).then(res => {
294 293
295 if (res && res.data) { 294 if (res && res.data) {
296 295
@@ -341,16 +340,15 @@ module.exports = class extends global.yoho.BaseModel { @@ -341,16 +340,15 @@ module.exports = class extends global.yoho.BaseModel {
341 return null; 340 return null;
342 } 341 }
343 342
344 - let options = { 343 + return this.get({
345 url: 'guang/api/v2/article/getTagTop', 344 url: 'guang/api/v2/article/getTagTop',
346 data: data, 345 data: data,
347 param: { 346 param: {
348 cache: true 347 cache: true
349 }, 348 },
350 api: global.yoho.ServiceAPI 349 api: global.yoho.ServiceAPI
351 - };  
352 350
353 - return this.get(options).then(res => { 351 + }).then(res => {
354 return _.map((res && res.data) || [], it => { 352 return _.map((res && res.data) || [], it => {
355 let param = { 353 let param = {
356 query: it.tag_name 354 query: it.tag_name
@@ -385,16 +383,15 @@ module.exports = class extends global.yoho.BaseModel { @@ -385,16 +383,15 @@ module.exports = class extends global.yoho.BaseModel {
385 content_code: contentCode 383 content_code: contentCode
386 }; 384 };
387 385
388 - let options = { 386 + return this.get({
389 url: URL_OPERATIONS_RESOURCE_GET, 387 url: URL_OPERATIONS_RESOURCE_GET,
390 data: data, 388 data: data,
391 param: { 389 param: {
392 cache: true 390 cache: true
393 }, 391 },
394 api: global.yoho.ServiceAPI 392 api: global.yoho.ServiceAPI
395 - };  
396 393
397 - return this.get(options).then(res => { 394 + }).then(res => {
398 let list = []; 395 let list = [];
399 396
400 if (res && res.code === 200 && res.data && res.data[0] && res.data[0].data) { 397 if (res && res.code === 200 && res.data && res.data[0] && res.data[0].data) {
@@ -423,16 +420,15 @@ module.exports = class extends global.yoho.BaseModel { @@ -423,16 +420,15 @@ module.exports = class extends global.yoho.BaseModel {
423 content_code: contentCode 420 content_code: contentCode
424 }; 421 };
425 422
426 - let options = { 423 + return this.get({
427 url: URL_OPERATIONS_RESOURCE_GET, 424 url: URL_OPERATIONS_RESOURCE_GET,
428 data: data, 425 data: data,
429 param: { 426 param: {
430 cache: true 427 cache: true
431 }, 428 },
432 api: global.yoho.ServiceAPI 429 api: global.yoho.ServiceAPI
433 - };  
434 430
435 - return this.get(options).then(res => { 431 + }).then(res => {
436 432
437 let list = []; 433 let list = [];
438 434
@@ -453,15 +449,14 @@ module.exports = class extends global.yoho.BaseModel { @@ -453,15 +449,14 @@ module.exports = class extends global.yoho.BaseModel {
453 449
454 currentSortId = currentSortId || 0; 450 currentSortId = currentSortId || 0;
455 451
456 - let options = { 452 + return this.get({
457 url: 'guang/api/v1/category/get', 453 url: 'guang/api/v1/category/get',
458 param: { 454 param: {
459 cache: true 455 cache: true
460 }, 456 },
461 api: global.yoho.ServiceAPI 457 api: global.yoho.ServiceAPI
462 - };  
463 458
464 - return this.get(options).then(res => { 459 + }).then(res => {
465 let list = []; 460 let list = [];
466 461
467 if (res && res.code === 200 && res.data) { 462 if (res && res.code === 200 && res.data) {
@@ -498,16 +493,15 @@ module.exports = class extends global.yoho.BaseModel { @@ -498,16 +493,15 @@ module.exports = class extends global.yoho.BaseModel {
498 limit: limit 493 limit: limit
499 }; 494 };
500 495
501 - let options = { 496 + return this.get({
502 url: 'guang/api/v2/article/getArticleByViewsNum', 497 url: 'guang/api/v2/article/getArticleByViewsNum',
503 data: data, 498 data: data,
504 param: { 499 param: {
505 cache: true 500 cache: true
506 }, 501 },
507 api: global.yoho.ServiceAPI 502 api: global.yoho.ServiceAPI
508 - };  
509 503
510 - return this.get(options).then(res => { 504 + }).then(res => {
511 505
512 let list = []; 506 let list = [];
513 507
@@ -541,16 +535,15 @@ module.exports = class extends global.yoho.BaseModel { @@ -541,16 +535,15 @@ module.exports = class extends global.yoho.BaseModel {
541 author_id: authorId 535 author_id: authorId
542 }; 536 };
543 537
544 - let options = { 538 + return this.get({
545 url: 'guang/service/v1/author/getAuthor', 539 url: 'guang/service/v1/author/getAuthor',
546 data: data, 540 data: data,
547 param: { 541 param: {
548 cache: 3600 542 cache: 3600
549 }, 543 },
550 api: global.yoho.ServiceAPI 544 api: global.yoho.ServiceAPI
551 - };  
552 545
553 - return this.get(options).then(res => { 546 + }).then(res => {
554 if (res && res.data) { 547 if (res && res.data) {
555 let d = res.data; 548 let d = res.data;
556 549
@@ -574,16 +567,15 @@ module.exports = class extends global.yoho.BaseModel { @@ -574,16 +567,15 @@ module.exports = class extends global.yoho.BaseModel {
574 article_id: aid 567 article_id: aid
575 }; 568 };
576 569
577 - let options = { 570 + return this.get({
578 url: 'guang/service/v2/article/getArticle', 571 url: 'guang/service/v2/article/getArticle',
579 data: data, 572 data: data,
580 param: { 573 param: {
581 cache: true 574 cache: true
582 }, 575 },
583 api: global.yoho.ServiceAPI 576 api: global.yoho.ServiceAPI
584 - };  
585 577
586 - return this.get(options).then(res => { 578 + }).then(res => {
587 if (res && res.code === 200 && res.data) { 579 if (res && res.code === 200 && res.data) {
588 let d = res.data; 580 let d = res.data;
589 let tags = []; 581 let tags = [];
@@ -643,22 +635,20 @@ module.exports = class extends global.yoho.BaseModel { @@ -643,22 +635,20 @@ module.exports = class extends global.yoho.BaseModel {
643 getProductList(params, arr) { 635 getProductList(params, arr) {
644 636
645 let data = { 637 let data = {
  638 + method: 'web.search.search',
646 order: 's_n_desc', 639 order: 's_n_desc',
647 limit: 60 640 limit: 60
648 }; 641 };
649 642
650 Object.assign(data, params); 643 Object.assign(data, params);
651 644
652 - let options = {  
653 - url: 'web.search.search', 645 + return this.get({
654 data: data, 646 data: data,
655 param: { 647 param: {
656 cache: true 648 cache: true
657 - },  
658 - api: global.yoho.API  
659 - }; 649 + }
660 650
661 - return this.get(options).then(ret => { 651 + }).then(ret => {
662 if (ret && ret.code === 200 && ret.data && ret.data.product_list) { 652 if (ret && ret.code === 200 && ret.data && ret.data.product_list) {
663 return this._formatProduct(ret.data.product_list, arr); 653 return this._formatProduct(ret.data.product_list, arr);
664 } 654 }
@@ -763,16 +753,15 @@ module.exports = class extends global.yoho.BaseModel { @@ -763,16 +753,15 @@ module.exports = class extends global.yoho.BaseModel {
763 article_id: aid 753 article_id: aid
764 }; 754 };
765 755
766 - let options = { 756 + return this.get({
767 url: 'guang/service/v2/article/getArticleContent', 757 url: 'guang/service/v2/article/getArticleContent',
768 data: data, 758 data: data,
769 param: { 759 param: {
770 cache: true 760 cache: true
771 }, 761 },
772 api: global.yoho.ServiceAPI 762 api: global.yoho.ServiceAPI
773 - };  
774 763
775 - return this.get(options).then(res => { // 内容内推荐的商品 764 + }).then(res => { // 内容内推荐的商品
776 765
777 let gpromises = [], ggpromises = []; 766 let gpromises = [], ggpromises = [];
778 767
@@ -845,13 +834,12 @@ module.exports = class extends global.yoho.BaseModel { @@ -845,13 +834,12 @@ module.exports = class extends global.yoho.BaseModel {
845 udid: udid 834 udid: udid
846 }; 835 };
847 836
848 - let options = { 837 + return this.get({
849 url: 'guang/api/v1/article/getArticleBaseInfo', 838 url: 'guang/api/v1/article/getArticleBaseInfo',
850 data: data, 839 data: data,
851 api: global.yoho.ServiceAPI 840 api: global.yoho.ServiceAPI
852 - };  
853 841
854 - return this.get(options).then(res => ({ 842 + }).then(res => ({
855 isLike: res && res.isPraise === 'Y', 843 isLike: res && res.isPraise === 'Y',
856 likeNum: res.praise_num || 0, 844 likeNum: res.praise_num || 0,
857 isCollected: res && res.isFavor === 'Y' 845 isCollected: res && res.isFavor === 'Y'
@@ -870,16 +858,15 @@ module.exports = class extends global.yoho.BaseModel { @@ -870,16 +858,15 @@ module.exports = class extends global.yoho.BaseModel {
870 article_id: aid 858 article_id: aid
871 }; 859 };
872 860
873 - let options = { 861 + return this.get({
874 url: 'guang/service/v2/article/getBrand', 862 url: 'guang/service/v2/article/getBrand',
875 data: data, 863 data: data,
876 param: { 864 param: {
877 cache: true 865 cache: true
878 }, 866 },
879 api: global.yoho.ServiceAPI 867 api: global.yoho.ServiceAPI
880 - };  
881 868
882 - return this.get(options).then(res => { 869 + }).then(res => {
883 870
884 if (res && res.code === 200 && res.data) { 871 if (res && res.code === 200 && res.data) {
885 return _.map(res.data, it => { 872 return _.map(res.data, it => {
@@ -909,16 +896,15 @@ module.exports = class extends global.yoho.BaseModel { @@ -909,16 +896,15 @@ module.exports = class extends global.yoho.BaseModel {
909 limit: size 896 limit: size
910 }; 897 };
911 898
912 - let options = { 899 + return this.get({
913 url: 'guang/service/v2/article/getOtherArticle', 900 url: 'guang/service/v2/article/getOtherArticle',
914 data: data, 901 data: data,
915 param: { 902 param: {
916 cache: true 903 cache: true
917 }, 904 },
918 api: global.yoho.ServiceAPI 905 api: global.yoho.ServiceAPI
919 - };  
920 906
921 - return this.get(options).then(res => { 907 + }).then(res => {
922 if (res && res.code === 200 && res.data) { 908 if (res && res.code === 200 && res.data) {
923 return _.map(res.data, it => { 909 return _.map(res.data, it => {
924 it.thumb = helpers.image(it.thumb, 264, 173, 1); 910 it.thumb = helpers.image(it.thumb, 264, 173, 1);
@@ -942,13 +928,12 @@ module.exports = class extends global.yoho.BaseModel { @@ -942,13 +928,12 @@ module.exports = class extends global.yoho.BaseModel {
942 limit: pageSize 928 limit: pageSize
943 }; 929 };
944 930
945 - let options = { 931 + return this.get({
946 url: 'guang/api/v1/comments/getList', 932 url: 'guang/api/v1/comments/getList',
947 data: data, 933 data: data,
948 api: global.yoho.ServiceAPI 934 api: global.yoho.ServiceAPI
949 - };  
950 935
951 - return this.get(options).then(res => { 936 + }).then(res => {
952 937
953 let num = (res.data && res.data.total) || 0; 938 let num = (res.data && res.data.total) || 0;
954 let list = []; 939 let list = [];
@@ -995,13 +980,12 @@ module.exports = class extends global.yoho.BaseModel { @@ -995,13 +980,12 @@ module.exports = class extends global.yoho.BaseModel {
995 content: content 980 content: content
996 }; 981 };
997 982
998 - let options = { 983 + this.get({
999 url: 'guang/api/v1/comments/add', 984 url: 'guang/api/v1/comments/add',
1000 data: data, 985 data: data,
1001 api: global.yoho.ServiceAPI 986 api: global.yoho.ServiceAPI
1002 - };  
1003 987
1004 - this.get(options).then(res => { 988 + }).then(res => {
1005 if (res && res.code === 200) { 989 if (res && res.code === 200) {
1006 return res.data; 990 return res.data;
1007 } else { 991 } else {
@@ -1023,13 +1007,11 @@ module.exports = class extends global.yoho.BaseModel { @@ -1023,13 +1007,11 @@ module.exports = class extends global.yoho.BaseModel {
1023 udid: udid 1007 udid: udid
1024 }; 1008 };
1025 1009
1026 - let options = { 1010 + return this.get({
1027 url: 'guang/api/v2/praise/setPraise', 1011 url: 'guang/api/v2/praise/setPraise',
1028 data: data, 1012 data: data,
1029 api: global.yoho.ServiceAPI 1013 api: global.yoho.ServiceAPI
1030 - };  
1031 -  
1032 - return this.get(options); 1014 + });
1033 } 1015 }
1034 1016
1035 /** 1017 /**
@@ -1045,13 +1027,11 @@ module.exports = class extends global.yoho.BaseModel { @@ -1045,13 +1027,11 @@ module.exports = class extends global.yoho.BaseModel {
1045 udid: udid 1027 udid: udid
1046 }; 1028 };
1047 1029
1048 - let options = { 1030 + return this.get({
1049 url: 'guang/api/v2/praise/cancel', 1031 url: 'guang/api/v2/praise/cancel',
1050 data: data, 1032 data: data,
1051 api: global.yoho.ServiceAPI 1033 api: global.yoho.ServiceAPI
1052 - };  
1053 -  
1054 - return this.get(options); 1034 + });
1055 } 1035 }
1056 1036
1057 /** 1037 /**
@@ -1067,13 +1047,11 @@ module.exports = class extends global.yoho.BaseModel { @@ -1067,13 +1047,11 @@ module.exports = class extends global.yoho.BaseModel {
1067 uid: uid 1047 uid: uid
1068 }; 1048 };
1069 1049
1070 - let options = { 1050 + return this.get({
1071 url: 'guang/api/v1/favorite/setFavorite', 1051 url: 'guang/api/v1/favorite/setFavorite',
1072 data: data, 1052 data: data,
1073 api: global.yoho.ServiceAPI 1053 api: global.yoho.ServiceAPI
1074 - };  
1075 -  
1076 - return this.get(options); 1054 + });
1077 } 1055 }
1078 1056
1079 /** 1057 /**
@@ -1089,13 +1067,11 @@ module.exports = class extends global.yoho.BaseModel { @@ -1089,13 +1067,11 @@ module.exports = class extends global.yoho.BaseModel {
1089 uid: uid 1067 uid: uid
1090 }; 1068 };
1091 1069
1092 - let options = { 1070 + return this.get({
1093 url: 'guang/api/v1/favorite/cancelFavorite', 1071 url: 'guang/api/v1/favorite/cancelFavorite',
1094 data: data, 1072 data: data,
1095 api: global.yoho.ServiceAPI 1073 api: global.yoho.ServiceAPI
1096 - };  
1097 -  
1098 - return this.get(options); 1074 + });
1099 } 1075 }
1100 1076
1101 /** 1077 /**
@@ -1111,13 +1087,11 @@ module.exports = class extends global.yoho.BaseModel { @@ -1111,13 +1087,11 @@ module.exports = class extends global.yoho.BaseModel {
1111 udid: udid 1087 udid: udid
1112 }; 1088 };
1113 1089
1114 - let options = { 1090 + return this.get({
1115 url: 'guang/api/*/article/getArticlePraiseAndFavor', 1091 url: 'guang/api/*/article/getArticlePraiseAndFavor',
1116 data: data, 1092 data: data,
1117 api: global.yoho.ServiceAPI 1093 api: global.yoho.ServiceAPI
1118 - };  
1119 -  
1120 - return this.get(options); 1094 + });
1121 } 1095 }
1122 1096
1123 /** 1097 /**
@@ -1151,13 +1125,11 @@ module.exports = class extends global.yoho.BaseModel { @@ -1151,13 +1125,11 @@ module.exports = class extends global.yoho.BaseModel {
1151 }); 1125 });
1152 } 1126 }
1153 1127
1154 - let options = { 1128 + return this.get({
1155 url: 'guang/api/*/article/getSimpleArticleList', 1129 url: 'guang/api/*/article/getSimpleArticleList',
1156 data: params, 1130 data: params,
1157 api: global.yoho.ServiceAPI 1131 api: global.yoho.ServiceAPI
1158 - };  
1159 -  
1160 - return this.get(options); 1132 + });
1161 } 1133 }
1162 1134
1163 }; 1135 };