Showing
7 changed files
with
93 additions
and
43 deletions
@@ -2,8 +2,6 @@ | @@ -2,8 +2,6 @@ | ||
2 | const mRoot = '../models'; | 2 | const mRoot = '../models'; |
3 | const brandShopModel = require(`${mRoot}/brand-shop`); | 3 | const brandShopModel = require(`${mRoot}/brand-shop`); |
4 | 4 | ||
5 | -const _ = require('lodash'); | ||
6 | - | ||
7 | /** | 5 | /** |
8 | * 品牌店铺获取优惠券信息 | 6 | * 品牌店铺获取优惠券信息 |
9 | * @param {[type]} req [description] | 7 | * @param {[type]} req [description] |
@@ -16,8 +14,8 @@ exports.coupon = (req, res, next) => { | @@ -16,8 +14,8 @@ exports.coupon = (req, res, next) => { | ||
16 | // module: 'product', | 14 | // module: 'product', |
17 | // page: 'brand-shop' | 15 | // page: 'brand-shop' |
18 | // }, | 16 | // }, |
19 | - var brandId = req.query.brand_id, | ||
20 | - uid = _.isEmpty(req.user.uid) ? null : req.user.uid; | 17 | + var brandId = req.query.brand_id || 536, |
18 | + uid = req.user.uid || 0; | ||
21 | 19 | ||
22 | // // 测试假数据 | 20 | // // 测试假数据 |
23 | // res.render('brand-shop/index', { | 21 | // res.render('brand-shop/index', { |
@@ -30,18 +28,19 @@ exports.coupon = (req, res, next) => { | @@ -30,18 +28,19 @@ exports.coupon = (req, res, next) => { | ||
30 | brandShopModel.getBrandIntro({ | 28 | brandShopModel.getBrandIntro({ |
31 | brand_id: brandId, | 29 | brand_id: brandId, |
32 | uid: uid | 30 | uid: uid |
33 | - }).then((preferenceData) => { | 31 | + }).then((brandIntroData) => { |
34 | 32 | ||
35 | - if (preferenceData.code === 200) { | 33 | + if (brandIntroData.code === 200) { |
36 | // 获取信息成功 | 34 | // 获取信息成功 |
37 | } | 35 | } |
38 | - console.log(preferenceData); | ||
39 | - res.render('brand-shop/index', { | ||
40 | - layout: false, | ||
41 | - result: preferenceData, | ||
42 | - module: 'product', | ||
43 | - page: 'brand-shop' | ||
44 | - }); | 36 | + if (brandIntroData.coupons.length) { |
37 | + res.render('brand-shop/index', { | ||
38 | + layout: false, | ||
39 | + result: brandIntroData, | ||
40 | + module: 'product', | ||
41 | + page: 'brand-shop' | ||
42 | + }); | ||
43 | + } | ||
45 | }).catch(next); | 44 | }).catch(next); |
46 | }; | 45 | }; |
47 | 46 | ||
@@ -53,17 +52,17 @@ exports.coupon = (req, res, next) => { | @@ -53,17 +52,17 @@ exports.coupon = (req, res, next) => { | ||
53 | */ | 52 | */ |
54 | exports.getCoupon = (req, res, next) => { | 53 | exports.getCoupon = (req, res, next) => { |
55 | 54 | ||
56 | -// 测试假数据 | ||
57 | - // var couponData = { | ||
58 | - // logIn: true | ||
59 | - // }, | ||
60 | - var uid = _.isEmpty(req.user.uid) ? null : req.user.uid, | ||
61 | - couponId = req.query.couponId ? req.query.couponId : 23121; | 55 | + var uid = req.user.uid || 0, |
56 | + couponId = req.query.couponId; | ||
57 | + | ||
58 | + // 没有登录情况跳登录页面 | ||
59 | + if (!uid) { | ||
60 | + res.json({ | ||
61 | + result: {logIn: false} | ||
62 | + }); | ||
63 | + return; | ||
64 | + } | ||
62 | 65 | ||
63 | - // 测试假数据 | ||
64 | - // res.json({ | ||
65 | - // result: couponData | ||
66 | - // }); | ||
67 | 66 | ||
68 | brandShopModel.getCoupon({ | 67 | brandShopModel.getCoupon({ |
69 | uid: uid, | 68 | uid: uid, |
@@ -3,21 +3,63 @@ | @@ -3,21 +3,63 @@ | ||
3 | var api = global.yoho.API; | 3 | var api = global.yoho.API; |
4 | 4 | ||
5 | const camelCase = global.yoho.camelCase; | 5 | const camelCase = global.yoho.camelCase; |
6 | +const _ = require('lodash'); | ||
6 | 7 | ||
7 | /** | 8 | /** |
8 | - * 分享页面基础参数 | 9 | + * 查询品牌店铺优惠券结果处理 |
9 | * @param {object} sizeInfo [接口原始数据] | 10 | * @param {object} sizeInfo [接口原始数据] |
10 | * @return {object} [description] | 11 | * @return {object} [description] |
11 | */ | 12 | */ |
12 | -// const getPreferenceData = (data) => { | ||
13 | -// var dest = {}; | 13 | +const processBrandCouponData = (data) => { |
14 | + var dest = {}, | ||
15 | + list = data.data || {}, | ||
16 | + distCoupons = []; | ||
14 | 17 | ||
15 | -// let list = data.data || {}; | 18 | + list = camelCase(list); |
19 | + dest.code = data.code; | ||
20 | + _.forEach(list.coupons, function(value) { | ||
16 | 21 | ||
17 | -// list = camelCase(list); | 22 | + if (!value.status) { |
23 | + return; | ||
24 | + } | ||
25 | + let coupon = value; | ||
18 | 26 | ||
19 | -// return dest; | ||
20 | -// }; | 27 | + coupon.money = parseInt(value.money); |
28 | + if (coupon.status === 1) { | ||
29 | + coupon.cooponStateMessage = '可以领取'; | ||
30 | + } else if (coupon.status === 2) { | ||
31 | + coupon.cooponStateMessage = '已抢光'; | ||
32 | + } else if (coupon.status === 3) { | ||
33 | + coupon.cooponStateMessage = '已领取'; | ||
34 | + } | ||
35 | + | ||
36 | + distCoupons.push(coupon); | ||
37 | + distCoupons.push(coupon); | ||
38 | + | ||
39 | + }); | ||
40 | + | ||
41 | + if (distCoupons.length > 1) { | ||
42 | + dest.mutilCoupon = true; | ||
43 | + } | ||
44 | + dest.coupons = distCoupons; | ||
45 | + dest.message = list.message; | ||
46 | + return dest; | ||
47 | +}; | ||
48 | + | ||
49 | + | ||
50 | +/** | ||
51 | + * 领取品牌店铺优惠券 | ||
52 | + * @param {object} sizeInfo [接口原始数据] | ||
53 | + * @return {object} [description] | ||
54 | + */ | ||
55 | +const getBrandCouponStatus = (data) => { | ||
56 | + var dest = {}; | ||
57 | + | ||
58 | + dest.code = data.code; | ||
59 | + dest.message = data.message; | ||
60 | + dest.logIn = true; | ||
61 | + return dest; | ||
62 | +}; | ||
21 | 63 | ||
22 | /** | 64 | /** |
23 | * 获取品牌信息及其优惠券 | 65 | * 获取品牌信息及其优惠券 |
@@ -29,7 +71,7 @@ exports.getBrandIntro = (data) => { | @@ -29,7 +71,7 @@ exports.getBrandIntro = (data) => { | ||
29 | infoData = Object.assign(defaultParam, data); // 处理完成后,发给后端 | 71 | infoData = Object.assign(defaultParam, data); // 处理完成后,发给后端 |
30 | 72 | ||
31 | return api.get('', infoData).then(result => { | 73 | return api.get('', infoData).then(result => { |
32 | - return camelCase(result); | 74 | + return processBrandCouponData(result); |
33 | }); // 所有数据返回一个 Promise,方便 Promise.all 调用 | 75 | }); // 所有数据返回一个 Promise,方便 Promise.all 调用 |
34 | }; | 76 | }; |
35 | 77 | ||
@@ -44,6 +86,6 @@ exports.getCoupon = (data) => { | @@ -44,6 +86,6 @@ exports.getCoupon = (data) => { | ||
44 | infoData = Object.assign(defaultParam, data); // 处理完成后,发给后端 | 86 | infoData = Object.assign(defaultParam, data); // 处理完成后,发给后端 |
45 | 87 | ||
46 | return api.get('', infoData).then(result => { | 88 | return api.get('', infoData).then(result => { |
47 | - return camelCase(result); | 89 | + return getBrandCouponStatus(result); |
48 | }); // 所有数据返回一个 Promise,方便 Promise.all 调用 | 90 | }); // 所有数据返回一个 Promise,方便 Promise.all 调用 |
49 | }; | 91 | }; |
1 | {{# result}} | 1 | {{# result}} |
2 | <div class="brand-shop-page"> | 2 | <div class="brand-shop-page"> |
3 | <div class="big-coupon-constainer"> | 3 | <div class="big-coupon-constainer"> |
4 | - <div class="coupon-containter mutil-coupon"> | ||
5 | - <img src="../../../../../public/img/coupon/coupon-footer.png"> | ||
6 | - </div> | ||
7 | 4 | ||
8 | - | ||
9 | - <div class="coupon-containter mutil-coupon"> | ||
10 | - <img src="../../../../../public/img/coupon/coupon-footer.png"> | ||
11 | - </div> | ||
12 | - | ||
13 | - <div class="coupon-containter mutil-coupon"> | ||
14 | - <img src="../../../../../public/img/coupon/coupon-footer.png"> | ||
15 | - </div> | 5 | + {{#if mutilCoupon}} |
6 | + {{# coupons}} | ||
7 | + <div class="coupon-containter-multi" value="{{couponId}}"> | ||
8 | + <div class="money-icon">¥</div> | ||
9 | + <div class="money-value">{{money}}</div> | ||
10 | + <div class="coupon-name">{{couponName}}</div> | ||
11 | + <div class="coupon-state">{{cooponStateMessage}}</div> | ||
12 | + </div> | ||
13 | + {{/ coupons}} | ||
14 | + {{^}} | ||
15 | + {{# coupons}} | ||
16 | + <div class="coupon-containter" value="{{couponId}}"> | ||
17 | + <div class="money-icon">¥</div> | ||
18 | + <div class="money-value">{{money}}</div> | ||
19 | + <div class="coupon-name">{{couponName}}</div> | ||
20 | + <div class="coupon-state">{{cooponStateMessage}}</div> | ||
21 | + </div> | ||
22 | + {{/ coupons}} | ||
23 | + {{/ if}} | ||
24 | + | ||
16 | </div> | 25 | </div> |
17 | </div> | 26 | </div> |
18 | {{/ result}} | 27 | {{/ result}} |
public/img/product/coupons_l_g.png
0 → 100644

3.54 KB
public/img/product/coupons_l_r.png
0 → 100644

3.59 KB
public/img/product/coupons_s_g.png
0 → 100644

961 Bytes
public/img/product/coupons_s_r.png
0 → 100644

931 Bytes
-
Please register or login to post a comment