seckill.js 1.67 KB
/**
 * 秒杀models
 * @author: 陈峰<feng.chen@yoho.cn>
 * @date: 2016/9/18
 */

'use strict';

const api = global.yoho.API;
const _ = require('lodash');
const mock = require('./seckill-mock');

/**
 * [获取秒杀时间栏接口]
 * @return {[object]}
 */
const queryActivity = () => {
    return api.get('', {
        method: 'app.seckill.queryActivity'
    }, {
        cache: true
    });

    // TODO: REMOVE follow
    // .catch()
    // .then(() => {
    //     return _.cloneDeep(mock.activities);
    // });
};

/**
 * [获取指定秒杀活动商品列表接口]
 * @param  {[int]} activityId [秒杀活动id]
 * @return {[object]}
 */
const queryProductList = (activityId) => {
    return api.get('', {
        method: 'app.seckill.queryProductList',
        activityId: activityId
    }, {
        cache: true
    });

    // TODO: remove follow
    // .catch()
    //     .then(() => {
    //         let result;

    //         switch (activityId) { // eslint-disable-line
    //             case 1:
    //                 result = mock.inActivityData;
    //                 break;
    //             case 2:
    //                 result = mock.inActivityData;
    //                 break;
    //             case 3:
    //                 result = mock.waitData;
    //                 break;
    //         }

    //         return _.cloneDeep(result);
    //     });
};

const remind = (options) => {
    let url = '';
    let formData = Object.assign({
        method: !options.on_off ? 'app.seckill.cancelUserReminder' : 'app.seckill.addUserReminder',
    }, options);

    return api.get(url, formData);
};

module.exports = {
    queryActivity,
    queryProductList,
    remind
};