Authored by htoooth

Merge branch 'master' into feature/channel-op

@@ -17,7 +17,7 @@ const getArea = (req, res, next) => { @@ -17,7 +17,7 @@ const getArea = (req, res, next) => {
17 }); 17 });
18 } 18 }
19 19
20 - address.getAreaListData(id).then(result => { 20 + req.ctx(address).getAreaListData(id).then(result => {
21 res.send(result); 21 res.send(result);
22 }).catch(next); 22 }).catch(next);
23 }; 23 };
@@ -32,7 +32,7 @@ const getList = (req, res, next) => { @@ -32,7 +32,7 @@ const getList = (req, res, next) => {
32 }); 32 });
33 } 33 }
34 34
35 - address.getAddressListData(uid).then(result => { 35 + req.ctx(address).getAddressListData(uid).then(result => {
36 res.send(result); 36 res.send(result);
37 }).catch(next); 37 }).catch(next);
38 }; 38 };
@@ -45,7 +45,7 @@ const delAddress = (req, res, next) => { @@ -45,7 +45,7 @@ const delAddress = (req, res, next) => {
45 return next(); 45 return next();
46 } 46 }
47 47
48 - address.delAddressById(uid, id).then(result => { 48 + req.ctx(address).delAddressById(uid, id).then(result => {
49 res.send(result); 49 res.send(result);
50 }).catch(next); 50 }).catch(next);
51 }; 51 };
@@ -58,7 +58,7 @@ const saveAddress = (req, res, next) => { @@ -58,7 +58,7 @@ const saveAddress = (req, res, next) => {
58 return next(); 58 return next();
59 } 59 }
60 60
61 - address.saveAddressData(uid, params).then(result => { 61 + req.ctx(address).saveAddressData(uid, params).then(result => {
62 res.send(result); 62 res.send(result);
63 }).catch(next); 63 }).catch(next);
64 }; 64 };
@@ -71,7 +71,7 @@ const setDefault = (req, res, next) => { @@ -71,7 +71,7 @@ const setDefault = (req, res, next) => {
71 return next(); 71 return next();
72 } 72 }
73 73
74 - address.setDefaultAddress(uid, id).then(result => { 74 + req.ctx(address).setDefaultAddress(uid, id).then(result => {
75 res.send(result); 75 res.send(result);
76 }).catch(next); 76 }).catch(next);
77 }; 77 };
@@ -17,7 +17,7 @@ const index = (req, res, next) => { @@ -17,7 +17,7 @@ const index = (req, res, next) => {
17 let uid = req.user.uid; 17 let uid = req.user.uid;
18 let params = req.query; 18 let params = req.query;
19 19
20 - easypay.getEasypayOrderData(params, uid).then(result => { 20 + req.ctx(easypay).getEasypayOrderData(params, uid).then(result => {
21 let header = headerModel.setSimpleHeaderData() || {}; 21 let header = headerModel.setSimpleHeaderData() || {};
22 22
23 result.stepper = stepper; 23 result.stepper = stepper;
@@ -39,7 +39,7 @@ const compute = (req, res, next) => { @@ -39,7 +39,7 @@ const compute = (req, res, next) => {
39 let uid = req.user.uid; 39 let uid = req.user.uid;
40 let params = req.body; 40 let params = req.body;
41 41
42 - easypay.getOrderComputeData(uid, 'ordinary', params).then(result => { 42 + req.ctx(easypay).getOrderComputeData(uid, 'ordinary', params).then(result => {
43 res.json(result); 43 res.json(result);
44 }).catch(next); 44 }).catch(next);
45 }; 45 };
@@ -53,7 +53,7 @@ const submit = (req, res, next) => { @@ -53,7 +53,7 @@ const submit = (req, res, next) => {
53 return next(); 53 return next();
54 } 54 }
55 55
56 - easypay.easypayOrderSubmit(uid, 'ordinary', params, remoteIp).then(result => { 56 + req.ctx(easypay).easypayOrderSubmit(uid, 'ordinary', params, remoteIp).then(result => {
57 res.json(result); 57 res.json(result);
58 }).catch(next); 58 }).catch(next);
59 }; 59 };
@@ -23,7 +23,7 @@ const stepper = [ @@ -23,7 +23,7 @@ const stepper = [
23 const index = (req, res, next) => { 23 const index = (req, res, next) => {
24 let cartType = req.query.type === '2' ? 'advance' : 'ordinary'; 24 let cartType = req.query.type === '2' ? 'advance' : 'ordinary';
25 25
26 - oeModel.index(req.user.uid, cartType).then(result => { 26 + req.ctx(oeModel).index(req.user.uid, cartType).then(result => {
27 let header = headerModel.setSimpleHeaderData() || {}; 27 let header = headerModel.setSimpleHeaderData() || {};
28 28
29 Object.assign(result, { 29 Object.assign(result, {
@@ -46,14 +46,14 @@ const index = (req, res, next) => { @@ -46,14 +46,14 @@ const index = (req, res, next) => {
46 46
47 // 获取优惠券列表 47 // 获取优惠券列表
48 const getCoupons = (req, res, next) => { 48 const getCoupons = (req, res, next) => {
49 - oeModel.getCoupons(req.user.uid).then(data => { 49 + req.ctx(oeModel).getCoupons(req.user.uid).then(data => {
50 res.send(data); 50 res.send(data);
51 }).catch(next); 51 }).catch(next);
52 }; 52 };
53 53
54 // 获取优惠券列表 54 // 获取优惠券列表
55 const convertCoupons = (req, res, next) => { 55 const convertCoupons = (req, res, next) => {
56 - oeModel.convertCoupons(req.user.uid, req.query.code).then(data => { 56 + req.ctx(oeModel).convertCoupons(req.user.uid, req.query.code).then(data => {
57 res.send(data); 57 res.send(data);
58 }).catch(next); 58 }).catch(next);
59 }; 59 };
@@ -64,11 +64,11 @@ const compute = (req, res, next) => { @@ -64,11 +64,11 @@ const compute = (req, res, next) => {
64 let cartType = params.cartType === '2' ? 'advance' : 'ordinary'; 64 let cartType = params.cartType === '2' ? 'advance' : 'ordinary';
65 65
66 if (params.sku) { // 快捷结算 66 if (params.sku) { // 快捷结算
67 - easypayModel.getOrderComputeData(req.user.uid, 'ordinary', params).then(result => { 67 + req.ctx(easypayModel).getOrderComputeData(req.user.uid, 'ordinary', params).then(result => {
68 res.json(result); 68 res.json(result);
69 }).catch(next); 69 }).catch(next);
70 } else { 70 } else {
71 - oeModel.compute(req.user.uid, cartType, params).then(data => { 71 + req.ctx(oeModel).compute(req.user.uid, cartType, params).then(data => {
72 res.send(data); 72 res.send(data);
73 }).catch(next); 73 }).catch(next);
74 } 74 }
@@ -153,11 +153,11 @@ const submit = (req, res, next) => { @@ -153,11 +153,11 @@ const submit = (req, res, next) => {
153 params.udid = req.cookies._yasvd || 'yoho_pc'; 153 params.udid = req.cookies._yasvd || 'yoho_pc';
154 154
155 if (params.sku) { // 快捷结算 155 if (params.sku) { // 快捷结算
156 - easypayModel.easypayOrderSubmit(uid, 'ordinary', params, remoteIp).then(result => { 156 + req.ctx(easypayModel).easypayOrderSubmit(uid, 'ordinary', params, remoteIp).then(result => {
157 res.json(result); 157 res.json(result);
158 }).catch(next); 158 }).catch(next);
159 } else { 159 } else {
160 - oeModel.submit(uid, cartType, params, remoteIp).then(data => { 160 + req.ctx(oeModel).submit(uid, cartType, params, remoteIp).then(data => {
161 if (data && data.code === 200 && unionKey) { 161 if (data && data.code === 200 && unionKey) {
162 data.data.unionKey = { 162 data.data.unionKey = {
163 client_id: clientId 163 client_id: clientId
@@ -21,7 +21,7 @@ const ticketEnsure = (req, res, next) => { @@ -21,7 +21,7 @@ const ticketEnsure = (req, res, next) => {
21 let buyNumber = req.query.buyNumber || 0; 21 let buyNumber = req.query.buyNumber || 0;
22 let skn = req.query.productSkn || 0; 22 let skn = req.query.productSkn || 0;
23 23
24 - ticketService.addTicket(uid, sku, buyNumber).then(result => { 24 + req.ctx(ticketService).addTicket(uid, sku, buyNumber).then(result => {
25 let header = headerModel.setSimpleHeaderData() || {}; 25 let header = headerModel.setSimpleHeaderData() || {};
26 26
27 result.stepper = stepper; 27 result.stepper = stepper;
@@ -51,7 +51,7 @@ const ticketSubmit = (req, res, next) => { @@ -51,7 +51,7 @@ const ticketSubmit = (req, res, next) => {
51 }); 51 });
52 } 52 }
53 53
54 - ticketService.submitTicket(uid, sku, count, mobile, yohoCoin).then(result => { 54 + req.ctx(ticketService).submitTicket(uid, sku, count, mobile, yohoCoin).then(result => {
55 return res.json(result); 55 return res.json(result);
56 }).catch(next); 56 }).catch(next);
57 }; 57 };
@@ -62,7 +62,7 @@ const ticketCompute = (req, res, next) => { @@ -62,7 +62,7 @@ const ticketCompute = (req, res, next) => {
62 let buyNumber = req.body.count || 0; 62 let buyNumber = req.body.count || 0;
63 let yohoCoin = req.body.coin || 0; 63 let yohoCoin = req.body.coin || 0;
64 64
65 - ticketService.addTicket(uid, sku, buyNumber, yohoCoin).then(result => { 65 + req.ctx(ticketService).addTicket(uid, sku, buyNumber, yohoCoin).then(result => {
66 if (_.isEmpty(result)) { 66 if (_.isEmpty(result)) {
67 return res.json({ 67 return res.json({
68 code: 401, 68 code: 401,
@@ -5,40 +5,55 @@ @@ -5,40 +5,55 @@
5 */ 5 */
6 'use strict'; 6 'use strict';
7 7
8 -const api = global.yoho.API; 8 +module.exports = class extends global.yoho.BaseModel {
  9 + constructor(ctx) {
  10 + super(ctx);
  11 + }
9 12
10 -/** 13 + /**
11 * 获取用户收货地址列表 14 * 获取用户收货地址列表
12 * @param uid [number] uid 15 * @param uid [number] uid
13 */ 16 */
14 -const getAddressListAsync = (uid) => api.get('', { 17 + getAddressListAsync(uid) {
  18 + let options = {
15 method: 'app.address.gethidden', 19 method: 'app.address.gethidden',
16 uid: uid 20 uid: uid
17 -}, {code: 200}); 21 + };
18 22
19 -/** 23 + return this.get({data: options, param: {
  24 + code: 200
  25 + }});
  26 + }
  27 +
  28 + /**
20 * 省市区列表 29 * 省市区列表
21 * @param id [number] 省市区id 30 * @param id [number] 省市区id
22 */ 31 */
23 -const getAreaListAsync = (id) => {  
24 - return api.get('', { 32 + getAreaListAsync(id) {
  33 + let options = {
25 method: 'app.address.provinces', 34 method: 'app.address.provinces',
26 id: id || 0 35 id: id || 0
27 - });  
28 -}; 36 + };
29 37
30 -/** 38 + return this.get({data: options});
  39 + }
  40 +
  41 + /**
31 * 地址删除 42 * 地址删除
32 * @param uid [number] uid 43 * @param uid [number] uid
33 * @param id [string] address id 44 * @param id [string] address id
34 */ 45 */
35 -const delAddressAsync = (uid, id) => api.get('', { 46 + delAddressAsync(uid, id) {
  47 + let options = {
36 method: 'app.address.del', 48 method: 'app.address.del',
37 uid: uid, 49 uid: uid,
38 id: id 50 id: id
39 -}); 51 + };
40 52
41 -/** 53 + return this.get({data: options});
  54 + }
  55 +
  56 + /**
42 * 新增地址api 57 * 新增地址api
43 * @param uid [Number] 58 * @param uid [Number]
44 * @param consignee [String] 收货人 59 * @param consignee [String] 收货人
@@ -49,7 +64,8 @@ const delAddressAsync = (uid, id) => api.get('', { @@ -49,7 +64,8 @@ const delAddressAsync = (uid, id) => api.get('', {
49 * @param zipCode [String] 邮编 64 * @param zipCode [String] 邮编
50 * @param email [String] 邮箱 65 * @param email [String] 邮箱
51 */ 66 */
52 -const addAddressAsync = (uid, consignee, areaCode, address, mobile, phone, zipCode, email) => api.get('', { 67 + addAddressAsync(uid, consignee, areaCode, address, mobile, phone, zipCode, email) {
  68 + let options = {
53 method: 'app.address.add', 69 method: 'app.address.add',
54 uid: uid, 70 uid: uid,
55 consignee: consignee, 71 consignee: consignee,
@@ -59,9 +75,12 @@ const addAddressAsync = (uid, consignee, areaCode, address, mobile, phone, zipCo @@ -59,9 +75,12 @@ const addAddressAsync = (uid, consignee, areaCode, address, mobile, phone, zipCo
59 phone: phone, 75 phone: phone,
60 zip_code: zipCode, 76 zip_code: zipCode,
61 email: email 77 email: email
62 -}); 78 + };
63 79
64 -/** 80 + return this.get({data: options});
  81 + }
  82 +
  83 + /**
65 * 更新地址地址api 84 * 更新地址地址api
66 * @param uid [Number] 85 * @param uid [Number]
67 * @param id [Number] 地址id 86 * @param id [Number] 地址id
@@ -73,7 +92,8 @@ const addAddressAsync = (uid, consignee, areaCode, address, mobile, phone, zipCo @@ -73,7 +92,8 @@ const addAddressAsync = (uid, consignee, areaCode, address, mobile, phone, zipCo
73 * @param zipCode [String] 邮编 92 * @param zipCode [String] 邮编
74 * @param email [String] 邮箱 93 * @param email [String] 邮箱
75 */ 94 */
76 -const updateAddressAsync = (uid, id, consignee, areaCode, address, mobile, phone, zipCode, email) => api.get('', { 95 + updateAddressAsync(uid, id, consignee, areaCode, address, mobile, phone, zipCode, email) {
  96 + let options = {
77 method: 'app.address.update', 97 method: 'app.address.update',
78 uid: uid, 98 uid: uid,
79 id: id, 99 id: id,
@@ -84,25 +104,23 @@ const updateAddressAsync = (uid, id, consignee, areaCode, address, mobile, phone @@ -84,25 +104,23 @@ const updateAddressAsync = (uid, id, consignee, areaCode, address, mobile, phone
84 phone: phone, 104 phone: phone,
85 zip_code: zipCode, 105 zip_code: zipCode,
86 email: email 106 email: email
87 -}); 107 + };
88 108
89 -/** 109 + return this.get({data: options});
  110 + }
  111 +
  112 + /**
90 * 设置默认地址 113 * 设置默认地址
91 * @param uid [Number] 114 * @param uid [Number]
92 * @param id [Number] 地址id 115 * @param id [Number] 地址id
93 */ 116 */
94 -const setDefaultAddressAsync = (uid, id) => api.get('', { 117 + setDefaultAddressAsync(uid, id) {
  118 + let options = {
95 method: 'app.address.setdefault', 119 method: 'app.address.setdefault',
96 uid: uid, 120 uid: uid,
97 id: id 121 id: id
98 -});  
99 - 122 + };
100 123
101 -module.exports = {  
102 - getAddressListAsync,  
103 - getAreaListAsync,  
104 - delAddressAsync,  
105 - addAddressAsync,  
106 - updateAddressAsync,  
107 - setDefaultAddressAsync 124 + return this.get({data: options});
  125 + }
108 }; 126 };
@@ -10,12 +10,17 @@ const _ = require('lodash'); @@ -10,12 +10,17 @@ const _ = require('lodash');
10 const crypto = global.yoho.crypto; 10 const crypto = global.yoho.crypto;
11 11
12 const pinyin = require('../models/province-pinyin'); 12 const pinyin = require('../models/province-pinyin');
13 -const addressApi = require('../models/address-api'); 13 +const AddressApi = require('../models/address-api');
14 14
15 const worldSort = 'abcdefghijklmnopqrstuvwxyz'; 15 const worldSort = 'abcdefghijklmnopqrstuvwxyz';
16 16
17 -const getAreaListData = (id) => {  
18 - return addressApi.getAreaListAsync(id).then(result => { 17 +module.exports = class extends global.yoho.BaseModel {
  18 + constructor(ctx) {
  19 + super(ctx);
  20 + }
  21 +
  22 + getAreaListData(id) {
  23 + return new AddressApi(this.ctx).getAreaListAsync(id).then(result => {
19 let list = _.get(result, 'data', []); 24 let list = _.get(result, 'data', []);
20 25
21 if (id * 1 === 0 && list.length) { 26 if (id * 1 === 0 && list.length) {
@@ -27,10 +32,10 @@ const getAreaListData = (id) => { @@ -27,10 +32,10 @@ const getAreaListData = (id) => {
27 } 32 }
28 return result; 33 return result;
29 }); 34 });
30 -}; 35 + }
31 36
32 -const getAddressListData = (uid) => {  
33 - return addressApi.getAddressListAsync(uid).then(result => { 37 + getAddressListData(uid) {
  38 + return new AddressApi(this.ctx).getAddressListAsync(uid).then(result => {
34 if (result.code !== 200) { 39 if (result.code !== 200) {
35 return result; 40 return result;
36 } 41 }
@@ -52,22 +57,23 @@ const getAddressListData = (uid) => { @@ -52,22 +57,23 @@ const getAddressListData = (uid) => {
52 57
53 return result; 58 return result;
54 }); 59 });
55 -}; 60 + }
56 61
57 -const delAddressById = (uid, id) => { 62 + delAddressById(uid, id) {
58 id = crypto.decrypt('', `${id}`); 63 id = crypto.decrypt('', `${id}`);
  64 + return new AddressApi(this.ctx).delAddressAsync(uid, id);
  65 + }
59 66
60 - return addressApi.delAddressAsync(uid, id);  
61 -}; 67 + saveAddressData(uid, info) {
  68 + let addressApiModel = new AddressApi(this.ctx);
62 69
63 -const saveAddressData = (uid, info) => {  
64 if (info.id) { 70 if (info.id) {
65 let id = crypto.decrypt('', `${info.id}`); 71 let id = crypto.decrypt('', `${info.id}`);
66 72
67 - return addressApi.updateAddressAsync(uid, id, info.consignee, info.areaCode, info.address, 73 + return addressApiModel.updateAddressAsync(uid, id, info.consignee, info.areaCode, info.address,
68 info.mobile, info.phone, info.zipCode, info.email); 74 info.mobile, info.phone, info.zipCode, info.email);
69 } else { 75 } else {
70 - return addressApi.addAddressAsync(uid, info.consignee, info.areaCode, info.address, info.mobile, 76 + return addressApiModel.addAddressAsync(uid, info.consignee, info.areaCode, info.address, info.mobile,
71 info.phone, info.zipCode, info.email).then(result => { 77 info.phone, info.zipCode, info.email).then(result => {
72 if (result.code === 200) { 78 if (result.code === 200) {
73 let d = result.data; 79 let d = result.data;
@@ -81,18 +87,11 @@ const saveAddressData = (uid, info) => { @@ -81,18 +87,11 @@ const saveAddressData = (uid, info) => {
81 }); 87 });
82 } 88 }
83 89
84 -}; 90 + }
85 91
86 -const setDefaultAddress = (uid, id) => { 92 + setDefaultAddress(uid, id) {
87 id = crypto.decrypt('', `${id}`); 93 id = crypto.decrypt('', `${id}`);
88 94
89 - return addressApi.setDefaultAddressAsync(uid, id);  
90 -};  
91 -  
92 -module.exports = {  
93 - getAreaListData,  
94 - getAddressListData,  
95 - delAddressById,  
96 - saveAddressData,  
97 - setDefaultAddress 95 + return new AddressApi(this.ctx).setDefaultAddressAsync(uid, id);
  96 + }
98 }; 97 };
@@ -5,9 +5,12 @@ @@ -5,9 +5,12 @@
5 */ 5 */
6 'use strict'; 6 'use strict';
7 7
8 -const api = global.yoho.API; 8 +module.exports = class extends global.yoho.BaseModel {
  9 + constructor(ctx) {
  10 + super(ctx);
  11 + }
9 12
10 -const getEasyPaymentAsync = (uid, goods, activity) => { 13 + getEasyPaymentAsync(uid, goods, activity) {
11 let param = { 14 let param = {
12 method: 'app.Shopping.easyPayment', 15 method: 'app.Shopping.easyPayment',
13 uid: uid, 16 uid: uid,
@@ -21,11 +24,10 @@ const getEasyPaymentAsync = (uid, goods, activity) => { @@ -21,11 +24,10 @@ const getEasyPaymentAsync = (uid, goods, activity) => {
21 param.activity_id = activity; 24 param.activity_id = activity;
22 } 25 }
23 26
24 - return api.get('', param, {code: 200});  
25 -};  
26 - 27 + return this.get({data: param});
  28 + }
27 29
28 -/** 30 + /**
29 * 订单计算API 31 * 订单计算API
30 * @param uid [number] uid 32 * @param uid [number] uid
31 * @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售 33 * @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售
@@ -36,9 +38,8 @@ const getEasyPaymentAsync = (uid, goods, activity) => { @@ -36,9 +38,8 @@ const getEasyPaymentAsync = (uid, goods, activity) => {
36 * @param couponCode [string] 优惠券码 38 * @param couponCode [string] 优惠券码
37 * @param promotionCode [string] 优惠码 39 * @param promotionCode [string] 优惠码
38 * @param productSkuList [string] 限购商品 40 * @param productSkuList [string] 限购商品
39 -  
40 */ 41 */
41 -const getEasypayComputeAsync = (uid, cartType, paymentType, deliveryWay, other) => { 42 + getEasypayComputeAsync(uid, cartType, paymentType, deliveryWay, other) {
42 let param = { 43 let param = {
43 method: 'app.Shopping.easyCompute', 44 method: 'app.Shopping.easyCompute',
44 uid: uid, 45 uid: uid,
@@ -84,13 +85,12 @@ const getEasypayComputeAsync = (uid, cartType, paymentType, deliveryWay, other) @@ -84,13 +85,12 @@ const getEasypayComputeAsync = (uid, cartType, paymentType, deliveryWay, other)
84 }); 85 });
85 } 86 }
86 } 87 }
87 -  
88 } 88 }
89 89
90 - return api.get('', param);  
91 -}; 90 + return this.get({data: param});
  91 + }
92 92
93 -/** 93 + /**
94 * 订单提交API 94 * 订单提交API
95 * @param uid [number] uid 95 * @param uid [number] uid
96 * @param cartType [String] 购物车类型,ordinary表示普通, advance表示预售 96 * @param cartType [String] 购物车类型,ordinary表示普通, advance表示预售
@@ -109,7 +109,7 @@ const getEasypayComputeAsync = (uid, cartType, paymentType, deliveryWay, other) @@ -109,7 +109,7 @@ const getEasypayComputeAsync = (uid, cartType, paymentType, deliveryWay, other)
109 * @param couponCode [string] 优惠券码 109 * @param couponCode [string] 优惠券码
110 * @param printPrice [string] 是否打印价格 110 * @param printPrice [string] 是否打印价格
111 */ 111 */
112 -const easypayOrderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliveryWay, paymentType, paymentId, printPrice, other, remoteIp) => { // eslint-disable-line 112 + easypayOrderSubmitAsync(uid, cartType, addressId, deliveryTime, deliveryWay, paymentType, paymentId, printPrice, other, remoteIp) { // eslint-disable-line
113 let param = { 113 let param = {
114 method: 'app.Shopping.easySubmit', 114 method: 'app.Shopping.easySubmit',
115 uid: uid, 115 uid: uid,
@@ -178,13 +178,10 @@ const easypayOrderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliver @@ -178,13 +178,10 @@ const easypayOrderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliver
178 }); 178 });
179 } 179 }
180 180
181 - return api.get('', param, {  
182 - headers: {'X-Forwarded-For': remoteIp || ''}  
183 - });  
184 -};  
185 -  
186 -module.exports = {  
187 - getEasyPaymentAsync,  
188 - getEasypayComputeAsync,  
189 - easypayOrderSubmitAsync 181 + return this.get({data: param, param: {
  182 + headers: {
  183 + 'X-Forwarded-For': remoteIp || ''
  184 + }
  185 + }});
  186 + }
190 }; 187 };
@@ -10,13 +10,18 @@ const _ = require('lodash'); @@ -10,13 +10,18 @@ const _ = require('lodash');
10 const helper = global.yoho.helpers; 10 const helper = global.yoho.helpers;
11 const crypto = global.yoho.crypto; 11 const crypto = global.yoho.crypto;
12 12
13 -const easypayApi = require('./easypay-api');  
14 -const addressApi = require('./address-api');  
15 -const ensureApi = require('./order-ensure-api'); 13 +const EasypayApi = require('./easypay-api');
  14 +const AddressApi = require('./address-api');
  15 +const EnsureApi = require('./order-ensure-api');
16 16
17 -const ensureHandle = require('./order-ensure-handle'); 17 +const EnsureHandle = require('./order-ensure-handle');
18 18
19 -const _getLimitProductData = (params) => { 19 +module.exports = class extends global.yoho.BaseModel {
  20 + constructor(ctx) {
  21 + super(ctx);
  22 + }
  23 +
  24 + _getLimitProductData(params) {
20 let resList = []; 25 let resList = [];
21 26
22 if (params.limitcode && params.sku && params.skn) { 27 if (params.limitcode && params.sku && params.skn) {
@@ -40,25 +45,25 @@ const _getLimitProductData = (params) => { @@ -40,25 +45,25 @@ const _getLimitProductData = (params) => {
40 } 45 }
41 46
42 return resList.length ? JSON.stringify(resList) : false; 47 return resList.length ? JSON.stringify(resList) : false;
43 -}; 48 + }
44 49
45 -// 获取结算信息  
46 -const getEasypayOrderData = (params, uid) => { 50 + // 获取结算信息
  51 + getEasypayOrderData(params, uid) {
47 let resData = {}; 52 let resData = {};
48 - let strInfo = _getLimitProductData(params); 53 + let strInfo = this._getLimitProductData(params);
49 let bundle = params.bundle ? parseInt(params.bundle, 10) : false; 54 let bundle = params.bundle ? parseInt(params.bundle, 10) : false;
50 55
51 return Promise.all([ 56 return Promise.all([
52 - easypayApi.getEasyPaymentAsync(uid, strInfo, bundle),  
53 - addressApi.getAddressListAsync(uid),  
54 - ensureApi.getUserProfileAsync(uid) 57 + new EasypayApi(this.ctx).getEasyPaymentAsync(uid, strInfo, bundle),
  58 + new AddressApi(this.ctx).getAddressListAsync(uid),
  59 + new EnsureApi(this.ctx).getUserProfileAsync(uid)
55 ]).then(result => { 60 ]).then(result => {
56 let data = _.get(result, '[0].data', false); 61 let data = _.get(result, '[0].data', false);
57 let address = _.get(result, '[1].data', []); 62 let address = _.get(result, '[1].data', []);
58 let receiver = _.get(result, '[2].data.mobile', ''); 63 let receiver = _.get(result, '[2].data.mobile', '');
59 64
60 if (data) { 65 if (data) {
61 - Object.assign(resData, ensureHandle.handlePaymentInfo(data, address), { 66 + Object.assign(resData, new EnsureHandle(this.ctx).handlePaymentInfo(data, address), {
62 receiverMobile: receiver, 67 receiverMobile: receiver,
63 hideReceiverMobile: _.replace(receiver, /(\d{3})\d{4}(\d{4,9})/, '$1****$2') 68 hideReceiverMobile: _.replace(receiver, /(\d{3})\d{4}(\d{4,9})/, '$1****$2')
64 }); 69 });
@@ -66,35 +71,40 @@ const getEasypayOrderData = (params, uid) => { @@ -66,35 +71,40 @@ const getEasypayOrderData = (params, uid) => {
66 71
67 return resData; 72 return resData;
68 }); 73 });
69 -}; 74 + }
70 75
71 -// 价格计算  
72 -const getOrderComputeData = (uid, cartType, params) => {  
73 - params.productSkuList = _getLimitProductData(params); 76 + // 价格计算
  77 + getOrderComputeData(uid, cartType, params) {
  78 + params.productSkuList = this._getLimitProductData(params);
74 79
75 - return easypayApi.getEasypayComputeAsync(uid, cartType, params.paymentType, params.deliveryWay, params).then(result => { // eslint-disable-line 80 + return new EasypayApi(this.ctx).getEasypayComputeAsync(uid, cartType, params.paymentType, params.deliveryWay, params).then(result => { // eslint-disable-line
76 if (result.code === 200) { 81 if (result.code === 200) {
  82 + let ensureHandleModel = new EnsureHandle(this.ctx);
  83 +
77 if (_.has(result, 'data.last_order_amount')) { 84 if (_.has(result, 'data.last_order_amount')) {
78 result.data.last_order_amount = (result.data.last_order_amount).toFixed(2); 85 result.data.last_order_amount = (result.data.last_order_amount).toFixed(2);
79 } 86 }
80 87
81 if (_.has(result, 'data.promotion_formula_list')) { 88 if (_.has(result, 'data.promotion_formula_list')) {
82 - ensureHandle.handleViewPrice(result.data.promotion_formula_list); 89 + ensureHandleModel.handleViewPrice(result.data.promotion_formula_list);
83 } 90 }
84 91
85 - result.data = Object.assign(result.data, ensureHandle.handleUseYohoCoin(result.data)); 92 + result.data = Object.assign(result.data, ensureHandleModel.handleUseYohoCoin(result.data));
86 } 93 }
87 return result; 94 return result;
88 }); 95 });
89 -}; 96 + }
90 97
91 -// 订单提交  
92 -const easypayOrderSubmit = (uid, cartType, params, remoteIp) => { 98 + // 订单提交
  99 + easypayOrderSubmit(uid, cartType, params, remoteIp) {
93 params.addressId = crypto.decrypt('', params.addressId); 100 params.addressId = crypto.decrypt('', params.addressId);
94 - params.productSkuList = _getLimitProductData(params); 101 + params.productSkuList = this._getLimitProductData(params);
95 102
96 - return easypayApi.easypayOrderSubmitAsync(uid, cartType, params.addressId, params.deliveryTime,  
97 - params.deliveryWay, params.paymentType, params.paymentId, params.printPrice, params, remoteIp).then(result => { 103 + return new EasypayApi(this.ctx).easypayOrderSubmitAsync(
  104 + uid, cartType, params.addressId, params.deliveryTime,
  105 + params.deliveryWay, params.paymentType, params.paymentId,
  106 + params.printPrice, params, remoteIp
  107 + ).then(result => {
98 if (result.code === 200) { 108 if (result.code === 200) {
99 let d = result.data; 109 let d = result.data;
100 110
@@ -103,12 +113,6 @@ const easypayOrderSubmit = (uid, cartType, params, remoteIp) => { @@ -103,12 +113,6 @@ const easypayOrderSubmit = (uid, cartType, params, remoteIp) => {
103 }); 113 });
104 } 114 }
105 return result; 115 return result;
  116 + });
106 } 117 }
107 - );  
108 -};  
109 -  
110 -module.exports = {  
111 - getEasypayOrderData,  
112 - getOrderComputeData,  
113 - easypayOrderSubmit  
114 }; 118 };
@@ -5,52 +5,71 @@ @@ -5,52 +5,71 @@
5 */ 5 */
6 'use strict'; 6 'use strict';
7 7
8 -const api = global.yoho.API; 8 +module.exports = class extends global.yoho.BaseModel {
  9 + constructor(ctx) {
  10 + super(ctx);
  11 + }
9 12
10 -/** 13 + /**
11 * 获取用户信息API 14 * 获取用户信息API
12 * @param uid [number] uid 15 * @param uid [number] uid
13 */ 16 */
14 -const getUserProfileAsync = (uid) => api.get('', { 17 + getUserProfileAsync(uid) {
  18 + let options = {
15 method: 'app.passport.profile', 19 method: 'app.passport.profile',
16 uid: uid 20 uid: uid
17 -}); 21 + };
18 22
19 -/** 23 + return this.get({data: options});
  24 + }
  25 +
  26 + /**
20 * 购物车结算API 27 * 购物车结算API
21 * @param uid [number] uid 28 * @param uid [number] uid
22 * @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售 29 * @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售
23 * @param yohoCoinMode [number] 是否使用yoho币,1使用,0不使用 30 * @param yohoCoinMode [number] 是否使用yoho币,1使用,0不使用
24 */ 31 */
25 -const getOrderPaymentAsync = (uid, cartType, yohoCoinMode) => api.get('', { 32 + getOrderPaymentAsync(uid, cartType, yohoCoinMode) {
  33 + let options = {
26 method: 'app.Shopping.payment', 34 method: 'app.Shopping.payment',
27 cart_type: cartType, 35 cart_type: cartType,
28 yoho_coin_mode: yohoCoinMode, 36 yoho_coin_mode: yohoCoinMode,
29 uid: uid 37 uid: uid
30 -}); 38 + };
31 39
32 -/** 40 + return this.get({data: options});
  41 + }
  42 +
  43 + /**
33 * 获取用户优惠券信息API 44 * 获取用户优惠券信息API
34 * @param uid [number] uid 45 * @param uid [number] uid
35 */ 46 */
36 -const getUesrCouponAsync = (uid) => api.get('', { 47 + getUesrCouponAsync(uid) {
  48 + let options = {
37 method: 'app.Shopping.listCoupon', 49 method: 'app.Shopping.listCoupon',
38 uid: uid, 50 uid: uid,
39 is_group_frees: 'Y' 51 is_group_frees: 'Y'
40 -}); 52 + };
41 53
42 -/** 54 + return this.get({data: options});
  55 + }
  56 +
  57 + /**
43 * 优惠码兑换优惠券API 58 * 优惠码兑换优惠券API
44 * @param uid [number] uid 59 * @param uid [number] uid
45 * @param code [number] code 60 * @param code [number] code
46 */ 61 */
47 -const getCouponByCodeAsync = (uid, code) => api.get('', { 62 + getCouponByCodeAsync(uid, code) {
  63 + let options = {
48 method: 'app.Shopping.useCoupon', 64 method: 'app.Shopping.useCoupon',
49 uid: uid, 65 uid: uid,
50 coupon_code: code 66 coupon_code: code
51 -}); 67 + };
52 68
53 -/** 69 + return this.get({data: options});
  70 + }
  71 +
  72 + /**
54 * 订单计算API 73 * 订单计算API
55 * @param uid [number] uid 74 * @param uid [number] uid
56 * @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售 75 * @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售
@@ -61,7 +80,7 @@ const getCouponByCodeAsync = (uid, code) => api.get('', { @@ -61,7 +80,7 @@ const getCouponByCodeAsync = (uid, code) => api.get('', {
61 * @param couponCode [string] 优惠券码 80 * @param couponCode [string] 优惠券码
62 * @param promotionCode [string] 优惠码 81 * @param promotionCode [string] 优惠码
63 */ 82 */
64 -const getOrderComputeAsync = (uid, cartType, paymentType, deliveryWay, other) => { 83 + getOrderComputeAsync(uid, cartType, paymentType, deliveryWay, other) {
65 let param = { 84 let param = {
66 method: 'app.Shopping.compute', 85 method: 'app.Shopping.compute',
67 uid: uid, 86 uid: uid,
@@ -95,10 +114,10 @@ const getOrderComputeAsync = (uid, cartType, paymentType, deliveryWay, other) => @@ -95,10 +114,10 @@ const getOrderComputeAsync = (uid, cartType, paymentType, deliveryWay, other) =>
95 } 114 }
96 } 115 }
97 116
98 - return api.get('', param);  
99 -}; 117 + return this.get({data: param});
  118 + }
100 119
101 -/** 120 + /**
102 * 订单提交API 121 * 订单提交API
103 * @param uid [number] uid 122 * @param uid [number] uid
104 * @param cartType [String] 购物车类型,ordinary表示普通, advance表示预售 123 * @param cartType [String] 购物车类型,ordinary表示普通, advance表示预售
@@ -117,7 +136,7 @@ const getOrderComputeAsync = (uid, cartType, paymentType, deliveryWay, other) => @@ -117,7 +136,7 @@ const getOrderComputeAsync = (uid, cartType, paymentType, deliveryWay, other) =>
117 * @param couponCode [string] 优惠券码 136 * @param couponCode [string] 优惠券码
118 * @param printPrice [string] 是否打印价格 137 * @param printPrice [string] 是否打印价格
119 */ 138 */
120 -const orderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliveryWay, paymentType, paymentId, printPrice, other, remoteIp) => { // eslint-disable-line 139 + orderSubmitAsync(uid, cartType, addressId, deliveryTime, deliveryWay, paymentType, paymentId, printPrice, other, remoteIp) { // eslint-disable-line
121 let param = { 140 let param = {
122 method: 'app.Shopping.submit', 141 method: 'app.Shopping.submit',
123 uid: uid, 142 uid: uid,
@@ -194,19 +213,12 @@ const orderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliveryWay, p @@ -194,19 +213,12 @@ const orderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliveryWay, p
194 }); 213 });
195 } 214 }
196 215
197 - return api.get('', param, { 216 + return this.get({data: param, param: {
198 headers: { 217 headers: {
199 'X-Forwarded-For': remoteIp || '', 218 'X-Forwarded-For': remoteIp || '',
200 'User-Agent': other.userAgent || '' 219 'User-Agent': other.userAgent || ''
201 } 220 }
202 - }); 221 + }});
  222 + }
203 }; 223 };
204 224
205 -module.exports = {  
206 - getUserProfileAsync,  
207 - getOrderPaymentAsync,  
208 - getUesrCouponAsync,  
209 - getCouponByCodeAsync,  
210 - getOrderComputeAsync,  
211 - orderSubmitAsync  
212 -};  
@@ -6,11 +6,15 @@ @@ -6,11 +6,15 @@
6 'use strict'; 6 'use strict';
7 7
8 const _ = require('lodash'); 8 const _ = require('lodash');
9 -  
10 const helper = global.yoho.helpers; 9 const helper = global.yoho.helpers;
11 const crypto = global.yoho.crypto; 10 const crypto = global.yoho.crypto;
12 11
13 -const handleViewPrice = list => { 12 +module.exports = class extends global.yoho.BaseModel {
  13 + constructor(ctx) {
  14 + super(ctx);
  15 + }
  16 +
  17 + handleViewPrice(list) {
14 if (list) { 18 if (list) {
15 _.forEach(list, val => { 19 _.forEach(list, val => {
16 if (val.promotion === '商品金额') { 20 if (val.promotion === '商品金额') {
@@ -22,9 +26,9 @@ const handleViewPrice = list => { @@ -22,9 +26,9 @@ const handleViewPrice = list => {
22 } 26 }
23 }); 27 });
24 } 28 }
25 -}; 29 + }
26 30
27 -const handleUseYohoCoin = (info) => { 31 + handleUseYohoCoin(info) {
28 let resData = {}; 32 let resData = {};
29 let limitCoin = _.get(info, 'yoho_coin_pay_rule.num_limit', 0); 33 let limitCoin = _.get(info, 'yoho_coin_pay_rule.num_limit', 0);
30 34
@@ -52,9 +56,9 @@ const handleUseYohoCoin = (info) => { @@ -52,9 +56,9 @@ const handleUseYohoCoin = (info) => {
52 } 56 }
53 57
54 return resData; 58 return resData;
55 -}; 59 + }
56 60
57 -const handlePaymentInfo = (d, address) => { 61 + handlePaymentInfo(d, address) {
58 let resData = {}; 62 let resData = {};
59 let defAddrId = _.get(d, 'delivery_address.address_id', 0); 63 let defAddrId = _.get(d, 'delivery_address.address_id', 0);
60 64
@@ -101,14 +105,14 @@ const handlePaymentInfo = (d, address) => { @@ -101,14 +105,14 @@ const handlePaymentInfo = (d, address) => {
101 resData.goodsList = d.goods_list; 105 resData.goodsList = d.goods_list;
102 106
103 if (d.shopping_cart_data && d.shopping_cart_data.promotion_formula_list) { 107 if (d.shopping_cart_data && d.shopping_cart_data.promotion_formula_list) {
104 - handleViewPrice(d.shopping_cart_data.promotion_formula_list); 108 + this.handleViewPrice(d.shopping_cart_data.promotion_formula_list);
105 } 109 }
106 110
107 Object.assign(resData, { 111 Object.assign(resData, {
108 paymentWay: d.payment_way, 112 paymentWay: d.payment_way,
109 deliveryTime: d.delivery_time, 113 deliveryTime: d.delivery_time,
110 deliveryWay: d.delivery_way, 114 deliveryWay: d.delivery_way,
111 - shoppingCartData: Object.assign(d.shopping_cart_data, handleUseYohoCoin(d), { 115 + shoppingCartData: Object.assign(d.shopping_cart_data, this.handleUseYohoCoin(d), {
112 redEnvelopes: d.red_envelopes, 116 redEnvelopes: d.red_envelopes,
113 useRedEnvelopes: d.use_red_envelopes 117 useRedEnvelopes: d.use_red_envelopes
114 }), 118 }),
@@ -116,11 +120,5 @@ const handlePaymentInfo = (d, address) => { @@ -116,11 +120,5 @@ const handlePaymentInfo = (d, address) => {
116 }); 120 });
117 121
118 return resData; 122 return resData;
119 -};  
120 -  
121 -  
122 -module.exports = {  
123 - handleViewPrice,  
124 - handleUseYohoCoin,  
125 - handlePaymentInfo 123 + }
126 }; 124 };
@@ -6,33 +6,35 @@ @@ -6,33 +6,35 @@
6 'use strict'; 6 'use strict';
7 7
8 const _ = require('lodash'); 8 const _ = require('lodash');
9 -  
10 -// const api = global.yoho.API;  
11 const helper = global.yoho.helpers; 9 const helper = global.yoho.helpers;
12 -  
13 const crypto = global.yoho.crypto; 10 const crypto = global.yoho.crypto;
14 11
15 -// const config = global.yoho.config;  
16 -  
17 -const ensureApi = require('./order-ensure-api');  
18 -const addressApi = require('./address-api'); 12 +const EnsureApi = require('./order-ensure-api');
  13 +const AddressApi = require('./address-api');
  14 +const EnsureHandle = require('./order-ensure-handle');
19 15
20 -const ensureHandle = require('./order-ensure-handle'); 16 +module.exports = class extends global.yoho.BaseModel {
  17 + constructor(ctx) {
  18 + super(ctx);
  19 + }
21 20
22 -const index = (uid, cartType) => { 21 + index(uid, cartType) {
23 let resData = {}; 22 let resData = {};
  23 + let addressApiModel = new AddressApi(this.ctx);
  24 + let ensureApiModel = new EnsureApi(this.ctx);
  25 + let ensureHandleModel = new EnsureHandle(this.ctx);
24 26
25 return Promise.all([ 27 return Promise.all([
26 - ensureApi.getOrderPaymentAsync(uid, cartType, 0),  
27 - addressApi.getAddressListAsync(uid),  
28 - ensureApi.getUserProfileAsync(uid) 28 + ensureApiModel.getOrderPaymentAsync(uid, cartType, 0),
  29 + addressApiModel.getAddressListAsync(uid),
  30 + ensureApiModel.getUserProfileAsync(uid)
29 ]).then(result => { 31 ]).then(result => {
30 let data = _.get(result, '[0].data', false); 32 let data = _.get(result, '[0].data', false);
31 let address = _.get(result, '[1].data', []); 33 let address = _.get(result, '[1].data', []);
32 let receiver = _.get(result, '[2].data.mobile', ''); 34 let receiver = _.get(result, '[2].data.mobile', '');
33 35
34 if (data) { 36 if (data) {
35 - Object.assign(resData, ensureHandle.handlePaymentInfo(data, address), { 37 + Object.assign(resData, ensureHandleModel.handlePaymentInfo(data, address), {
36 receiverMobile: receiver, 38 receiverMobile: receiver,
37 hideReceiverMobile: _.replace(receiver, /(\d{3})\d{4}(\d{4,9})/, '$1****$2') 39 hideReceiverMobile: _.replace(receiver, /(\d{3})\d{4}(\d{4,9})/, '$1****$2')
38 }); 40 });
@@ -40,43 +42,49 @@ const index = (uid, cartType) => { @@ -40,43 +42,49 @@ const index = (uid, cartType) => {
40 42
41 return resData; 43 return resData;
42 }); 44 });
43 -}; 45 + }
44 46
45 -// 获取优惠券列表  
46 -const getCoupons = (uid) => ensureApi.getUesrCouponAsync(uid).then(result => { 47 + // 获取优惠券列表
  48 + getCoupons(uid) {
  49 + return new EnsureApi(this.ctx).getUesrCouponAsync(uid).then(result => {
47 if (_.isEmpty(_.get(result, 'data.usable_coupons', [])) && 50 if (_.isEmpty(_.get(result, 'data.usable_coupons', [])) &&
48 _.isEmpty(_.get(result, 'data.usable_frees_coupons', []))) { 51 _.isEmpty(_.get(result, 'data.usable_frees_coupons', []))) {
49 _.set(result, 'data.emptyUsable', true); 52 _.set(result, 'data.emptyUsable', true);
50 } 53 }
51 -  
52 return result; 54 return result;
53 -});  
54 -  
55 -// 兑换优惠券  
56 -const convertCoupons = (uid, code) => ensureApi.getCouponByCodeAsync(uid, code); 55 + });
  56 + }
57 57
  58 + // 兑换优惠券
  59 + convertCoupons(uid, code) {
  60 + return new EnsureApi(this.ctx).getCouponByCodeAsync(uid, code);
  61 + }
58 62
59 -// 订单计算  
60 -const compute = (uid, cartType, pa) => {  
61 - return ensureApi.getOrderComputeAsync(uid, cartType, pa.paymentType, pa.deliveryWay, pa).then(result => { 63 + // 订单计算
  64 + compute(uid, cartType, pa) {
  65 + return new EnsureApi(this.ctx).getOrderComputeAsync(
  66 + uid, cartType, pa.paymentType, pa.deliveryWay, pa
  67 + ).then(result => {
62 if (result.code === 200) { 68 if (result.code === 200) {
  69 + let ensureHandleModel = new EnsureHandle(this.ctx);
  70 +
63 if (_.has(result, 'data.last_order_amount')) { 71 if (_.has(result, 'data.last_order_amount')) {
64 result.data.last_order_amount = (result.data.last_order_amount).toFixed(2); 72 result.data.last_order_amount = (result.data.last_order_amount).toFixed(2);
65 } 73 }
66 74
67 if (_.has(result, 'data.promotion_formula_list')) { 75 if (_.has(result, 'data.promotion_formula_list')) {
68 - ensureHandle.handleViewPrice(result.data.promotion_formula_list); 76 + ensureHandleModel.handleViewPrice(result.data.promotion_formula_list);
69 } 77 }
70 78
71 - result.data = Object.assign(result.data, ensureHandle.handleUseYohoCoin(result.data)); 79 + result.data = Object.assign(result.data, ensureHandleModel.handleUseYohoCoin(result.data));
72 } 80 }
73 81
74 return result; 82 return result;
75 }); 83 });
76 -}; 84 + }
77 85
78 -// 订单提交  
79 -const submit = (uid, cartType, p, remoteIp) => { 86 + // 订单提交
  87 + submit(uid, cartType, p, remoteIp) {
80 if (p.addressId) { 88 if (p.addressId) {
81 p.addressId = crypto.decrypt('', `${p.addressId}`); 89 p.addressId = crypto.decrypt('', `${p.addressId}`);
82 } 90 }
@@ -90,7 +98,7 @@ const submit = (uid, cartType, p, remoteIp) => { @@ -90,7 +98,7 @@ const submit = (uid, cartType, p, remoteIp) => {
90 }); 98 });
91 } 99 }
92 100
93 - return ensureApi.orderSubmitAsync(uid, cartType, p.addressId, p.deliveryTime, 101 + return new EnsureApi(this.ctx).orderSubmitAsync(uid, cartType, p.addressId, p.deliveryTime,
94 p.deliveryWay, p.paymentType, p.paymentId, p.printPrice, p, remoteIp).then(result => { 102 p.deliveryWay, p.paymentType, p.paymentId, p.printPrice, p, remoteIp).then(result => {
95 if (result.code === 200) { 103 if (result.code === 200) {
96 let d = result.data; 104 let d = result.data;
@@ -103,12 +111,5 @@ const submit = (uid, cartType, p, remoteIp) => { @@ -103,12 +111,5 @@ const submit = (uid, cartType, p, remoteIp) => {
103 return result; 111 return result;
104 } 112 }
105 ); 113 );
106 -};  
107 -  
108 -module.exports = {  
109 - index,  
110 - getCoupons,  
111 - convertCoupons,  
112 - compute,  
113 - submit 114 + }
114 }; 115 };
@@ -2,9 +2,12 @@ @@ -2,9 +2,12 @@
2 * Created by TaoHuang on 2017/6/22. 2 * Created by TaoHuang on 2017/6/22.
3 */ 3 */
4 4
5 -const api = global.yoho.API; 5 +module.exports = class extends global.yoho.BaseModel {
  6 + constructor(ctx) {
  7 + super(ctx);
  8 + }
6 9
7 -/** 10 + /**
8 * 电子票下单 11 * 电子票下单
9 * @param uid 用户id 12 * @param uid 用户id
10 * @param sku 商品sku 13 * @param sku 商品sku
@@ -12,7 +15,7 @@ const api = global.yoho.API; @@ -12,7 +15,7 @@ const api = global.yoho.API;
12 * @param mobile 手机号码 15 * @param mobile 手机号码
13 * @param yohoCoin 有货币 16 * @param yohoCoin 有货币
14 */ 17 */
15 -function submit(uid, sku, count, mobile, yohoCoin) { 18 + submit(uid, sku, count, mobile, yohoCoin) {
16 let params = { 19 let params = {
17 method: 'app.shopping.submitTicket', 20 method: 'app.shopping.submitTicket',
18 uid, 21 uid,
@@ -25,17 +28,17 @@ function submit(uid, sku, count, mobile, yohoCoin) { @@ -25,17 +28,17 @@ function submit(uid, sku, count, mobile, yohoCoin) {
25 params.use_yoho_coin = yohoCoin / 100; 28 params.use_yoho_coin = yohoCoin / 100;
26 } 29 }
27 30
28 - return api.get('', params);  
29 -} 31 + return this.get({data: params});
  32 + }
30 33
31 -/** 34 + /**
32 * 电子票添加和查询 35 * 电子票添加和查询
33 * @param uid 用户 id 36 * @param uid 用户 id
34 * @param sku 商品sku 37 * @param sku 商品sku
35 * @param count 购买数量 1-4 38 * @param count 购买数量 1-4
36 * @param yohoCoin 有货币 39 * @param yohoCoin 有货币
37 */ 40 */
38 -function add(uid, sku, count, yohoCoin) { 41 + add(uid, sku, count, yohoCoin) {
39 let params = { 42 let params = {
40 method: 'app.shopping.ticket', 43 method: 'app.shopping.ticket',
41 uid, 44 uid,
@@ -47,10 +50,6 @@ function add(uid, sku, count, yohoCoin) { @@ -47,10 +50,6 @@ function add(uid, sku, count, yohoCoin) {
47 params.use_yoho_coin = yohoCoin / 100; 50 params.use_yoho_coin = yohoCoin / 100;
48 } 51 }
49 52
50 - return api.get('', params);  
51 -}  
52 -  
53 -module.exports = {  
54 - submit,  
55 - add 53 + return this.get({data: params});
  54 + }
56 }; 55 };
@@ -2,27 +2,30 @@ @@ -2,27 +2,30 @@
2 * Created by TaoHuang on 2017/6/22. 2 * Created by TaoHuang on 2017/6/22.
3 */ 3 */
4 4
5 -const api = require('./ticket-api');  
6 -const Promise = require('bluebird');  
7 -const co = Promise.coroutine; 5 +const TicketApi = require('./ticket-api');
8 const _ = require('lodash'); 6 const _ = require('lodash');
9 const helpers = global.yoho.helpers; 7 const helpers = global.yoho.helpers;
10 -const _handleUseYhoCoin = require('./order-ensure-handle').handleUseYohoCoin; 8 +const OrderEnsureHandle = require('./order-ensure-handle');
11 9
12 -function _handleGoodsList(list) { 10 +module.exports = class extends global.yoho.BaseModel {
  11 + constructor(ctx) {
  12 + super(ctx);
  13 + }
  14 +
  15 + _handleGoodsList(list) {
13 return list.map((i) => { 16 return list.map((i) => {
14 i.linkToGoods = helpers.getUrlBySkc(i.product_skn); 17 i.linkToGoods = helpers.getUrlBySkc(i.product_skn);
15 i.productPrice = i.sales_price; 18 i.productPrice = i.sales_price;
16 return i; 19 return i;
17 }); 20 });
18 -} 21 + }
19 22
20 -function _handleAmount(info) { 23 + _handleAmount(info) {
21 return _.get(info, 'data.shopping_cart_data.last_order_amount', 0); 24 return _.get(info, 'data.shopping_cart_data.last_order_amount', 0);
22 -} 25 + }
23 26
24 -const addTicket = co(function * (uid, sku, count, yohoCoin) {  
25 - let ticketInfo = yield api.add(uid, sku, count, yohoCoin); 27 + addTicket(uid, sku, count, yohoCoin) {
  28 + return new TicketApi(this.ctx).add(uid, sku, count, yohoCoin).then(ticketInfo => {
26 let result = {}; 29 let result = {};
27 30
28 if (_.isEmpty(ticketInfo)) { 31 if (_.isEmpty(ticketInfo)) {
@@ -40,16 +43,19 @@ const addTicket = co(function * (uid, sku, count, yohoCoin) { @@ -40,16 +43,19 @@ const addTicket = co(function * (uid, sku, count, yohoCoin) {
40 } 43 }
41 44
42 result.virtualGood = true; 45 result.virtualGood = true;
43 - result.goodsList = _handleGoodsList(_.get(ticketInfo, 'data.goods_list', []));  
44 - result.last_order_amount = _handleAmount(ticketInfo);  
45 - Object.assign(result, _handleUseYhoCoin(_.get(ticketInfo, 'data.shopping_cart_data', {}))); 46 + result.goodsList = this._handleGoodsList(_.get(ticketInfo, 'data.goods_list', []));
  47 + result.last_order_amount = this._handleAmount(ticketInfo);
46 48
47 - return result;  
48 -}); 49 + Object.assign(result, new OrderEnsureHandle(this.ctx).handleUseYohoCoin(
  50 + _.get(ticketInfo, 'data.shopping_cart_data', {}
  51 + )));
49 52
50 -const submitTicket = co(function * (uid, sku, count, mobile, yohoCoin) {  
51 - let result = yield api.submit(uid, sku, count, mobile, yohoCoin); 53 + return result;
  54 + });
  55 + }
52 56
  57 + submitTicket(uid, sku, count, mobile, yohoCoin) {
  58 + return new TicketApi(this.ctx).submit(uid, sku, count, mobile, yohoCoin).then(result => {
53 if (_.isEmpty(result)) { 59 if (_.isEmpty(result)) {
54 return { 60 return {
55 code: 500, 61 code: 500,
@@ -73,9 +79,6 @@ const submitTicket = co(function * (uid, sku, count, mobile, yohoCoin) { @@ -73,9 +79,6 @@ const submitTicket = co(function * (uid, sku, count, mobile, yohoCoin) {
73 }) 79 })
74 } 80 }
75 }; 81 };
76 -});  
77 -  
78 -module.exports = {  
79 - addTicket,  
80 - submitTicket 82 + });
  83 + }
81 }; 84 };
@@ -12,7 +12,7 @@ const helpers = global.yoho.helpers; @@ -12,7 +12,7 @@ const helpers = global.yoho.helpers;
12 exports.QRcode = (req, res, next) => { 12 exports.QRcode = (req, res, next) => {
13 let id = req.query.orderCode || 0; 13 let id = req.query.orderCode || 0;
14 14
15 - QRcodeModel.getQRcodeData(id, req.user.uid).then((result)=>{ 15 + req.ctx(QRcodeModel).getQRcodeData(id, req.user.uid).then((result)=>{
16 if (!result) { 16 if (!result) {
17 return next(); 17 return next();
18 } 18 }
@@ -6,14 +6,20 @@ @@ -6,14 +6,20 @@
6 'use strict'; 6 'use strict';
7 7
8 const logger = global.yoho.logger; 8 const logger = global.yoho.logger;
9 -var api = global.yoho.API;  
10 9
11 -exports.getQRcodeData = (id, uid) => {  
12 - return api.get('', { 10 +module.exports = class extends global.yoho.BaseModel {
  11 + constructor(ctx) {
  12 + super(ctx);
  13 + }
  14 +
  15 + getQRcodeData(id, uid) {
  16 + let options = {
13 method: 'app.SpaceOrders.getQrByOrderCode', 17 method: 'app.SpaceOrders.getQrByOrderCode',
14 order_code: id, 18 order_code: id,
15 uid: uid 19 uid: uid
16 - }).then(result => { 20 + };
  21 +
  22 + return this.get({data: options}).then(result => {
17 if (result && result.code === 200) { 23 if (result && result.code === 200) {
18 return result.data; 24 return result.data;
19 } else { 25 } else {
@@ -21,4 +27,5 @@ exports.getQRcodeData = (id, uid) => { @@ -21,4 +27,5 @@ exports.getQRcodeData = (id, uid) => {
21 return false; 27 return false;
22 } 28 }
23 }); 29 });
  30 + }
24 }; 31 };
@@ -183,8 +183,8 @@ exports.isFavoriteBrand = (req, res, next) => { @@ -183,8 +183,8 @@ exports.isFavoriteBrand = (req, res, next) => {
183 return next(); 183 return next();
184 } 184 }
185 185
186 - if (!req.body.brandId || !uid) {  
187 - return res.json({code: 400, message: '用户未登录或缺少参数'}); 186 + if (!req.body.brandId) {
  187 + return res.json({code: 400, message: '缺少参数'});
188 } 188 }
189 189
190 req.ctx(searchApi).isFavoriteBrand(uid, brandId).then(result => { 190 req.ctx(searchApi).isFavoriteBrand(uid, brandId).then(result => {
@@ -207,8 +207,8 @@ exports.shopCouponSync = (req, res, next) => { @@ -207,8 +207,8 @@ exports.shopCouponSync = (req, res, next) => {
207 return next(); 207 return next();
208 } 208 }
209 209
210 - if (!id || !uid) {  
211 - return res.json({code: 400, message: '用户未登录或缺少参数'}); 210 + if (!id) {
  211 + return res.json({code: 400, message: '缺少参数'});
212 } 212 }
213 213
214 req.ctx(list).getUserCoupunStatus(id, uid, 'shop').then(result => { 214 req.ctx(list).getUserCoupunStatus(id, uid, 'shop').then(result => {
@@ -225,7 +225,14 @@ const keyId = (req, res, next) => { @@ -225,7 +225,14 @@ const keyId = (req, res, next) => {
225 title: `${query}价格_图片_品牌_怎么样-YOHO!BUY有货`, 225 title: `${query}价格_图片_品牌_怎么样-YOHO!BUY有货`,
226 keywords: `${query},${query}价格,${query}图片,${query}怎么样,${query}品牌,YOHO!BUY有货`, 226 keywords: `${query},${query}价格,${query}图片,${query}怎么样,${query}品牌,YOHO!BUY有货`,
227 description: `YOHO!BUY有货网yohobuy.com是国内专业的${query}网上潮流购物商城,为您找到${_.get(result, 227 description: `YOHO!BUY有货网yohobuy.com是国内专业的${query}网上潮流购物商城,为您找到${_.get(result,
228 - 'search.totalCount', 0)}${query}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${query},就上YOHO!BUY有货` 228 + 'search.totalCount', 0)}${query}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${query},就上YOHO!BUY有货`,
  229 + pageFooterSeo: {
  230 + description: `YOHO!BUY有货网yohobuy.com是国内专业的<b>${query}</b>网上潮流购物商城,为您找到<b>${_.get(result,
  231 + 'search.totalCount', 0)}</b>条<b>${query}</b>、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买<b>` +
  232 + `${query}</b>,就上YOHO!BUY有货!`,
  233 + queryKey: query,
  234 + wapUrl: helpers.urlFormat(`/chanpin/${id}.html`, null, 'm')
  235 + }
229 }); 236 });
230 237
231 if (!_.get(result, 'search.goods') || !_.get(result, 'search.goods').length) { 238 if (!_.get(result, 'search.goods') || !_.get(result, 'search.goods').length) {
@@ -444,7 +444,15 @@ function getSearchKeywordDataById(id, params, channel) { @@ -444,7 +444,15 @@ function getSearchKeywordDataById(id, params, channel) {
444 }); 444 });
445 }); 445 });
446 446
447 - _.set(resData, 'search.leftContent.allSuggest.list', redisData.data); 447 + let rarr = _.chunk(redisData.data, 12);
  448 +
  449 + if (rarr.length) {
  450 + _.set(resData, 'search.leftContent.allSuggest.list', rarr.shift());
  451 + _.set(resData, 'recommendKeywordsInfo', {
  452 + recommendKeywordsTitle: '更多推荐',
  453 + recommendKeywords: _.concat(...rarr)
  454 + });
  455 + }
448 } 456 }
449 457
450 return resData; 458 return resData;
1 -<div class="product-list-page search-page product-page yoho-page"> 1 +<div class="product-list-page product-search-page product-page yoho-page">
2 {{# search}} 2 {{# search}}
3 3
4 {{> list/list}} 4 {{> list/list}}
@@ -65,17 +65,14 @@ @@ -65,17 +65,14 @@
65 {{> product/left-content}} 65 {{> product/left-content}}
66 </div> 66 </div>
67 <div class="list-right pull-right"> 67 <div class="list-right pull-right">
68 -  
69 {{#if_cond goods.length '<' 20 }} 68 {{#if_cond goods.length '<' 20 }}
70 -  
71 {{#if suggest}} 69 {{#if suggest}}
72 {{#unless changedQuery}} 70 {{#unless changedQuery}}
73 -  
74 <div class="search-suggest-less"> 71 <div class="search-suggest-less">
75 <em>"{{name}}"</em>&nbsp;搜索结果太少了,试试{{#suggest}}&nbsp;"<a href="/?query={{.}}&is_rec=Y">{{.}}</a>"&nbsp;{{/suggest}}关键词搜索 72 <em>"{{name}}"</em>&nbsp;搜索结果太少了,试试{{#suggest}}&nbsp;"<a href="/?query={{.}}&is_rec=Y">{{.}}</a>"&nbsp;{{/suggest}}关键词搜索
76 </div> 73 </div>
77 {{/unless}} 74 {{/unless}}
78 - {{/if}} 75 + {{/if}}
79 {{/if_cond}} 76 {{/if_cond}}
80 77
81 {{#if changedQuery}} 78 {{#if changedQuery}}
@@ -108,10 +105,10 @@ @@ -108,10 +105,10 @@
108 105
109 {{> product/standard-content}} 106 {{> product/standard-content}}
110 107
111 - {{#if @root.search.isSearch}}  
112 -  
113 - {{#if_cond goods.length '<' 20 }} 108 + {{> product/recommend-keywords goodsInfo=@root.recommendKeywordsInfo}}
114 109
  110 + {{#if @root.search.isSearch}}
  111 + {{#if_cond goods.length '<' 20}}
115 <div> 112 <div>
116 <textarea class="lazy-load-object-2" style="visibility: hidden;"> 113 <textarea class="lazy-load-object-2" style="visibility: hidden;">
117 <script>getSearchRecommend();</script> 114 <script>getSearchRecommend();</script>
@@ -125,13 +122,17 @@ @@ -125,13 +122,17 @@
125 <div class="goods-slide"> 122 <div class="goods-slide">
126 <div data-role="recommend-slide" class="slide-panel recommend-slider"></div> 123 <div data-role="recommend-slide" class="slide-panel recommend-slider"></div>
127 </div> 124 </div>
128 -  
129 {{/if_cond}} 125 {{/if_cond}}
130 -  
131 {{/if}} 126 {{/if}}
132 127
133 {{> product/latest-walk}} 128 {{> product/latest-walk}}
134 129
  130 + {{# @root.pageFooterSeo}}
  131 + <div class="page-footer-seo">
  132 + <div>{{{description}}}</div>
  133 + <p class="wap-page-href">移动版:<a href="{{wapUrl}}">{{queryKey}}</a></p>
  134 + </div>
  135 + {{/ @root.pageFooterSeo}}
135 </div> 136 </div>
136 {{/ brandAbout}} 137 {{/ brandAbout}}
137 </div> 138 </div>
1 -{{#if goodsInfo.recommendKeywords}} 1 +{{# goodsInfo}}
  2 + {{#if recommendKeywords}}
2 <div class="recommend-keywords"> 3 <div class="recommend-keywords">
3 - <h3>相关推荐</h3> 4 + <h3>{{#if recommendKeywordsTitle}}{{recommendKeywordsTitle}}{{^}}相关推荐{{/if}}</h3>
4 <p> 5 <p>
5 - {{# goodsInfo.recommendKeywords}} 6 + {{# recommendKeywords}}
6 <a href="{{url}}" title="{{keyword}}" target="_blank" class="keyword">{{keyword}}</a> 7 <a href="{{url}}" title="{{keyword}}" target="_blank" class="keyword">{{keyword}}</a>
7 - {{/ goodsInfo.recommendKeywords}} 8 + {{/ recommendKeywords}}
8 </p> 9 </p>
9 </div> 10 </div>
10 -{{/if}} 11 + {{/if}}
11 12
12 -{{#if goodsInfo.recommendNewProducts}} 13 + {{#if recommendNewProducts}}
13 <div class="recommend-keywords"> 14 <div class="recommend-keywords">
14 <h3>新品推荐</h3> 15 <h3>新品推荐</h3>
15 <p> 16 <p>
16 - {{# goodsInfo.recommendNewProducts}} 17 + {{# recommendNewProducts}}
17 <a href="{{url}}" title="{{name}}" target="_blank" class="common">{{name}}</a> 18 <a href="{{url}}" title="{{name}}" target="_blank" class="common">{{name}}</a>
18 - {{/ goodsInfo.recommendNewProducts}} 19 + {{/ recommendNewProducts}}
19 </p> 20 </p>
20 </div> 21 </div>
21 -{{/if}} 22 + {{/if}}
22 23
23 -{{#if goodsInfo.recommendArticles}} 24 + {{#if recommendArticles}}
24 <div class="recommend-keywords"> 25 <div class="recommend-keywords">
25 <h3>文章推荐</h3> 26 <h3>文章推荐</h3>
26 <p> 27 <p>
27 - {{# goodsInfo.recommendArticles}} 28 + {{# recommendArticles}}
28 <a href="{{url}}" title="{{name}}" target="_blank" class="common">{{name}}</a> 29 <a href="{{url}}" title="{{name}}" target="_blank" class="common">{{name}}</a>
29 - {{/ goodsInfo.recommendArticles}} 30 + {{/ recommendArticles}}
30 </p> 31 </p>
31 </div> 32 </div>
32 -{{/if}} 33 + {{/if}}
  34 +{{/ goodsInfo}}
@@ -168,7 +168,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -168,7 +168,7 @@ module.exports = class extends global.yoho.BaseModel {
168 168
169 if (orderInfo.order_code) { 169 if (orderInfo.order_code) {
170 // 订单处理 170 // 订单处理
171 - if (orderInfo.attribute === 3) { 171 + if (+orderInfo.attribute === 3) {
172 orderInfo.deliveryTimes = '自动发货 - 在您支付成功后,系统将立即为您发放二维码,您可以在您的订单中查看。'; 172 orderInfo.deliveryTimes = '自动发货 - 在您支付成功后,系统将立即为您发放二维码,您可以在您的订单中查看。';
173 } else { 173 } else {
174 orderInfo.deliveryTimes = orderInfo.delivery_time || ''; 174 orderInfo.deliveryTimes = orderInfo.delivery_time || '';
@@ -17,12 +17,12 @@ module.exports = { @@ -17,12 +17,12 @@ module.exports = {
17 cookieDomain: '.yohobuy.com', 17 cookieDomain: '.yohobuy.com',
18 domains: { 18 domains: {
19 // test3 19 // test3
20 - // singleApi: 'http://api-test3.yohops.com:9999/',  
21 - // api: 'http://api-test3.yohops.com:9999/',  
22 - // service: 'http://service-test3.yohops.com:9999/',  
23 - // serviceNotify: 'http://service-test3.yohops.com:9999/',  
24 - // global: 'http://global-test-soa.yohops.com:9999/',  
25 - // platformApi: 'http://192.168.102.48:8088/', 20 + singleApi: 'http://api-test3.yohops.com:9999/',
  21 + api: 'http://api-test3.yohops.com:9999/',
  22 + service: 'http://service-test3.yohops.com:9999/',
  23 + serviceNotify: 'http://service-test3.yohops.com:9999/',
  24 + global: 'http://global-test-soa.yohops.com:9999/',
  25 + platformApi: 'http://192.168.102.48:8088/',
26 26
27 // test2 27 // test2
28 // singleApi: 'http://api-test2.yohops.com:9999/', 28 // singleApi: 'http://api-test2.yohops.com:9999/',
1 { 1 {
2 "name": "yohobuy-node", 2 "name": "yohobuy-node",
3 - "version": "6.0.18", 3 + "version": "6.0.20",
4 "private": true, 4 "private": true,
5 "description": "A New Yohobuy Project With Express", 5 "description": "A New Yohobuy Project With Express",
6 "repository": { 6 "repository": {
@@ -137,7 +137,6 @@ function syncCouponStatus() { @@ -137,7 +137,6 @@ function syncCouponStatus() {
137 for (i = 0; i < info.length; i++) { 137 for (i = 0; i < info.length; i++) {
138 asyncObj[info[i].coupon_id] = info[i]; 138 asyncObj[info[i].coupon_id] = info[i];
139 } 139 }
140 - }  
141 140
142 for (i in couponObj) { 141 for (i in couponObj) {
143 if (couponObj.hasOwnProperty(i)) { 142 if (couponObj.hasOwnProperty(i)) {
@@ -152,6 +151,7 @@ function syncCouponStatus() { @@ -152,6 +151,7 @@ function syncCouponStatus() {
152 } 151 }
153 } 152 }
154 } 153 }
  154 + }
155 }); 155 });
156 } 156 }
157 157
@@ -17,6 +17,60 @@ @@ -17,6 +17,60 @@
17 font-weight: bold; 17 font-weight: bold;
18 } 18 }
19 } 19 }
  20 +
  21 + .recommend-keywords {
  22 + margin-top: 30px;
  23 + margin-bottom: 20px;
  24 + border: 1px #e0e0e0 solid;
  25 +
  26 + h3 {
  27 + height: 46px;
  28 + border-bottom: 1px #e0e0e0 solid;
  29 + line-height: 44px;
  30 + background: #f5f5f5;
  31 + text-align: center;
  32 + font-size: 15px;
  33 + }
  34 +
  35 + p {
  36 + padding: 10px;
  37 +
  38 + .keyword {
  39 + display: inline-block;
  40 + margin: 5px 15px;
  41 + font-size: 12px;
  42 + width: 150px;
  43 + white-space: nowrap;
  44 + overflow: hidden;
  45 + text-overflow: ellipsis;
  46 + }
  47 +
  48 + .common {
  49 + display: inline-block;
  50 + margin: 5px 15px;
  51 + font-size: 12px;
  52 + width: 190px;
  53 + white-space: nowrap;
  54 + overflow: hidden;
  55 + text-overflow: ellipsis;
  56 + }
  57 + }
  58 + }
  59 +
  60 + .page-footer-seo {
  61 + font-size: 13px;
  62 + margin: 30px 0;
  63 +
  64 + b {
  65 + font-weight: bold;
  66 + line-height: 2;
  67 + }
  68 +
  69 + .wap-page-href {
  70 + text-align: right;
  71 + font-weight: bold;
  72 + }
  73 + }
20 } 74 }
21 75
22 .min-screen .product-search-page { 76 .min-screen .product-search-page {