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

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

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

        return this.get({
            data: params,
            param: {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;
            });
    }
};