Authored by yyq

退货申请接口

... ... @@ -5,6 +5,7 @@
*/
'use strict';
const _ = require('lodash');
const returns = require('../models/returns');
const detail = (req, res, next) => {
... ... @@ -28,6 +29,28 @@ const refund = (req, res, next) => {
}).catch(next);
};
const refundApply = (req, res, next) => {
let orderCode = req.body.orderCode,
uid = req.user.uid,
goods = req.body.goods,
payment = req.body.payment;
uid = '8050560';
orderCode = '160192757';
if (!orderCode || _.isEmpty(goods) || _.isEmpty(payment)) {
return res.json({
code: 203,
message: '非法提交'
});
}
returns.saveRefund(orderCode, uid, goods, payment).then(result => {
res.json(result);
}).catch(next);
};
const exchange = (req, res, next) => {
next();
};
... ... @@ -35,5 +58,6 @@ const exchange = (req, res, next) => {
module.exports = {
detail,
refund,
refundApply,
exchange
};
... ...
... ... @@ -7,6 +7,15 @@
const api = global.yoho.API;
const getOrderInfoAsync = (orderCode, uid, sessionKey) => {
return api.get('', {
method: 'app.SpaceOrders.info',
order_code: orderCode,
uid: uid,
session_key: sessionKey
}, {code: 200});
};
const getRefundGoodsAsync = (orderCode, uid) => {
return api.get('', {
method: 'app.refund.goodsList',
... ... @@ -15,7 +24,19 @@ const getRefundGoodsAsync = (orderCode, uid) => {
}, {code: 200});
};
const refundSubmitAsync = (orderCode, uid, goods, payment) => {
return api.get('', {
method: 'app.refund.submit',
order_code: orderCode,
uid: uid,
goods: JSON.stringify(goods),
payment: JSON.stringify(payment)
});
};
module.exports = {
getRefundGoodsAsync
getOrderInfoAsync,
getRefundGoodsAsync,
refundSubmitAsync
};
... ...
... ... @@ -71,6 +71,19 @@ const getRefundGoodsData = (orderCode, uid) => {
});
};
const saveRefund = (orderCode, uid, goods, payment) => {
return returnsAPI.getOrderInfoAsync(orderCode, uid, '').then(result => {
if (!_.isEmpty(result)) {
return returnsAPI.refundSubmitAsync(orderCode, uid, goods, payment).then(subRes => {
return subRes;
});
} else {
return {code: 403, message: '没有找到该订单'};
}
});
};
module.exports = {
getRefundGoodsData
getRefundGoodsData,
saveRefund
};
... ...
... ... @@ -31,6 +31,7 @@ router.get('/editOrder', order.editOrder);
router.get('/return/refund/:orderCode', returns.refund);
router.get('/return/exchange/:orderCode', returns.exchange);
router.get('/return/:returnId', returns.detail);
router.post('/return/refund/apply', returns.refundApply);
// 个人中心首页/收货地址
router.get('/address', address.index);
... ...
... ... @@ -45,3 +45,18 @@ $refundType.on('click', '.type-item', function() {
$typeInfo.eq(index).removeClass('hide');
}
});
$applyBtn.click(function() {
$.ajax({
type: 'POST',
url: '/me/return/refund/apply',
data: {
id: 11
},
success: function(data) {
if (data.code === 200) {
console.log(data);
}
}
});
});
... ...