Authored by 陈峰

redpack user

@@ -2,7 +2,7 @@ const redbagModel = require('../models/red-envelope'); @@ -2,7 +2,7 @@ const redbagModel = require('../models/red-envelope');
2 const headerModel = require('../../../doraemon/models/header'); // 头部model 2 const headerModel = require('../../../doraemon/models/header'); // 头部model
3 3
4 4
5 -const redbagPage = async(req, res) => { 5 +const redbagPage = async(req, res, next) => {
6 try { 6 try {
7 let isApp = req.yoho.isApp; 7 let isApp = req.yoho.isApp;
8 let obj = {uid: req.user.uid || false, shareCode: req.query.shareCode || 'c80f714bf980bdc8'}; // TODO 删除测试数据 8 let obj = {uid: req.user.uid || false, shareCode: req.query.shareCode || 'c80f714bf980bdc8'}; // TODO 删除测试数据
@@ -33,7 +33,8 @@ const redbagPage = async(req, res) => { @@ -33,7 +33,8 @@ const redbagPage = async(req, res) => {
33 title: '红包-客服' 33 title: '红包-客服'
34 }); 34 });
35 } else { 35 } else {
36 - await req.ctx(redbagModel).renderByUser(obj); 36 + const pageData = await req.ctx(redbagModel).renderByUser(obj);
  37 +
37 return res.render('red-envelope/redbag-user', { 38 return res.render('red-envelope/redbag-user', {
38 pageHeader: headerModel.setNav({ 39 pageHeader: headerModel.setNav({
39 navTitle: '红包-用户' 40 navTitle: '红包-用户'
@@ -43,16 +44,46 @@ const redbagPage = async(req, res) => { @@ -43,16 +44,46 @@ const redbagPage = async(req, res) => {
43 localCss: true, 44 localCss: true,
44 module: 'activity', 45 module: 'activity',
45 page: 'redbag-user', 46 page: 'redbag-user',
  47 + pageData: Object.assign({
  48 + shareCode: obj.shareCode
  49 + }, pageData),
46 title: '红包-用户' 50 title: '红包-用户'
47 }); 51 });
48 } 52 }
49 - } catch (e) {  
50 - console.log(e); 53 + } catch (error) {
  54 + return next(error);
51 } 55 }
52 }; 56 };
53 57
54 -const receiveRedBag = (req, res, next) => {  
55 - return next(); 58 +const receiveRedBag = async(req, res, next) => {
  59 + const {shareCode} = req.body;
  60 +
  61 + if (!shareCode) {
  62 + return res.json({
  63 + code: 400,
  64 + message: '分享码不能为空'
  65 + });
  66 + }
  67 + try {
  68 + const result = await req.ctx(redbagModel).receiveRedBag({
  69 + uid: req.user.uid,
  70 + shareCode
  71 + });
  72 +
  73 + if (result.code === 200) {
  74 + return res.json({
  75 + code: 200,
  76 + message: '领取成功'
  77 + });
  78 + } else {
  79 + return res.json({
  80 + code: 201,
  81 + message: result.message
  82 + });
  83 + }
  84 + } catch (error) {
  85 + return next(error);
  86 + }
56 }; 87 };
57 88
58 89
1 -'use strict';  
2 -  
3 class redEnvelopeModel extends global.yoho.BaseModel { 1 class redEnvelopeModel extends global.yoho.BaseModel {
4 constructor(ctx) { 2 constructor(ctx) {
5 super(ctx); 3 super(ctx);
@@ -35,33 +33,51 @@ class redEnvelopeModel extends global.yoho.BaseModel { @@ -35,33 +33,51 @@ class redEnvelopeModel extends global.yoho.BaseModel {
35 }); 33 });
36 } 34 }
37 35
38 - async renderByUser(obj) {  
39 - await this.get({ 36 + async renderByUser({uid, shareCode}) {
  37 + const {code, data = {}} = await this.get({
40 data: { 38 data: {
41 method: 'app.passport.getIsCanReceive', 39 method: 'app.passport.getIsCanReceive',
42 - uid: obj.uid,  
43 - shareCode: obj.shareCode 40 + uid,
  41 + shareCode
44 } 42 }
45 }); 43 });
46 44
47 - // if (ret.data.recieveCode == 201) {  
48 - // this.setData({  
49 - // isAlreadyReceived: true,  
50 - // rewardType: ret.data.rewardType || ''  
51 - // });  
52 - //  
53 - // if (this.data.rewardType == 1) {  
54 - // this.setData({  
55 - // redBagType: ret.data.couponAmount || ''  
56 - // });  
57 - // }  
58 - //  
59 - // if (this.data.rewardType == 2) {  
60 - // this.setData({  
61 - // rewardUrl: ret.data.rewardUrl || ''  
62 - // });  
63 - // }  
64 - // } 45 + if (code !== 200) {
  46 + return {};
  47 + }
  48 +
  49 + switch (data.recieveCode) {
  50 + case 200:
  51 + return {
  52 + received: false,
  53 + };
  54 + case 201:
  55 + return {
  56 + received: true,
  57 + rewardType: data.rewardType,
  58 + couponAmount: data.couponAmount,
  59 + rewardUrl: data.rewardUrl,
  60 + };
  61 + case 202:
  62 + return {
  63 + received: false,
  64 + message: data.recieveMessage,
  65 + };
  66 + default:
  67 + return {
  68 + received: false,
  69 + message: data.message,
  70 + };
  71 + }
  72 + }
  73 + receiveRedBag({uid, shareCode}) {
  74 + return this.get({
  75 + data: {
  76 + method: 'app.passport.receiveCouponForWxCS',
  77 + uid,
  78 + shareCode
  79 + }
  80 + });
65 } 81 }
66 82
67 } 83 }
  1 +<div class="redbag-user-container" data-received="{{pageData.received}}" data-sharecode="{{pageData.shareCode}}">
  2 + {{# pageData}}
  3 + {{#if received}}
  4 + <div class="received-content">
  5 + {{#isEqualOr rewardType 1}}
  6 + {{#isEqualOr couponAmount 5}}
  7 + <img src="http://img12.static.yhbimg.com/sns/2018/08/02/15/02a4fbd09374acfdc2b97cabd059e32669.png" class="red-bag1 use" />
  8 + {{/isEqualOr}}
  9 + {{#isEqualOr couponAmount 10}}
  10 + <img src="http://img11.static.yhbimg.com/sns/2018/08/02/15/0188ee9e04c067fa701f33f7be24bb97ca.png" class="red-bag2 use" />
  11 + {{/isEqualOr}}
  12 + {{#isEqualOr couponAmount 20}}
  13 + <img src="http://img11.static.yhbimg.com/sns/2018/08/02/15/0185441fd89c3bc4a78cd202c9c40eb633.png" class="red-bag3 use" />
  14 + {{/isEqualOr}}
  15 + {{#isEqualOr couponAmount 50}}
  16 + <img src="http://img11.static.yhbimg.com/sns/2018/08/02/15/01645486f02c4d38679b5058bde79abf02.png" class="red-bag50 use" />
  17 + {{/isEqualOr}}
  18 + {{#isEqualOr couponAmount 80}}
  19 + <img src="http://img12.static.yhbimg.com/sns/2018/08/02/15/02c329c8192bcdddd7467a8c44501b4525.png" class="red-bag80 use" />
  20 + {{/isEqualOr}}
  21 + {{#isEqualOr couponAmount 100}}
  22 + <img src="http://img11.static.yhbimg.com/sns/2018/08/02/15/01b6568f91129e886548ab5ff0f5a71ae8.png" class="red-bag100 use" />
  23 + {{/isEqualOr}}
  24 + {{/isEqualOr}}
  25 + {{#isEqualOr rewardType 2}}
  26 + <img src="{{rewardUrl}}" class="red-bag-other use"/>
  27 + {{/isEqualOr}}
  28 + <button type="button" class="go-use"></button>
  29 + </div>
  30 + {{else}}
  31 + <div class="rewards-content">
  32 + <i class="cuo-icon"></i>
  33 + <img src="http://img12.static.yhbimg.com/sns/2018/10/09/18/02c54d5277b89d3b72a4ac4eae7624bbf3.png" class="receiveRedBag"/>
  34 + </div>
  35 + {{/if}}
  36 + <input type="hidden" id="msg" value="{{message}}">
  37 + {{/ pageData}}
  38 + <div class="activity-rule">
  39 + <i class="hand"></i>
  40 + <p class="title">活动规则</p>
  41 + <p class="txt txt-1">领取权益需填写注册有货账户时绑定的手机号,认证后即可参与抽奖;</p>
  42 + <p class="txt txt-2">若忘记或不确定手机号是否绑定账户,请先联系微信客服进行查询;</p>
  43 + <p class="txt txt-3">抽中的优惠券将被放入您的有货账户中,若抽中免单/微信红包/实物奖品,请截图后联系微信客服;</p>
  44 + <p class="txt last">*此活动最终解释权归Yoho!Buy所有</p>
  45 + </div>
  46 +</div>
  1 +import 'scss/activity/redbag-user.page';
  2 +import $ from 'yoho-jquery';
  3 +import tip from 'js/plugin/tip';
  4 +
  5 +$(() => {
  6 + const $container = $('.redbag-user-container'),
  7 + $msg = $('#msg');
  8 +
  9 + if ($msg.length && $msg.val()) {
  10 + tip.show($msg.val());
  11 + }
  12 +
  13 + if ($container.data('received')) {
  14 + $(document).on('click', '.go-use', () => {
  15 + tip.show('请下载App');
  16 + });
  17 + } else {
  18 + let posting = false;
  19 +
  20 + $(document).on('click', '.receiveRedBag', () => {
  21 + const shareCode = $container.data('sharecode');
  22 +
  23 + if (!shareCode) {
  24 + return;
  25 + }
  26 + if (posting) {
  27 + return;
  28 + }
  29 + posting = true;
  30 + $.ajax({
  31 + method: 'POST',
  32 + url: '/activity/red-envelope/receive',
  33 + data: {
  34 + shareCode
  35 + },
  36 + success: function(res) {
  37 + if (res.code === 200) {
  38 + // setTimeout(() => {
  39 + // window.location.reload();
  40 + // }, 500);
  41 + }
  42 + tip.show(res.message);
  43 + },
  44 + complete() {
  45 + posting = false;
  46 + }
  47 + });
  48 + });
  49 + }
  50 +});
  1 +.redbag-user-container {
  2 + width: 100%;
  3 + background: url(http://img12.static.yhbimg.com/sns/2018/09/27/11/025d67e459f2b67afd343540569e56d7b9.jpg) no-repeat;
  4 + background-size: cover;
  5 + padding-top: 244px;
  6 +
  7 + .rewards-content {
  8 + position: relative;
  9 + overflow: hidden;
  10 + padding-bottom: 100px;
  11 +
  12 + .cuo-icon {
  13 + width: 284px;
  14 + height: 111px;
  15 + top: 0;
  16 + right: 49px;
  17 + background: url(//img12.static.yhbimg.com/sns/2018/09/27/12/02598d832b6ecfae4ef6a18c3dd904e90c.png) no-repeat;
  18 + background-size: contain;
  19 + position: absolute;
  20 + }
  21 +
  22 + img {
  23 + width: 570px;
  24 + height: 553px;
  25 + overflow: hidden;
  26 + margin-top: 130px;
  27 + }
  28 + }
  29 +
  30 + .received-content {
  31 + padding-top: 176px;
  32 + overflow: hidden;
  33 + padding-bottom: 160px;
  34 + position: relative;
  35 +
  36 + .use {
  37 + width: 750px;
  38 + height: 443px;
  39 + background-size: contain;
  40 +
  41 + &.red-bag1 {
  42 + height: 458px;
  43 + }
  44 +
  45 + &.red-bag2 {
  46 + height: 464px;
  47 + }
  48 +
  49 + &.red-bag3 {
  50 + height: 454px;
  51 + }
  52 +
  53 + &.red-bag50 {
  54 + height: 439px;
  55 + }
  56 +
  57 + &.red-bag80 {
  58 + height: 431px;
  59 + }
  60 +
  61 + &.red-bag100 {
  62 + height: 443px;
  63 + }
  64 +
  65 + &.red-bag-other {
  66 + height: 443px;
  67 + }
  68 + }
  69 +
  70 + .go-use {
  71 + position: absolute;
  72 + width: 310px;
  73 + height: 180px;
  74 + top: 386px;
  75 + left: 200px;
  76 + background: none !important;
  77 + border: none !important;
  78 + }
  79 + }
  80 +
  81 + .activity-rule {
  82 + width: 680px;
  83 + height: 440px;
  84 + margin: 0 auto;
  85 + padding: 33px;
  86 + background: url("img/activity/red-envelope/txt-bg.png") no-repeat;
  87 + background-size: contain;
  88 + position: relative;
  89 + font-family: PingFang-SC-Medium, sans-serif;
  90 + color: #000;
  91 + letter-spacing: 0;
  92 +
  93 + .hand {
  94 + position: absolute;
  95 + width: 91px;
  96 + height: 91px;
  97 + right: 33px;
  98 + top: -39px;
  99 + background: url(http://img11.static.yhbimg.com/sns/2018/09/27/11/01c13a6c46302940f9c1656f5893236d97.png) no-repeat;
  100 + background-size: contain;
  101 + }
  102 +
  103 + .title {
  104 + font-size: 38px;
  105 + font-weight: bold;
  106 + margin-bottom: 18px;
  107 + position: relative;
  108 + }
  109 +
  110 + .txt {
  111 + font-size: 25px;
  112 + line-height: 34px;
  113 + width: 100%;
  114 + margin-bottom: 14px;
  115 + padding-left: 50px;
  116 +
  117 + &:before {
  118 + font-size: 32px;
  119 + font-family: Arial, sans-serif;
  120 + font-weight: bold;
  121 + margin-left: -50px;
  122 + margin-right: 25px;
  123 + }
  124 +
  125 + &.txt-1:before {
  126 + content: "1.";
  127 + }
  128 +
  129 + &.txt-2:before {
  130 + content: "2.";
  131 + }
  132 +
  133 + &.txt-3:before {
  134 + content: "3.";
  135 + }
  136 +
  137 + &.last {
  138 + font-size: 20px;
  139 + }
  140 + }
  141 + }
  142 +}