sale.js 6.95 KB
/*
 * @Author: Targaryen
 * @Date:   2016-05-19 10:20:08
 * @Last Modified by:   Targaryen
 * @Last Modified time: 2016-05-31 09:43:24
 */

'use strict';
const library = '../../../library';
const utils = '../../../utils';
const API = require(`${library}/api`).API;
const api = new API();
const saleApi = require('./sale-api');
const saleHandler = require('./sale-handler');
const productProcess = require(`${utils}/product-process`);
const _ = require('lodash');

/**
 * 获取Sale首页商品列表数据 仅 Ajax 调用 Controller 调用
 * @return {[type]} [description]
 */
exports.getSaleGoodsData = (params) => {

    return saleApi.getSaleGoodsList(params).then(result => {
        let finalResult = {};

        if (result.code === 200) {
            finalResult.goods = productProcess.processProductList(result.data.product_list);
        }
        return finalResult;
    });
};

/**
 * 获取 Sale 首页数据 Controller 调用
 * @return {[type]} [description]
 */
exports.getSaleIndexData = () => {

    return api.all([
        saleApi.getSaleActivityList(),
        saleApi.getSaleBannerList('7c2b77093421efa8ae9302c91460db73')
    ]).then(result => {
        var finalResult = {};

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

        if (result[1].code === 200) {
            finalResult.topBanner = saleHandler.handleSaleBannerData(result[1].data);
            finalResult.activityEnter = saleHandler.handleSaleBannerSmallData(result[1].data);
        }

        finalResult.saleCategory = [{
                title: 'VIP会员专享',
                urlLocation: 'www.baidu.com',
                navItem: [{
                    vip: true,
                    urlLocation: '/sa/ds',
                    title: '今日推荐'
                }, {
                    incompleteSize: true,
                    urlLocation: '/sa/ds',
                    title: '上装'
                }, {
                    newDiscount: true,
                    urlLocation: '/sa/ds',
                    title: '裤装'
                }, {
                    vip: true,
                    urlLocation: '/sa/ds',
                    title: '鞋履'
                }, {
                    vip: true,
                    urlLocation: '/sa/ds',
                    title: '配饰'
                }]
            }, {
                title: '断码区',
                urlLocation: 'www',
                navItem: [{
                    vip: true,
                    urlLocation: '/sa/ds',
                    title: '今日推荐'
                }, {
                    incompleteSize: true,
                    urlLocation: '/sa/ds',
                    title: '上装'
                }, {
                    newDiscount: true,
                    urlLocation: '/sa/ds',
                    title: '裤装'
                }, {
                    vip: true,
                    urlLocation: '/sa/ds',
                    title: '鞋履'
                }, {
                    vip: true,
                    urlLocation: '/sa/ds',
                    title: '配饰'
                }]
            }];

        return finalResult;
    });
};

/**
 * 获取 VIP 会员专享和新降价专区数据 Controller 调用
 * @return {[type]} [description]
 */
exports.getSaleOthersData = (params) => {

    // cCode 是资源位代码,根据页面不同传不同的 CODE,目前一样,待处理
    let cCode = '7c2b77093421efa8ae9302c91460db73';

    if (!_.isEmpty(params.saleType) && params.saleType === 2) {
        cCode = '7c2b77093421efa8ae9302c91460db73';
    } else {
        cCode = '7c2b77093421efa8ae9302c91460db73';
    }
    return api.all([
        saleApi.getSaleGoodsList(params),
        saleApi.getSaleBannerList(cCode),
        saleApi.getLeftContentList()
    ]).then(result => {
        let finalResult = {};

        if (result[0].code === 200) {
            finalResult.goods = productProcess.processProductList(result[0].data.product_list);
            finalResult.filters = saleHandler.handleSaleFilterData(result[0].data.filter, params);
        }

        if (result[1].code === 200) {
            finalResult.topBanner = saleHandler.handleSaleBannerData(result[1].data);
        }

        if (result[2].code === 200) {
            if (params.gender === '2,3') {
                finalResult.leftContent = saleHandler.handleSaleSortData(result[2].data.girl, params);
            } else {
                finalResult.leftContent = saleHandler.handleSaleSortData(result[2].data.boy, params);
            }

        }

        finalResult.filters.discount = saleHandler.handleSaleNewSaleSortData(params);

        finalResult.opts = saleHandler.handleSaleOptsData(params);

        return finalResult;
    });
};

/**
 * 获取折扣专场数据 Controller 调用
 * @return {[type]} [description]
 */
exports.getSaleDiscountData = (params) => {
    return api.all([
        saleApi.getSaleGoodsList(params),
        saleApi.getSaleBannerList('7c2b77093421efa8ae9302c91460db73'),
        saleApi.getLeftContentList()
    ]).then(result => {
        let finalResult = {};

        if (result[0].code === 200) {
            finalResult.saleList = {};
            finalResult.saleList.goods = productProcess.processProductList(result[0].data.product_list);
            finalResult.leftContent = saleHandler.handleSaleSortData(result[0].data.filter.group_sort, params);
        }

        if (result[1].code === 200) {
            finalResult.topBanner = saleHandler.handleSaleBannerData(result[1].data);
        }

        return finalResult;
    });
};

/**
 * 获取断码区数据 Controller 调用
 * @param  {[type]} params [description]
 * @return {[type]}        [description]
 */
exports.getSalebreakingYardsData = (params) => {
    return api.all([
        saleApi.getSaleGoodsList(params),
        saleApi.getSalebreakingYardsSortList(),
        saleApi.getSaleBannerList('7c2b77093421efa8ae9302c91460db73'),
        saleApi.getLeftContentList()
    ]).then(result => {
        let finalResult = {};

        if (result[0].code === 200) {
            finalResult.goods = productProcess.processProductList(result[0].data.product_list);
            finalResult.filters = saleHandler.handleSaleFilterData(result[0].data.filter, params);
        }

        if (result[1].code === 200) {
            finalResult.filters.size = saleHandler.handleSalebreakingYardsSortData(result[1].data, params);
        }

        if (result[2].code === 200) {
            finalResult.topBanner = saleHandler.handleSaleBannerData(result[2].data);
        }

        if (result[3].code === 200) {
            if (params.gender === '2,3') {
                finalResult.leftContent = saleHandler.handleSaleSortData(result[3].data.girl, params);
            } else {
                finalResult.leftContent = saleHandler.handleSaleSortData(result[3].data.boy, params);
            }

        }

        finalResult.opts = saleHandler.handleSaleOptsData(params);

        return finalResult;
    });
};