Authored by 郭成尧

coupon-get

// 领券中心 by acgpiano 16-9-19
'use strict';
const _ = require('lodash');
const model = require('../models/coupon-floor'),
headerModel = require('../../../doraemon/models/header');
const CONTENT_CODE_DEFAULT = 'b78b32ed81b18dde8ac84fd33602b88b'; // 取得是潮童频道的资源码
... ... @@ -57,15 +58,24 @@ exports.status = (req, res, next) => {
};
exports.receive = (req, res, next) => {
let uid = req.user.uid || req.query.uid;
if (!uid) {
return res.jsonp({
code: 400,
message: '抱歉,您暂未登录!'
});
let app = req.query.app;
// 接口要加 session 校验,跨域异步请求未添加相关参数
if (req.yoho.isApp) {
if (app.app_version && app.client_type && app.session_key && app.uid) {
req.user.uid = {
toString: () => {
return _.parseInt(app.uid);
},
sessionKey: app.session_key,
appVersion: app.app_version,
appSessionType: app.client_type
};
}
}
let uid = req.user.uid;
req.ctx(model).receiveCoupon({
couponID: req.query.couponID
}, uid).then(result => {
... ...
... ... @@ -3,9 +3,12 @@
*/
require('activity/coupon-floor.page.css');
let $ = require('yoho-jquery'),
const $ = require('yoho-jquery'),
Swiper = require('yoho-swiper2'),
tip = require('plugin/tip');
const yoho = require('../yoho-app');
const cookie = require('yoho-cookie');
const qs = require('yoho-qs');
let $receive = $('.main-right-receive'),
$mask = $('.floor-mask'),
$message = $('.floor-message'),
... ... @@ -71,30 +74,36 @@ setTimeout(function() {
$receive.on('click', function() {
let $curDom = $(this);
let requestParams = {
code: qs.code,
couponID: $curDom.parents('.coupon-floor').attr('coupon-id')
};
if (qs.app_version) {
requestParams.app_version = qs.app_version;
}
let req = '',
version = getUrlParam('app_version'),
uid = getUrlParam('uid');
if (version) {
req += '&app_version=' + version;
if (qs.uid) {
requestParams.uid = qs.uid;
}
if (uid) {
req += '&uid=' + uid;
if (yoho.isApp) {
requestParams.app = {
uid: cookie.get('app_uid') || qs.uid,
app_version: cookie.get('app_version') || qs.app_version,
client_type: cookie.get('app_client_type') || qs.client_type,
session_key: cookie.get('app_session_key') || qs.session_key
};
}
$.ajax({
url: '//m.yohobuy.com/activity/coupon/receiveCoupon?code=' + getUrlParam('code') + req,
data: {
couponID: $curDom.parents('.coupon-floor').attr('coupon-id')
},
url: '//m.yohobuy.com/activity/coupon/receiveCoupon',
data: requestParams,
dataType: 'json',
success: function(data) {
if (data.code === 400) {
// 未登录情况下,跳转登陆页
if (version) {
if (qs.app_version) {
if ($('#intimacy-link').length <= 0) {
$('body').append('<a href=\'' + $('#appurl').val() +
'\' style="display:none;" id="intimacy-link"><span class="intimacy-link"></span></a>');
... ...