Blame view

apps/home/controllers/returns.js 5.54 KB
陈轩 authored
1 2 3 4
/**
 *  个人中心 退换货
 *  @author 陈轩 <xuan.chen@yoho.cn>
 */
陈轩 authored
5
'use strict';
hongweigao authored
6
const helpers = global.yoho.helpers;
陈轩 authored
7
const returnsModel = require('../models/returns');
陈轩 authored
8
OF1706 authored
9 10
/**
 * 我的退换货-列表页
陈轩 authored
11
 */
yyq authored
12
const index = (req, res, next) => {
陈轩 authored
13 14
    const page = req.query.page;
yyq authored
15
    returnsModel.getReturnsList(req.user.uid, page, 10)
陈轩 authored
16 17 18 19 20 21
        .then(data => {
            const viewData = Object.assign({
                module: 'home',
                page: 'returns',
                meReturnsPage: true
            }, data);
陈轩 authored
22
陈轩 authored
23 24 25 26
            res.render('returns/returns', viewData);
        })
        .catch(next);
};
陈轩 authored
27
OF1706 authored
28 29
/**
 * 我的订单-退货申请页
陈轩 authored
30
 */
yyq authored
31
const refundApply = (req, res, next) => {
陈轩 authored
32
    const orderCode = req.query.orderCode;
yyq authored
33
    const uid = req.user.uid;
陈轩 authored
34
yyq authored
35 36 37 38 39
    returnsModel.getOrderRefund(orderCode, uid).then(result => {
        res.render('returns/returns-apply', result);
    }).catch(next);
};
OF1706 authored
40 41
/**
 * 我的订单-退货提交
hongweigao authored
42 43 44 45 46 47 48 49 50
 */
const saveRefund = (req, res, next) => {
    const uid = req.user.uid;

    returnsModel.saveRefund(req, uid).then(result => {
        res.send(result);
    }).catch(next);
};
OF1706 authored
51 52
/**
 * 退货成功
hongweigao authored
53 54 55 56 57 58 59 60 61 62 63 64 65 66
 */
const refundSuccess = (req, res) => {
    let resData = {
        save: {
            type: '退货',
            ordersHref: helpers.urlFormat('/home/orders'),
            returnsHref: helpers.urlFormat('/home/returns'),
            refund: {// 退货时传退货收件地址
                address: '南京市江宁区江宁经济技术开发区苏源大道87号YOHO!有货物流中心东一楼',
                name: 'YOHO!有货',
                phone: '400-889-9646',
                postcode: '211106'
            }
        }
OF1706 authored
67
    };
hongweigao authored
68 69 70 71

    res.render('returns/returns-save', {returns: resData});
};
OF1706 authored
72 73
/**
 * 换货成功
hongweigao authored
74 75 76 77 78 79 80 81
 */
const exchangeSuccess = (req, res) => {
    let resData = {
        save: {
            type: '换货',
            ordersHref: helpers.urlFormat('/home/orders'),
            returnsHref: helpers.urlFormat('/home/returns')
        }
OF1706 authored
82
    };
hongweigao authored
83 84 85 86

    res.render('returns/returns-save', {returns: resData});
};
OF1706 authored
87 88
/**
 * 我的退换货-退货详情页
yyq authored
89 90 91 92
 */
const refundDetail = (req, res, next) => {
    const code = req.query.id;
    const uid = req.user.uid;
93 94 95 96
    let resData = {
        module: 'home',
        page: 'returns'
    };
yyq authored
97 98

    returnsModel.getRefundDetail(code, uid).then(result => {
99 100 101 102 103
        Object.assign(resData, result);
        res.render('returns/returns-detail', resData);
    }).catch(next);
};
OF1706 authored
104 105 106 107 108 109 110 111 112 113 114 115 116 117
/**
 * 我的订单-提交换货申请
 */
const saveExchange = (req, res, next) => {

    let uid = req.user.uid;

    returnsModel.saveExchange(req, uid).then(result => {
        res.send(result);

    }).catch(next);
};

/**
118 119 120 121 122 123 124 125 126 127 128 129 130
 * 我的退换货-换货详情页
 */
