spread.js 1.43 KB
/**
 * 我的消息model
 * @author: yyq<yanqing.yang@yoho.cn>
 * @date: 2016/8/29
 */
'use strict';
const _ = require('lodash');
const setPager = require(`${global.utils}/pager`).setPager;

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
            }})
        ]).then(result => {
            let resData = _.get(result, '[0].data', {});

            let resList = result[1];

            if (resList.code === 200) {
                let list = _.get(resList, 'data.data', []);

                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
                    })
                }
            }

            return resData;
        });
    }
};