order.js 1.71 KB
/**
 * 订单 controller
 * @author: TODO
 * @date: 2016/07/04
 */

'use strict';

const orderModel = require('../models/order');

const index = (req, res, next) => {
    orderModel.index(req.user.uid).then(result => {

        // 设置头部路径索引focus
        result.data.bcNavFocus = 2;

        // 发票抬头
        result.data.invoices.invoiceTitle = [
            {
                name: '个人',
                value: 1,
                checked: true,
                myClass: 'personal'
            },
            {
                name: '单位',
                value: 2
            }
        ];

        result.data.invoices.invoiceContentList[0].checked = true; // 发票类型默认选中第一项

        // 是否打印价格radio
        result.data.printPriceRadio = [
            {
                value: '1',
                name: '是',
                checked: true
            },
            {
                value: '0',
                name: '否'
            }
        ];

        res.display('order', {
            content: result.data,
            defaultHeader: false
        });
    }).catch(next);
};

// 订单金额计算
const compute = (req, res, next) => {
    orderModel.compute(req.user.uid, req.query.coin).then(result => {
        res.send(result);
    }).catch(next);
};

// 订单提交
const orderSub = (req, res, next) => {
    var other = req.body;

    // 参数校验
    if (!other.address_id) {
        res.send({
            code: 500,
            message: '配送地址不能为空'
        });
        return;
    }

    orderModel.submit(req.user.uid, other).then(result => {
        res.send(result);
    }).catch(next);
};

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