easypay.js 1.41 KB
/**
 * 立即购买controller
 * @author: yyq<yanqing.yang@yoho.cn>
 * @date: 2016/9/23
 */
'use strict';

const easypay = require('../models/easypay');
const headerModel = require('../../../doraemon/models/simple-header');

const stepper = [
    {name: '填写订单', focus: true},
    {name: '付款,完成购买'}
];

const index = (req, res, next) => {
    let uid = req.user.uid;
    let params = req.query;

// params = {bundle: 1124, sku: '809291,789238'};
    easypay.getEasypayOrderData(params, uid).then(result => {
        let header = headerModel.setSimpleHeaderData() || {};

        result.stepper = stepper;

        if (params.limitcode) { // 限定发售不支持优惠券
            result.couponUnsupport = true;
        }

        res.render('order-ensure', {
            page: 'easypay',
            content: result,
            simpleHeader: header
        });
    }).catch(next);
};

const compute = (req, res, next) => {
    let uid = req.user.uid;
    let params = req.body;

    easypay.getOrderComputeData(uid, 'ordinary', params).then(result => {
        res.json(result);
    }).catch(next);
};

const submit = (req, res, next) => {
    let uid = req.user.uid;
    let params = req.body;

    if (!uid) {
        return next();
    }

    easypay.easypayOrderSubmit(uid, 'ordinary', params).then(result => {
        res.json(result);
    }).catch(next);
};

module.exports = {
    index,
    compute,
    submit
};