Showing
4 changed files
with
192 additions
and
52 deletions
@@ -52,7 +52,7 @@ const component = { | @@ -52,7 +52,7 @@ const component = { | ||
52 | uid: req.user.uid || 0 | 52 | uid: req.user.uid || 0 |
53 | }; | 53 | }; |
54 | 54 | ||
55 | - model.product(params).then(product => { | 55 | + req.ctx(model).product(params).then(product => { |
56 | product = product.data || {}; | 56 | product = product.data || {}; |
57 | 57 | ||
58 | product.formatPrice = product.format_sales_price !== '0' ? product.format_sales_price : product.format_market_price;//eslint-disable-line | 58 | product.formatPrice = product.format_sales_price !== '0' ? product.format_sales_price : product.format_market_price;//eslint-disable-line |
@@ -76,7 +76,7 @@ const component = { | @@ -76,7 +76,7 @@ const component = { | ||
76 | uid: req.user.uid || 0 | 76 | uid: req.user.uid || 0 |
77 | }; | 77 | }; |
78 | 78 | ||
79 | - model.product(params).then(product => { | 79 | + req.ctx(model).product(params).then(product => { |
80 | product = product.data || {}; | 80 | product = product.data || {}; |
81 | 81 | ||
82 | product.formatPrice = product.format_sales_price !== '0' ? product.format_sales_price : product.format_market_price;//eslint-disable-line | 82 | product.formatPrice = product.format_sales_price !== '0' ? product.format_sales_price : product.format_market_price;//eslint-disable-line |
@@ -98,8 +98,8 @@ const component = { | @@ -98,8 +98,8 @@ const component = { | ||
98 | product_id: _.toString(pid), | 98 | product_id: _.toString(pid), |
99 | uid: req.user.uid || 0 | 99 | uid: req.user.uid || 0 |
100 | }; | 100 | }; |
101 | - const productPromise = model.product(params); | ||
102 | - const vipPromise = req.user.uid ? model.getVipData(params) : Promise.resolve(); | 101 | + const productPromise = req.ctx(model).product(params); |
102 | + const vipPromise = req.user.uid ? req.ctx(model).getVipData(params) : Promise.resolve(); | ||
103 | 103 | ||
104 | Promise.all([productPromise, vipPromise]).then((result) => { | 104 | Promise.all([productPromise, vipPromise]).then((result) => { |
105 | let vipPrice = []; | 105 | let vipPrice = []; |
@@ -130,7 +130,7 @@ const component = { | @@ -130,7 +130,7 @@ const component = { | ||
130 | uid: req.user.uid || '' | 130 | uid: req.user.uid || '' |
131 | }; | 131 | }; |
132 | 132 | ||
133 | - model.intro(params).then(result => { | 133 | + req.ctx(model).intro(params).then(result => { |
134 | res.json(result); | 134 | res.json(result); |
135 | }).catch(next); | 135 | }).catch(next); |
136 | }, | 136 | }, |
@@ -151,7 +151,7 @@ const component = { | @@ -151,7 +151,7 @@ const component = { | ||
151 | shopping_key: global.yoho.cookie.getShoppingKey(req) | 151 | shopping_key: global.yoho.cookie.getShoppingKey(req) |
152 | }; | 152 | }; |
153 | 153 | ||
154 | - model.addToCart(params).then(result => { | 154 | + req.ctx(model).addToCart(params).then(result => { |
155 | if (result.code === 200) { | 155 | if (result.code === 200) { |
156 | // 将 shopping_key 写入Cookie | 156 | // 将 shopping_key 写入Cookie |
157 | res.cookie('_SPK', result.data.shopping_key, { | 157 | res.cookie('_SPK', result.data.shopping_key, { |
@@ -192,7 +192,7 @@ const component = { | @@ -192,7 +192,7 @@ const component = { | ||
192 | return; | 192 | return; |
193 | } | 193 | } |
194 | 194 | ||
195 | - model.favorite(params).then(result => { | 195 | + req.ctx(model).favorite(params).then(result => { |
196 | res.json(result); | 196 | res.json(result); |
197 | }).catch(next); | 197 | }).catch(next); |
198 | }, | 198 | }, |
@@ -210,7 +210,7 @@ const component = { | @@ -210,7 +210,7 @@ const component = { | ||
210 | uid: req.user.uid | 210 | uid: req.user.uid |
211 | }; | 211 | }; |
212 | 212 | ||
213 | - model.isFavorite(params).then(result => { | 213 | + req.ctx(model).isFavorite(params).then(result => { |
214 | res.json(result); | 214 | res.json(result); |
215 | }).catch(next); | 215 | }).catch(next); |
216 | }, | 216 | }, |
@@ -277,7 +277,7 @@ const component = { | @@ -277,7 +277,7 @@ const component = { | ||
277 | product_skn: req.params.skn | 277 | product_skn: req.params.skn |
278 | }; | 278 | }; |
279 | 279 | ||
280 | - model.refundExchange(params).then(result => { | 280 | + req.ctx(model).refundExchange(params).then(result => { |
281 | res.json(result); | 281 | res.json(result); |
282 | }).catch(next); | 282 | }).catch(next); |
283 | }, | 283 | }, |
@@ -298,7 +298,7 @@ const component = { | @@ -298,7 +298,7 @@ const component = { | ||
298 | yh_channel: CHANNEL_MAP[channel] || 1 | 298 | yh_channel: CHANNEL_MAP[channel] || 1 |
299 | }; | 299 | }; |
300 | 300 | ||
301 | - return model.mightLike(params).then(result => { | 301 | + return req.ctx(model).mightLike(params).then(result => { |
302 | if (result && result.code === 200) { | 302 | if (result && result.code === 200) { |
303 | res.json({ | 303 | res.json({ |
304 | code: 200, | 304 | code: 200, |
@@ -11,13 +11,134 @@ const singleAPI = global.yoho.SingleAPI; | @@ -11,13 +11,134 @@ const singleAPI = global.yoho.SingleAPI; | ||
11 | /** | 11 | /** |
12 | * 商品详情 | 12 | * 商品详情 |
13 | */ | 13 | */ |
14 | -const model = { | 14 | +// const model = { |
15 | +// product(params) { | ||
16 | +// return api.get('', Object.assign({ | ||
17 | +// method: 'app.product.data' | ||
18 | +// }, params), { | ||
19 | +// code: 200, | ||
20 | +// cache: true | ||
21 | +// }).then(result => { | ||
22 | + | ||
23 | +// if (result.data) { | ||
24 | +// let storage = 0; // result.storage 的 数值 不可靠,循环累加 库存 | ||
25 | +// const goodsList = result.data.goods_list; | ||
26 | + | ||
27 | +// if (goodsList) { | ||
28 | +// for (let good of goodsList) { | ||
29 | +// for (let size of good.size_list) { | ||
30 | +// storage += size.storage_number; | ||
31 | +// } | ||
32 | +// } | ||
33 | +// } | ||
34 | + | ||
35 | +// result.data.storage = storage; | ||
36 | +// } | ||
37 | + | ||
38 | +// return result; | ||
39 | +// }); | ||
40 | +// }, | ||
41 | +// getVipData(params) { | ||
42 | +// return api.get('', { | ||
43 | +// method: 'app.passport.vip', | ||
44 | +// uid: params.uid | ||
45 | +// }, { | ||
46 | +// code: 200 | ||
47 | +// }); | ||
48 | +// }, | ||
49 | +// intro(params) { | ||
50 | +// return api.get('', Object.assign({ | ||
51 | +// method: 'h5.product.intro' | ||
52 | +// }, params)); | ||
53 | +// }, | ||
54 | + | ||
55 | +// /** | ||
56 | +// * 加入购物车接口 | ||
57 | +// * | ||
58 | +// */ | ||
59 | +// addToCart(params) { | ||
60 | +// return api.get('', Object.assign({ | ||
61 | +// method: 'app.Shopping.add' | ||
62 | +// }, params)); | ||
63 | +// }, | ||
64 | + | ||
65 | +// /** | ||
66 | +// * 添加收藏/取消收藏 | ||
67 | +// * | ||
68 | +// * @param params | ||
69 | +// */ | ||
70 | +// favorite(params, flag) { | ||
71 | +// let method = ''; | ||
72 | + | ||
73 | +// if (flag) { | ||
74 | +// method = 'app.favorite.add'; | ||
75 | +// } else { | ||
76 | +// method = 'app.favorite.cancel'; | ||
77 | +// } | ||
78 | + | ||
79 | +// return api.get('', Object.assign({ | ||
80 | +// method: method | ||
81 | +// }, params)); | ||
82 | +// }, | ||
83 | + | ||
84 | +// /** | ||
85 | +// * 判断是否收藏 | ||
86 | +// * @param params | ||
87 | +// */ | ||
88 | +// isFavorite(params) { | ||
89 | +// return singleAPI.get('/favorite', Object.assign({ | ||
90 | +// method: 'app.favorite.isFavoriteNew' | ||
91 | +// }, params)); | ||
92 | +// }, | ||
93 | + | ||
94 | +// /** | ||
95 | +// * 获取购物车数量 | ||
96 | +// * | ||
97 | +// * @param params | ||
98 | +// */ | ||
99 | +// getCartCount: (params) => { | ||
100 | +// return api.get('', Object.assign({ | ||
101 | +// method: 'app.Shopping.count' | ||
102 | +// }, params)); | ||
103 | +// }, | ||
104 | + | ||
105 | +// /** | ||
106 | +// * 是否支持退换货 | ||
107 | +// * @param params | ||
108 | +// */ | ||
109 | +// refundExchange(params) { | ||
110 | +// return api.get('', Object.assign({ | ||
111 | +// method: 'app.product.refundExchange' | ||
112 | +// }, params), { | ||
113 | +// cache: true | ||
114 | +// }); | ||
115 | +// }, | ||
116 | + | ||
117 | +// /** | ||
118 | +// * 猜你喜欢 | ||
119 | +// * @param params | ||
120 | +// */ | ||
121 | +// mightLike(params) { | ||
122 | +// return api.get('', Object.assign({ | ||
123 | +// method: 'app.blk.shopRecommend' | ||
124 | +// }, params)); | ||
125 | +// } | ||
126 | +// }; | ||
127 | + | ||
128 | +module.exports = class extends global.yoho.BaseModel { | ||
129 | + constructor(ctx) { | ||
130 | + super(ctx); | ||
131 | + } | ||
132 | + | ||
15 | product(params) { | 133 | product(params) { |
16 | - return api.get('', Object.assign({ | ||
17 | - method: 'app.product.data' | ||
18 | - }, params), { | ||
19 | - code: 200, | ||
20 | - cache: true | 134 | + return this.get({ |
135 | + data: Object.assign({ | ||
136 | + method: 'app.product.data' | ||
137 | + }, params), | ||
138 | + params: { | ||
139 | + code: 200, | ||
140 | + cache: true | ||
141 | + } | ||
21 | }).then(result => { | 142 | }).then(result => { |
22 | 143 | ||
23 | if (result.data) { | 144 | if (result.data) { |
@@ -37,30 +158,39 @@ const model = { | @@ -37,30 +158,39 @@ const model = { | ||
37 | 158 | ||
38 | return result; | 159 | return result; |
39 | }); | 160 | }); |
40 | - }, | 161 | + } |
162 | + | ||
41 | getVipData(params) { | 163 | getVipData(params) { |
42 | - return api.get('', { | ||
43 | - method: 'app.passport.vip', | ||
44 | - uid: params.uid | ||
45 | - }, { | ||
46 | - code: 200 | 164 | + return this.get({ |
165 | + data: { | ||
166 | + method: 'app.passport.vip', | ||
167 | + uid: params.uid | ||
168 | + }, | ||
169 | + params: { | ||
170 | + code: 200 | ||
171 | + } | ||
47 | }); | 172 | }); |
48 | - }, | 173 | + } |
174 | + | ||
49 | intro(params) { | 175 | intro(params) { |
50 | - return api.get('', Object.assign({ | ||
51 | - method: 'h5.product.intro' | ||
52 | - }, params)); | ||
53 | - }, | 176 | + return this.get({ |
177 | + data: Object.assign({ | ||
178 | + method: 'h5.product.intro' | ||
179 | + }, params) | ||
180 | + }); | ||
181 | + } | ||
54 | 182 | ||
55 | /** | 183 | /** |
56 | * 加入购物车接口 | 184 | * 加入购物车接口 |
57 | * | 185 | * |
58 | */ | 186 | */ |
59 | addToCart(params) { | 187 | addToCart(params) { |
60 | - return api.get('', Object.assign({ | ||
61 | - method: 'app.Shopping.add' | ||
62 | - }, params)); | ||
63 | - }, | 188 | + return this.get({ |
189 | + data: Object.assign({ | ||
190 | + method: 'app.Shopping.add' | ||
191 | + }, params) | ||
192 | + }); | ||
193 | + } | ||
64 | 194 | ||
65 | /** | 195 | /** |
66 | * 添加收藏/取消收藏 | 196 | * 添加收藏/取消收藏 |
@@ -76,10 +206,12 @@ const model = { | @@ -76,10 +206,12 @@ const model = { | ||
76 | method = 'app.favorite.cancel'; | 206 | method = 'app.favorite.cancel'; |
77 | } | 207 | } |
78 | 208 | ||
79 | - return api.get('', Object.assign({ | ||
80 | - method: method | ||
81 | - }, params)); | ||
82 | - }, | 209 | + return this.get({ |
210 | + data: Object.assign({ | ||
211 | + method: method | ||
212 | + }, params) | ||
213 | + }); | ||
214 | + } | ||
83 | 215 | ||
84 | /** | 216 | /** |
85 | * 判断是否收藏 | 217 | * 判断是否收藏 |
@@ -89,40 +221,45 @@ const model = { | @@ -89,40 +221,45 @@ const model = { | ||
89 | return singleAPI.get('/favorite', Object.assign({ | 221 | return singleAPI.get('/favorite', Object.assign({ |
90 | method: 'app.favorite.isFavoriteNew' | 222 | method: 'app.favorite.isFavoriteNew' |
91 | }, params)); | 223 | }, params)); |
92 | - }, | 224 | + } |
93 | 225 | ||
94 | /** | 226 | /** |
95 | * 获取购物车数量 | 227 | * 获取购物车数量 |
96 | * | 228 | * |
97 | * @param params | 229 | * @param params |
98 | */ | 230 | */ |
99 | - getCartCount: (params) => { | ||
100 | - return api.get('', Object.assign({ | ||
101 | - method: 'app.Shopping.count' | ||
102 | - }, params)); | ||
103 | - }, | 231 | + getCartCount(params) { |
232 | + return this.get({ | ||
233 | + data: Object.assign({ | ||
234 | + method: 'app.Shopping.count' | ||
235 | + }, params) | ||
236 | + }); | ||
237 | + } | ||
104 | 238 | ||
105 | /** | 239 | /** |
106 | * 是否支持退换货 | 240 | * 是否支持退换货 |
107 | * @param params | 241 | * @param params |
108 | */ | 242 | */ |
109 | refundExchange(params) { | 243 | refundExchange(params) { |
110 | - return api.get('', Object.assign({ | ||
111 | - method: 'app.product.refundExchange' | ||
112 | - }, params), { | ||
113 | - cache: true | 244 | + return this.get({ |
245 | + data: Object.assign({ | ||
246 | + method: 'app.product.refundExchange' | ||
247 | + }, params), | ||
248 | + params: { | ||
249 | + cache: true | ||
250 | + } | ||
114 | }); | 251 | }); |
115 | - }, | 252 | + } |
116 | 253 | ||
117 | /** | 254 | /** |
118 | * 猜你喜欢 | 255 | * 猜你喜欢 |
119 | * @param params | 256 | * @param params |
120 | */ | 257 | */ |
121 | mightLike(params) { | 258 | mightLike(params) { |
122 | - return api.get('', Object.assign({ | ||
123 | - method: 'app.blk.shopRecommend' | ||
124 | - }, params)); | 259 | + return this.get({ |
260 | + data: Object.assign({ | ||
261 | + method: 'app.blk.shopRecommend' | ||
262 | + }, params) | ||
263 | + }); | ||
125 | } | 264 | } |
126 | -}; | ||
127 | - | ||
128 | -module.exports = model; | 265 | +} |
@@ -50,6 +50,9 @@ exports.createApp = async (app) => { | @@ -50,6 +50,9 @@ exports.createApp = async (app) => { | ||
50 | app.use(devtools()); | 50 | app.use(devtools()); |
51 | } | 51 | } |
52 | 52 | ||
53 | + // 添加请求上下文 | ||
54 | + app.use(global.yoho.httpCtx()); | ||
55 | + | ||
53 | app.use(global.yoho.hbs({ | 56 | app.use(global.yoho.hbs({ |
54 | extname: '.hbs', | 57 | extname: '.hbs', |
55 | defaultLayout: 'layout', | 58 | defaultLayout: 'layout', |
This diff could not be displayed because it is too large.
-
Please register or login to post a comment