tide-command.js 1.45 KB
const _ = require('lodash');

module.exports = class extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    // 文字说明
    invitionText(uid) {
        return this.get({
            data: {
                method: 'app.invitecode.my',
                uid: uid
            },
            api: global.yoho.API,
            param: {code: 200}
        }).then((result) => {

            if (result && result.code === 200 && result.data) {

                return result.data;
            } else {
                return {};
            }
        });
    }

    // 资源位图
    resources(contentCode) {
        return this.get({
            url: 'operations/api/v5/resource/get',
            data: {
                content_code: contentCode
            },
            api: global.yoho.ServiceAPI,
            param: {code: 200}
        }).then((result) => {
            if (result && result.data) {

                return result.data[0];
            }
        });
    }

    invitionData(uid, contentCode, hideTips) {
        return Promise.all([this.invitionText(uid), this.resources(contentCode)]).then((result) => {

            let finaData = {};

            finaData = Object.assign(finaData, result[0]);
            finaData.imgSrc = _.get(result[1], 'data[0].src', '');
            finaData.resourcesUrl = _.get(result[1], 'data[0].url', '');
            finaData.hideTips = hideTips;

            return finaData;
        });
    }
};