const exchangeDetail = (req, res, next) => {
    const code = req.query.id;
    const uid = req.user.uid;
    let resData = {
        module: 'home',
        page: 'returns'
    };

    returnsModel.getChangeDetail(code, uid).then(result => {
        Object.assign(resData, result);
        res.render('returns/returns-detail', resData);
yyq authored
131 132 133
    }).catch(next);
};
OF1706 authored
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
/**
 * 我的订单-获取换货方式
 */
const getDelivery = (req, res, next) => {

    let areaCode = req.body.areaCode;

    // 获取必要参数
    let uid = req.user.uid;
    let gender = req.yoho.gender;
    let channel = req.yoho.channel;

    // 调用接口获得该用户支持的换货方式(白金会员可享受上门换货,偏远地区不支持上门换货)
    returnsModel.getDelivery(areaCode, uid, gender, channel).then(result => {
        res.send(result);
    }).catch(next);
};

/**
 * 我的订单-换货申请页
yyq authored
154 155 156 157 158 159 160 161 162 163
 */
const exchangeApply = (req, res, next) => {
    const orderCode = req.query.orderCode;
    const uid = req.user.uid;

    returnsModel.getOrderExchange(orderCode, uid).then(result => {
        res.render('returns/returns-apply', result);
    }).catch(next);
};
OF1706 authored
164 165 166 167
/**
 * 取消退货申请
 */
const cancelRefund = (req, res, next) => {
OF1706 authored
168 169
    let id = req.body.id;
    let uid = req.user.uid;
OF1706 authored
170 171 172 173 174 175 176 177 178 179

    returnsModel.getCancelRefund(id, uid).then(result => {
        res.send(result);
    }).catch(next);
};

/**
 * 取消换货申请
 */
const cancelChange = (req, res, next) => {
OF1706 authored
180 181
    let id = req.body.id;
    let uid = req.user.uid;
OF1706 authored
182 183 184 185 186 187

    returnsModel.getCancelChange(id, uid).then(result => {
        res.send(result);
    }).catch(next);
};
OF1706 authored
188 189 190 191 192 193 194
/**
 * 我的退换货-设置快递单号
 */
const setExpressNumber = (req, res, next) => {

    let uid = req.user.uid;
    let id = req.body.id;
OF1706 authored
195
    let isChange = req.body.isChange === 'false' ? false : true;
OF1706 authored
196 197 198 199 200 201
    let expressId = req.body.expressId;
    let expressNumber = req.body.expressNumber;
    let expressCompany = req.body.expressCompany;

    returnsModel.setExpressNumber(id, expressId, expressNumber, uid, expressCompany, isChange).then(result => {
OF1706 authored
202
        if (res.code && res.code === 201) {
OF1706 authored
203
            res.json({message: '请求失败'});
OF1706 authored
204 205 206 207 208 209 210 211 212
        }

        if (id || expressId || expressNumber || uid || expressCompany || isChange) {
            res.send(result);
        }

    }).catch(next);

};
OF1706 authored
213
郝肖肖 authored
214 215
const refundCompute = (req, res, next) => {
    let uid = req.user.uid;
216 217
    let orderCode = req.body.orderCode;
    let goods = req.body.goods;
郝肖肖 authored
218 219 220 221 222 223

    returnsModel.refundCompute(uid, orderCode, goods).then(d => {
        res.json(d);
    }).catch(next);
};
yyq authored
224 225
module.exports = {
    index,
yyq authored
226
    refundApply,
hongweigao authored
227
    saveRefund,
hongweigao authored
228
    refundSuccess,
yyq authored
229
    refundDetail,
OF1706 authored
230
    saveExchange,
231
    exchangeApply,
hongweigao authored
232
    exchangeSuccess,
OF1706 authored
233
    exchangeDetail,
OF1706 authored
234
    getDelivery,
OF1706 authored
235
    cancelRefund,
OF1706 authored
236
    cancelChange,
郝肖肖 authored
237 238
    setExpressNumber,
    refundCompute
陈轩 authored
239
};