Authored by zzzzzzz

完成40%

1 -"use strict"; 1 +'use strict';
2 2
3 -const model = require('../models/coupon-floor'); 3 +const model = require('../models/coupon-floor'),
  4 + headerModel = require('../../../doraemon/models/header');
4 5
5 exports.index = (req, res, next) => { 6 exports.index = (req, res, next) => {
6 let uid = ''; 7 let uid = '';
7 - if(req.yoho.isApp){ 8 +
  9 + if (req.yoho.isApp) {
8 uid = req.query.uid; 10 uid = req.query.uid;
9 - }  
10 - else{ 11 + } else {
11 uid = req.user.uid; 12 uid = req.user.uid;
12 } 13 }
13 model.floor({ 14 model.floor({
14 uid: uid || 15184104, 15 uid: uid || 15184104,
15 contentCode: req.query.code 16 contentCode: req.query.code
16 - }, req.yoho.isApp);  
17 -}  
  17 + }, req.yoho.isApp).then(result => {
  18 + res.render('coupon-floor', {
  19 + module: 'activity',
  20 + page: 'coupon-floor',
  21 + wechatShare: true,
  22 + title: '领券中心',
  23 + pageHeader: headerModel.setNav({
  24 + navTitle: '领券中心'
  25 + }),
  26 + content: result,
  27 + });
  28 + }).catch(next);
  29 +};
1 -"use strict"; 1 +'use strict';
2 2
3 const Promise = require('bluebird'); 3 const Promise = require('bluebird');
4 const api = global.yoho.API; 4 const api = global.yoho.API;
5 const _ = require('lodash'); 5 const _ = require('lodash');
  6 +const helpers = global.yoho.helpers;
  7 +const crypto = global.yoho.crypto;
  8 +
  9 +const processFun = {
  10 + carousel_banner(data, isApp) {
  11 + if (!data.list || !data.list.length) {
  12 + return [];
  13 + }
  14 + for (let item of data.list) {
  15 + item.img = helpers.image(item.src, 0, 0);
  16 + if (typeof item.url !== 'string') {
  17 + item.url = '';
  18 + }
  19 + }
  20 + data.isCarouselBanner = true;
  21 + return data;
  22 + },
  23 +
  24 + getCoupon(data, isApp) {
  25 + let result = [];
  26 +
  27 + if (!data.length) {
  28 + return [];
  29 + }
  30 + let floorTitle = '',
  31 + item = data[0],
  32 + imageSrc = '';
  33 +
  34 + for (let key in item) {
  35 + if (key === 'floorTitle') {
  36 + floorTitle = (_.has(item[key], 'text') && (item[key].text !== '')) ? item[key].text : '';
  37 + continue;
  38 + }
  39 + if (!item.encrypt) {
  40 + item.couponID = crypto.encryption('yoho9646abcdefgh', item.couponID);
  41 + item.encrypt = true;
  42 + }
  43 + imageSrc = helpers.image(item.image.src, 0, 0);
  44 + item.image.src = imageSrc;
  45 +
  46 + // 貌似不需要
  47 + // item.image.url = isApp ? item.image.url : _getFilterUrl(item.image.url);
  48 + switch (item.status) {
  49 + case '1':
  50 + item.isGet = true;
  51 + break;
  52 + case '2':
  53 + item.isZero = true;
  54 + break;
  55 + case '3':
  56 + item.isGeted = true;
  57 + break;
  58 + default:
  59 + break;
  60 + }
  61 + }
  62 + if (floorTitle !== '') {
  63 + data[0].floorTitle = floorTitle;
  64 + data[0].showFloorTitle = true;
  65 + }
  66 + result = data[0];
  67 + result.isCoupon = true;
  68 + return result;
  69 + },
  70 +
  71 + text(data, isApp) {
  72 + data.isTitle = true;
  73 + if (data.text) {
  74 + data.isShow = true;
  75 + }
  76 + return data;
  77 + },
  78 +
  79 + single_image(data, isApp) {
  80 + data[0].isSingleImage = true;
  81 + return data[0];
  82 + },
  83 +
  84 + focus(data, isApp) {
  85 + let result = {};
  86 +
  87 + result.isFocus = true;
  88 + result.data = data;
  89 + return result;
  90 + },
  91 +
  92 + image_list(data, isApp) {
  93 + let result = {},
  94 + num,
  95 + width;
  96 +
  97 + for (let image of data.list) {
  98 + num = data.title.column_num;
  99 + if (num === 0) {
  100 + image.src = image.src.replace('?imageView/{mode}/w/{width}/h/{height}', '');
  101 + } else {
  102 + if (640 % num === 0) {
  103 + width = parseInt(640 / num, 10);
  104 + width = !width ? 640 : width;
  105 + image.src = image.src.replace('?imageView/{mode}/w/{width}/h/{height}', '?imageView2/2/w/' + width);
  106 + image.src = helpers.image(image.src, width, 0);
  107 + } else {
  108 + image.src = image.src.replace('?imageView/{mode}/w/{width}/h/{height}', '');
  109 + }
  110 + }
  111 + image.url = !image.url ? 'javascript:void(0);' : image.url;
  112 +
  113 + // if(isApp){
  114 + // image.url = !image.url ? 'javascript:void(0);' : image.url;
  115 + // }else{
  116 + // image.url = !image.url ? 'javascript:void(0);' : Helpers::getFilterUrl(image['url']);
  117 + // }
  118 + }
  119 + result.isImageList = true;
  120 + result.imageList = {
  121 + col: data.title.column_num,
  122 + title: data.title.title,
  123 + list: data.list,
  124 + };
  125 + return result;
  126 + },
  127 + promotion() {
  128 + console.log(7);
  129 + }
  130 +};
