Authored by Zhang

接口联调

... ... @@ -3,19 +3,38 @@
const freeMailModel = require('../models/free-mail');
exports.freeMailIndex = (req, res) => {
let uid = req.user.uid;
res.render('free-mail/index', {
page: 'free-mail-index',
localCss: true
})
});
};
exports.freeMailList = (req, res) => {
exports.freeMailList = (req, res, next) => {
let uid = req.user.uid;
res.render('free-mail/list', {
page: 'free-mail-list',
localCss: true
})
};
\ No newline at end of file
req.ctx(freeMailModel).freeMail(uid).then(result => {
res.render('free-mail/list', {
page: 'free-mail-list',
localCss: true,
listData: result
});
}).catch(next);
};
exports.receiveVerify = (req, res, next) => {
let uid = req.user.uid,
verify = true;
req.ctx(freeMailModel).freeMail(uid, verify).then(result => {
res.json(result);
}).catch(next);
};
exports.receiveCoupon = (req, res, next) => {
let uid = req.user.uid;
req.ctx(freeMailModel).receiveCoupon(uid).then(result => {
res.json(result);
}).catch(next);
};
... ...
const api = global.yoho.API;
const _ = require('lodash');
const helpers = global.yoho.helpers;
const service = global.yoho.ServiceAPI;
const moment = require('moment');
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 领取验证以及领卷列表
*/
freeMail(uid, verify) {
return api.get('', {
method: 'app.coupons.queryFreePostCoupons',
uid: uid
}).then((result) => {
if (verify) {
return result;
} else {
if (result && result.code === 200) {
_.forEach(result.data.freePostCoupons, function(data) {
data.startTime = moment.unix(data.startTime).format('YYYY.M.D');
data.endTime = moment.unix(data.endTime).format('YYYY.M.D');
})
return result.data;
} else {
return {};
}
}
})
}
receiveCoupon(uid) {
return api.get('', {
method: 'app.coupons.getFreePostCoupons',
uid: uid
}).then((result) => {
return result;
})
}
};
\ No newline at end of file
... ...
... ... @@ -270,5 +270,7 @@ router.get('/reward-detail', auth, expand.rewardDetail); // 拓展新客 我的
router.get('/free-mail/index', auth, freeMail.freeMailIndex); // 免邮券主页
router.get('/free-mail/list', auth, freeMail.freeMailList); // 免邮券列表页
router.get('/free-mail/verify', auth, freeMail.receiveVerify); // 免邮券领取验证
router.get('/free-mail/verifyCoupon', auth, freeMail.receiveCoupon); // 免邮券领取
module.exports = router;
... ...
... ... @@ -39,4 +39,7 @@
</div>
</div>
</div>
<div class="pop-up">
</div>
</div>
\ No newline at end of file
... ...
<div class="free-mail-list-page yoho-page">
{{# listData}}
<div class="top-banner">
<span class="coupon-name">5月优惠券</span>
<span class="coupon-name">{{name}}</span>
</div>
<div class="coupon-list">
{{# freePostCoupons}}
<div class="coupon-item">
<div class="item-left">
<span class="name">5月优惠券</span>
<span class="time">2012.09.07-2012.19.02</span>
<span class="name">{{couponName}}</span>
<span class="time">{{startTime}}-{{endTime}}</span>
</div>
<div class="item-right">
<span class="amount">10</span>
</div>
</div>
<div class="coupon-item">
<div class="item-left">
<span class="name">5月优惠券</span>
<span class="time">2012.09.07-2012.19.02</span>
</div>
<div class="item-right">
<span class="amount">10</span>
</div>
</div>
<div class="coupon-item">
<div class="item-left">
<span class="name">5月优惠券</span>
<span class="time">2012.09.07-2012.19.02</span>
</div>
<div class="item-right">
<span class="amount">10</span>
<span class="amount">{{amount}}</span>
</div>
</div>
{{/ freePostCoupons}}
</div>
<div class="receive-btn"></div>
{{/ listData}}
</div>
\ No newline at end of file
... ...
'use strict';
require('activity/free-mail-index.page.css');
require('common');
'use strict';
const yoho = require('yoho-app');
import {
Controller
} from 'yoho-mvc';
import {
IndexView
} from './view';
import {
FreeMail
} from './model';
class FreeMailIndexController extends Controller {
constructor() {
super();
this.receiveView = new IndexView();
this.freeMailModel = new FreeMail();
this.receiveView.on('goReceive', this.goReceive.bind(this));
}
goReceive() {
this.freeMailModel.receiveVerify().then(result => {
if (result.code === 200) {
if (yoho.isApp) {
yoho.goH5('http://m.yohobuy.com/activity/free-mail/list', JSON.stringify({
action: 'go.h5',
params: {
islogin: 'N',
url: 'http://m.yohobuy.com/activity/free-mail/list'
}
}));
} else {
location.href = '//m.yohobuy.com/activity/free-mail/list';
}
} else if (result.code === 419) {
$('.pop-up').html('<div class="details"><span></span>' + result.message + '</div>').show();
} else if (result.code === 418) {
$('.pop-up').html('<div class="big">本月已领取过<br>下月再来哦~</div>').show();
} else {
$('.pop-up').html(result.message).show();
}
this.receiveView.popHide();
});
}
}
module.exports = FreeMailIndexController;
... ...
require('activity/free-mail-index.page.css');
const FreeMailIndexController = require('./controller');
new FreeMailIndexController();
... ...
'use strict';
import {
http
} from 'yoho-mvc';
class FreeMail {
/**
* 首页立即领取
*/
receiveVerify() {
return http({
type: 'GET',
url: '/activity/free-mail/verify'
});
}
}
module.exports = {
FreeMail
};
... ...
import {
View
} from 'yoho-mvc';
class IndexView extends View {
constructor() {
super('.top-banner');
this.receiveBtn = $('.receive-btn');
this.on('touchend touchcancel', 'span', this.btnClick.bind(this));
}
/**
* 立即领取按钮
*/
btnClick() {
this.emit('goReceive');
}
/**
* 弹框消失
*/
popHide() {
setTimeout(function() {
if ($('.pop-up').css('display') === 'block') {
$('.pop-up').hide();
}
}, 2000);
}
}
module.exports = {
IndexView
};
... ...
'use strict';
require('activity/free-mail-list.page.css');
require('common');
'use strict';
const tip = require('plugin/tip'),
yoho = require('yoho-app');
import {
Controller
} from 'yoho-mvc';
import {
ListView
} from './view';
import {
FreeMailList
} from './model';
class FreeMailIndexController extends Controller {
constructor() {
super();
this.listView = new ListView();
this.listMailModel = new FreeMailList();
this.listView.on('receiveCoupon', this.receiveCoupon.bind(this));
}
receiveCoupon() {
this.listMailModel.receiveCoupon().then(result => {
if (result.code === 200) {
tip.show('领取成功');
setTimeout(function() {
if (yoho.isApp) {
yoho.goH5('http://m.yohobuy.com/home/coupons', JSON.stringify({
action: 'go.coupon',
params: {
islogin: 'N',
url: 'http://m.yohobuy.com/home/coupons'
}
}));
} else {
location.href = '//m.yohobuy.com/home/coupons';
}
}, 2000);
} else {
tip.show(result.message);
}
});
}
}
module.exports = FreeMailIndexController;
... ...
require('activity/free-mail-list.page.css');
const FreeMailListController = require('./controller');
new FreeMailListController();
... ...
'use strict';
import {
http
} from 'yoho-mvc';
class FreeMailList {
/**
* 列表页领取劵
*/
receiveCoupon() {
return http({
type: 'GET',
url: '/activity/free-mail/verifyCoupon'
});
}
}
module.exports = {
FreeMailList
};
... ...
import {
View
} from 'yoho-mvc';
class ListView extends View {
constructor() {
super('.free-mail-list-page');
this.receiveBtn = $('.receive-btn');
this.on('touchend touchcancel', '.receive-btn', this.receiveClick.bind(this));
}
/**
* 领券按钮
*/
receiveClick() {
this.emit('receiveCoupon');
}
}
module.exports = {
ListView
};
... ...
... ... @@ -20,6 +20,7 @@
background: #c70e0e;
width: 100%;
padding: 30px 25px 40px;
font-family: "SourceHanSansCN";
.instructions-detail {
width: 100%;
... ... @@ -105,4 +106,45 @@
background-repeat: no-repeat;
}
}
.pop-up {
position: fixed;
text-align: center;
width: 405px;
padding: 15PX;
top: 500px;
left: 50%;
margin-left: -30%;
margin-top: -170px;
background-color: #959595;
color: #fff;
font-size: 18PX;
border: none;
z-index: 100;
box-sizing: border-box;
border-radius: 42px;
display: none;
.details {
padding-top: 5px;
span {
display: block;
width: 91px;
height: 91px;
background-image: resolve("activity/free-mail/failure.png");
background-repeat: no-repeat;
background-size: 100%;
position: relative;
left: 50%;
margin-left: -46px;
margin-bottom: 14px;
}
}
}
.big {
font-size: 36px;
padding: 30px 0;
}
}
... ...
... ... @@ -5,6 +5,7 @@
background-image: resolve("activity/free-mail/list-banner.png");
background-repeat: no-repeat;
background-size: 100%;
margin-bottom: 15px;
.coupon-name {
display: inline-block;
... ... @@ -18,9 +19,9 @@
}
.coupon-list {
padding: 15px 35px 0;
padding: 0 35px;
color: #fff;
height: 456px;
max-height: 452px;
overflow-y: scroll;
.coupon-item {
... ... @@ -43,6 +44,11 @@
.name {
font-size: 42px;
font-weight: 700;
display: inline-block;
max-width: 205px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.time {
... ...