Merge branch 'feature/context' of git.yoho.cn:fe/yohoblk-wap into feature/context
Showing
13 changed files
with
309 additions
and
198 deletions
@@ -26,7 +26,7 @@ module.exports = { | @@ -26,7 +26,7 @@ module.exports = { | ||
26 | /* 获取品牌列表数据 */ | 26 | /* 获取品牌列表数据 */ |
27 | getBrandList: (req, res, next) => { | 27 | getBrandList: (req, res, next) => { |
28 | 28 | ||
29 | - brandModel.getBrandListData({ | 29 | + req.ctx(brandModel).getBrandListData({ |
30 | channel: req.query.channel | 30 | channel: req.query.channel |
31 | }).then(result => { | 31 | }).then(result => { |
32 | res.json(result); | 32 | res.json(result); |
@@ -44,7 +44,7 @@ module.exports = { | @@ -44,7 +44,7 @@ module.exports = { | ||
44 | 44 | ||
45 | // 全部分类api | 45 | // 全部分类api |
46 | getCateList: (req, res, next) => { | 46 | getCateList: (req, res, next) => { |
47 | - brandModel.getCateListData({ | 47 | + req.ctx(brandModel).getCateListData({ |
48 | app_type: 1 | 48 | app_type: 1 |
49 | }).then(result => { | 49 | }).then(result => { |
50 | res.json(result); | 50 | res.json(result); |
@@ -19,7 +19,7 @@ module.exports = { | @@ -19,7 +19,7 @@ module.exports = { | ||
19 | index(req, res, next) { | 19 | index(req, res, next) { |
20 | let channel = req.path.split('/')[1] || req.yoho.channel; | 20 | let channel = req.path.split('/')[1] || req.yoho.channel; |
21 | 21 | ||
22 | - channelModel.getResourcesData({ | 22 | + req.ctx(channelModel).getResourcesData({ |
23 | contentCode: channelMap[channel] | 23 | contentCode: channelMap[channel] |
24 | }).then(result => { | 24 | }).then(result => { |
25 | const resources = result.slice(0, 3); | 25 | const resources = result.slice(0, 3); |
@@ -41,17 +41,17 @@ module.exports = { | @@ -41,17 +41,17 @@ module.exports = { | ||
41 | }).catch(next); | 41 | }).catch(next); |
42 | }, | 42 | }, |
43 | channel(req, res, next) { | 43 | channel(req, res, next) { |
44 | - channelModel.getChannelData().then(result => { | 44 | + req.ctx(channelModel).getChannelData().then(result => { |
45 | return res.json(result); | 45 | return res.json(result); |
46 | }).catch(next); | 46 | }).catch(next); |
47 | }, | 47 | }, |
48 | resources(req, res, next) { | 48 | resources(req, res, next) { |
49 | - channelModel.getResourcesData(req.query).then(result => { | 49 | + req.ctx(channelModel).getResourcesData(req.query).then(result => { |
50 | return res.json(result); | 50 | return res.json(result); |
51 | }).catch(next); | 51 | }).catch(next); |
52 | }, | 52 | }, |
53 | goods(req, res, next) { | 53 | goods(req, res, next) { |
54 | - channelModel.getGoodsData(req.query).then(result => { | 54 | + req.ctx(channelModel).getGoodsData(req.query).then(result => { |
55 | return res.json(result); | 55 | return res.json(result); |
56 | }).catch(next); | 56 | }).catch(next); |
57 | }, | 57 | }, |
@@ -62,7 +62,7 @@ module.exports = { | @@ -62,7 +62,7 @@ module.exports = { | ||
62 | page: 'sidebar' | 62 | page: 'sidebar' |
63 | }); | 63 | }); |
64 | } | 64 | } |
65 | - channelModel.getSidebarData(req.query).then(result => { | 65 | + req.ctx(channelModel).getSidebarData(req.query).then(result => { |
66 | return res.json(result); | 66 | return res.json(result); |
67 | }).catch(next); | 67 | }).catch(next); |
68 | } | 68 | } |
@@ -5,7 +5,8 @@ | @@ -5,7 +5,8 @@ | ||
5 | * Time: 14:02 | 5 | * Time: 14:02 |
6 | */ | 6 | */ |
7 | 'use strict'; | 7 | 'use strict'; |
8 | -const api = global.yoho.API; | 8 | + |
9 | +// const api = global.yoho.API; | ||
9 | 10 | ||
10 | const yhChannel = { | 11 | const yhChannel = { |
11 | men: { | 12 | men: { |
@@ -19,32 +20,42 @@ const yhChannel = { | @@ -19,32 +20,42 @@ const yhChannel = { | ||
19 | } | 20 | } |
20 | }; | 21 | }; |
21 | 22 | ||
22 | -module.exports = { | 23 | +module.exports = class extends global.yoho.BaseModel{ |
24 | + constructor(ctx) { | ||
25 | + super(ctx); | ||
26 | + } | ||
23 | 27 | ||
24 | /** | 28 | /** |
25 | * 从接口获取品牌列表页数据 | 29 | * 从接口获取品牌列表页数据 |
26 | * @returns {*} | 30 | * @returns {*} |
27 | */ | 31 | */ |
28 | getBrandListOriginData(params) { | 32 | getBrandListOriginData(params) { |
29 | - return api.get('', { | ||
30 | - method: 'app.brand.allBrandList', | ||
31 | - yh_channel: params.channel ? yhChannel[params.channel].channel : '' | ||
32 | - }, { | ||
33 | - code: 200, | ||
34 | - cache: true | 33 | + |
34 | + return this.get({ | ||
35 | + data: { | ||
36 | + yh_channel: params.channel ? yhChannel[params.channel].channel : '', | ||
37 | + method: 'app.brand.allBrandList' | ||
38 | + }, | ||
39 | + param: { | ||
40 | + code: 200, | ||
41 | + cache: true | ||
42 | + } | ||
35 | }); | 43 | }); |
36 | - }, | 44 | + } |
37 | 45 | ||
38 | /** | 46 | /** |
39 | * 从接口获取全部分类数据 | 47 | * 从接口获取全部分类数据 |
40 | * @returns {*} | 48 | * @returns {*} |
41 | */ | 49 | */ |
42 | getCateListData(params) { | 50 | getCateListData(params) { |
43 | - return api.get('', Object.assign(params, { | ||
44 | - method: 'app.sort.get' | ||
45 | - }, { | ||
46 | - code: 200, | ||
47 | - cache: true | ||
48 | - })); | 51 | + return this.get({ |
52 | + data: Object.assign(params, { | ||
53 | + method: 'app.sort.get' | ||
54 | + }), | ||
55 | + param: { | ||
56 | + code: 200, | ||
57 | + cache: true | ||
58 | + } | ||
59 | + }); | ||
49 | } | 60 | } |
50 | }; | 61 | }; |
@@ -6,36 +6,80 @@ | @@ -6,36 +6,80 @@ | ||
6 | */ | 6 | */ |
7 | 'use strict'; | 7 | 'use strict'; |
8 | 8 | ||
9 | -const brandApi = require('./brand-api'); | 9 | +const BrandApi = require('./brand-api'); |
10 | const _ = require('lodash'); | 10 | const _ = require('lodash'); |
11 | 11 | ||
12 | -/** | ||
13 | - * 处理品牌一览品牌列表数据 | ||
14 | - * @param origin | ||
15 | - * @returns {Array} | ||
16 | - */ | ||
17 | -const handleBrandList = origin => { | ||
18 | - let dest = { | ||
19 | - brandList: [], | ||
20 | - indexList: [] | ||
21 | - }; | 12 | +module.exports = class extends global.yoho.BaseModel { |
13 | + constructor(ctx) { | ||
14 | + super(ctx); | ||
15 | + } | ||
22 | 16 | ||
23 | - // 标记是否有数字,有数字先暂存 | ||
24 | - let hasNum = false; | ||
25 | - let numTemp = {}; | 17 | + /** |
18 | + * 处理品牌一览品牌列表数据 | ||
19 | + * @param origin | ||
20 | + * @returns {Array} | ||
21 | + */ | ||
22 | + handleBrandList(origin) { | ||
23 | + let dest = { | ||
24 | + brandList: [], | ||
25 | + indexList: [] | ||
26 | + }; | ||
27 | + | ||
28 | + // 标记是否有数字,有数字先暂存 | ||
29 | + let hasNum = false; | ||
30 | + let numTemp = {}; | ||
31 | + | ||
32 | + _.forEach(origin, (value, key) => { | ||
33 | + let brands = []; | ||
34 | + | ||
35 | + if (_.size(value) <= 0) { | ||
36 | + return; | ||
37 | + } | ||
38 | + | ||
39 | + if (key === '0~9') { | ||
40 | + hasNum = true; | ||
41 | + numTemp = origin[key]; | ||
42 | + } else { | ||
43 | + _.forEach(value, (subValue) => { | ||
44 | + brands.push({ | ||
45 | + name: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name, | ||
46 | + logo: subValue.brand_ico, | ||
47 | + domain: subValue.brand_domain, | ||
48 | + shopId: subValue.shop_id, | ||
49 | + shopName: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name, | ||
50 | + isRedShop: subValue.is_red_shop, | ||
51 | + shopTemplateType: subValue.shop_template_type | ||
52 | + }); | ||
53 | + }); | ||
26 | 54 | ||
27 | - _.forEach(origin, (value, key) => { | ||
28 | - let brands = []; | 55 | + dest.brandList.push({ |
56 | + index: key, | ||
57 | + brands: brands | ||
58 | + }); | ||
29 | 59 | ||
30 | - if (_.size(value) <= 0) { | ||
31 | - return; | ||
32 | - } | 60 | + dest.indexList.push({ |
61 | + index: key, | ||
62 | + name: key === '0~9' ? '0' : key | ||
63 | + }); | ||
64 | + } | ||
33 | 65 | ||
34 | - if (key === '0~9') { | ||
35 | - hasNum = true; | ||
36 | - numTemp = origin[key]; | ||
37 | - } else { | ||
38 | - _.forEach(value, (subValue) => { | 66 | + }); |
67 | + | ||
68 | + // 商品列表排序一次 | ||
69 | + _.sortBy(dest.brandList, o => { | ||
70 | + return o.index.charCodeAt(); | ||
71 | + }); | ||
72 | + | ||
73 | + // 字母列表排序一次 | ||
74 | + _.sortBy(dest.indexList, o => { | ||
75 | + return o.index.charCodeAt(); | ||
76 | + }); | ||
77 | + | ||
78 | + // 如果有数字,单独处理 | ||
79 | + if (hasNum) { | ||
80 | + let brands = []; | ||
81 | + | ||
82 | + _.forEach(numTemp, (subValue) => { | ||
39 | brands.push({ | 83 | brands.push({ |
40 | name: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name, | 84 | name: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name, |
41 | logo: subValue.brand_ico, | 85 | logo: subValue.brand_ico, |
@@ -46,85 +90,52 @@ const handleBrandList = origin => { | @@ -46,85 +90,52 @@ const handleBrandList = origin => { | ||
46 | shopTemplateType: subValue.shop_template_type | 90 | shopTemplateType: subValue.shop_template_type |
47 | }); | 91 | }); |
48 | }); | 92 | }); |
49 | - | ||
50 | dest.brandList.push({ | 93 | dest.brandList.push({ |
51 | - index: key, | 94 | + index: '0~9', |
52 | brands: brands | 95 | brands: brands |
53 | }); | 96 | }); |
54 | 97 | ||
55 | dest.indexList.push({ | 98 | dest.indexList.push({ |
56 | - index: key, | ||
57 | - name: key === '0~9' ? '0' : key | 99 | + index: '0_9', |
100 | + name: '0' | ||
58 | }); | 101 | }); |
59 | } | 102 | } |
60 | 103 | ||
61 | - }); | ||
62 | - | ||
63 | - // 商品列表排序一次 | ||
64 | - _.sortBy(dest.brandList, o => { | ||
65 | - return o.index.charCodeAt(); | ||
66 | - }); | ||
67 | - | ||
68 | - // 字母列表排序一次 | ||
69 | - _.sortBy(dest.indexList, o => { | ||
70 | - return o.index.charCodeAt(); | ||
71 | - }); | ||
72 | - | ||
73 | - // 如果有数字,单独处理 | ||
74 | - if (hasNum) { | ||
75 | - let brands = []; | ||
76 | - | ||
77 | - _.forEach(numTemp, (subValue) => { | ||
78 | - brands.push({ | ||
79 | - name: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name, | ||
80 | - logo: subValue.brand_ico, | ||
81 | - domain: subValue.brand_domain, | ||
82 | - shopId: subValue.shop_id, | ||
83 | - shopName: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name, | ||
84 | - isRedShop: subValue.is_red_shop, | ||
85 | - shopTemplateType: subValue.shop_template_type | ||
86 | - }); | ||
87 | - }); | ||
88 | - dest.brandList.push({ | ||
89 | - index: '0~9', | ||
90 | - brands: brands | ||
91 | - }); | 104 | + return dest; |
105 | + } | ||
92 | 106 | ||
93 | - dest.indexList.push({ | ||
94 | - index: '0_9', | ||
95 | - name: '0' | 107 | + /** |
108 | + * 获取品牌列表页数据 | ||
109 | + * @param params | ||
110 | + */ | ||
111 | + getBrandListData(params) { | ||
112 | + let finalResult = {}; | ||
113 | + let brandData = new BrandApi(this.ctx); | ||
114 | + let that = this; | ||
115 | + | ||
116 | + return brandData.getBrandListOriginData(params).then(result => { | ||
117 | + if (result && result.data) { | ||
118 | + Object.assign(finalResult, that.handleBrandList(result.data.all_list)); | ||
119 | + } | ||
120 | + | ||
121 | + return finalResult; | ||
96 | }); | 122 | }); |
97 | } | 123 | } |
98 | 124 | ||
99 | - return dest; | ||
100 | -}; | ||
101 | 125 | ||
102 | -/** | ||
103 | - * 获取品牌列表页数据 | ||
104 | - * @param params | ||
105 | - */ | ||
106 | -const getBrandListData = params => { | ||
107 | - let finalResult = {}; | 126 | + /** |
127 | + * 获取全部分类数据 | ||
128 | + * @param params | ||
129 | + * @returns {*|Promise.<TResult>} | ||
130 | + */ | ||
131 | + getCateListData(params) { | ||
132 | + let brandData = new BrandApi(this.ctx); | ||
108 | 133 | ||
109 | - return brandApi.getBrandListOriginData(params).then(result => { | ||
110 | - if (result && result.data) { | ||
111 | - Object.assign(finalResult, handleBrandList(result.data.all_list)); | ||
112 | - } | ||
113 | - | ||
114 | - return finalResult; | ||
115 | - }); | ||
116 | -}; | ||
117 | - | ||
118 | -/** | ||
119 | - * 获取全部分类数据 | ||
120 | - * @param params | ||
121 | - * @returns {*|Promise.<TResult>} | ||
122 | - */ | ||
123 | -const getCateListData = params => { | ||
124 | - return brandApi.getCateListData(params); | 134 | + return brandData.getCateListData(params); |
135 | + } | ||
125 | }; | 136 | }; |
126 | 137 | ||
127 | -module.exports = { | 138 | +/* module.exports = { |
128 | getBrandListData, | 139 | getBrandListData, |
129 | getCateListData | 140 | getCateListData |
130 | -}; | 141 | +}; */ |
1 | 'use strict'; | 1 | 'use strict'; |
2 | + | ||
3 | +// const api = global.yoho.API; | ||
2 | const service = global.yoho.ServiceAPI; | 4 | const service = global.yoho.ServiceAPI; |
3 | -const api = global.yoho.API; | ||
4 | const processResources = require(`${global.utils}/beautify/resources`); | 5 | const processResources = require(`${global.utils}/beautify/resources`); |
5 | const processProductList = require(`${global.utils}/beautify/product`); | 6 | const processProductList = require(`${global.utils}/beautify/product`); |
6 | 7 | ||
7 | -let channel = { | 8 | + |
9 | +let channel = class extends global.yoho.BaseModel { | ||
10 | + constructor(ctx) { | ||
11 | + super(ctx); | ||
12 | + } | ||
13 | + | ||
8 | getResourcesData(params) { | 14 | getResourcesData(params) { |
9 | if (!params.contentCode) { | 15 | if (!params.contentCode) { |
10 | return Promise.resolve([]); | 16 | return Promise.resolve([]); |
11 | } | 17 | } |
12 | - return service.get('operations/api/v5/resource/get', { | ||
13 | - content_code: params.contentCode | ||
14 | - }, { | ||
15 | - cache: true, | ||
16 | - code: 200 | 18 | + |
19 | + return this.get({ | ||
20 | + api: service, | ||
21 | + url: 'operations/api/v5/resource/get', | ||
22 | + data: { | ||
23 | + content_code: params.contentCode | ||
24 | + }, | ||
25 | + param: { | ||
26 | + cache: true, | ||
27 | + code: 200 | ||
28 | + } | ||
17 | }).then(result => { | 29 | }).then(result => { |
18 | return result && result.data ? processResources(result.data) : []; | 30 | return result && result.data ? processResources(result.data) : []; |
19 | }); | 31 | }); |
20 | - }, | 32 | + } |
33 | + | ||
21 | getSidebarData() { | 34 | getSidebarData() { |
22 | - return service.get('operations/api/v6/category/getCategory', {}, { | ||
23 | - cache: true, | ||
24 | - code: 200 | 35 | + return this.get({ |
36 | + api: service, | ||
37 | + url: 'operations/api/v6/category/getCategory', | ||
38 | + data: {}, | ||
39 | + param: { | ||
40 | + cache: true, | ||
41 | + code: 200 | ||
42 | + } | ||
25 | }); | 43 | }); |
26 | - }, | 44 | + } |
45 | + | ||
27 | getGoodsData(params) { | 46 | getGoodsData(params) { |
28 | if (!params.productSkn || !params.productSkn.length) { | 47 | if (!params.productSkn || !params.productSkn.length) { |
29 | return Promise.resolve([]); | 48 | return Promise.resolve([]); |
30 | } | 49 | } |
31 | - return api.get('', { | ||
32 | - method: 'h5.product.batch', | ||
33 | - productSkn: params.productSkn | ||
34 | - }, { | ||
35 | - cache: true, | ||
36 | - code: 200 | 50 | + |
51 | + return this.get({ | ||
52 | + data: { | ||
53 | + productSkn: params.productSkn, | ||
54 | + method: 'h5.product.batch' | ||
55 | + }, | ||
56 | + param: { | ||
57 | + cache: true, | ||
58 | + code: 200 | ||
59 | + } | ||
37 | }).then(result => { | 60 | }).then(result => { |
38 | return result && result.data ? processProductList(result.data.product_list) : []; | 61 | return result && result.data ? processProductList(result.data.product_list) : []; |
39 | }); | 62 | }); |
40 | - }, | 63 | + } |
64 | + | ||
41 | getChannelData() { | 65 | getChannelData() { |
42 | - return api.get('', { | ||
43 | - method: 'app.blk.getAllChannels' | ||
44 | - }, { | ||
45 | - cache: true, | ||
46 | - code: 200 | 66 | + return this.get({ |
67 | + data: { | ||
68 | + method: 'app.blk.getAllChannels' | ||
69 | + }, | ||
70 | + param: { | ||
71 | + cache: true, | ||
72 | + code: 200 | ||
73 | + } | ||
47 | }); | 74 | }); |
48 | } | 75 | } |
49 | }; | 76 | }; |
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | */ | 5 | */ |
6 | 'use strict'; | 6 | 'use strict'; |
7 | 7 | ||
8 | -const model = require('../models/detail'); | 8 | +const DetailModel = require('../models/detail'); |
9 | 9 | ||
10 | /** | 10 | /** |
11 | * 商品详情 | 11 | * 商品详情 |
@@ -29,7 +29,7 @@ const component = { | @@ -29,7 +29,7 @@ const component = { | ||
29 | client_type: 'h5' | 29 | client_type: 'h5' |
30 | }; | 30 | }; |
31 | 31 | ||
32 | - model.index(params).then(result => { | 32 | + req.ctx(DetailModel).index(params).then(result => { |
33 | res.json(result); | 33 | res.json(result); |
34 | }).catch(next); | 34 | }).catch(next); |
35 | }, | 35 | }, |
@@ -49,7 +49,7 @@ const component = { | @@ -49,7 +49,7 @@ const component = { | ||
49 | // uid: req.user.uid || 8050378 | 49 | // uid: req.user.uid || 8050378 |
50 | }; | 50 | }; |
51 | 51 | ||
52 | - model.like(params, req.query.flag === 'true').then(result => { | 52 | + req.ctx(DetailModel).like(params, req.query.flag === 'true').then(result => { |
53 | res.json(result); | 53 | res.json(result); |
54 | }).catch(next); | 54 | }).catch(next); |
55 | }, | 55 | }, |
@@ -75,7 +75,7 @@ const component = { | @@ -75,7 +75,7 @@ const component = { | ||
75 | return; | 75 | return; |
76 | } | 76 | } |
77 | 77 | ||
78 | - model.favorite(params, req.query.flag === 'true').then(result => { | 78 | + req.ctx(DetailModel).favorite(params, req.query.flag === 'true').then(result => { |
79 | res.json(result); | 79 | res.json(result); |
80 | }).catch(next); | 80 | }).catch(next); |
81 | }, | 81 | }, |
@@ -94,7 +94,7 @@ const component = { | @@ -94,7 +94,7 @@ const component = { | ||
94 | udid: req.sessionID | 94 | udid: req.sessionID |
95 | }; | 95 | }; |
96 | 96 | ||
97 | - model.misc(params).then(result => { | 97 | + req.ctx(DetailModel).misc(params).then(result => { |
98 | res.json(result); | 98 | res.json(result); |
99 | }).catch(next); | 99 | }).catch(next); |
100 | } | 100 | } |
@@ -27,7 +27,7 @@ module.exports = { | @@ -27,7 +27,7 @@ module.exports = { | ||
27 | uid: req.user.uid | 27 | uid: req.user.uid |
28 | }; | 28 | }; |
29 | 29 | ||
30 | - listModel.editorialList(params).then(result => { | 30 | + req.ctx(listModel).editorialList(params).then(result => { |
31 | res.json(result); | 31 | res.json(result); |
32 | }).catch(next); | 32 | }).catch(next); |
33 | } | 33 | } |
@@ -10,27 +10,47 @@ const Promise = require('bluebird'); | @@ -10,27 +10,47 @@ const Promise = require('bluebird'); | ||
10 | /** | 10 | /** |
11 | * 资讯详情 | 11 | * 资讯详情 |
12 | */ | 12 | */ |
13 | -const model = { | 13 | +const model = class extends global.yoho.BaseModel{ |
14 | + constructor(ctx) { | ||
15 | + super(ctx); | ||
16 | + } | ||
17 | + | ||
14 | index(params) { | 18 | index(params) { |
15 | const URI_PACKAGE_ARTICLE = 'guang/service/v2/article/'; | 19 | const URI_PACKAGE_ARTICLE = 'guang/service/v2/article/'; |
16 | 20 | ||
17 | - return serviceAPI.all([ | ||
18 | - serviceAPI.get(URI_PACKAGE_ARTICLE + 'getArticle', params), | ||
19 | - serviceAPI.get(URI_PACKAGE_ARTICLE + 'getArticleContent', params), | ||
20 | - serviceAPI.get(URI_PACKAGE_ARTICLE + 'getBrand', params), | 21 | + return Promise.all([ |
22 | + this.get({ | ||
23 | + api: serviceAPI, | ||
24 | + url: URI_PACKAGE_ARTICLE + 'getArticle', | ||
25 | + data: params | ||
26 | + }), | ||
27 | + this.get({ | ||
28 | + api: serviceAPI, | ||
29 | + url: URI_PACKAGE_ARTICLE + 'getArticleContent', | ||
30 | + data: params | ||
31 | + }), | ||
32 | + this.get({ | ||
33 | + api: serviceAPI, | ||
34 | + url: URI_PACKAGE_ARTICLE + 'getBrand', | ||
35 | + data: params | ||
36 | + }) | ||
21 | ]).then(res => { | 37 | ]).then(res => { |
22 | const article = res[0]; | 38 | const article = res[0]; |
23 | 39 | ||
24 | - return serviceAPI.get(URI_PACKAGE_ARTICLE + 'getOtherArticle', Object.assign({ | ||
25 | - tags: article.data ? article.data.tag : {}, | ||
26 | - offset: 0, | ||
27 | - limit: 3 | ||
28 | - }, params)).then(other => { | 40 | + return this.get({ |
41 | + api: serviceAPI, | ||
42 | + url: URI_PACKAGE_ARTICLE + 'getOtherArticle', | ||
43 | + data: Object.assign({ | ||
44 | + tags: article.data ? article.data.tag : {}, | ||
45 | + offset: 0, | ||
46 | + limit: 3 | ||
47 | + }, params) | ||
48 | + }).then(other => { | ||
29 | res.push(other); | 49 | res.push(other); |
30 | return res; | 50 | return res; |
31 | }); | 51 | }); |
32 | }); | 52 | }); |
33 | - }, | 53 | + } |
34 | 54 | ||
35 | /** | 55 | /** |
36 | * 点赞 | 56 | * 点赞 |
@@ -40,22 +60,36 @@ const model = { | @@ -40,22 +60,36 @@ const model = { | ||
40 | * @returns {*} | 60 | * @returns {*} |
41 | */ | 61 | */ |
42 | like(params, flag) { | 62 | like(params, flag) { |
63 | + let that = this; | ||
64 | + | ||
43 | return Promise.coroutine(function*() { | 65 | return Promise.coroutine(function*() { |
44 | let ret = null; | 66 | let ret = null; |
45 | 67 | ||
46 | if (flag) { | 68 | if (flag) { |
47 | - ret = yield serviceAPI.get('guang/api/v2/praise/setPraise', params); | 69 | + ret = yield that.get({ |
70 | + api: serviceAPI, | ||
71 | + url: 'guang/api/v2/praise/setPraise', | ||
72 | + data: params | ||
73 | + }); | ||
48 | } else { | 74 | } else { |
49 | - ret = yield serviceAPI.get('guang/api/v2/praise/cancel', params); | 75 | + ret = yield that.get({ |
76 | + api: serviceAPI, | ||
77 | + url: 'guang/api/v2/praise/cancel', | ||
78 | + data: params | ||
79 | + }); | ||
50 | } | 80 | } |
51 | 81 | ||
52 | - const misc = yield serviceAPI.get('guang/api/v2/article/getArticleBaseInfo', Object.assign({ | ||
53 | - id: params.article_id | ||
54 | - }, params)); | 82 | + const misc = yield that.get({ |
83 | + api: serviceAPI, | ||
84 | + url: 'guang/api/v2/article/getArticleBaseInfo', | ||
85 | + data: Object.assign({ | ||
86 | + id: params.article_id | ||
87 | + }, params) | ||
88 | + }); | ||
55 | 89 | ||
56 | return [ret, misc]; | 90 | return [ret, misc]; |
57 | })(); | 91 | })(); |
58 | - }, | 92 | + } |
59 | 93 | ||
60 | /** | 94 | /** |
61 | * 收藏 | 95 | * 收藏 |
@@ -65,22 +99,36 @@ const model = { | @@ -65,22 +99,36 @@ const model = { | ||
65 | * @returns {*} | 99 | * @returns {*} |
66 | */ | 100 | */ |
67 | favorite(params, flag) { | 101 | favorite(params, flag) { |
102 | + let that = this; | ||
103 | + | ||
68 | return Promise.coroutine(function*() { | 104 | return Promise.coroutine(function*() { |
69 | let ret = null; | 105 | let ret = null; |
70 | 106 | ||
71 | if (flag) { | 107 | if (flag) { |
72 | - ret = yield serviceAPI.get('guang/api/v1/favorite/setFavorite', params); | 108 | + ret = yield that.get({ |
109 | + api: serviceAPI, | ||
110 | + url: 'guang/api/v1/favorite/setFavorite', | ||
111 | + data: params | ||
112 | + }); | ||
73 | } else { | 113 | } else { |
74 | - ret = yield serviceAPI.get('guang/api/v1/favorite/cancelFavorite', params); | 114 | + ret = yield that.get({ |
115 | + api: serviceAPI, | ||
116 | + url: 'guang/api/v1/favorite/cancelFavorite', | ||
117 | + data: params | ||
118 | + }); | ||
75 | } | 119 | } |
76 | 120 | ||
77 | - const misc = yield serviceAPI.get('guang/api/v2/article/getArticleBaseInfo', Object.assign({ | ||
78 | - id: params.article_id | ||
79 | - }, params)); | 121 | + const misc = yield that.get({ |
122 | + api: serviceAPI, | ||
123 | + url: 'guang/api/v2/article/getArticleBaseInfo', | ||
124 | + data: Object.assign({ | ||
125 | + id: params.article_id | ||
126 | + }, params) | ||
127 | + }); | ||
80 | 128 | ||
81 | return [ret, misc]; | 129 | return [ret, misc]; |
82 | })(); | 130 | })(); |
83 | - }, | 131 | + } |
84 | 132 | ||
85 | /** | 133 | /** |
86 | * 其它信息 | 134 | * 其它信息 |
@@ -88,9 +136,13 @@ const model = { | @@ -88,9 +136,13 @@ const model = { | ||
88 | * @param params | 136 | * @param params |
89 | */ | 137 | */ |
90 | misc(params) { | 138 | misc(params) { |
91 | - return serviceAPI.get('guang/api/v2/article/getArticleBaseInfo', Object.assign({ | ||
92 | - id: params.article_id | ||
93 | - }, params)); | 139 | + return this.get({ |
140 | + api: serviceAPI, | ||
141 | + url: 'guang/api/v2/article/getArticleBaseInfo', | ||
142 | + data: Object.assign({ | ||
143 | + id: params.article_id | ||
144 | + }, params) | ||
145 | + }); | ||
94 | } | 146 | } |
95 | }; | 147 | }; |
96 | 148 |
@@ -20,16 +20,27 @@ const yhChannel = { | @@ -20,16 +20,27 @@ const yhChannel = { | ||
20 | } | 20 | } |
21 | }; | 21 | }; |
22 | 22 | ||
23 | -module.exports = { | 23 | +module.exports = class extends global.yoho.BaseModel{ |
24 | + constructor(ctx) { | ||
25 | + super(ctx); | ||
26 | + } | ||
24 | 27 | ||
25 | /* 资讯列表页数据获取 */ | 28 | /* 资讯列表页数据获取 */ |
26 | getEditorialListData(params) { | 29 | getEditorialListData(params) { |
27 | - return serviceAPI.get('guang/api/v2/article/getList', { | ||
28 | - sort_id: '', | ||
29 | - gender: yhChannel[params.channel || 'all'].channel, | ||
30 | - uid: params.uid || '0', | ||
31 | - page: params.page, | ||
32 | - limit: '10' | ||
33 | - }, {code: 200, cache: true}); | 30 | + return this.get({ |
31 | + api: serviceAPI, | ||
32 | + url: 'guang/api/v2/article/getList', | ||
33 | + data: { | ||
34 | + sort_id: '', | ||
35 | + gender: yhChannel[params.channel || 'all'].channel, | ||
36 | + uid: params.uid || '0', | ||
37 | + page: params.page, | ||
38 | + limit: '10' | ||
39 | + }, | ||
40 | + param: { | ||
41 | + code: 200, | ||
42 | + cache: true | ||
43 | + } | ||
44 | + }); | ||
34 | } | 45 | } |
35 | }; | 46 | }; |
@@ -6,31 +6,35 @@ | @@ -6,31 +6,35 @@ | ||
6 | */ | 6 | */ |
7 | 'use strict'; | 7 | 'use strict'; |
8 | 8 | ||
9 | -const editorialListApi = require('./list-api'); | 9 | +const EditorialListApi = require('./list-api'); |
10 | 10 | ||
11 | /** | 11 | /** |
12 | * 资讯列表数据 | 12 | * 资讯列表数据 |
13 | * @param params | 13 | * @param params |
14 | * @returns {*|Promise.<TResult>} | 14 | * @returns {*|Promise.<TResult>} |
15 | */ | 15 | */ |
16 | -const editorialList = params => { | ||
17 | - let finalResult = {}; | ||
18 | 16 | ||
19 | - return editorialListApi.getEditorialListData(params).then(result => { | ||
20 | - if (result && result.data) { | ||
21 | - Object.assign(finalResult, { | ||
22 | - data: { | ||
23 | - list: result.data.list ? result.data.list.artList : [], | ||
24 | - totalPage: result.data.totalPage | ||
25 | - }, | ||
26 | - code: 200 | ||
27 | - }); | ||
28 | - } | 17 | +module.exports = class extends global.yoho.BaseModel { |
18 | + constructor(ctx) { | ||
19 | + super(ctx); | ||
20 | + } | ||
29 | 21 | ||
30 | - return finalResult; | ||
31 | - }); | ||
32 | -}; | 22 | + editorialList(params) { |
23 | + let finalResult = {}; | ||
24 | + let editorialListData = new EditorialListApi(this.ctx); | ||
25 | + | ||
26 | + return editorialListData.getEditorialListData(params).then(result => { | ||
27 | + if (result && result.data) { | ||
28 | + Object.assign(finalResult, { | ||
29 | + data: { | ||
30 | + list: result.data.list ? result.data.list.artList : [], | ||
31 | + totalPage: result.data.totalPage | ||
32 | + }, | ||
33 | + code: 200 | ||
34 | + }); | ||
35 | + } | ||
33 | 36 | ||
34 | -module.exports = { | ||
35 | - editorialList | 37 | + return finalResult; |
38 | + }); | ||
39 | + } | ||
36 | }; | 40 | }; |
@@ -12,7 +12,7 @@ const config = require('./config/common'); | @@ -12,7 +12,7 @@ const config = require('./config/common'); | ||
12 | // require('oneapm'); | 12 | // require('oneapm'); |
13 | // } | 13 | // } |
14 | 14 | ||
15 | -const heapdump = require('heapdump'); | 15 | +// const heapdump = require('heapdump'); |
16 | const express = require('express'); | 16 | const express = require('express'); |
17 | const path = require('path'); | 17 | const path = require('path'); |
18 | const bodyParser = require('body-parser'); | 18 | const bodyParser = require('body-parser'); |
@@ -37,7 +37,6 @@ | @@ -37,7 +37,6 @@ | ||
37 | "express-session": "^1.14.1", | 37 | "express-session": "^1.14.1", |
38 | "global": "^4.3.2", | 38 | "global": "^4.3.2", |
39 | "happypack": "^3.1.0", | 39 | "happypack": "^3.1.0", |
40 | - "heapdump": "^0.3.9", | ||
41 | "influxdb-winston": "^1.0.1", | 40 | "influxdb-winston": "^1.0.1", |
42 | "lodash": "^4.15.0", | 41 | "lodash": "^4.15.0", |
43 | "lodash-cli": "^4.17.4", | 42 | "lodash-cli": "^4.17.4", |
@@ -4022,10 +4022,6 @@ header-case@^1.0.0: | @@ -4022,10 +4022,6 @@ header-case@^1.0.0: | ||
4022 | no-case "^2.2.0" | 4022 | no-case "^2.2.0" |
4023 | upper-case "^1.1.3" | 4023 | upper-case "^1.1.3" |
4024 | 4024 | ||
4025 | -heapdump@^0.3.9: | ||
4026 | - version "0.3.9" | ||
4027 | - resolved "http://npm.yohops.com/heapdump/-/heapdump-0.3.9.tgz#03c74eb0df5d67be0982e83429ba9c9d2b3b7f78" | ||
4028 | - | ||
4029 | hmac-drbg@^1.0.0: | 4025 | hmac-drbg@^1.0.0: |
4030 | version "1.0.1" | 4026 | version "1.0.1" |
4031 | resolved "http://npm.yohops.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1" | 4027 | resolved "http://npm.yohops.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1" |
-
Please register or login to post a comment