6 131
7 const _getContent = (data, isApp) => { 132 const _getContent = (data, isApp) => {
8 let result = [], 133 let result = [],
9 - funcList = { 134 + build = [];
10 135
11 - };  
12 const TEMPLATE_LIST = ['single_image', 'focus']; 136 const TEMPLATE_LIST = ['single_image', 'focus'];
  137 +
13 if (!data) { 138 if (!data) {
14 return []; 139 return [];
15 } 140 }
16 141
17 - build = [];  
18 - for(let i = 0,n=data.length;i<n;i++)//k v 142 + for (let i = 0, n = data.length; i < n; i++) {
  143 +
19 let fun = ''; 144 let fun = '';
20 - if (!data[i] || typeof data[i] !== 'object' || ! _.has(data[i],'template_name')) { 145 +
  146 + if (!data[i] || typeof data[i] !== 'object' || !_.has(data[i], 'template_name')) {
21 if (data[i].templateName) { 147 if (data[i].templateName) {
22 fun = data[i].templateName; 148 fun = data[i].templateName;
23 } else { 149 } else {
24 continue; 150 continue;
25 } 151 }
26 } 152 }
27 - if (TEMPLATE_LIST.indexof(fun) === -1) { 153 + if (TEMPLATE_LIST.indexOf(fun) === -1) {
28 fun = data[i].template_name; 154 fun = data[i].template_name;
29 } 155 }
30 - if (!data[i].data || !is_callable("self::fun")) { 156 + if (!data[i].data || !_.has(processFun, fun)) {
31 continue; 157 continue;
32 } 158 }
  159 +
33 // tar note 处理楼层标题 160 // tar note 处理楼层标题
34 if (fun === 'getCoupon' && _.has(data[i - 1], 'template_name') && data[i - 1].template_name === 'text') { 161 if (fun === 'getCoupon' && _.has(data[i - 1], 'template_name') && data[i - 1].template_name === 'text') {
35 - data[i].data.floorTitle = data[k - 1].data; 162 + data[i].data[0].floorTitle = data[i - 1].data;
36 } 163 }
37 - build = self::fun(v['data'], isApp);  
38 - if (empty(build)) { 164 + build = processFun[fun](data[i].data, isApp);
  165 + if (!build) {
39 continue; 166 continue;
40 } 167 }
41 result.push(build); 168 result.push(build);
42 } 169 }
43 - build = array(); 170 + build = [];
44 return result; 171 return result;
45 -} 172 +};
46 173
47 exports.floor = (params, isApp) => { 174 exports.floor = (params, isApp) => {
48 - Promise.coroutine(function* (){ 175 + return Promise.coroutine(function*() {
49 let shareData, 176 let shareData,
50 - resource = yield api.get('',Object.assign(params, { 177 + result = {},
  178 + resource = yield api.get('', Object.assign(params, {
51 method: 'app.promotion.queryCouponCenter', 179 method: 'app.promotion.queryCouponCenter',
52 })); 180 }));
53 181
54 - if(resource && resource.caode === 200){  
55 - let result = _getContent(resource.data, isApp);  
56 - }  
57 - else{ 182 + if (resource && resource.code === 200) {
  183 + result = _getContent(resource.data, isApp);
  184 + } else {
58 result.noData = true; 185 result.noData = true;
59 } 186 }
  187 + return result;
60 188
61 - shareData = _getShare(params.contentCode, '领券中心'); 189 + // shareData = _getShare(params.contentCode, '领券中心');
62 })(); 190 })();
63 -}  
  191 +};
