Authored by 郝肖肖

'newsale-ctx'

@@ -11,7 +11,6 @@ const helpers = global.yoho.helpers; @@ -11,7 +11,6 @@ const helpers = global.yoho.helpers;
11 const URI_PACKAGE_ARTICLE = 'guang/service/v2/article/'; 11 const URI_PACKAGE_ARTICLE = 'guang/service/v2/article/';
12 const URI_PACKAGE_AUTHOR = 'guang/service/v1/author/'; 12 const URI_PACKAGE_AUTHOR = 'guang/service/v1/author/';
13 13
14 -  
15 class DetailModel extends global.yoho.BaseModel { 14 class DetailModel extends global.yoho.BaseModel {
16 constructor(ctx) { 15 constructor(ctx) {
17 super(ctx); 16 super(ctx);
@@ -44,8 +44,7 @@ const index = (req, res, next) => { @@ -44,8 +44,7 @@ const index = (req, res, next) => {
44 // 唤起 APP 的路径 44 // 唤起 APP 的路径
45 res.locals.appPath = 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.top100","params":{"page":"0"}}'; 45 res.locals.appPath = 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.top100","params":{"page":"0"}}';
46 46
47 - newsaleModel.getHotRank(codeKey).then((result) => {  
48 - 47 + req.ctx(newsaleModel).getHotRank(codeKey).then((result) => {
49 res.render('newsale/hotrank', { 48 res.render('newsale/hotrank', {
50 module: 'product', 49 module: 'product',
51 page: 'hot-rank', 50 page: 'hot-rank',
@@ -68,8 +67,7 @@ const selectHotrank = (req, res, next) => { @@ -68,8 +67,7 @@ const selectHotrank = (req, res, next) => {
68 let yhChannel = (req.query.gender && yhchannels[req.query.gender]) || 67 let yhChannel = (req.query.gender && yhchannels[req.query.gender]) ||
69 (req.cookies._Channel && channels[req.cookies._Channel]) || 1; 68 (req.cookies._Channel && channels[req.cookies._Channel]) || 1;
70 69
71 - newsaleModel.selectHotrank(yhChannel, sort, tab_id, limit, page, notab).then((result) => {  
72 - 70 + req.ctx(newsaleModel).selectHotrank(yhChannel, sort, tab_id, limit, page, notab).then((result) => {
73 res.render('newsale/hotlist', { 71 res.render('newsale/hotlist', {
74 layout: false, 72 layout: false,
75 tabs: result.tabs, 73 tabs: result.tabs,
@@ -2,134 +2,142 @@ @@ -2,134 +2,142 @@
2 2
3 const utils = '../../../utils'; 3 const utils = '../../../utils';
4 const productNameProcess = require(`${utils}/product-name-process`); 4 const productNameProcess = require(`${utils}/product-name-process`);
5 -const api = global.yoho.API;  
6 const _ = require('lodash'); 5 const _ = require('lodash');
7 const serviceAPI = global.yoho.ServiceAPI; 6 const serviceAPI = global.yoho.ServiceAPI;
8 const logger = global.yoho.logger; 7 const logger = global.yoho.logger;
9 8
10 -const getHotRank = (codeKey) => {  
11 - return serviceAPI.get('operations/api/v5/resource/get', {  
12 - content_code: codeKey  
13 - }, {  
14 - cache: true  
15 - }).then((result) => { 9 +module.exports = class extends global.yoho.BaseModel {
  10 + constructor(ctx) {
  11 + super(ctx);
  12 + }
  13 +
  14 + getHotRank(codeKey) {
  15 + return this.get({
  16 + api: serviceAPI,
  17 + url: 'operations/api/v5/resource/get',
  18 + data: {
  19 + content_code: codeKey
  20 + },
  21 + param: {
  22 + cache: true
  23 + }
  24 + }).then((result) => {
16 25
17 - if (result && result.code === 200) {  
18 - let formData = {}; 26 + if (result && result.code === 200) {
  27 + let formData = {};
19 28
20 - if (result.data[0].data.length === 1) {  
21 - formData.url = result.data[0].data[0].url;  
22 - formData.img = result.data[0].data[0].src;  
23 - } else {  
24 - let list = []; 29 + if (result.data[0].data.length === 1) {
  30 + formData.url = result.data[0].data[0].url;
  31 + formData.img = result.data[0].data[0].src;
  32 + } else {
  33 + let list = [];
25 34
26 - _.forEach(result.data[0].data, function(val) {  
27 - list.push({  
28 - url: val.url,  
29 - img: val.src 35 + _.forEach(result.data[0].data, function(val) {
  36 + list.push({
  37 + url: val.url,
  38 + img: val.src
  39 + });
30 }); 40 });
31 - });  
32 41
33 - formData.list = list; 42 + formData.list = list;
  43 + }
  44 + return formData;
  45 + } else {
  46 + logger.error('getHotRank data return code is not 200');
  47 + return {};
34 } 48 }
35 - return formData;  
36 - } else {  
37 - logger.error('getHotRank data return code is not 200');  
38 - return {};  
39 - }  
40 - });  
41 -}; 49 + });
  50 + }
42 51
43 -const selectHotrank = (yhChannel, sort, tabId, limit, page, notab) => {  
44 - let param = {  
45 - method: 'app.search.top',  
46 - yh_channel: yhChannel,  
47 - page: page,  
48 - limit: limit  
49 - }; 52 + selectHotrank(yhChannel, sort, tabId, limit, page, notab) {
  53 + let param = {
  54 + method: 'app.search.top',
  55 + yh_channel: yhChannel,
  56 + page: page,
  57 + limit: limit
  58 + };
50 59
51 - if (sort) {  
52 - param.sort = sort;  
53 - } 60 + if (sort) {
  61 + param.sort = sort;
  62 + }
54 63
55 - if (tabId) {  
56 - param.tab_id = tabId;  
57 - } 64 + if (tabId) {
  65 + param.tab_id = tabId;
  66 + }
58 67
59 - return api.get('', param, {  
60 - cache: true  
61 - }).then((result) => { 68 + return this.get({
  69 + data: param,
  70 + param: {
  71 + cache: true
  72 + }
  73 + }).then((result) => {
  74 +
  75 + if (result && result.code === 200 && result.data.product_list) {
62 76
63 - if (result && result.code === 200 && result.data.product_list) { 77 + let formData = {};
64 78
65 - let formData = {}; 79 + if (notab && parseInt(notab, 10) === 0 && result.data.tabs) {
  80 + let tabs = [];
66 81
67 - if (notab && parseInt(notab, 10) === 0 && result.data.tabs) {  
68 - let tabs = []; 82 + _.forEach(result.data.tabs, function(val, index) {
  83 + let obj = {};
69 84
70 - _.forEach(result.data.tabs, function(val, index) {  
71 - let obj = {}; 85 + if (index === 0) {
  86 + obj = _.assign(obj, {
  87 + focus: true
  88 + });
  89 + }
72 90
73 - if (index === 0) {  
74 obj = _.assign(obj, { 91 obj = _.assign(obj, {
75 - focus: true 92 + title: val,
  93 + dataId: index
76 }); 94 });
77 - }  
78 95
79 - obj = _.assign(obj, {  
80 - title: val,  
81 - dataId: index 96 + tabs.push(obj);
82 }); 97 });
83 98
84 - tabs.push(obj);  
85 - });  
86 -  
87 - formData.tabs = tabs;  
88 - } 99 + formData.tabs = tabs;
  100 + }
89 101
90 - if (result.data.product_list && result.data.product_list.length !== 0) { 102 + if (result.data.product_list && result.data.product_list.length !== 0) {
91 103
92 - let goods = []; 104 + let goods = [];
93 105
94 - _.forEach(result.data.product_list, function(data, index) {  
95 - let one = {}; 106 + _.forEach(result.data.product_list, function(data, index) {
  107 + let one = {};
96 108
97 - if (data === null || !data.product_skn || !data.goods_list[0]) {  
98 - return false;  
99 - } 109 + if (data === null || !data.product_skn || !data.goods_list[0]) {
  110 + return false;
  111 + }
100 112
101 - if (data.cn_alphabet) {  
102 - data.cn_alphabet = productNameProcess(data.cn_alphabet);  
103 - } 113 + if (data.cn_alphabet) {
  114 + data.cn_alphabet = productNameProcess(data.cn_alphabet);
  115 + }
104 116
105 - one = _.assign(one, {  
106 - url: '/product/' + data.product_skn + '.html', // 商品url改版  
107 - thumb: data.default_images,  
108 - rank: limit * (page - 1) + index + 1,  
109 - name: data.product_name,  
110 - salePrice: data.sales_price  
111 - });  
112 -  
113 - if (data.sales_phrase) {  
114 one = _.assign(one, { 117 one = _.assign(one, {
115 - sales_phrase: data.sales_phrase 118 + url: '/product/' + data.product_skn + '.html', // 商品url改版
  119 + thumb: data.default_images,
  120 + rank: limit * (page - 1) + index + 1,
  121 + name: data.product_name,
  122 + salePrice: data.sales_price
116 }); 123 });
117 - }  
118 - goods.push(one);  
119 - });  
120 124
121 - formData.goods = goods;  
122 - } 125 + if (data.sales_phrase) {
  126 + one = _.assign(one, {
  127 + sales_phrase: data.sales_phrase
  128 + });
  129 + }
  130 + goods.push(one);
  131 + });
123 132
124 - return formData;  
125 - } else {  
126 - return {};  
127 - } 133 + formData.goods = goods;
  134 + }
128 135
129 - });  
130 -}; 136 + return formData;
  137 + } else {
  138 + return {};
  139 + }
131 140
132 -module.exports = {  
133 - getHotRank,  
134 - selectHotrank 141 + });
  142 + }
135 }; 143 };