BuyNowController.js
4.17 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* @Author: Targaryen
* @Date: 2017-06-21 10:15:38
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-22 15:11:44
*/
const co = require('bluebird').coroutine;
const headerModel = require('../../../doraemon/models/header');
const BuyNowModel = require('../models/BuyNowModel');
const utils = '../../../utils';
const paymentProcess = require(`${utils}/payment-process`);
const logger = global.yoho.logger;
// cookie 参数
const actCkOpthn = {
path: '/cart/index'
};
class BuyNowController {
/**
* 确认订单页面
* @param {*} req
* @param {*} res
* @param {*} next
*/
orderEnsure(req, res, next) {
let orderInfo;
try {
orderInfo = JSON.parse(req.cookies['buynow-order-info']);
} catch (e) {
logger.info(`orderEnsure: get buynow-order-info from cookie error:${JSON.stringify(e)}`);
orderInfo = {};
res.clearCookie('buynow-order-info', actCkOpthn);
}
co(function * () {
let result = yield req.ctx(BuyNowModel).payment({
uid: req.user.uid,
product_sku: req.query.product_sku || '2026740', // TODO
sku_type: req.query.sku_type,
buy_number: req.query.buy_number,
});
let computeData = yield req.ctx(BuyNowModel).compute({
uid: req.user.uid,
product_sku: req.query.product_sku || '2026740', // TODO
sku_type: req.query.sku_type,
buy_number: req.query.buy_number,
use_yoho_coin: parseInt(orderInfo.use_yoho_coin, 10)
});
let headerData = headerModel.setNav({
navTitle: '确认订单',
navBtn: false
});
return res.render('buynow/order-ensure', {
pageHeader: headerData,
module: 'buynow',
page: 'order-ensure',
title: '确认订单',
orderEnsure: paymentProcess.tranformPayment(result.data, orderInfo, null, null, computeData.data)
});
})().catch(next);
}
/**
* 参数更改,重新运算结算数据
* @param {*} req
* @param {*} res
* @param {*} next
*/
orderCompute(req, res, next) {
co(function * () {
let result = yield req.ctx(BuyNowModel).compute({
uid: req.user.uid,
cart_type: req.body.cart_type,
delivery_way: req.body.delivery_way,
payment_type: req.body.payment_type,
product_sku: req.body.product_sku || '2026740', // TODO
coupon_code: req.body.coupon_code,
use_yoho_coin: req.body.use_yoho_coin,
});
result.data.use_yoho_coin = paymentProcess.transPrice(result.data.use_yoho_coin);
result.data.yohoCoinCompute = paymentProcess.yohoCoinCompute(result.data);
return res.json(result.data);
})().catch(next);
}
/**
* 提交订单
* @param {*} req
* @param {*} res
* @param {*} next
*/
orderSub(req, res, next) {
let qhy_union = ''; // TODO
co(function * () {
let result = yield req.ctx(BuyNowModel).submit({
uid: req.user.uid,
cart_type: req.body.cart_type,
address_id: req.body.address_id,
delivery_time: req.body.delivery_time,
delivery_way: req.body.delivery_way,
use_yoho_coin: req.body.use_yoho_coin,
use_red_envelopes: req.body.use_red_envelopes,
payment_id: req.body.payment_id,
payment_type: req.body.payment_type,
product_sku_list: req.body.product_sku_list,
is_print_price: req.body.is_print_price,
qhy_union: qhy_union,
invoices_title: req.body.invoices_title,
invoices_type_id: req.body.invoices_type_id,
remark: req.body.remark,
activity_id: req.body.activity_id
});
return res.json(result);
})().catch(next);
}
}
module.exports = new BuyNowController();