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
|
+}; |