Authored by zzzzzzz

完成40%

"use strict";
'use strict';
const model = require('../models/coupon-floor');
const model = require('../models/coupon-floor'),
headerModel = require('../../../doraemon/models/header');
exports.index = (req, res, next) => {
let uid = '';
if(req.yoho.isApp){
if (req.yoho.isApp) {
uid = req.query.uid;
}
else{
} else {
uid = req.user.uid;
}
model.floor({
uid: uid || 15184104,
contentCode: req.query.code
}, req.yoho.isApp);
}
\ No newline at end of file
}, req.yoho.isApp).then(result => {
res.render('coupon-floor', {
module: 'activity',
page: 'coupon-floor',
wechatShare: true,
title: '领券中心',
pageHeader: headerModel.setNav({
navTitle: '领券中心'
}),
content: result,
});
}).catch(next);
};
... ...
"use strict";
'use strict';
const Promise = require('bluebird');
const api = global.yoho.API;
const _ = require('lodash');
const helpers = global.yoho.helpers;
const crypto = global.yoho.crypto;
const _getContent = (data, isApp) => {
let result = [],
funcList = {
const processFun = {
carousel_banner(data, isApp) {
if (!data.list || !data.list.length) {
return [];
}
for (let item of data.list) {
item.img = helpers.image(item.src, 0, 0);
if (typeof item.url !== 'string') {
item.url = '';
}
}
data.isCarouselBanner = true;
return data;
},
};
const TEMPLATE_LIST = ['single_image', 'focus'];
if (!data) {
getCoupon(data, isApp) {
let result = [];
if (!data.length) {
return [];
}
let floorTitle = '',
item = data[0],
imageSrc = '';
build = [];
for(let i = 0,n=data.length;i<n;i++)//k v
let fun = '';
if (!data[i] || typeof data[i] !== 'object' || ! _.has(data[i],'template_name')) {
if (data[i].templateName) {
fun = data[i].templateName;
} else {
continue;
}
for (let key in item) {
if (key === 'floorTitle') {
floorTitle = (_.has(item[key], 'text') && (item[key].text !== '')) ? item[key].text : '';
continue;
}
if (TEMPLATE_LIST.indexof(fun) === -1) {
fun = data[i].template_name;
if (!item.encrypt) {
item.couponID = crypto.encryption('yoho9646abcdefgh', item.couponID);
item.encrypt = true;
}
if (!data[i].data || !is_callable("self::fun")) {
continue;
imageSrc = helpers.image(item.image.src, 0, 0);
item.image.src = imageSrc;
// 貌似不需要
// item.image.url = isApp ? item.image.url : _getFilterUrl(item.image.url);
switch (item.status) {
case '1':
item.isGet = true;
break;
case '2':
item.isZero = true;
break;
case '3':
item.isGeted = true;
break;
default:
break;
}
// tar note 处理楼层标题
if (fun === 'getCoupon' && _.has(data[i - 1], 'template_name') && data[i - 1].template_name === 'text') {
data[i].data.floorTitle = data[k - 1].data;
}
if (floorTitle !== '') {
data[0].floorTitle = floorTitle;
data[0].showFloorTitle = true;
}
result = data[0];
result.isCoupon = true;
return result;
},
text(data, isApp) {
data.isTitle = true;
if (data.text) {
data.isShow = true;
}
return data;
},
single_image(data, isApp) {
data[0].isSingleImage = true;
return data[0];
},
focus(data, isApp) {
let result = {};
result.isFocus = true;
result.data = data;
return result;
},
image_list(data, isApp) {
let result = {},
num,
width;
for (let image of data.list) {
num = data.title.column_num;
if (num === 0) {
image.src = image.src.replace('?imageView/{mode}/w/{width}/h/{height}', '');
} else {
if (640 % num === 0) {
width = parseInt(640 / num, 10);
width = !width ? 640 : width;
image.src = image.src.replace('?imageView/{mode}/w/{width}/h/{height}', '?imageView2/2/w/' + width);
image.src = helpers.image(image.src, width, 0);
} else {
image.src = image.src.replace('?imageView/{mode}/w/{width}/h/{height}', '');
}
}
build = self::fun(v['data'], isApp);
if (empty(build)) {
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']);
// }
}
result.isImageList = true;
result.imageList = {
col: data.title.column_num,
title: data.title.title,
list: data.list,
};
return result;
},
promotion() {
console.log(7);
}
};
const _getContent = (data, isApp) => {
let result = [],
build = [];
const TEMPLATE_LIST = ['single_image', 'focus'];
if (!data) {
return [];
}
for (let i = 0, n = data.length; i < n; i++) {
let fun = '';
if (!data[i] || typeof data[i] !== 'object' || !_.has(data[i], 'template_name')) {
if (data[i].templateName) {
fun = data[i].templateName;
} else {
continue;
}
result.push(build);
}
build = array();
return result;
}
if (TEMPLATE_LIST.indexOf(fun) === -1) {
fun = data[i].template_name;
}
if (!data[i].data || !_.has(processFun, fun)) {
continue;
}
// tar note 处理楼层标题
if (fun === 'getCoupon' && _.has(data[i - 1], 'template_name') && data[i - 1].template_name === 'text') {
data[i].data[0].floorTitle = data[i - 1].data;
}
build = processFun[fun](data[i].data, isApp);
if (!build) {
continue;
}
result.push(build);
}
build = [];
return result;
};
exports.floor = (params, isApp) => {
Promise.coroutine(function* (){
return Promise.coroutine(function*() {
let shareData,
resource = yield api.get('',Object.assign(params, {
method: 'app.promotion.queryCouponCenter',
}));
if(resource && resource.caode === 200){
let result = _getContent(resource.data, isApp);
}
else{
result = {},
resource = yield api.get('', Object.assign(params, {
method: 'app.promotion.queryCouponCenter',
}));
if (resource && resource.code === 200) {
result = _getContent(resource.data, isApp);
} else {
result.noData = true;
}
return result;
shareData = _getShare(params.contentCode, '领券中心');
// shareData = _getShare(params.contentCode, '领券中心');
})();
}
\ No newline at end of file
};
... ...
<div class="coupon-area-page yoho-page">
{{# content}}
{{#if isSingleImage}}
<a href="{{url}}"><img src="{{src}}" class="just-img"/></a>
{{/if}}
{{#if isCarouselBanner}}
{{> home/banner_top}}
{{/if}}
{{#if isFocus}}
{{> home/banner_top}}
{{/if}}
{{#if isCoupon}}
<div class="coupon-floor" coupon-id="{{couponID}}">
{{#if showFloorTitle}}
<div class="floor-title">
{{floorTitle}}
</div>
{{/if}}
<div class="floor-main" style="background-image: url({{image.src}});">
<a href="{{image.url}}" class="main-left"></a>
{{#if isGet}}
<div class="main-right-receive">
<span class="on-receive"></span>
</div>
<a href="{{image.url}}" class="main-right-use" style="display: none">
<span class="received"></span>
</a>
{{/if}}
{{#if isGeted}}
<a href="{{image.url}}" class="main-right-use">
<span class="received"></span>
</a>
{{/if}}
{{#if isZero}}
<a href="{{image.url}}" class="main-right-go">
<span class="zero"></span>
</a>
{{/if}}
</div>
</div>
{{/if}}
{{#if isImageList}}
{{> coupon/imagelist}}
{{/if}}
{{#if isNewArrival}}
{{> coupon/newarrival}}
{{/if}}
{{# share}}
<input id="shareLink" type="hidden" value="{{shareLink}}">
<input id="shareDesc" type="hidden" value="{{shareDesc}}">
<input id="shareImg" type="hidden" value="{{shareImg}}">
<input id="shareTitle" type="hidden" value="{{shareTitle}}">
{{/ share}}
{{#if noData}}
<input id="noData" type="hidden">
{{/if}}
{{/ content}}
</div>
<div class="floor-mask"></div>
<div class="floor-message">
<div class="coupon-message-content"></div>
<div class="coupon-message-op">
<span class="coupon-message-op-rel">刷新</span>
</div>
</div>
<div class="floor-tooltip">
<div class="iconfont icon-box">&#xe648;</div>
<div class="icon-msg">领取成功</div>
</div>
\ No newline at end of file