Authored by ccbikai(👎🏻🍜)

异步查询个性化券

... ... @@ -4,8 +4,7 @@ const model = require('../models/feature');
exports.index = function(req, res, next) {
model.index({
code: req.params.code,
type: req.query.type,
user_id: req.user.uid || 0
type: req.query.type
}).then((result) => {
if (!result) {
return next();
... ... @@ -15,6 +14,7 @@ exports.index = function(req, res, next) {
page: 'feature',
title: result.name || 'Yoho!Buy有货',
content: result,
activity_id: req.params.code,
isFeature: true
});
}).catch(next);
... ...
... ... @@ -45,14 +45,12 @@ module.exports = {
if (params.type === 'preview') { // 开发/预览模式
data = yield api.get('', {
method: 'app.activity.template.ignoreCache',
activity_id: params.code,
user_id: params.user_id
activity_id: params.code
});
} else {
data = yield api.get('', { // 生产模式
method: 'app.activity.template',
activity_id: params.code,
user_id: params.user_id
activity_id: params.code
}, {
cache: true
});
... ...
<div class="feature-page yoho-page">
<div class="feature-page yoho-page" data-id="{{activity_id}}">
{{#unless content.visiable}}
<div class="over">
<p>此活动已结束</p>
... ... @@ -41,14 +41,8 @@
{{#isEqualOr type 'coupon'}}
{{! 优惠券}}
{{#if personCoupon}}
{{! 个性化优惠券,使用:分割}}
<a class="anchor yoho-conpon" style="{{styleFormat this percent=1}}" data-token="{{personCoupon.couponId}}:{{personCoupon.personCouponId}}"
href="{{#if url}}{{url}}{{else}}javascript:void(0);{{/if}}" fp="{{getAnalysis ../this @index}}"></a>
{{else}}
<a class="anchor yoho-conpon" style="{{styleFormat this percent=1}}" data-token="{{token}}"
href="{{#if url}}{{url}}{{else}}javascript:void(0);{{/if}}" fp="{{getAnalysis ../this @index}}"></a>
{{/if}}
<a class="anchor yoho-conpon" style="{{styleFormat this percent=1}}" data-persenal-enable="{{persenal_enable}}" data-token="{{token}}" href="{{#if url}}{{url}}{{else}}javascript:void(0);{{/if}}"
fp="{{getAnalysis ../this @index}}"></a>
{{/isEqualOr}}
{{#isEqualOr type 'yohoCoin'}}
... ...
var $ = require('yoho-jquery');
var lazyLoad = require('yoho-jquery-lazyload');
var Swiper = require('yoho-swiper');
var qs = require('yoho-qs');
var yoho = require('../yoho-app');
global.jQuery = $;
... ... @@ -156,7 +157,29 @@ function modalInit() {
});
}
function persenalCouponInit() {
let activityId = $('.feature-page').data('id');
$('.yoho-conpon').each(function() {
let $this = $(this);
if ($this.data('persenal-enable')) {
$.ajax({
url: '//m.yohobuy.com/activity/individuation/coupon',
dataType: 'jsonp',
data: {
uid: qs.uid || 0,
activity_id: activityId
},
success: function(res) {
if (res.code === 200 && res.data && res.data.couponId && res.data.personCouponId) {
$this.attr('data-token', `${res.data.couponId}:${res.data.personCouponId}`);
}
}
});
}
});
}
$(function() {
if ($('.over').length) {
... ... @@ -197,4 +220,7 @@ $(function() {
// 模态框
modalInit();
// 个性化券查询
persenalCouponInit();
});
... ...