students-handler.js
3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
* 处理学生营销相关数据结构
* @date: 2016-08-06 18:20:52
* @author: sefon<809775195@qq.com>
*/
'use strict';
const utils = '../../../utils';
const _ = require('lodash');
const helpers = global.yoho.helpers;
const productProcess = require(`${utils}/product-process`);
const crypto = global.yoho.crypto;
/**
* 优惠券
* @params data array
* @return Object
*/
const getCoupon = (data) => {
let dest = [];
_.forEach(data, (value) => {
dest.push({
imgUrl: helpers.image(value.image.src, 400, 400),
url: value.image.url,
id: crypto.encryption('yoho9646abcdefgh', value.couponID)
});
});
return dest;
};
/**
* 补零
* @params data array
* @return Object
*/
const pad = (num, n) => {
let len = num.toString().length;
while (len < n) {
num = '0' + num;
len++;
}
return num;
};
/**
* 认证学生总数
* @params data array
* @return Object
*/
exports.studentsNum = (data) => {
let dest = [];
data = pad(data, 7);
for (let i = 0; i < data.length; i++) {
dest.push(data.charAt(i));
}
return dest;
};
/**
* 处理学生营销资源位数据
* @params data array 资源位接口返回数据
* @return object
*/
exports.studentResource = (data) => {
let dest = {couponObj: {}};
_.forEach(data, (value) => {
switch (value.template_name) {
case 'focus':
Object.assign(dest, {mainBanner: {list: value.data, floorId: value.template_id}});
break;
case 'getCoupon':
Object.assign(dest.couponObj, {couponItem: getCoupon(value.data), floorId: value.template_id});
break;
case 'recommend_content_five':
Object.assign(dest, {rightsObj: {rightsItem: value.data.list || {}, floorId: value.template_id}});
break;
case 'image_list':
Object.assign(dest, {activityObj: {activityItem: value.data.list || {}, floorId: value.template_id} });
break;
case 'link':
Object.assign(dest, {moreProducts: value.data[0].url || ''});
break;
case 'single_image':
Object.assign(dest, {identityObj: {
adImg: value.data[0].src || '', url: value.data[0].url,
identityItem: {sendCoin: value.data[0].title || 100},
floorId: value.template_id}
});
break;
case 'titleFloor':
Object.assign(dest.couponObj, {couponMore: value.data.title || {}});
break;
default:
break;
}
});
return dest;
};
/**
* 处理学生商品
* @params data array 资源位接口返回数据
* @return object
*/
exports.stuProducts = (data) => {
let products = productProcess.processProductList(data, {showTags: false});
_.forEach(data, (value, key) => {
delete data[key].discount;
data[key].market_price = data[key].sales_price;
delete data[key].sales_price;
if (value.student_price) {
Object.assign(data[key], {for_stu: true});
}
});
return products;
};
exports.stuVerify = (result, params) => {
let data = {resultParams: params};
if (result.code === 200) {
data.isError = false;
data.isStudent = result.data.isStudent === 1 ? true : false;
data.prompt = result.data.prompt;
} else {
data.isError = true;
data.errorMsg = result.message;
}
return data;
};