index.js 2.33 KB
'use strict';
const api = global.yoho.API;
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const helpers = global.yoho.helpers;

/**
 * 处理用户个人详情数据
 *
 * @param int uid 用户ID
 * @return Object 处理之后的个人详情数据
 */
const _getUserProfileData = (uid) => {
    return co(function*() {
        // 调用接口获取个人详情
        const data = {};
        return data;

        // return api.get('operations/api/v5/resource/get', {
        //     uid: uid
        // }, {
        //     cache: true,
        //     code: 200
        // });
    })();
};

/**
 * 处理个人中心页面优惠券,收藏的商品等的数目数据
 *
 * @param int uid 用户ID
 * @return Object 处理之后的个人中心页面收藏的商品等的数目数据
 */
const _getInfoNumData = (uid) => {
    return co(function*() {
        const data = {
            wait_pay_num: 1,
            wait_cargo_num: 2,
            send_cargo_num: 3,
            address_num: 4,
            product_favorite_total: 5,
            brand_favorite_total: 6,
            yoho_coin_num: 7
        };
        return data;
    })();

};

exports.getUserHomeData = (uid) => {
    return Promise.all([_getUserProfileData(uid), _getInfoNumData(uid)]);
};

const helpListDataProc = (helpData) => {
    const formatData = [];

    helpData = helpData || [];
    _.forEach(helpData, (item) => {
        formatData.push({
            name: item.caption,
            code: item.code,
            url: helpers.urlFormat('/home/helpDetail', {
                code: item.code,
                caption: item.caption,
            })
        });
    });
    return formatData;
};



/**
 * 帮助中心列表页
 *
 * @param data
 *
 */
exports.getHelpInfo = (data) => {
    var defaultParam = {
            method: 'app.help.li'
        },
        infoData = Object.assign(defaultParam, data);

    return api.get('', infoData).then(result => {

        return helpListDataProc(result.data);
    });
};

/**
 * 帮助中心详情页
 *
 * @param data
 */
exports.getHelpDetail = (data) => {
    var defaultParam = {
            method: 'app.help.detail',
            return_type: 'html'
        },
        detailData = Object.assign(defaultParam, data);

    return api.get('', detailData).then(result => {
        return result;
    });
};