Authored by 郝肖肖

'我的礼品卡列表接口'

... ... @@ -40,3 +40,14 @@ exports.detail = (req, res, next) => {
res.render('home/gift/me-detail', responseData);
}).catch(next);
};
/**
* 激活礼品卡
*/
exports.activateGift = (req, res, next) => {
let uid = req.user.uid;
req.ctx(meGiftService).activateGift(req.body, uid).then(result => {
res.json(result);
}).catch(next);
};
... ...
... ... @@ -11,11 +11,13 @@ module.exports = class extends global.yoho.BaseModel {
* @param {[type]} status [1-可使用,2-已冻结,3-已过期,4-已用完]
* @return {[type]} [{}]
*/
getList(uid, status) {
getList(uid, status, page, limit) {
let options = {
method: 'app.giftcard.pagelist',
uid: uid,
status: status
status: status,
page: page,
limit: limit || 10
};
return this.get({data: options});
... ...
... ... @@ -8,6 +8,8 @@ const Promise = require('bluebird');
const _ = require('lodash');
const helpers = global.yoho.helpers;
const MeGiftAPi = require('./me-gift-api');
const setPager = require(`${global.utils}/pager`).setPager;
const crypto = global.yoho.crypto;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
... ... @@ -47,7 +49,8 @@ module.exports = class extends global.yoho.BaseModel {
getList(params, uid) {
let status = 1;
params.type = params.type > -1 && params.type < 4 ? params.type : 0;
params.type = Number(params.type > -1 && params.type < 4 ? params.type : 0);
params.page = Number(params.page) || 1;
switch (params.type) {
case 1: status = 3; break;
... ... @@ -57,11 +60,22 @@ module.exports = class extends global.yoho.BaseModel {
}
return Promise.all([
this.meGiftAPi.getList(uid, status),
this.meGiftAPi.getList(uid, status, params.page),
this.verifyBinMobile(uid)
]).then(rlist => {
let giftData = {};
giftData.data = _.get(rlist[0], 'data.giftCardInfoBOList', []);
giftData.pager = Object.assign({
count: _.get(rlist[0], 'data.total', 0),
curPage: params.page,
totalPages: _.get(rlist[0], 'data.pageSize', 0)
}, setPager(_.get(rlist[0], 'data.pageSize', 0), {
page: params.page
}));
return {
giftData: giftData,
userInfo: rlist[1],
tabs: this.headTab(params)
};
... ... @@ -76,7 +90,7 @@ module.exports = class extends global.yoho.BaseModel {
// 礼品卡列表
verifyBinMobile(uid) {
let userInfo = {
isBinMobile: _.get(this.ctx, 'req.user.isBinMobile', false)
isBinMobile: _.get(this.ctx, 'req.session.isBinMobile', false)
};
if (userInfo.isBinMobile) {
... ... @@ -85,12 +99,22 @@ module.exports = class extends global.yoho.BaseModel {
return this.meGiftAPi.getProfile(uid).then(lres => {
lres = _.get(lres, 'data', {});
let isBinMobile = Number(!!lres.verify_mobile);
_.set(this.ctx, 'req.session.isBinMobile', isBinMobile);
return Object.assign({}, userInfo, {
isBinMobile: Number(!!lres.verify_mobile),
isBinMobile: isBinMobile,
email: lres.verify_email,
mobile: lres.verify_mobile
});
});
}
// 激活礼品卡
activateGift(params, uid) {
return this.meGiftAPi.activateGift(uid, params.cardCode, crypto.encryption('yoho9646yoho9646', params.cardPwd));
}
};
... ...
... ... @@ -275,5 +275,6 @@ router.get('/newuser', newUserController.check);
// 我的礼品卡
router.get('/megift', tabsMiddleware.getCommonHeader, meGiftController.index);
router.post('/activateGift', meGiftController.activateGift);// 激活礼品卡
module.exports = router;
... ...
... ... @@ -6,6 +6,7 @@
<div class="title">
<h2>礼品卡</h2>
</div>
<div class="me-content" data-is-bin-mobile={{userInfo.isBinMobile}} data-email={{userInfo.email}}>
{{> tabs}}
<div class="me-gift-table">
... ... @@ -17,34 +18,26 @@
<div class="invalid-time">失效时间</div>
<div class="cart-operation">操作</div>
</div>
<div class="me-gift-tr">
<div>L242353456436456</div>
<div>2000</div>
<div>1980</div>
<div>2017-12-36</div>
<div>2017-12-36</div>
<div class="info-list">消费明细</div>
</div>
<div class="me-gift-tr">
<div>L242353456436456</div>
<div>2000</div>
<div>1980</div>
<div>2017-12-36</div>
<div>2017-12-36</div>
<div class="info-list">消费明细</div>
</div>
<div class="me-gift-tr">
<div>L242353456436456</div>
<div>2000</div>
<div>1980</div>
<div>2017-12-36</div>
<div>2017-12-36</div>
<div class="info-list">消费明细</div>
</div>
<div class="cart-list-empty"></div>
{{#if giftData.data}}
{{#giftData.data}}
<div class="me-gift-tr">
<div>{{cardCode}}</div>
<div>{{amount}}</div>
<div>{{remainAmount}}</div>
<div>{{activateTime}}</div>
<div>{{endTime}}</div>
<div class="info-list">消费明细</div>
</div>
{{/giftData.data}}
{{^}}
<div class="cart-list-empty"></div>
{{/if}}
</div>
</div>
{{> pager}}
{{#giftData}}
{{> pager}}
{{/giftData}}
</div>
</div>
</div>
... ...
... ... @@ -130,6 +130,7 @@ meGift = {
// 激活礼品卡
activateGift: function() {
var that = this;
var isFlag = false;
var dg = new dialog.Dialog({
content: that.giftTpl({}),
className: 'me-gift-confirm',
... ... @@ -145,8 +146,40 @@ meGift = {
name: '激活',
btnClass: ['confirm-sure'],
cb: function() {
dg.close();
that.meAlert('<p>您的礼品卡激活成功</p><p>请尽情享用</p>');
var $confirm = $('.me-gift-confirm');
if ($confirm.find('.card-code').val() === '') {
that.meAlert('礼品卡卡号不能为空');
return false;
} else if ($confirm.find('.card-pwd').val() === '') {
that.meAlert('礼品卡卡密不能为空');
return false;
}
if (isFlag) {
return false;
}
isFlag = true;
$.ajax({
url: '/home/activateGift',
type: 'post',
data: {
cardCode: $confirm.find('.card-code').val(),
cardPwd: $confirm.find('.card-pwd').val()
}
}).then(function(res) {
isFlag = false;
if (res.code === 200) {
dg.close();
that.meAlert('<p>您的礼品卡激活成功</p><p>请尽情享用</p>');
} else {
that.meAlert(res.message);
}
}, function() {
isFlag = false;
});
}
}]
}).show();
... ...
.me-gift-page {
.me-gift {
.me-gift .me-content {
min-height: 370px;
}
... ... @@ -88,11 +88,11 @@
.me-gift-alert {
width: 350px;
height: 180px;
height: 190px;
.content {
color: #444;
padding: 40px 0;
padding: 55px 0;
font-size: 18px;
p {
... ... @@ -129,8 +129,7 @@
}
.verify-input {
margin: 15px 20px 40px;
text-align: left;
margin: 15px 10px 40px;
input {
height: 30px;
... ... @@ -153,7 +152,7 @@
}
input.mobile {
width: 240px;
width: 260px;
border-left: none;
}
... ... @@ -172,8 +171,8 @@
.ul-list {
position: absolute;
width: 139px;
margin-left: -35px;
width: 130px;
margin-left: -25px;
background-color: #fff;
margin-top: -3px;
border: 1px solid #e6e6e6;
... ... @@ -192,12 +191,12 @@
}
input.mobile-code {
width: 197px;
width: 217px;
}
.card-code,
.card-pwd {
width: 295px;
width: 310px;
}
.border-top-info {
... ... @@ -239,7 +238,7 @@
.gift-filter .ul-list {
width: 69px;
margin-left: 51px;
margin-left: 52px;
margin-top: 0;
}
}
... ...