sale-api.js 3.38 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 _ = require('lodash');
const config = global.yoho.config;

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


module.exports = class extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    /**
     * 获取商品列表 promise 对象
     * @return {[type]} [description]
     */
    getSaleGoodsList(params) {
        let finalParams = {
            method: 'app.search.sales',
            limit: 60,
            order: 's_t_desc',
            productSize: '384x511'
        };

        if (params && params.channel) {
            finalParams.yh_channel = yhChannel[params.channel].channel;
        }

        return this.get({data: Object.assign(finalParams, params), param: config.apiCache});
    }

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

        return this.get({
            data: {
                method: 'app.sale.getBreakingSort',
                yh_channel: yhChannel[tempChannel].channel
            }, param: config.apiCache
        });
    }

    /**
     * 获取折扣专区活动列表 promise 对象
     * @return {[type]} [description]
     */
    getSaleActivityList(params, channel) {
        let tempChannel = yhChannel[channel] || yhChannel.boys;

        return this.get({
            data: {
                id: params.id || null,
                method: 'app.activity.get',
                sort: '2',
                plateform: '1',
                yh_channel: tempChannel.channel
            }, param: config.apiCache
        });
    }

    /**
     * 获取Sale首页顶部 banner promise 对象
     * @return {[type]} [description]
     */
    getSaleBannerList(cCode) {
        return this.get({
            url: 'operations/api/v5/resource/get',
            data: {
                content_code: cCode
            },
            param: config.apiCache,
            api: global.yoho.ServiceAPI
        });
    }

    /**
     * 获取左侧类目列表
     * @return {[type]} [description]
     */
    getLeftContentList() {
        return this.get({
            data: {
                method: 'app.sort.get'
            }, param: config.apiCache
        });
    }

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

    /**
     * 获取用户数据信息
     * @param  {[string]} uid
     * @return {[array]}
     */
    getSaleSpecialAsync(specialId) {
        return this.get({
            data: {
                method: 'app.resources.getOneSpecial',
                special_id: specialId
            },
            param: {
                code: 200,
                cache: true
            }
        });
    }
};