Authored by zzzzzzz

领券中心完成

// 领券中心 by acgpiano 16-9-19
'use strict';
const model = require('../models/coupon-floor'),
... ... @@ -12,7 +13,7 @@ exports.index = (req, res, next) => {
uid = req.user.uid;
}
model.floor({
uid: uid || 15184104,
uid: uid,
contentCode: req.query.code
}, req.yoho.isApp).then(result => {
res.render('coupon-floor', {
... ... @@ -27,3 +28,23 @@ exports.index = (req, res, next) => {
});
}).catch(next);
};
exports.receive = (req, res, next) => {
let receiveData = {
couponID: req.query.couponID,
code: req.query.code,
app_version: req.query.app_version,
};
let uid = '';
if (req.yoho.isApp) {
uid = req.query.uid;
} else {
uid = req.user.uid;
}
model.receiveCoupon(receiveData, req.yoho.isApp, uid).then(result => {
res.json(result);
}).catch(next);
};
... ...
// 领券中心 by acgpiano 16-9-19
'use strict';
const Promise = require('bluebird');
... ... @@ -6,8 +7,82 @@ const _ = require('lodash');
const helpers = global.yoho.helpers;
const crypto = global.yoho.crypto;
const SUB_DOMAIN = '.dev.yohobuy.com',
OLD_MAIN = '//m.yohobuy.com',
SITE_MAIN = '//m.dev.yohobuy.com';
/**
* 仿php的strrpos
*/
const strrpos = (str1, str2) => {
return str1.indexOf(str2) > -1 ? str1.indexOf(str2) : false;
};
/**
* 仿php的strstr
*/
const strstr = (str1, str2, bfsearch) => {
if (str1.indexOf(str2) > -1) {
if (bfsearch) {
return str1.substring(0, str1.indexOf(str2));
} else {
return str1.substr(str1.indexOf(str2));
}
} else {
return false;
}
};
const rtrim = (str1, str2) => {
return str1[str1.length - 1] === str2 ? str1.substr(0, str1.length - 1) : str1;
};
const transHttpsUrl = url => {
return url.replace(/^\/\//, 'http://');
};
/**
* app内的分享按钮
*/
const getShare = (code, shareTitle, shareDesc, shareImg) => {
return {
shareLink: helpers.urlFormat('/coupon/floor', { code: code }, ''),
shareTitle: shareTitle || '',
shareDesc: shareDesc || '',
shareImg: shareImg || '',
hasWxShare: true,
};
};
/**
* 过滤app的url
*/
const _getFilterUrl = url => {
url = url.replace('.m.yohobuy.com', SUB_DOMAIN).replace(OLD_MAIN, SITE_MAIN).replace('www.yohobuy.com', SITE_MAIN);
if (strrpos(url, 'm.yohobuy.com') && !strrpos(url, 'sale.m.yohobuy.com') && !strrpos(url, 'cuxiao.m.yohobuy.com') &&
!strrpos(url, 'activity.m.yohobuy.com') && !strrpos(url, 'huodong.m.yohobuy.com') &&
strrpos(url, 'cdn.yoho.cn/myohobuy') && !strrpos(url, '/home/orders/pay')) {
url = url.replace('http://', '//');
}
if (strrpos(url, 'feature.yoho.cn')) {
url = transHttpsUrl(url);
}
let filter = strstr(url, 'openby:yohobuy=', true);
if (filter) {
return rtrim(rtrim(filter, '?'), '&');
} else {
return url;
}
};
/**
* 获得的数据处理
*/
const processFun = {
carousel_banner(data, isApp) {
carousel_banner(data) {
if (!data.list || !data.list.length) {
return [];
}
... ... @@ -43,8 +118,7 @@ const processFun = {
imageSrc = helpers.image(item.image.src, 0, 0);
item.image.src = imageSrc;
// 貌似不需要
// item.image.url = isApp ? item.image.url : _getFilterUrl(item.image.url);
item.image.url = isApp ? item.image.url : _getFilterUrl(item.image.url);
switch (item.status) {
case '1':
item.isGet = true;
... ... @@ -68,7 +142,7 @@ const processFun = {
return result;
},
text(data, isApp) {
text(data) {
data.isTitle = true;
if (data.text) {
data.isShow = true;
... ... @@ -78,12 +152,16 @@ const processFun = {
single_image(data, isApp) {
data[0].isSingleImage = true;
data[0].url = isApp ? data[0].url : _getFilterUrl(data[0].url);
return data[0];
},
focus(data, isApp) {
let result = {};
for (let item of data) {
item.url = isApp ? item.url : _getFilterUrl(item.url);
}
result.isFocus = true;
result.data = data;
return result;
... ... @@ -108,13 +186,12 @@ const processFun = {
image.src = image.src.replace('?imageView/{mode}/w/{width}/h/{height}', '');
}
}
image.url = !image.url ? 'javascript:void(0);' : image.url;
// if(isApp){
// image.url = !image.url ? 'javascript:void(0);' : image.url;
// }else{
// image.url = !image.url ? 'javascript:void(0);' : Helpers::getFilterUrl(image['url']);
// }
if (isApp) {
image.url = !image.url ? 'javascript:void(0);' : image.url;
} else {
image.url = !image.url ? 'javascript:void(0);' : _getFilterUrl(image.url);
}
}
result.isImageList = true;
result.imageList = {
... ... @@ -124,9 +201,6 @@ const processFun = {
};
return result;
},
promotion() {
console.log(7);
}
};
const _getContent = (data, isApp) => {
... ... @@ -173,8 +247,7 @@ const _getContent = (data, isApp) => {
exports.floor = (params, isApp) => {
return Promise.coroutine(function*() {
let shareData,
result = {},
let result = {},
resource = yield api.get('', Object.assign(params, {
method: 'app.promotion.queryCouponCenter',
}));
... ... @@ -184,8 +257,73 @@ exports.floor = (params, isApp) => {
} else {
result.noData = true;
}
return result;
// shareData = _getShare(params.contentCode, '领券中心');
result.share = getShare(params.contentCode, '领券中心');
return result;
})();
};
/**
* 前端ajax领券
*/
exports.receiveCoupon = (receiveData, isApp, uid) => {
let returnData = {};
// 获取优惠券 ID
if (receiveData.couponID) {
receiveData.couponID = crypto.decrypt(undefined, receiveData.couponID);
}
// 跳转 URl
let playUrl = helpers.urlFormat('/coupon/floor');
// 判断用户是否登录
let isLogin = false;
if (uid) {
isLogin = true;
}
if (!isLogin) {
// 用户未登录,跳转登录页面
returnData.noLogin = true;
if (!isApp) {
returnData.url = helpers.urlFormat('/signin.html', { refer: playUrl }, 'default');
} else {
returnData.isApp = true;
// let playUrlEncode = '{playUrl}?code={receiveData.code}&app_version={receiveData.app_version}'.replace('/', '\\/');
returnData.url = '{playUrl}?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"http:{playUrlEncode}","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}';
// playUrlEncode = strtr(playUrl, array('/: '\\/'));
// returnData['url'] = playUrl . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . playUrlEncode . '","param":{"from":"app","code":"' . receiveData['code'] . '"}},"requesturl":{"url":"","param":{}},"priority":"N"}}';
}
return new Promise(resolve => {
resolve(returnData);
});
} else {
// 登录后调用领券接口
return api.get('', {
method: 'app.promotion.getCoupon',
couponId: receiveData.couponID,
uid: uid,
}).then(result => {
switch (result.code) {
case 200:
returnData = {
msg: '领券成功!',
status: true,
};
break;
default:
returnData = {
msg: '领券失败!',
status: false,
};
break;
}
return returnData;
});
}
};
... ...
... ... @@ -15,6 +15,7 @@ const student = require(`${cRoot}/student`);
const live = require(`${cRoot}/live`);
const invite = require(`${cRoot}/invite`);
const couponFloor = require(`${cRoot}/coupon-floor`);
const auth = require('../../doraemon/middleware/auth');
// routers
... ... @@ -26,7 +27,9 @@ router.get('/coupon/verify', coupon.verify);
router.get('/wechat/share', wechat.wechatShare);
router.get('/coupon/floor', couponFloor.index);
router.get('/coupon/floor', auth, couponFloor.index);
router.get('/coupon/receiveCoupon', auth, couponFloor.receive);
router.get('/student', student.getUser, student.index);
... ...
/**
* Created by Acgpiano on 2016/9/19.
*/
var $ = require('yoho-jquery'),
Swiper = require('yoho-swiper'),
$receive = $('.main-right-receive'),
$mask = $('.floor-mask'),
$message = $('.floor-message'),
$tooltip = $('.floor-tooltip'),
tip = require('../plugin/tip');
var bannerSwiper;
// 获取url中的参数
function getUrlParam(name) {
// 构造一个含有目标参数的正则表达式对象
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
// 匹配目标参数
var r = window.location.search.substr(1).match(reg);
// 返回参数值
if (r !== null) {
return r[2];
}
return null;
}
$receive.on('click', function() {
var $curDom = $(this),
req = '';
if (getUrlParam('app_version')) {
req += '&app_version=' + getUrlParam('app_version');
}
if (getUrlParam('uid')) {
req += '&uid=' + getUrlParam('uid');
}
$.ajax({
url: '//m.yohobuy.com/coupon/receiveCoupon?code=' + getUrlParam('code') + req,
data: {
couponID: $curDom.parents('.coupon-floor').attr('coupon-id')
},
dataType: 'json',
success: function(data) {
var msg = data.msg,
status = data.status,
newUrl = data.url + '?code=' + getUrlParam('code');
if (data.isApp === true) {
newUrl = data.url;
}
if (data.noLogin === true) {
if ($('#intimacy-link').length <= 0) {
$('body').append('<a href=\'' + newUrl + '\' style="display:none;" id="intimacy-link">' +
'<span class="intimacy-link"></span></a>');
}
$('.intimacy-link').click();
} else {
if (status) {
$curDom.hide();
$curDom.next().show();
$tooltip.show();
setTimeout(function() {
$tooltip.hide();
}, 3000);
} else {
$message.find('.coupon-message-content').text(msg);
$mask.show();
$message.show();
}
}
},
error: function() {
tip.show('网络异常!');
}
});
});
$('.coupon-floor a, .banner-top a').on('click', function() {
if ($(this).attr('href').length <= 0 || $(this).attr('href') === '#') {
return false;
}
});
if ($('.banner-swiper').find('li').length > 1) {
bannerSwiper = new Swiper('.banner-swiper', {
lazyLoading: true,
lazyLoadingInPrevNext: true,
loop: true,
autoplay: 3000,
autoplayDisableOnInteraction: false,
paginationClickable: true,
slideElement: 'li',
pagination: '.banner-top .pagination-inner'
});
}
$('.coupon-message-op-rel').on('click', function() {
location.reload();
});
if ($('#noData').length > 0) {
if (location.href.indexOf('?openby:yohobuy=') <= 0) {
tip.show('网络异常!');
}
}
$mask.on('click', function() {
$mask.hide();
$message.hide();
});
... ...