sale.js 1.94 KB
/**
 * 频道页面 model
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/05/17
 */
'use strict';
const library = '../../../library';
const API = require(`${library}/api`).API;
const sign = require(`${library}/sign`);
const _ = require('lodash');
const camelCase = require(`${library}/camel-case`);
const api = new API();

/**
 * 折扣专场跳转链接处理
 */
const processSpecial = (list) => {
    const formatData = [];

    list = list || [];
    list = camelCase(list);

    _.forEach(list, (data) => {
        data.specialUrl = `/product/specialDetail?id=${data.id}`;
        formatData.push(data);
    });

    return formatData;
}

/**
 * 获取首页数据
 * @param  {[object]} params
 * @return {[object]}
 */
exports.getSaleData = (params) => {

    return api.get('', sign.apiSign(Object.assign({
        method: 'app.search.sales',
        sort: 2,
        plateform: 2
    }, params)));
};

/**
 * 获取折扣专场专题列表数据
 * @param  {[object]} params
 * @return {[object]}
 */
exports.getSpecialData = (params) => {
    const specialData = {};

    return api.get('', sign.apiSign(Object.assign({
        method: 'app.activity.get',
        sort: 2,
        plateform: 2
    }, params))).then((result) => {
        if (result && result.code === 200) {
            specialData.data = processSpecial(result.data);
            return specialData;
            // return camelCase(result);
        } else {
            return Promise.reject('error');
        }
    });
};


/**
 * 获取折扣专场专题详情数据
 * @param  {[object]} params
 * @return {[object]}
 */
exports.getSpecialDetailData = (params) => {
    return api.get('', sign.apiSign(Object.assign({
        method: 'app.activity.get',
        sort: 2,
        plateform: 2
    }, params))).then((result) => {
        if (result && result.code === 200) {
            return camelCase(result.data);
        } else {
            return Promise.reject('error');
        }
    });
}