outlets.js 3.59 KB
/*
 * @Author: Targaryen
 * @Date:   2016-05-30 16:20:03
 * @Last Modified by:   Targaryen
 * @Last Modified time: 2016-05-30 18:21:08
 */

'use strict';
const library = '../../../library';
const _ = require('lodash');
const API = require(`${library}/api`).API;
const ServiceAPI = require(`${global.library}/api`).ServiceAPI;
const serviceApi = new ServiceAPI();
const api = new API();
const sign = require(`${library}/sign`);
const helpers = require(`${library}/helpers`);
const camelCase = require('../../../library/camel-case');
const saleApi = require('./sale-api');
const outletsProcess = require('./outlets-handler');


/**
 * 处理奥莱活动数据
 * @param  {[type]} origin [description]
 * @return {[type]}        [description]
 */
const handleOutletsActivityData = (origin) => {
    var dest = {};

    dest = origin;

    return dest;
};

/**
 * 接口获取奥莱活动数据
 * @param  {[type]} params [description]
 * @return {[type]}        [description]
 */
const getOutletsActivityOrigin = (params) => {
    return api.get('', sign.apiSign({
        id: params.id || null,
        platform: 1,
        size: params.size || null,
        yh_channel: 1,
        type: params.type || 0
    }));
};

/**
 * 获取奥莱首页数据
 * @param  {[type]} origin [description]
 * @return {[type]}        [description]
 */
exports.getOutletsIndexData = (params) => {
    return api.all([
        getOutletsActivityOrigin(params)
    ]).then(result => {
        let finalResult = {};

        if (result[0].code === 200) {
            finalResult = handleOutletsActivityData(result[0].data);
        }

        return finalResult;
    });
};


//奥莱频道资源码
const channelCode = {
    'boys' : '2af513637dc5feeec7f6f8b52989b24b',
    // 'boys' : 'e0565dad65fb8da1f39bc1ac83fc8346',
    'girls' : 'd1b56b56c3a12dc1f2f83958680a0911',
    'kids' : '0fd7ad594940f9ec5a03697317cf6521',
    'lifestyle' : 'b3d3f55a26f130ac2b516b9fb3823711',
}

/**
 * 获取奥莱频道页面数据
 * @param  {[object]} gender
 * @return {[type]}
 */
exports.getOutletsChannelData = (params) => {
    var channelData = {};
    return api.all([getChannelResouceData({content_code: channelCode[params.channel]}), getOutletsActivityData({platform: 2, size: 0, type:1})]).then(result => {
        if (result[0].code === 200) {
            Object.assign(channelData, outletsProcess.processFloor(result[0].data.list));
        }
        if (result[1].code === 200) {
            Object.assign(channelData, {flashSale: outletsProcess.formatActivityData(result[1].data)});
        }
        return channelData;
    });
}

/**
 * 获取奥莱频道资源位数据
 * @param  {[object]} params
 * @return {[type]}
 */
const getChannelResouceData = (params) => {
    return serviceApi.get('operations/api/v5/resource/home', sign.apiSign(params))
}

/**
 * 获取奥莱活动列表接口
 * @param  {[int]} id 活动id 为空表示查询全部活动
 * @param  {[int ]} platform 活动平台 1--WEB,2--APP,3--WAP,4--IPAD
 * @param  {[int]} size 查询数量,默认查询全部
 * @param  {[int]} channel 频道: 1 || 2 || 3 || 4
 * @param  {[int]} type 
 * @return {[type]} 0 活动列表,1 限时嗨购 2 即将结束 3.即将上线
 */
const getOutletsActivityData = (params) => {
    
    return api.get('', sign.apiSign(
        Object.assign({
            method: 'app.outlets.activityGet',
        }, params)));
}

/**
 * 获取奥莱频道商品分类
 * @param  {[object]} params
 * @return {[type]}
 */
 const getOutletsSortData = (params) => {
    return api.get('', sign.apiSign(
        Object.assign({
            method: 'app.outlets.activityGet',
        }, params)));
 }