sale.js 2.06 KB
/*
 * @Author: Targaryen
 * @Date:   2016-05-19 10:20:08
 * @Last Modified by:   Targaryen
 * @Last Modified time: 2016-05-20 15:05:05
 */

'use strict';
const library = '../../../library';
const API = require(`${library}/api`).API;
const sign = require(`${library}/sign`);
const api = new API();
const _ = require('lodash');

/**
 * 处理 sale 首页原始数据
 * @param  {Object} origin [原始数据]
 * @return {Object}        [结果]
 */
const handleSaleData = (origin) => {
    var dest = {};

    dest = origin;
    return dest;
};

/**
 * 处理商品列表数据
 * @param  {[type]} origin [description]
 * @return {[type]}        [description]
 */
const handleSaleGoodsListData = (origin) => {
    var dest = {};
    
    dest.saleList = {};
    dest.saleList.leftContent = {};
    dest.saleList.goods = [];


    if (!_.isEmpty(origin.product_list)) {

        _.forEach(origin.product_list, function(value) {
            let goods = {};

            goods.tags = value.tags;
            goods.url = ''; // 待处理
            goods.thumb = value.goods_list;
            goods.name = value.product_name;
            goods.brand = {};
            goods.brand.url = ''; // 待处理
            goods.brand.name = value.brand_name;
            goods.marketPrice = value.market_price;

            dest.saleList.goods.push(goods);
        });
    }

    return dest;
};

/**
 * 获取首页数据
 * @return {[type]} [description]
 */
exports.getSaleDate = () => {
    return api.get('', sign.apiSign({
        method: 'app.activity.get',
        sort: 2,
        plateform: 2
    })).then(result => {

        return handleSaleData(result);
    });
};

/**
 * 获取商品列表数据
 * @return {[type]} [description]
 */
exports.getSaleGoodsListData = () => {

    return api.get('', sign.apiSign({
        method: 'app.search.sales',
        limit: 5,
        order: 's_t_desc',
        page: 1,
        productSize: '384x511',
        yh_channel: 1
    })).then(result => {
        if (result.code === 200) {
            return handleSaleGoodsListData(result.data);
        }
    });
};