1
|
'use strict';
|
1
|
'use strict';
|
2
|
-const api = global.yoho.API;
|
|
|
3
|
const serviceAPI = global.yoho.ServiceAPI;
|
2
|
const serviceAPI = global.yoho.ServiceAPI;
|
4
|
const _ = require('lodash');
|
3
|
const _ = require('lodash');
|
5
|
const rp = require('request-promise');
|
4
|
const rp = require('request-promise');
|
|
@@ -10,47 +9,54 @@ const wxCode = { |
|
@@ -10,47 +9,54 @@ const wxCode = { |
10
|
wxAppSecret: 'ce21ae4a3f93852279175a167e54509b'
|
9
|
wxAppSecret: 'ce21ae4a3f93852279175a167e54509b'
|
11
|
};
|
10
|
};
|
12
|
|
11
|
|
13
|
-/**
|
12
|
+module.exports = class extends global.yoho.BaseModel {
|
|
|
13
|
+ constructor(ctx) {
|
|
|
14
|
+ super(ctx);
|
|
|
15
|
+ }
|
|
|
16
|
+
|
|
|
17
|
+ /**
|
14
|
* 获取微信授权地址
|
18
|
* 获取微信授权地址
|
15
|
* @param callback
|
19
|
* @param callback
|
16
|
* @returns {string}
|
20
|
* @returns {string}
|
17
|
*/
|
21
|
*/
|
18
|
-const getWxOauthUrl = (callback) => {
|
22
|
+ getWxOauthUrl(callback) {
|
19
|
return 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
|
23
|
return 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
|
20
|
wxCode.wxAppId + '&redirect_uri=' + callback +
|
24
|
wxCode.wxAppId + '&redirect_uri=' + callback +
|
21
|
'&response_type=code&scope=snsapi_userinfo#wechat_redirect';
|
25
|
'&response_type=code&scope=snsapi_userinfo#wechat_redirect';
|
22
|
-};
|
26
|
+ }
|
23
|
|
27
|
|
24
|
-/**
|
28
|
+ /**
|
25
|
* 生成分享url
|
29
|
* 生成分享url
|
26
|
* @param shareUid
|
30
|
* @param shareUid
|
27
|
* @param actId
|
31
|
* @param actId
|
28
|
* @param nums
|
32
|
* @param nums
|
29
|
* @returns {string}
|
33
|
* @returns {string}
|
30
|
*/
|
34
|
*/
|
31
|
-const createShareUrl = (shareUid, actId, nums) => {
|
35
|
+ createShareUrl(shareUid, actId, nums) {
|
32
|
return 'http://m.yohobuy.com/activity/invite/share_' + shareUid + '_' + actId + '_' + nums + '.html';
|
36
|
return 'http://m.yohobuy.com/activity/invite/share_' + shareUid + '_' + actId + '_' + nums + '.html';
|
33
|
-};
|
37
|
+ }
|
34
|
|
38
|
|
35
|
-/**
|
39
|
+ /**
|
36
|
* 根据第三方id,查询绑定信息
|
40
|
* 根据第三方id,查询绑定信息
|
37
|
* @param {[string || array]} openIds 第三方id数组
|
41
|
* @param {[string || array]} openIds 第三方id数组
|
38
|
* @return {[array]}
|
42
|
* @return {[array]}
|
39
|
*/
|
43
|
*/
|
40
|
-const getBindLogByOpenId = (openIds) => {
|
44
|
+ getBindLogByOpenId(openIds) {
|
41
|
openIds = _.isArray(openIds) ? openIds : [openIds];
|
45
|
openIds = _.isArray(openIds) ? openIds : [openIds];
|
42
|
- return api.get('', {
|
46
|
+ return this.get({
|
|
|
47
|
+ data: {
|
43
|
method: 'wap.invite.getBindLogByOpenId',
|
48
|
method: 'wap.invite.getBindLogByOpenId',
|
44
|
openIds: openIds.join(',')
|
49
|
openIds: openIds.join(',')
|
|
|
50
|
+ }
|
45
|
});
|
51
|
});
|
46
|
-};
|
52
|
+ }
|
47
|
|
53
|
|
48
|
-/**
|
54
|
+ /**
|
49
|
* 合并第三方头像和昵称
|
55
|
* 合并第三方头像和昵称
|
50
|
* @param {[array]} data 邀请的用户列表,最主要的是openId字段
|
56
|
* @param {[array]} data 邀请的用户列表,最主要的是openId字段
|
51
|
* @return {[array]}
|
57
|
* @return {[array]}
|
52
|
*/
|
58
|
*/
|
53
|
-const mergeBindLogDate = (data) => {
|
59
|
+ mergeBindLogDate(data) {
|
54
|
let openIds = [];
|
60
|
let openIds = [];
|
55
|
let photo = '//static.yohobuy.com/m/v1/activity/newyear/images/108.png';
|
61
|
let photo = '//static.yohobuy.com/m/v1/activity/newyear/images/108.png';
|
56
|
|
62
|
|
|
@@ -61,7 +67,7 @@ const mergeBindLogDate = (data) => { |
|
@@ -61,7 +67,7 @@ const mergeBindLogDate = (data) => { |
61
|
openIds.push(req.openId);
|
67
|
openIds.push(req.openId);
|
62
|
});
|
68
|
});
|
63
|
|
69
|
|
64
|
- return getBindLogByOpenId(openIds).then(result => {
|
70
|
+ return this.getBindLogByOpenId(openIds).then(result => {
|
65
|
if (!_.isEmpty(result.data)) {
|
71
|
if (!_.isEmpty(result.data)) {
|
66
|
_.forEach(data, (req, key) => {
|
72
|
_.forEach(data, (req, key) => {
|
67
|
data[key].img = photo;
|
73
|
data[key].img = photo;
|
|
@@ -76,21 +82,22 @@ const mergeBindLogDate = (data) => { |
|
@@ -76,21 +82,22 @@ const mergeBindLogDate = (data) => { |
76
|
}
|
82
|
}
|
77
|
return data;
|
83
|
return data;
|
78
|
});
|
84
|
});
|
79
|
-};
|
85
|
+ }
|
80
|
|
86
|
|
81
|
-/**
|
87
|
+ /**
|
82
|
* 获取分享页面列表数据
|
88
|
* 获取分享页面列表数据
|
83
|
* @param {[int]} uid 用户id
|
89
|
* @param {[int]} uid 用户id
|
84
|
* @param {[int]} activityId 活动id
|
90
|
* @param {[int]} activityId 活动id
|
85
|
* @return {[array]}
|
91
|
* @return {[array]}
|
86
|
*/
|
92
|
*/
|
87
|
-const index = (params) => {
|
93
|
+ index(params) {
|
88
|
params = params || {};
|
94
|
params = params || {};
|
89
|
|
95
|
|
90
|
- return api.get('', Object.assign({
|
96
|
+ return this.get({
|
|
|
97
|
+ data: Object.assign({
|
91
|
method: 'wap.invite.index'
|
98
|
method: 'wap.invite.index'
|
92
|
- }, params
|
|
|
93
|
- )).then((result) => {
|
99
|
+ }, params)
|
|
|
100
|
+ }).then((result) => {
|
94
|
let firstData = {
|
101
|
let firstData = {
|
95
|
isNil: false,
|
102
|
isNil: false,
|
96
|
isEmpty: false,
|
103
|
isEmpty: false,
|
|
@@ -106,7 +113,7 @@ const index = (params) => { |
|
@@ -106,7 +113,7 @@ const index = (params) => { |
106
|
firstData.isNil = true;
|
113
|
firstData.isNil = true;
|
107
|
break;
|
114
|
break;
|
108
|
case 200:
|
115
|
case 200:
|
109
|
- return mergeBindLogDate(result.data).then(data => {
|
116
|
+ return this.mergeBindLogDate(result.data).then(data => {
|
110
|
let len = data.length;
|
117
|
let len = data.length;
|
111
|
|
118
|
|
112
|
// 判断是否否5条分享
|
119
|
// 判断是否否5条分享
|
|
@@ -132,58 +139,66 @@ const index = (params) => { |
|
@@ -132,58 +139,66 @@ const index = (params) => { |
132
|
|
139
|
|
133
|
return Object.assign(firstData, result);
|
140
|
return Object.assign(firstData, result);
|
134
|
});
|
141
|
});
|
135
|
-};
|
142
|
+ }
|
136
|
|
143
|
|
137
|
-/**
|
144
|
+ /**
|
138
|
* 通过手机号发送验证码
|
145
|
* 通过手机号发送验证码
|
139
|
* @param {[int]} area 区域,中国:86
|
146
|
* @param {[int]} area 区域,中国:86
|
140
|
* @param {[string]} mobile 手机号
|
147
|
* @param {[string]} mobile 手机号
|
141
|
* @return {[array]}
|
148
|
* @return {[array]}
|
142
|
*/
|
149
|
*/
|
143
|
-const sendRegCodeToMobile = (params) => {
|
|
|
144
|
- return api.get('', Object.assign({
|
150
|
+ sendRegCodeToMobile(params) {
|
|
|
151
|
+ return this.get({
|
|
|
152
|
+ data: Object.assign({
|
145
|
method: 'app.register.sendRegCodeToMobile'
|
153
|
method: 'app.register.sendRegCodeToMobile'
|
146
|
- }, params));
|
|
|
147
|
-};
|
154
|
+ }, params)
|
|
|
155
|
+ });
|
|
|
156
|
+ }
|
148
|
|
157
|
|
149
|
-/**
|
158
|
+ /**
|
150
|
* 发送已注册用户参与活动的优惠券
|
159
|
* 发送已注册用户参与活动的优惠券
|
151
|
* @param {[string]} mobile 手机号
|
160
|
* @param {[string]} mobile 手机号
|
152
|
* @param {[int]} activityId 活动id
|
161
|
* @param {[int]} activityId 活动id
|
153
|
* @return {[array]}
|
162
|
* @return {[array]}
|
154
|
*/
|
163
|
*/
|
155
|
-const checkOldUserCoupon = (params) => {
|
|
|
156
|
- return api.get('', Object.assign({
|
164
|
+ checkOldUserCoupon(params) {
|
|
|
165
|
+ return this.get({
|
|
|
166
|
+ data: Object.assign({
|
157
|
method: 'wap.invite.checkOldUserCoupon'
|
167
|
method: 'wap.invite.checkOldUserCoupon'
|
158
|
- }, params));
|
|
|
159
|
-};
|
168
|
+ }, params)
|
|
|
169
|
+ });
|
|
|
170
|
+ }
|
160
|
|
171
|
|
161
|
-/**
|
172
|
+ /**
|
162
|
* 验证手机验证码是否正确
|
173
|
* 验证手机验证码是否正确
|
163
|
* @param {[int]} area 区域,中国:86
|
174
|
* @param {[int]} area 区域,中国:86
|
164
|
* @param {[string]} mobile 手机号
|
175
|
* @param {[string]} mobile 手机号
|
165
|
* @param {[int]} code 验证码
|
176
|
* @param {[int]} code 验证码
|
166
|
* @return {[array]}
|
177
|
* @return {[array]}
|
167
|
*/
|
178
|
*/
|
168
|
-const validRegCode = (params) => {
|
|
|
169
|
- return api.get('', Object.assign({
|
179
|
+ validRegCode(params) {
|
|
|
180
|
+ return this.get({
|
|
|
181
|
+ data: Object.assign({
|
170
|
method: 'app.register.validRegCode'
|
182
|
method: 'app.register.validRegCode'
|
171
|
- }, params));
|
|
|
172
|
-};
|
183
|
+ }, params)
|
|
|
184
|
+ });
|
|
|
185
|
+ }
|
173
|
|
186
|
|
174
|
-/**
|
187
|
+ /**
|
175
|
* 手机账号注册
|
188
|
* 手机账号注册
|
176
|
* @param {[string]} mobile 手机号
|
189
|
* @param {[string]} mobile 手机号
|
177
|
* @param {[string]} activityName 活动名称
|
190
|
* @param {[string]} activityName 活动名称
|
178
|
* @return {[array]}
|
191
|
* @return {[array]}
|
179
|
*/
|
192
|
*/
|
180
|
-const register = (params) => {
|
|
|
181
|
- return api.get('', Object.assign({
|
193
|
+ register(params) {
|
|
|
194
|
+ return this.get({
|
|
|
195
|
+ data: Object.assign({
|
182
|
method: 'wap.invite.register'
|
196
|
method: 'wap.invite.register'
|
183
|
- }, params));
|
|
|
184
|
-};
|
197
|
+ }, params)
|
|
|
198
|
+ });
|
|
|
199
|
+ }
|
185
|
|
200
|
|
186
|
-/**
|
201
|
+ /**
|
187
|
* 微信好友获取红包方法(即分享出去的地址)
|
202
|
* 微信好友获取红包方法(即分享出去的地址)
|
188
|
* @param {[int]} uid 分享用户id
|
203
|
* @param {[int]} uid 分享用户id
|
189
|
* @param {[int]} activityId 活动id
|
204
|
* @param {[int]} activityId 活动id
|
|
@@ -193,7 +208,7 @@ const register = (params) => { |
|
@@ -193,7 +208,7 @@ const register = (params) => { |
193
|
* @param {[String]} headImgUrl 微信头像
|
208
|
* @param {[String]} headImgUrl 微信头像
|
194
|
* @returns {[array]}
|
209
|
* @returns {[array]}
|
195
|
*/
|
210
|
*/
|
196
|
-const shareModel = (params) => {
|
211
|
+ shareModel(params) {
|
197
|
let firstData = {
|
212
|
let firstData = {
|
198
|
isEmpty: false,
|
213
|
isEmpty: false,
|
199
|
isFive: false,
|
214
|
isFive: false,
|
|
@@ -204,16 +219,17 @@ const shareModel = (params) => { |
|
@@ -204,16 +219,17 @@ const shareModel = (params) => { |
204
|
let listData = [];
|
219
|
let listData = [];
|
205
|
|
220
|
|
206
|
// 这里面的逻辑就是获取第三方用户的头像和昵称,然后插入数据和更新数据
|
221
|
// 这里面的逻辑就是获取第三方用户的头像和昵称,然后插入数据和更新数据
|
207
|
- return api.get('', Object.assign({
|
222
|
+ return this.get({
|
|
|
223
|
+ data: Object.assign({
|
208
|
method: 'wap.invite.share'
|
224
|
method: 'wap.invite.share'
|
209
|
- }, params))
|
|
|
210
|
- .then((result) => {
|
225
|
+ }, params)
|
|
|
226
|
+ }).then((result) => {
|
211
|
// list为空,说明不是分享者本人
|
227
|
// list为空,说明不是分享者本人
|
212
|
if (result.code !== 200 || _.isEmpty(result.data.list)) {
|
228
|
if (result.code !== 200 || _.isEmpty(result.data.list)) {
|
213
|
return result;
|
229
|
return result;
|
214
|
}
|
230
|
}
|
215
|
|
231
|
|
216
|
- return mergeBindLogDate(result.data.list).then(data => {
|
232
|
+ return this.mergeBindLogDate(result.data.list).then(data => {
|
217
|
let len = data.length;
|
233
|
let len = data.length;
|
218
|
|
234
|
|
219
|
// 判断是否满5条分享
|
235
|
// 判断是否满5条分享
|
|
@@ -237,9 +253,9 @@ const shareModel = (params) => { |
|
@@ -237,9 +253,9 @@ const shareModel = (params) => { |
237
|
return result;
|
253
|
return result;
|
238
|
});
|
254
|
});
|
239
|
});
|
255
|
});
|
240
|
-};
|
256
|
+ }
|
241
|
|
257
|
|
242
|
-/**
|
258
|
+ /**
|
243
|
* 邀请好友赢福利之后领取优惠券
|
259
|
* 邀请好友赢福利之后领取优惠券
|
244
|
* @param {[int]} uid 用户id
|
260
|
* @param {[int]} uid 用户id
|
245
|
* @param {[int]} activityId 活动id
|
261
|
* @param {[int]} activityId 活动id
|
|
@@ -248,13 +264,15 @@ const shareModel = (params) => { |
|
@@ -248,13 +264,15 @@ const shareModel = (params) => { |
248
|
* @param {[string]} openId 微信的union_id
|
264
|
* @param {[string]} openId 微信的union_id
|
249
|
* @returns {[array]}
|
265
|
* @returns {[array]}
|
250
|
*/
|
266
|
*/
|
251
|
-const receiveCoupons = (params) => {
|
|
|
252
|
- return api.get('', Object.assign({
|
267
|
+ receiveCoupons(params) {
|
|
|
268
|
+ return this.get({
|
|
|
269
|
+ data: Object.assign({
|
253
|
method: 'wap.invite.receiveCoupons'
|
270
|
method: 'wap.invite.receiveCoupons'
|
254
|
- }, params));
|
|
|
255
|
-};
|
271
|
+ }, params)
|
|
|
272
|
+ });
|
|
|
273
|
+ }
|
256
|
|
274
|
|
257
|
-/**
|
275
|
+ /**
|
258
|
* 获取分享列表和用户信息
|
276
|
* 获取分享列表和用户信息
|
259
|
* @param {[int]} uid 用户id
|
277
|
* @param {[int]} uid 用户id
|
260
|
* @param {[int]} shareUid 分享着uid
|
278
|
* @param {[int]} shareUid 分享着uid
|
|
@@ -263,7 +281,7 @@ const receiveCoupons = (params) => { |
|
@@ -263,7 +281,7 @@ const receiveCoupons = (params) => { |
263
|
* @param {[int]} activityId 活动id
|
281
|
* @param {[int]} activityId 活动id
|
264
|
* @return {[array]}
|
282
|
* @return {[array]}
|
265
|
*/
|
283
|
*/
|
266
|
-const myCoupons = (params) => {
|
284
|
+ myCoupons(params) {
|
267
|
let mobile;
|
285
|
let mobile;
|
268
|
let firstData = {
|
286
|
let firstData = {
|
269
|
isEmpty: false,
|
287
|
isEmpty: false,
|
|
@@ -274,15 +292,17 @@ const myCoupons = (params) => { |
|
@@ -274,15 +292,17 @@ const myCoupons = (params) => { |
274
|
};
|
292
|
};
|
275
|
let listData = [];
|
293
|
let listData = [];
|
276
|
|
294
|
|
277
|
- return api.get('', Object.assign({
|
295
|
+ return this.get({
|
|
|
296
|
+ data: Object.assign({
|
278
|
method: 'wap.invite.myCoupons'
|
297
|
method: 'wap.invite.myCoupons'
|
279
|
- }, params)).then((result) => {
|
298
|
+ }, params)
|
|
|
299
|
+ }).then((result) => {
|
280
|
|
300
|
|
281
|
if (result.code !== 200) {
|
301
|
if (result.code !== 200) {
|
282
|
return result;
|
302
|
return result;
|
283
|
}
|
303
|
}
|
284
|
|
304
|
|
285
|
- return mergeBindLogDate(result.data.list).then(data => {
|
305
|
+ return this.mergeBindLogDate(result.data.list).then(data => {
|
286
|
listData = data;
|
306
|
listData = data;
|
287
|
|
307
|
|
288
|
if (listData.length < 5) {
|
308
|
if (listData.length < 5) {
|
|
@@ -304,13 +324,13 @@ const myCoupons = (params) => { |
|
@@ -304,13 +324,13 @@ const myCoupons = (params) => { |
304
|
return [result.data.list, result.data.myProfile];
|
324
|
return [result.data.list, result.data.myProfile];
|
305
|
});
|
325
|
});
|
306
|
});
|
326
|
});
|
307
|
-};
|
327
|
+ }
|
308
|
|
328
|
|
309
|
-/**
|
329
|
+ /**
|
310
|
* 授权后获取微信用户信息
|
330
|
* 授权后获取微信用户信息
|
311
|
* @return {[array]}
|
331
|
* @return {[array]}
|
312
|
*/
|
332
|
*/
|
313
|
-const getWxUserInfo = (params) => {
|
333
|
+ getWxUserInfo(params) {
|
314
|
let url1 = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' +
|
334
|
let url1 = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' +
|
315
|
wxCode.wxAppId + '&secret=' + wxCode.wxAppSecret + '&code=' +
|
335
|
wxCode.wxAppId + '&secret=' + wxCode.wxAppSecret + '&code=' +
|
316
|
params.code + '&grant_type=authorization_code';
|
336
|
params.code + '&grant_type=authorization_code';
|
|
@@ -340,31 +360,18 @@ const getWxUserInfo = (params) => { |
|
@@ -340,31 +360,18 @@ const getWxUserInfo = (params) => { |
340
|
return result2;
|
360
|
return result2;
|
341
|
});
|
361
|
});
|
342
|
});
|
362
|
});
|
343
|
-};
|
363
|
+ }
|
344
|
|
364
|
|
345
|
-/**
|
365
|
+ /**
|
346
|
* 获取 邀请好友赢福利的类型:
|
366
|
* 获取 邀请好友赢福利的类型:
|
347
|
* 1. 普通的要求好友赢福利
|
367
|
* 1. 普通的要求好友赢福利
|
348
|
* 2. 会员日的邀请好友 赢福利
|
368
|
* 2. 会员日的邀请好友 赢福利
|
349
|
*/
|
369
|
*/
|
350
|
-const checkType = () => {
|
|
|
351
|
- const url = '/activity/UserdaySigninController/isUserday';
|
|
|
352
|
-
|
|
|
353
|
- return serviceAPI.get(url, {});
|
|
|
354
|
-};
|
|
|
355
|
-
|
|
|
356
|
-module.exports = {
|
|
|
357
|
- index,
|
|
|
358
|
- checkType,
|
|
|
359
|
- shareModel,
|
|
|
360
|
- getBindLogByOpenId,
|
|
|
361
|
- sendRegCodeToMobile,
|
|
|
362
|
- checkOldUserCoupon,
|
|
|
363
|
- validRegCode,
|
|
|
364
|
- register,
|
|
|
365
|
- receiveCoupons,
|
|
|
366
|
- myCoupons,
|
|
|
367
|
- createShareUrl,
|
|
|
368
|
- getWxOauthUrl,
|
|
|
369
|
- getWxUserInfo
|
370
|
+ checkType() {
|
|
|
371
|
+ return this.get({
|
|
|
372
|
+ api: serviceAPI,
|
|
|
373
|
+ url: '/activity/UserdaySigninController/isUserday',
|
|
|
374
|
+ data: {}
|
|
|
375
|
+ });
|
|
|
376
|
+ }
|
370
|
}; |
377
|
}; |