order.js
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* 结算页
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/7/13
*/
'use strict';
const _ = require('lodash');
const api = global.yoho.API;
const helper = global.yoho.helpers;
/**
* 结算页面展示
* @param uid 用户id
*/
const _orderApi = uid => api.get('', {
method: 'app.Shopping.payment',
'cart_type': 'ordinary', // eslint-disable-line
'yoho_coin_mode': 0, // eslint-disable-line
uid: uid
});
const index = uid => {
return _orderApi(uid).then(data => {
if (data.code === 200) {
// do data package
let theData = data.data;
let goods = theData.goods_list;
_.forEach(goods, theGoods => {
let splitName = theGoods.product_name.split(' ');
// split brand name form product_name
theGoods.brandName = splitName.shift();
theGoods.name = splitName.join(' ');
// format goods link
theGoods.link = helper.urlFormat(
`/product/pro_${theGoods.product_id}_${theGoods.goods_id}_${theGoods.cn_alphabet}.html`);
// TODO:format brand url
});
theData.yoho_coin *= 100; // 有货币稀释
theData.shopping_cart_data.balanceCoin = (theData.use_yoho_coin * 1).toFixed(2);
return data;
}
return data;
});
};
/**
* 结算
* @param number uid user id
* @param number $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运
* @param int $paymentType 支付方式,1表示在线支付,2表示货到付款
* @param number $yohoCoin 使用的YOHO币数量
* */
const _computeApi = (uid, deliveryWay, paymentType, yohoCoin) => api.get('', {
method: 'app.Shopping.compute',
uid: uid,
delivery_way: deliveryWay,
payment_type: paymentType,
use_yoho_coin: yohoCoin
});
const compute = (uid, yohoCoin) => {
// 目前仅支持普通快递和在线支付
let deliveryWay = 1;
let paymentType = 1;
let coin;
// YOHO币稀释
if (yohoCoin) {
coin = yohoCoin / 100;
}
return _computeApi(uid, deliveryWay, paymentType, coin).then(result => {
console.log(result);
return result;
});
};
module.exports = {
index,
compute
};