sale-api.js 2.62 KB
/*
 * @Author: Targaryen
 * @Date:   2016-05-25 18:03:34
 * @Last Modified by:   Targaryen
 * @Last Modified time: 2016-06-07 13:58:53
 */

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

const yhChannel = {
    boys: {
        channel: '1'
    },
    girls: {
        channel: '2'
    },
    kids: {
        channel: '3'
    },
    lifestyle: {
        channel: '4'
    }
};

/**
 * 获取商品列表 promise 对象
 * @return {[type]} [description]
 */
exports.getSaleGoodsList = (params) => {

    let tempChannel = _.isEmpty(params.channel) ? 'boys' : params.channel;

    params = Object.assign({
        method: 'app.search.sales',
        limit: 60,
        order: 's_t_desc',
        productSize: '384x511',
        yh_channel: yhChannel[tempChannel].channel
    }, params);
    params.yh_channel = yhChannel[tempChannel].channel;
    return api.get('', sign.apiSign(params));
};

/**
 * 断码区分类信息数据 promise 对象
 * @return {[type]} [description]
 */
exports.getSalebreakingYardsSortList = (params) => {
    let tempChannel = _.isEmpty(params.channel) ? 'boys' : params.channel;

    return api.get('', sign.apiSign({
        method: 'app.sale.getBreakingSort',
        yh_channel: yhChannel[tempChannel].channel
    }));
};

/**
 * 获取折扣专区活动列表 promise 对象
 * @return {[type]} [description]
 */
exports.getSaleActivityList = (params, channel) => {
    let tempChannel = _.isEmpty(channel) ? 'boys' : channel;

    return api.get('', sign.apiSign({
        id: params.id || null,
        method: 'app.activity.get',
        sort: '2',
        plateform: '1',
        yh_channel: yhChannel[tempChannel].channel
    }));
};

/**
 * 获取Sale首页顶部 banner promise 对象
 * @return {[type]} [description]
 */
exports.getSaleBannerList = (cCode) => {
    return serviceAPI.get('operations/api/v5/resource/get', sign.apiSign({
        content_code: cCode
    }));
};

/**
 * 获取左侧类目列表
 * @return {[type]} [description]
 */
exports.getLeftContentList = () => {
    return api.get('', sign.apiSign({
        method: 'app.sort.get'
    }));
};

/**
 * 获取用户数据信息
 * @param  {[string]} uid
 * @return {[array]}
 */
exports.getUserProfile = (uid) => {
    if (!uid) {
        return Promise.resolve({
            code: 200,
            data: {}
        });
    }
    return api.get('', sign.apiSign({
        method: 'app.passport.profile',
        uid: uid
    }), true);
};