spread.js
2.63 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
/**
* 我的消息model
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/8/29
*/
'use strict';
const _ = require('lodash');
const setPager = require(`${global.utils}/pager`).setPager;
const POP_IMG_CODE = 'b2b5cde8144aff3073573c3b323344ab';
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getIndexData(uid, page) {
return Promise.all([
this.get({data: {
method: 'app.invitecode.my',
uid: uid
}}),
this.get({data: {
method: 'app.invitecode.history',
uid: uid,
page: page || 1
}}),
this.get({
api: global.yoho.ServiceAPI,
url: 'operations/api/v5/resource/get',
data: {
// 线上线下资源码不一致
content_code: _.get(this, 'ctx.req.app.locals.isProduction', false) ? POP_IMG_CODE : 'acf176e4f6259bebd64ffb13e102801b' // eslint-disable-line
}
})
]).then(result => {
let resData = _.get(result, '[0].data', {});
let resList = result[1];
// 已设置潮流口令,显示潮流口令
if (resData.trendWord) {
resData.inviteCode = resData.trendWord;
}
if (resList.code === 200) {
let list = _.get(resList, 'data.data', []);
resData.rules = _.get(resList, 'data.activityRuleDesc', '');
if (!_.isEmpty(list)) {
resData.list = list;
}
let totalPage = _.get(resList, 'data.pageSize', 1);
if (+totalPage > 1) {
resData.pager = setPager(totalPage, {page: page});
Object.assign(resData.pager, {
count: _.get(resList, 'data.total', 0),
curPage: _.get(resList, 'data.currPage', 1),
totalPages: totalPage
});
}
}
if (result[2].code === 200) {
let sourceData = result[2].data || [];
_.dropWhile(sourceData, o => {
return o.template_name !== 'single_image';
});
resData.popImgSrc = _.head(_.split(_.get(sourceData, '[0].data[0].src', ''), '?'));
}
return resData;
});
}
updateTrendWord(uid, word) {
return this.get({data: {
method: 'app.trendword.update',
uid: uid,
trendWord: word
}});
}
};