seckill-detail.js 1.14 KB
/**
 * [商品获取数据]
 */
'use strict';
const _ = require('lodash');
const api = global.yoho.API;

const newDetail = {
    /**
     * 获取秒杀列表
     */
    getSeckillData(param) {
        let params = {
            method: 'app.seckill.data',
            product_skn: param.productskn
        };

        return api.get('', params, {
            code: 200
        })

        // mock
            .catch()
            .then(result => {
                let data = {};

                if (_.get(result, 'data') && !_.isArray(result.data)) {
                    data = result.data;
                    if (data.storageSum > 0) {
                        data.storageSum = 1;
                    }
                    if (data.secKillSku) {
                        _.forEach(data.secKillSku, item => {
                            if (item.storageNum > 0) {
                                item.storageNum = 1;
                            }
                        });
                    }
                } else {
                    data.status = 0;
                }
                return data;
            });
    }
};

module.exports = newDetail;