bundle.js
1.51 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
/**
* Created by targaryen on 2016/11/28.
*/
'use strict';
const _ = require('lodash');
const mRoot = '../models';
const headerModel = require('../../../doraemon/models/header');
const bundleModel = require(`${mRoot}/bundle`);
/**
* 套餐详情页
* @param req
* @param res
* @param next
*/
exports.detail = (req, res, next) => {
bundleModel.detail(req.query, req.yoho.isApp).then(result => {
if (!result.bundleDatas) {
return next();
}
if (result.bundleDatas.length <= 3) {
result.any = true;
}
res.render('bundle/detail', Object.assign({
module: 'product',
page: 'bundle',
pageHeader: headerModel.setNav({
navTitle: result.bundleInfo.bundleName,
navBtn: false
}),
localCss: true
}, result));
}).catch(next);
};
/**
* 套餐加入购物车
*/
exports.addToCart = (req, res, next) => {
let shoppingKey = req.cookies._SPK || '';
bundleModel.addToCart({
uid: req.user.uid,
activity_id: req.body.activity_id,
product_sku_list: req.body.product_sku_list,
shopping_key: req.cookies._SPK || '',
userAgent: req.get('User-Agent')
}).then(result => {
if (!shoppingKey && _.has(result, 'data.shopping_key')) {
res.cookie('_SPK', result.data.shopping_key, {
expires: new Date(Date.now() + 86400 * 360)
});
}
return res.json(result);
}).catch(next);
};