ticket.js
2.18 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
/**
* 立即购买controller
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/9/23
*/
'use strict';
const headerModel = require('../../../doraemon/models/simple-header');
const ticketService = require('../models/ticket-service');
const _ = require('lodash');
const helpers = global.yoho.helpers;
const stepper = [
{ name: '填写订单', focus: true },
{ name: '付款,完成购买' }
];
const ticketEnsure = (req, res, next) => {
let uid = req.user.uid;
let sku = req.query.productSku || 0;
let buyNumber = req.query.buyNumber || 0;
let skn = req.query.productSkn || 0;
req.ctx(ticketService).addTicket(uid, sku, buyNumber).then(result => {
let header = headerModel.setSimpleHeaderData() || {};
result.stepper = stepper;
result.productUrl = helpers.getUrlBySkc(skn);
res.render('ticket-ensure', {
title: '填写订单 | ' + (res.locals.title || ''),
page: 'ticket',
content: result,
simpleHeader: header,
pageClass: 'order-easypay-page'
});
}).catch(next);
};
const ticketSubmit = (req, res, next) => {
let uid = req.user.uid;
let sku = req.body.sku || 0;
let count = req.body.count || 0;
let mobile = req.body.mobile || 0;
let yohoCoin = req.body.coin || 0;
if (!sku || !count || !mobile) {
return res.json({
code: 410,
message: '参数错误'
});
}
req.ctx(ticketService).submitTicket(uid, sku, count, mobile, yohoCoin).then(result => {
return res.json(result);
}).catch(next);
};
const ticketCompute = (req, res, next) => {
let uid = req.user.uid;
let sku = req.body.sku || 0;
let buyNumber = req.body.count || 0;
let yohoCoin = req.body.coin || 0;
req.ctx(ticketService).addTicket(uid, sku, buyNumber, yohoCoin).then(result => {
if (_.isEmpty(result)) {
return res.json({
code: 401,
message: '不成功'
});
}
return res.json({
code: 200,
data: result
});
}).catch(next);
};
module.exports = {
ticketSubmit,
ticketEnsure,
ticketCompute
};