orderDetail.js 2.88 KB
/**
 * 个人中心 controller
 * @author: chengyao.guo<chengyao.guo@yoho.cn>
 * @date: 2016/08/10
 */

'use strict';

const helpers = global.yoho.helpers;
const _ = require('lodash');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const orderDetailModel = require('../models/orderDetail');
const payModel = require('../models/pay');

const orderDetailData = (req, res, next) => {
    let uid = req.user.uid;
    let orderCode = req.query.order_code;
    let serviceUrl = _.get(req.app.locals.wap, 'clientService.new', false) ?
        helpers.urlFormat('/service/im') :
        'http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&configID=149091&jid=8732423409&info=';

    if (req.query.openId) {
        // 微信支付成功,发送支付确认接口
        payModel.sendPayConfirm(orderCode, 22, uid);
    }

    orderDetailModel.orderDetailData(uid, orderCode).then(result => {
        if (!result || _.isEmpty(result)) {
            return next(404);
        }

        result.serviceUrl = serviceUrl;
        res.render('orderDetail', {
            module: 'home',
            page: 'orderdetail',
            pageHeader: headerModel.setNav({
                navTitle: '订单详情',
                navBtn: false
            }),
            title: '订单详情',
            pageFooter: true,
            orderDetail: result,
            localCss: true,
        });
    }).catch(next);

};

// 删除订单
const delOrder = (req, res, next) => {
    let orderCode = req.query.id;
    let uid = req.user.uid;

    orderDetailModel.delOrder(orderCode, uid).then((result) => {
        res.json(result);
    }).catch(next);
};

// 再次购买
const readdData = (req, res, next) => {
    let orderCode = req.query.orderCode;
    let uid = req.user.uid;

    orderDetailModel.readdData(orderCode, uid).then((result) => {
        res.json(result);
    }).catch(next);
};

// 取消订单
const cancelOrder = (req, res, next) => {
    let orderCode = req.query.id;
    let uid = req.user.uid;
    let reasonId = req.query.reasonId || 1;
    let gender = req.query.gender || '1,3';
    let channel = req.query.channel || 1;
    let reason = req.query.reason;

    orderDetailModel.cancelOrder(orderCode, uid, reasonId, gender, channel, reason).then((result) => {
        res.json(result);
    }).catch(next);
};

/**
 * 我的订单-查看物流信息
 */
const logistic = (req, res, next) => {
    orderDetailModel.logistics(req.query.order_code, req.user.uid).then(result => {
        res.render('logistic', _.assign(result, {
            pageHeader: headerModel.setNav({
                navTitle: '订单详情',
                navBtn: false
            }),
            module: 'home',
            page: 'logistic',
            logisticInfoPage: true
        }));
    }).catch(next);
};

module.exports = {
    orderDetailData,
    delOrder,
    readdData,
    cancelOrder,
    logistic
};