Showing
6 changed files
with
126 additions
and
131 deletions
@@ -276,7 +276,7 @@ class BuyNowController { | @@ -276,7 +276,7 @@ class BuyNowController { | ||
276 | let userData = yield req.ctx(userModel).queryProfile(uid); | 276 | let userData = yield req.ctx(userModel).queryProfile(uid); |
277 | let mobile = _.get(userData, 'data.mobile', ''); | 277 | let mobile = _.get(userData, 'data.mobile', ''); |
278 | let addresslist = yield req.ctx(userModel).addressTextData(uid); | 278 | let addresslist = yield req.ctx(userModel).addressTextData(uid); |
279 | - let returnData = orderModel.processInvoiceData(orderInfo, mobile, addresslist); | 279 | + let returnData = req.ctx(orderModel).processInvoiceData(orderInfo, mobile, addresslist); |
280 | let headerData = headerModel.setNav({ | 280 | let headerData = headerModel.setNav({ |
281 | invoiceNotice: '发票须知', | 281 | invoiceNotice: '发票须知', |
282 | navTitle: '发票信息', | 282 | navTitle: '发票信息', |
@@ -82,7 +82,7 @@ exports.orderEnsure = (req, res, next) => { | @@ -82,7 +82,7 @@ exports.orderEnsure = (req, res, next) => { | ||
82 | ]; | 82 | ]; |
83 | 83 | ||
84 | if (_.isUndefined(req.cookies._isNewUser)) { | 84 | if (_.isUndefined(req.cookies._isNewUser)) { |
85 | - allPromise.push(orderModel.isNewUser(uid)); | 85 | + allPromise.push(req.ctx(orderModel).isNewUser(uid)); |
86 | } | 86 | } |
87 | 87 | ||
88 | return Promise.all(allPromise).then(result => { | 88 | return Promise.all(allPromise).then(result => { |
@@ -427,7 +427,7 @@ exports.invoiceInfo = (req, res, next) => { | @@ -427,7 +427,7 @@ exports.invoiceInfo = (req, res, next) => { | ||
427 | let userData = yield req.ctx(userModel).queryProfile(uid); | 427 | let userData = yield req.ctx(userModel).queryProfile(uid); |
428 | let mobile = _.get(userData, 'data.mobile', ''); | 428 | let mobile = _.get(userData, 'data.mobile', ''); |
429 | let addresslist = yield req.ctx(userModel).addressTextData(uid); | 429 | let addresslist = yield req.ctx(userModel).addressTextData(uid); |
430 | - let returnData = orderModel.processInvoiceData(orderInfo, mobile, addresslist); | 430 | + let returnData = req.ctx(orderModel).processInvoiceData(orderInfo, mobile, addresslist); |
431 | let headerData = headerModel.setNav({ | 431 | let headerData = headerModel.setNav({ |
432 | invoiceNotice: '发票须知', | 432 | invoiceNotice: '发票须知', |
433 | navTitle: '发票信息', | 433 | navTitle: '发票信息', |
1 | 'use strict'; | 1 | 'use strict'; |
2 | 2 | ||
3 | // doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/个人中心/地址管理.md'; | 3 | // doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/个人中心/地址管理.md'; |
4 | - | ||
5 | -const api = global.yoho.API; | ||
6 | const crypto = global.yoho.crypto; | 4 | const crypto = global.yoho.crypto; |
7 | 5 | ||
8 | class AddressModel extends global.yoho.BaseModel { | 6 | class AddressModel extends global.yoho.BaseModel { |
@@ -16,32 +14,26 @@ class AddressModel extends global.yoho.BaseModel { | @@ -16,32 +14,26 @@ class AddressModel extends global.yoho.BaseModel { | ||
16 | * @return | 14 | * @return |
17 | */ | 15 | */ |
18 | addressData(uid) { | 16 | addressData(uid) { |
19 | - let params = { | ||
20 | - method: 'app.address.gethidden', | ||
21 | - uid | ||
22 | - }; | ||
23 | - | ||
24 | - let options = { | ||
25 | - cache: false | ||
26 | - }; | ||
27 | - | ||
28 | - return api.get('', params, options) | ||
29 | - .then( | ||
30 | - result => { | ||
31 | - if (result.code === 200) { | ||
32 | - // 加密address_id | ||
33 | - result.data.forEach(address => { | ||
34 | - address.address_id = encodeURIComponent(crypto.encryption(null, address.address_id)); | ||
35 | - }); | ||
36 | - } | ||
37 | - | ||
38 | - return result; | ||
39 | - } | ||
40 | - , | ||
41 | - () => { | ||
42 | - return {code: 500, data: [], message: '地址获取失败'}; | ||
43 | - } | ||
44 | - ); | 17 | + return this.get({ |
18 | + data: { | ||
19 | + method: 'app.address.gethidden', | ||
20 | + uid | ||
21 | + }, | ||
22 | + param: { | ||
23 | + cache: false | ||
24 | + } | ||
25 | + }).then(result => { | ||
26 | + if (result.code === 200) { | ||
27 | + // 加密address_id | ||
28 | + result.data.forEach(address => { | ||
29 | + address.address_id = encodeURIComponent(crypto.encryption(null, address.address_id)); | ||
30 | + }); | ||
31 | + } | ||
32 | + | ||
33 | + return result; | ||
34 | + }, () => { | ||
35 | + return {code: 500, data: [], message: '地址获取失败'}; | ||
36 | + }); | ||
45 | } | 37 | } |
46 | } | 38 | } |
47 | 39 |
1 | 'use strict'; | 1 | 'use strict'; |
2 | - | ||
3 | -const api = global.yoho.API; | ||
4 | const _ = require('lodash'); | 2 | const _ = require('lodash'); |
5 | const crypto = global.yoho.crypto; | 3 | const crypto = global.yoho.crypto; |
6 | 4 | ||
7 | -const processInvoiceData = (orderInfo, mobile, addresslist) => { | ||
8 | - let invoices_title = false; | ||
9 | - let invoices_title_personal = false; | ||
10 | - let invoices_type = '2'; | ||
11 | - let addressId = orderInfo.addressId && | ||
12 | - parseInt(crypto.encryption('', orderInfo.addressId), 10) || 0; | ||
13 | - | ||
14 | - // 用户手机号处理 | ||
15 | - if (orderInfo.receiverMobile && orderInfo.isModifyTel) { | ||
16 | - mobile = orderInfo.receiverMobile; | ||
17 | - } else { | ||
18 | - _.forEach(addresslist, addressValue => { | ||
19 | - if (addressValue.address_id === addressId) { | ||
20 | - mobile = addressValue.mobile; | ||
21 | - return false; | ||
22 | - } | ||
23 | - }); | 5 | +class orderModel extends global.yoho.BaseModel { |
6 | + constructor(ctx) { | ||
7 | + super(ctx); | ||
24 | } | 8 | } |
25 | 9 | ||
26 | - // 发票信息处理 | ||
27 | - if (orderInfo.invoices_type && orderInfo.invoices_title) { | ||
28 | - invoices_title = orderInfo.invoices_title; | ||
29 | - invoices_type = orderInfo.invoices_type * 1; | ||
30 | - } | 10 | + processInvoiceData(orderInfo, mobile, addresslist) { |
11 | + let invoices_title = false; | ||
12 | + let invoices_title_personal = false; | ||
13 | + let invoices_type = '2'; | ||
14 | + let addressId = orderInfo.addressId && | ||
15 | + parseInt(crypto.encryption('', orderInfo.addressId), 10) || 0; | ||
31 | 16 | ||
32 | - invoices_title_personal = orderInfo.invoices_title_personal || '个人(可修改)'; | 17 | + // 用户手机号处理 |
18 | + if (orderInfo.receiverMobile && orderInfo.isModifyTel) { | ||
19 | + mobile = orderInfo.receiverMobile; | ||
20 | + } else { | ||
21 | + _.forEach(addresslist, addressValue => { | ||
22 | + if (addressValue.address_id === addressId) { | ||
23 | + mobile = addressValue.mobile; | ||
24 | + return false; | ||
25 | + } | ||
26 | + }); | ||
27 | + } | ||
33 | 28 | ||
34 | - let isCompany = invoices_title && invoices_title !== '个人'; | 29 | + // 发票信息处理 |
30 | + if (orderInfo.invoices_type && orderInfo.invoices_title) { | ||
31 | + invoices_title = orderInfo.invoices_title; | ||
32 | + invoices_type = orderInfo.invoices_type * 1; | ||
33 | + } | ||
35 | 34 | ||
36 | - return { | ||
37 | - phone: mobile ? mobile : '', | ||
38 | - completeTel: mobile, | ||
39 | - isCompany: isCompany, | ||
40 | - companyName: isCompany ? invoices_title : invoices_title_personal, | ||
41 | - buyerTaxNumber: orderInfo.buyerTaxNumber, | ||
42 | - isPaper: invoices_type === 1, | ||
43 | - invoicesType: [ | ||
44 | - { | ||
45 | - id: '2', | ||
46 | - type: '电子发票' | ||
47 | - } | ||
48 | - ], | ||
49 | - invoiceTitle: [ | ||
50 | - { | ||
51 | - type: '个人', | ||
52 | - choosed: !isCompany | ||
53 | - }, | ||
54 | - { | ||
55 | - type: '单位', | ||
56 | - choosed: isCompany | ||
57 | - } | ||
58 | - ] | ||
59 | - }; | 35 | + invoices_title_personal = orderInfo.invoices_title_personal || '个人(可修改)'; |
60 | 36 | ||
61 | -}; | 37 | + let isCompany = invoices_title && invoices_title !== '个人'; |
62 | 38 | ||
63 | -/** | ||
64 | - * 判断用户是否是老用户 | ||
65 | - */ | ||
66 | -const isNewUser = (uid) => { | ||
67 | - return api.get('', { | ||
68 | - method: 'app.SpaceOrders.get', | ||
69 | - type: '5', | ||
70 | - page: '1', | ||
71 | - limit: '1', | ||
72 | - uid: uid | ||
73 | - }, {code: 200}).then(result => { | ||
74 | - let order = _.get(result, 'data.order_list', []); | 39 | + return { |
40 | + phone: mobile ? mobile : '', | ||
41 | + completeTel: mobile, | ||
42 | + isCompany: isCompany, | ||
43 | + companyName: isCompany ? invoices_title : invoices_title_personal, | ||
44 | + buyerTaxNumber: orderInfo.buyerTaxNumber, | ||
45 | + isPaper: invoices_type === 1, | ||
46 | + invoicesType: [ | ||
47 | + { | ||
48 | + id: '2', | ||
49 | + type: '电子发票' | ||
50 | + } | ||
51 | + ], | ||
52 | + invoiceTitle: [ | ||
53 | + { | ||
54 | + type: '个人', | ||
55 | + choosed: !isCompany | ||
56 | + }, | ||
57 | + { | ||
58 | + type: '单位', | ||
59 | + choosed: isCompany | ||
60 | + } | ||
61 | + ] | ||
62 | + }; | ||
75 | 63 | ||
76 | - if (order.length > 0) { | ||
77 | - return false; | ||
78 | - } else { | ||
79 | - return true; | ||
80 | - } | ||
81 | - }); | ||
82 | -}; | 64 | + } |
65 | + | ||
66 | + /** | ||
67 | + * 判断用户是否是老用户 | ||
68 | + */ | ||
69 | + isNewUser(uid) { | ||
70 | + return this.get({ | ||
71 | + data: { | ||
72 | + method: 'app.SpaceOrders.get', | ||
73 | + type: '5', | ||
74 | + page: '1', | ||
75 | + limit: '1', | ||
76 | + uid: uid | ||
77 | + }, | ||
78 | + param: {code: 200} | ||
79 | + }).then(result => { | ||
80 | + let order = _.get(result, 'data.order_list', []); | ||
83 | 81 | ||
84 | -module.exports = { | ||
85 | - processInvoiceData, | ||
86 | - isNewUser | ||
87 | -}; | 82 | + if (order.length > 0) { |
83 | + return false; | ||
84 | + } else { | ||
85 | + return true; | ||
86 | + } | ||
87 | + }); | ||
88 | + } | ||
89 | +} | ||
90 | +module.exports = orderModel; |
@@ -6,8 +6,6 @@ | @@ -6,8 +6,6 @@ | ||
6 | 6 | ||
7 | 'use strict'; | 7 | 'use strict'; |
8 | 8 | ||
9 | -const api = global.yoho.API; | ||
10 | - | ||
11 | class payApiModel extends global.yoho.BaseModel { | 9 | class payApiModel extends global.yoho.BaseModel { |
12 | constructor(ctx) { | 10 | constructor(ctx) { |
13 | super(ctx); | 11 | super(ctx); |
@@ -15,64 +13,67 @@ class payApiModel extends global.yoho.BaseModel { | @@ -15,64 +13,67 @@ class payApiModel extends global.yoho.BaseModel { | ||
15 | 13 | ||
16 | // 获取支付宝等平台支付方式列表 | 14 | // 获取支付宝等平台支付方式列表 |
17 | getPayProvider() { | 15 | getPayProvider() { |
18 | - return api.get('', { | ||
19 | - method: 'web.SpaceOrders.getPaymentList' | ||
20 | - }, {cache: true}); | 16 | + return this.get({ |
17 | + data: { | ||
18 | + method: 'web.SpaceOrders.getPaymentList' | ||
19 | + }, | ||
20 | + param: {cache: true} | ||
21 | + }); | ||
21 | } | 22 | } |
22 | 23 | ||
23 | // 获取单个支付方式相关详细信息 | 24 | // 获取单个支付方式相关详细信息 |
24 | getPaymentInfo(id) { | 25 | getPaymentInfo(id) { |
25 | - return api.get('', { | 26 | + return this.get({data: { |
26 | method: 'web.SpaceOrders.getPaymentById', | 27 | method: 'web.SpaceOrders.getPaymentById', |
27 | id: id | 28 | id: id |
28 | - }, {cache: true}); | 29 | + }, param: {cache: true}}); |
29 | } | 30 | } |
30 | 31 | ||
31 | /* 获取上次使用的支付方式*/ | 32 | /* 获取上次使用的支付方式*/ |
32 | getBankByOrder(code) { | 33 | getBankByOrder(code) { |
33 | - return api.get('', { | 34 | + return this.get({data: { |
34 | method: 'web.SpaceOrders.getOrderPayBank', | 35 | method: 'web.SpaceOrders.getOrderPayBank', |
35 | orderCode: code | 36 | orderCode: code |
36 | - }); | 37 | + }}); |
37 | } | 38 | } |
38 | 39 | ||
39 | /* 记录支付方式*/ | 40 | /* 记录支付方式*/ |
40 | setOrderPayBank(code, payment, bankCode) { | 41 | setOrderPayBank(code, payment, bankCode) { |
41 | - return api.get('', { | 42 | + return this.get({data: { |
42 | method: 'web.SpaceOrders.addOrderPayBank', | 43 | method: 'web.SpaceOrders.addOrderPayBank', |
43 | orderCode: code, | 44 | orderCode: code, |
44 | payment: payment, | 45 | payment: payment, |
45 | bankCode: bankCode | 46 | bankCode: bankCode |
46 | - }); | 47 | + }}); |
47 | } | 48 | } |
48 | 49 | ||
49 | /* 更改支付方式*/ | 50 | /* 更改支付方式*/ |
50 | updateOrderPayBank(code, payment, bankCode) { | 51 | updateOrderPayBank(code, payment, bankCode) { |
51 | - return api.get('', { | 52 | + return this.get({data: { |
52 | method: 'web.SpaceOrders.modifyOrderPayBank', | 53 | method: 'web.SpaceOrders.modifyOrderPayBank', |
53 | orderCode: code, | 54 | orderCode: code, |
54 | payment: payment, | 55 | payment: payment, |
55 | bankCode: bankCode | 56 | bankCode: bankCode |
56 | - }); | 57 | + }}); |
57 | } | 58 | } |
58 | 59 | ||
59 | /* 发送支付确认*/ | 60 | /* 发送支付确认*/ |
60 | sendPayConfirm(code, payment, uid) { | 61 | sendPayConfirm(code, payment, uid) { |
61 | - return api.get('', { | 62 | + return this.get({data: { |
62 | method: 'app.SpaceOrders.payConfirm', | 63 | method: 'app.SpaceOrders.payConfirm', |
63 | order_code: code, | 64 | order_code: code, |
64 | payment_id: payment, | 65 | payment_id: payment, |
65 | uid: uid | 66 | uid: uid |
66 | - }); | 67 | + }}); |
67 | } | 68 | } |
68 | 69 | ||
69 | sendMessage(mobile, template, codes) { | 70 | sendMessage(mobile, template, codes) { |
70 | - return api.get('', { | 71 | + return this.get({data: { |
71 | method: 'app.message.sendMsg', | 72 | method: 'app.message.sendMsg', |
72 | mobile: mobile, | 73 | mobile: mobile, |
73 | template: template, | 74 | template: template, |
74 | codes: codes | 75 | codes: codes |
75 | - }); | 76 | + }}); |
76 | } | 77 | } |
77 | } | 78 | } |
78 | 79 |
1 | 'use strict'; | 1 | 'use strict'; |
2 | const _ = require('lodash'); | 2 | const _ = require('lodash'); |
3 | -const api = global.yoho.API; | ||
4 | 3 | ||
5 | class shoppingModel extends global.yoho.BaseModel { | 4 | class shoppingModel extends global.yoho.BaseModel { |
6 | constructor(ctx) { | 5 | constructor(ctx) { |
@@ -35,7 +34,7 @@ class shoppingModel extends global.yoho.BaseModel { | @@ -35,7 +34,7 @@ class shoppingModel extends global.yoho.BaseModel { | ||
35 | param.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list); | 34 | param.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list); |
36 | } | 35 | } |
37 | 36 | ||
38 | - return api.get('', param, {cache: false}); | 37 | + return this.get({data: param, param: {cache: false}}); |
39 | } | 38 | } |
40 | 39 | ||
41 | /** | 40 | /** |
@@ -69,7 +68,7 @@ class shoppingModel extends global.yoho.BaseModel { | @@ -69,7 +68,7 @@ class shoppingModel extends global.yoho.BaseModel { | ||
69 | finalParams.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list); | 68 | finalParams.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list); |
70 | } | 69 | } |
71 | 70 | ||
72 | - return api.get('', finalParams, {code: 200}); | 71 | + return this.get({data: finalParams, param: {code: 200}}); |
73 | } | 72 | } |
74 | 73 | ||
75 | /** | 74 | /** |
@@ -105,7 +104,7 @@ class shoppingModel extends global.yoho.BaseModel { | @@ -105,7 +104,7 @@ class shoppingModel extends global.yoho.BaseModel { | ||
105 | }); | 104 | }); |
106 | } | 105 | } |
107 | 106 | ||
108 | - return api.get('', params, {code: 200}); | 107 | + return this.get({data: params, param: {code: 200}}); |
109 | } | 108 | } |
110 | 109 | ||
111 | /** | 110 | /** |
@@ -192,12 +191,12 @@ class shoppingModel extends global.yoho.BaseModel { | @@ -192,12 +191,12 @@ class shoppingModel extends global.yoho.BaseModel { | ||
192 | finalParams.client_type = 'wechat'; | 191 | finalParams.client_type = 'wechat'; |
193 | } | 192 | } |
194 | 193 | ||
195 | - return api.post('', finalParams, { | 194 | + return this.post({data: finalParams, param: { |
196 | headers: { | 195 | headers: { |
197 | 'X-Forwarded-For': params.ip || '', | 196 | 'X-Forwarded-For': params.ip || '', |
198 | 'User-Agent': params.userAgent | 197 | 'User-Agent': params.userAgent |
199 | } | 198 | } |
200 | - }); | 199 | + }}); |
201 | } | 200 | } |
202 | 201 | ||
203 | 202 | ||
@@ -213,7 +212,7 @@ class shoppingModel extends global.yoho.BaseModel { | @@ -213,7 +212,7 @@ class shoppingModel extends global.yoho.BaseModel { | ||
213 | uid | 212 | uid |
214 | }; | 213 | }; |
215 | 214 | ||
216 | - return api.get('', param); | 215 | + return this.get({data: param}); |
217 | } | 216 | } |
218 | 217 | ||
219 | 218 | ||
@@ -231,7 +230,7 @@ class shoppingModel extends global.yoho.BaseModel { | @@ -231,7 +230,7 @@ class shoppingModel extends global.yoho.BaseModel { | ||
231 | is_group_frees: params.is_group_frees | 230 | is_group_frees: params.is_group_frees |
232 | }; | 231 | }; |
233 | 232 | ||
234 | - return api.get('', param); | 233 | + return this.get({data: param}); |
235 | } | 234 | } |
236 | 235 | ||
237 | /** | 236 | /** |
@@ -247,7 +246,7 @@ class shoppingModel extends global.yoho.BaseModel { | @@ -247,7 +246,7 @@ class shoppingModel extends global.yoho.BaseModel { | ||
247 | uid | 246 | uid |
248 | }; | 247 | }; |
249 | 248 | ||
250 | - return api.get('', param); | 249 | + return this.get({data: param}); |
251 | } | 250 | } |
252 | } | 251 | } |
253 | 252 |
-
Please register or login to post a comment