Authored by 陈峰

redpack user

... ... @@ -2,7 +2,7 @@ const redbagModel = require('../models/red-envelope');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const redbagPage = async(req, res) => {
const redbagPage = async(req, res, next) => {
try {
let isApp = req.yoho.isApp;
let obj = {uid: req.user.uid || false, shareCode: req.query.shareCode || 'c80f714bf980bdc8'}; // TODO 删除测试数据
... ... @@ -33,7 +33,8 @@ const redbagPage = async(req, res) => {
title: '红包-客服'
});
} else {
await req.ctx(redbagModel).renderByUser(obj);
const pageData = await req.ctx(redbagModel).renderByUser(obj);
return res.render('red-envelope/redbag-user', {
pageHeader: headerModel.setNav({
navTitle: '红包-用户'
... ... @@ -43,16 +44,46 @@ const redbagPage = async(req, res) => {
localCss: true,
module: 'activity',
page: 'redbag-user',
pageData: Object.assign({
shareCode: obj.shareCode
}, pageData),
title: '红包-用户'
});
}
} catch (e) {
console.log(e);
} catch (error) {
return next(error);
}
};
const receiveRedBag = (req, res, next) => {
return next();
const receiveRedBag = async(req, res, next) => {
const {shareCode} = req.body;
if (!shareCode) {
return res.json({
code: 400,
message: '分享码不能为空'
});
}
try {
const result = await req.ctx(redbagModel).receiveRedBag({
uid: req.user.uid,
shareCode
});
if (result.code === 200) {
return res.json({
code: 200,
message: '领取成功'
});
} else {
return res.json({
code: 201,
message: result.message
});
}
} catch (error) {
return next(error);
}
};
... ...
'use strict';
class redEnvelopeModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
... ... @@ -35,33 +33,51 @@ class redEnvelopeModel extends global.yoho.BaseModel {
});
}
async renderByUser(obj) {
await this.get({
async renderByUser({uid, shareCode}) {
const {code, data = {}} = await this.get({
data: {
method: 'app.passport.getIsCanReceive',
uid: obj.uid,
shareCode: obj.shareCode
uid,
shareCode
}
});
// if (ret.data.recieveCode == 201) {
// this.setData({
// isAlreadyReceived: true,
// rewardType: ret.data.rewardType || ''
// });
//
// if (this.data.rewardType == 1) {
// this.setData({
// redBagType: ret.data.couponAmount || ''
// });
// }
//
// if (this.data.rewardType == 2) {
// this.setData({
// rewardUrl: ret.data.rewardUrl || ''
// });
// }
// }
if (code !== 200) {
return {};
}
switch (data.recieveCode) {
case 200:
return {
received: false,
};
case 201:
return {
received: true,
rewardType: data.rewardType,
couponAmount: data.couponAmount,
rewardUrl: data.rewardUrl,
};
case 202:
return {
received: false,
message: data.recieveMessage,
};
default:
return {
received: false,
message: data.message,
};
}
}
receiveRedBag({uid, shareCode}) {
return this.get({
data: {
method: 'app.passport.receiveCouponForWxCS',
uid,
shareCode
}
});
}
}
... ...
<div class="redbag-user-container" data-received="{{pageData.received}}" data-sharecode="{{pageData.shareCode}}">
{{# pageData}}
{{#if received}}
<div class="received-content">
{{#isEqualOr rewardType 1}}
{{#isEqualOr couponAmount 5}}
<img src="http://img12.static.yhbimg.com/sns/2018/08/02/15/02a4fbd09374acfdc2b97cabd059e32669.png" class="red-bag1 use" />
{{/isEqualOr}}
{{#isEqualOr couponAmount 10}}
<img src="http://img11.static.yhbimg.com/sns/2018/08/02/15/0188ee9e04c067fa701f33f7be24bb97ca.png" class="red-bag2 use" />
{{/isEqualOr}}
{{#isEqualOr couponAmount 20}}
<img src="http://img11.static.yhbimg.com/sns/2018/08/02/15/0185441fd89c3bc4a78cd202c9c40eb633.png" class="red-bag3 use" />
{{/isEqualOr}}
{{#isEqualOr couponAmount 50}}
<img src="http://img11.static.yhbimg.com/sns/2018/08/02/15/01645486f02c4d38679b5058bde79abf02.png" class="red-bag50 use" />
{{/isEqualOr}}
{{#isEqualOr couponAmount 80}}
<img src="http://img12.static.yhbimg.com/sns/2018/08/02/15/02c329c8192bcdddd7467a8c44501b4525.png" class="red-bag80 use" />
{{/isEqualOr}}
{{#isEqualOr couponAmount 100}}
<img src="http://img11.static.yhbimg.com/sns/2018/08/02/15/01b6568f91129e886548ab5ff0f5a71ae8.png" class="red-bag100 use" />
{{/isEqualOr}}
{{/isEqualOr}}
{{#isEqualOr rewardType 2}}
<img src="{{rewardUrl}}" class="red-bag-other use"/>
{{/isEqualOr}}
<button type="button" class="go-use"></button>
</div>
{{else}}
<div class="rewards-content">
<i class="cuo-icon"></i>
<img src="http://img12.static.yhbimg.com/sns/2018/10/09/18/02c54d5277b89d3b72a4ac4eae7624bbf3.png" class="receiveRedBag"/>
</div>
{{/if}}
<input type="hidden" id="msg" value="{{message}}">
{{/ pageData}}
<div class="activity-rule">
<i class="hand"></i>
<p class="title">活动规则</p>
<p class="txt txt-1">领取权益需填写注册有货账户时绑定的手机号,认证后即可参与抽奖;</p>
<p class="txt txt-2">若忘记或不确定手机号是否绑定账户,请先联系微信客服进行查询;</p>
<p class="txt txt-3">抽中的优惠券将被放入您的有货账户中,若抽中免单/微信红包/实物奖品,请截图后联系微信客服;</p>
<p class="txt last">*此活动最终解释权归Yoho!Buy所有</p>
</div>
</div>
\ No newline at end of file
... ...
import 'scss/activity/redbag-user.page';
import $ from 'yoho-jquery';
import tip from 'js/plugin/tip';
$(() => {
const $container = $('.redbag-user-container'),
$msg = $('#msg');
if ($msg.length && $msg.val()) {
tip.show($msg.val());
}
if ($container.data('received')) {
$(document).on('click', '.go-use', () => {
tip.show('请下载App');
});
} else {
let posting = false;
$(document).on('click', '.receiveRedBag', () => {
const shareCode = $container.data('sharecode');
if (!shareCode) {
return;
}
if (posting) {
return;
}
posting = true;
$.ajax({
method: 'POST',
url: '/activity/red-envelope/receive',
data: {
shareCode
},
success: function(res) {
if (res.code === 200) {
// setTimeout(() => {
// window.location.reload();
// }, 500);
}
tip.show(res.message);
},
complete() {
posting = false;
}
});
});
}
});
... ...
.redbag-user-container {
width: 100%;
background: url(http://img12.static.yhbimg.com/sns/2018/09/27/11/025d67e459f2b67afd343540569e56d7b9.jpg) no-repeat;
background-size: cover;
padding-top: 244px;
.rewards-content {
position: relative;
overflow: hidden;
padding-bottom: 100px;
.cuo-icon {
width: 284px;
height: 111px;
top: 0;
right: 49px;
background: url(//img12.static.yhbimg.com/sns/2018/09/27/12/02598d832b6ecfae4ef6a18c3dd904e90c.png) no-repeat;
background-size: contain;
position: absolute;
}
img {
width: 570px;
height: 553px;
overflow: hidden;
margin-top: 130px;
}
}
.received-content {
padding-top: 176px;
overflow: hidden;
padding-bottom: 160px;
position: relative;
.use {
width: 750px;
height: 443px;
background-size: contain;
&.red-bag1 {
height: 458px;
}
&.red-bag2 {
height: 464px;
}
&.red-bag3 {
height: 454px;
}
&.red-bag50 {
height: 439px;
}
&.red-bag80 {
height: 431px;
}
&.red-bag100 {
height: 443px;
}
&.red-bag-other {
height: 443px;
}
}
.go-use {
position: absolute;
width: 310px;
height: 180px;
top: 386px;
left: 200px;
background: none !important;
border: none !important;
}
}
.activity-rule {
width: 680px;
height: 440px;
margin: 0 auto;
padding: 33px;
background: url("img/activity/red-envelope/txt-bg.png") no-repeat;
background-size: contain;
position: relative;
font-family: PingFang-SC-Medium, sans-serif;
color: #000;
letter-spacing: 0;
.hand {
position: absolute;
width: 91px;
height: 91px;
right: 33px;
top: -39px;
background: url(http://img11.static.yhbimg.com/sns/2018/09/27/11/01c13a6c46302940f9c1656f5893236d97.png) no-repeat;
background-size: contain;
}
.title {
font-size: 38px;
font-weight: bold;
margin-bottom: 18px;
position: relative;
}
.txt {
font-size: 25px;
line-height: 34px;
width: 100%;
margin-bottom: 14px;
padding-left: 50px;
&:before {
font-size: 32px;
font-family: Arial, sans-serif;
font-weight: bold;
margin-left: -50px;
margin-right: 25px;
}
&.txt-1:before {
content: "1.";
}
&.txt-2:before {
content: "2.";
}
&.txt-3:before {
content: "3.";
}
&.last {
font-size: 20px;
}
}
}
}
... ...