seckill.js 1.97 KB
'use strict';

const paymentProcess = require(global.utils + '/payment-process');

class seckillModel extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    /**
     *  获取 获取秒杀信息接口
     *  doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E5%95%86%E5%93%81%E5%88%97%E8%A1%A8/seckill.md
     */
    skillData(product_skn) {
        let queryData = {
            method: 'app.seckill.data',
            product_skn
        };

        return this.post({data: queryData});
    }

    payment(options, orderInfo, orderComputerData) {
        let queryData = Object.assign({
            method: 'app.Seckill.payment',
        }, options);

        return this.post({data: queryData})
            .then(result => {
                // TODO 数据处理
                if (result.code === 200 && result.data) {
                    result.data = paymentProcess.tranformPayment(result.data, orderInfo, null, null, orderComputerData);
                }
                return result;
            });
    }

    // http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E8%AE%A2%E5%8D%95/%E7%AB%8B%E5%8D%B3%E8%B4%AD%E4%B9%B0.md#L628
    compute(options) {
        let queryData = Object.assign({
            method: 'app.Seckill.compute',
        }, options);

        return this.post({data: queryData}).then(result => {
            // TODO 数据处理
            if (result.code === 200 && result.data) {
                result.data.yohoCoinCompute = paymentProcess.yohoCoinCompute(result.data);
            } else if (result.code === 9999992) {
                result.data = {
                    code: result.code,
                    message: result.message
                };
            }
            return result;
        });
    }

    submit(options) {
        let queryData = Object.assign({
            method: 'app.Seckill.submit'
        }, options);

        return this.post({data: queryData});
    }
}

module.exports = seckillModel;