Authored by 郭成尧

coupon-get

1 // 领券中心 by acgpiano 16-9-19 1 // 领券中心 by acgpiano 16-9-19
2 'use strict'; 2 'use strict';
3 3
  4 +const _ = require('lodash');
4 const model = require('../models/coupon-floor'), 5 const model = require('../models/coupon-floor'),
5 headerModel = require('../../../doraemon/models/header'); 6 headerModel = require('../../../doraemon/models/header');
6 const CONTENT_CODE_DEFAULT = 'b78b32ed81b18dde8ac84fd33602b88b'; // 取得是潮童频道的资源码 7 const CONTENT_CODE_DEFAULT = 'b78b32ed81b18dde8ac84fd33602b88b'; // 取得是潮童频道的资源码
@@ -57,15 +58,24 @@ exports.status = (req, res, next) => { @@ -57,15 +58,24 @@ exports.status = (req, res, next) => {
57 }; 58 };
58 59
59 exports.receive = (req, res, next) => { 60 exports.receive = (req, res, next) => {
60 - let uid = req.user.uid || req.query.uid;  
61 -  
62 - if (!uid) {  
63 - return res.jsonp({  
64 - code: 400,  
65 - message: '抱歉,您暂未登录!'  
66 - }); 61 + let app = req.query.app;
  62 +
  63 + // 接口要加 session 校验,跨域异步请求未添加相关参数
  64 + if (req.yoho.isApp) {
  65 + if (app.app_version && app.client_type && app.session_key && app.uid) {
  66 + req.user.uid = {
  67 + toString: () => {
  68 + return _.parseInt(app.uid);
  69 + },
  70 + sessionKey: app.session_key,
  71 + appVersion: app.app_version,
  72 + appSessionType: app.client_type
  73 + };
  74 + }
67 } 75 }
68 76
  77 + let uid = req.user.uid;
  78 +
69 req.ctx(model).receiveCoupon({ 79 req.ctx(model).receiveCoupon({
70 couponID: req.query.couponID 80 couponID: req.query.couponID
71 }, uid).then(result => { 81 }, uid).then(result => {
@@ -3,9 +3,12 @@ @@ -3,9 +3,12 @@
3 */ 3 */
4 require('activity/coupon-floor.page.css'); 4 require('activity/coupon-floor.page.css');
5 5
6 -let $ = require('yoho-jquery'), 6 +const $ = require('yoho-jquery'),
7 Swiper = require('yoho-swiper2'), 7 Swiper = require('yoho-swiper2'),
8 tip = require('plugin/tip'); 8 tip = require('plugin/tip');
  9 +const yoho = require('../yoho-app');
  10 +const cookie = require('yoho-cookie');
  11 +const qs = require('yoho-qs');
9 let $receive = $('.main-right-receive'), 12 let $receive = $('.main-right-receive'),
10 $mask = $('.floor-mask'), 13 $mask = $('.floor-mask'),
11 $message = $('.floor-message'), 14 $message = $('.floor-message'),
@@ -71,30 +74,36 @@ setTimeout(function() { @@ -71,30 +74,36 @@ setTimeout(function() {
71 74
72 $receive.on('click', function() { 75 $receive.on('click', function() {
73 let $curDom = $(this); 76 let $curDom = $(this);
  77 + let requestParams = {
  78 + code: qs.code,
  79 + couponID: $curDom.parents('.coupon-floor').attr('coupon-id')
  80 + };
74 81
  82 + if (qs.app_version) {
  83 + requestParams.app_version = qs.app_version;
  84 + }
75 85
76 - let req = '',  
77 - version = getUrlParam('app_version'),  
78 - uid = getUrlParam('uid');  
79 -  
80 - if (version) {  
81 - req += '&app_version=' + version; 86 + if (qs.uid) {
  87 + requestParams.uid = qs.uid;
82 } 88 }
83 89
84 - if (uid) {  
85 - req += '&uid=' + uid; 90 + if (yoho.isApp) {
  91 + requestParams.app = {
  92 + uid: cookie.get('app_uid') || qs.uid,
  93 + app_version: cookie.get('app_version') || qs.app_version,
  94 + client_type: cookie.get('app_client_type') || qs.client_type,
  95 + session_key: cookie.get('app_session_key') || qs.session_key
  96 + };
86 } 97 }
87 98
88 $.ajax({ 99 $.ajax({
89 - url: '//m.yohobuy.com/activity/coupon/receiveCoupon?code=' + getUrlParam('code') + req,  
90 - data: {  
91 - couponID: $curDom.parents('.coupon-floor').attr('coupon-id')  
92 - }, 100 + url: '//m.yohobuy.com/activity/coupon/receiveCoupon',
  101 + data: requestParams,
93 dataType: 'json', 102 dataType: 'json',
94 success: function(data) { 103 success: function(data) {
95 if (data.code === 400) { 104 if (data.code === 400) {
96 // 未登录情况下,跳转登陆页 105 // 未登录情况下,跳转登陆页
97 - if (version) { 106 + if (qs.app_version) {
98 if ($('#intimacy-link').length <= 0) { 107 if ($('#intimacy-link').length <= 0) {
99 $('body').append('<a href=\'' + $('#appurl').val() + 108 $('body').append('<a href=\'' + $('#appurl').val() +
100 '\' style="display:none;" id="intimacy-link"><span class="intimacy-link"></span></a>'); 109 '\' style="display:none;" id="intimacy-link"><span class="intimacy-link"></span></a>');