|
|
"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 |
|
|
}; |
...
|
...
|
|