store-home.js
5.86 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
'use strict';
const _ = require('lodash');
const rightsJson = require('../../../public/js/activity/store-home/rights-detail.json'); // 写死的会员特权
class storeHome extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
_userInfo(params) {
let options = {
data: {
method: 'extend.trade.userinfo',
uid: params.uid,
shop_type: params.shopType
},
param: {
code: 200
},
api: global.yoho.ExtStoreAPI
};
return this.get(options).then(result => {
return result;
});
}
baseInfo(params) {
return Promise.all([
this._userInfo(params)
]).then(result => {
if (_.get(result, '[0].data')) {
let coffee = result[0].data.vip_type === 1;
let green = result[0].data.vip_type === 2;
let photography = result[0].data.vip_type === 3;
Object.assign(result[0].data, {
photography: photography,
coffee: coffee,
green: green,
process: this.getProcess(_.get(result[0], 'data.credit_points'), result[0].data.vip_type)
});
result[0].data.parentsGender = result[0].data.gender === '1' ? '男' : '女';
if (result[0].data.babyInfo) {
let thisGender = result[0].data.babyInfo.gender;
if (!thisGender) {
result[0].data.unknow = true;
}
result[0].data.gender = (thisGender === '1' ? '男' : '女');
result[0].data.otherGender = (thisGender === '1' ? '女' : '男');
if (result[0].data.gender === '男') {
result[0].data.genderId = 1;
result[0].data.otherGenderId = 2;
} else {
result[0].data.genderId = 2;
result[0].data.otherGenderId = 1;
}
}
let rightsObj = {};
let build = [];
let rightsUrl = '';
let vipLevel = `vip${result[0].data.vip_level}`;
if (photography) {
rightsObj = rightsJson.photography;
rightsUrl = '//mp.weixin.qq.com/s/iSd__pG6tEodktIlPMJgoQ';
}
if (green) {
rightsObj = rightsJson.green;
rightsUrl = '//mp.weixin.qq.com/s/JJgJW77sT9Ur87BR0iWevw';
}
if (coffee) {
rightsObj = rightsJson.coffee;
rightsUrl = '//mp.weixin.qq.com/s/o04mbaNXZ_kmvT2Bvlqg9w';
}
_.forEach(rightsObj, (val, key) => {
if (key === vipLevel) {
build = val;
}
});
result[0].data.rights = build;
result[0].data.rightsUrl = rightsUrl;
result = result[0].data;
}
return result;
});
}
history(params) {
let options = {
data: {
method: 'extend.trade.consumelist',
uid: params.uid,
shop_type: params.shopType,
page: params.page || 1,
limit: 20
},
param: {
code: 200
},
api: global.yoho.ExtStoreAPI
};
return this.get(options).then(result => {
let resu = {
list: []
};
if (_.get(result, 'data.consume_list')) {
let build = [];
_.forEach(result.data.consume_list, val => {
build.push({
amount: val.trade_amount_desc,
date: val.trade_date,
title: val.trade_title
});
});
resu.list = build;
}
return resu;
});
}
modify(params) {
let options = {
data: {
method: 'extend.trade.editBabyInfo',
uid: params.uid,
nick_name: params.nickName,
gender: params.gender,
birthday: params.birthday
},
param: {
code: 200
},
api: global.yoho.ExtStoreAPI
};
return this.get(options).then(result => {
return result;
});
}
getProcess(amount, type) {
let process = 0;
switch (type) {
case 1:
if (amount <= 0) {
process = 0;
}
if (amount > 0 && amount <= 800) {
process = (amount / 800 * 0.5) * 100;
}
if (amount > 800 && amount < 2000) {
process = ((amount - 800) / 1200 * 0.5 + 0.5) * 100;
}
if (amount >= 2000) {
process = 100;
}
return process;
case 2:
amount -= 1000;
if (amount < 0) {
amount = 0;
}
if (amount > 4000) {
amount = 4000;
}
process = (amount / 4000) * 100;
return process;
case 3:
if (amount < 0) {
amount = 0;
}
if (amount > 10000) {
amount = 10000;
}
process = (amount / 10000) * 100;
return process;
default:
return process;
}
}
}
module.exports = storeHome;