brand-shop.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
'use strict';
const mRoot = '../models';
const brandShopModel = require(`${mRoot}/brand-shop`);
/**
* 品牌店铺获取优惠券信息
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.coupon = (req, res, next) => {
// 测试假数据
// var renderData = {
// module: 'product',
// page: 'brand-shop'
// },
var brandId = req.query.brand_id || 536,
uid = req.user.uid || 0;
// // 测试假数据
// res.render('brand-shop/index', {
// layout:false,
// result: renderData,
// module: 'product',
// page: 'brand-shop'
// }); // 渲染页面
brandShopModel.getBrandIntro({
brand_id: brandId,
uid: uid
}).then((brandIntroData) => {
if (brandIntroData.code === 200) {
// 获取信息成功
}
if (brandIntroData.coupons.length) {
res.render('brand-shop/index', {
layout: false,
result: brandIntroData,
module: 'product',
page: 'brand-shop'
});
}
}).catch(next);
};
/**
* 品牌店铺获取优惠券领取
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.getCoupon = (req, res, next) => {
var uid = req.user.uid || 0,
couponId = req.query.couponId;
// 没有登录情况跳登录页面
if (!uid) {
res.json({
result: {logIn: false}
});
return;
}
brandShopModel.getCoupon({
uid: uid,
couponId: couponId
}).then((couponInfo) => {
if (couponInfo.code === 200) {
// 操作成功
} else if (couponInfo.code === 402) {
// 优惠券不存在
} else if (couponInfo.code === 306) {
// 很抱歉!您的用户身份类型不可使用该券
} else if (couponInfo.code === 401) {
// 优惠券已经领取
} else if (couponInfo.code === 315) {
// 很抱歉!该优惠券未到使用时间或者已过期
}
res.json({
result: couponInfo // 记得更新优惠券状态
});
}).catch(next);
};