1 -<div class="coupon-area-page yoho-page">  
2 - {{# content}}  
3 - {{#if isSingleImage}}  
4 - <a href="{{url}}"><img src="{{src}}" class="just-img"/></a>  
5 - {{/if}}  
6 - {{#if isCarouselBanner}}  
7 - {{> home/banner_top}}  
8 - {{/if}}  
9 - {{#if isFocus}}  
10 - {{> home/banner_top}}  
11 - {{/if}}  
12 - {{#if isCoupon}}  
13 - <div class="coupon-floor" coupon-id="{{couponID}}">  
14 - {{#if showFloorTitle}}  
15 - <div class="floor-title">  
16 - {{floorTitle}}  
17 - </div>  
18 - {{/if}}  
19 - <div class="floor-main" style="background-image: url({{image.src}});">  
20 - <a href="{{image.url}}" class="main-left"></a>  
21 - {{#if isGet}}  
22 - <div class="main-right-receive">  
23 - <span class="on-receive"></span>  
24 - </div>  
25 - <a href="{{image.url}}" class="main-right-use" style="display: none">  
26 - <span class="received"></span>  
27 - </a>  
28 - {{/if}}  
29 - {{#if isGeted}}  
30 - <a href="{{image.url}}" class="main-right-use">  
31 - <span class="received"></span>  
32 - </a>  
33 - {{/if}}  
34 - {{#if isZero}}  
35 - <a href="{{image.url}}" class="main-right-go">  
36 - <span class="zero"></span>  
37 - </a>  
38 - {{/if}}  
39 - </div>  
40 - </div>  
41 - {{/if}}  
42 - {{#if isImageList}}  
43 - {{> coupon/imagelist}}  
44 - {{/if}}  
45 - {{#if isNewArrival}}  
46 - {{> coupon/newarrival}}  
47 - {{/if}}  
48 - {{# share}}  
49 - <input id="shareLink" type="hidden" value="{{shareLink}}">  
50 - <input id="shareDesc" type="hidden" value="{{shareDesc}}">  
51 - <input id="shareImg" type="hidden" value="{{shareImg}}">  
52 - <input id="shareTitle" type="hidden" value="{{shareTitle}}">  
53 - {{/ share}}  
54 - {{#if noData}}  
55 - <input id="noData" type="hidden">  
56 - {{/if}}  
57 - {{/ content}}  
58 -</div>  
59 -<div class="floor-mask"></div>  
60 -<div class="floor-message">  
61 - <div class="coupon-message-content"></div>  
62 - <div class="coupon-message-op">  
63 - <span class="coupon-message-op-rel">刷新</span>  
64 - </div>  
65 -</div>  
66 -<div class="floor-tooltip">  
67 - <div class="iconfont icon-box">&#xe648;</div>  
68 - <div class="icon-msg">领取成功</div>  
69 -</div>