...
|
...
|
@@ -6,13 +6,16 @@ |
|
|
'use strict';
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
const path = require('path');
|
|
|
|
|
|
// const path = require('path');
|
|
|
const Promise = require('bluebird');
|
|
|
const returnAPI = require('./returns-api');
|
|
|
|
|
|
const pager = require(`${global.utils}/pager`).setPager;
|
|
|
|
|
|
// 使用 product中的分页逻辑
|
|
|
const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler.js');
|
|
|
const pager = require(pagerPath).handlePagerData;
|
|
|
// const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler.js');
|
|
|
// const pager = require(pagerPath).handlePagerData;
|
|
|
|
|
|
const co = Promise.coroutine;
|
|
|
const api = global.yoho.API;
|
...
|
...
|
@@ -23,6 +26,8 @@ const REFUND = 1; // 退货 |
|
|
const EXCHANGE = 2; // 换货
|
|
|
const TRUE = 'Y';
|
|
|
const RETURNS_EMPTY = '您没有退/换货订单';
|
|
|
const CANCEL_REFUND_URI = '/home/returns/cancelRefund';
|
|
|
const CANCEL_EXCHANGE_URI = '/home/returns/cancelChange';
|
|
|
const REFUND_URI = '/home/returns/refundDetail';
|
|
|
const EXCHANGE_URI = '/home/returns/exchangeDetail';
|
|
|
|
...
|
...
|
@@ -48,19 +53,18 @@ const setDetailGoods = (list) => { |
|
|
|
|
|
// 处理订单商品的数据
|
|
|
function getGoodsData(goods) {
|
|
|
const arr = [];
|
|
|
let arr = [];
|
|
|
|
|
|
goods.forEach(good => {
|
|
|
const obj = {};
|
|
|
const cnAlphabet = good.cn_alphabet || '';
|
|
|
|
|
|
obj.href = getProductUrlBySkc(good.product_id, good.goods_id, cnAlphabet);
|
|
|
obj.thumb = helpers.image(good.goods_image, 60, 60);
|
|
|
obj.name = good.product_name;
|
|
|
obj.color = good.color_name;
|
|
|
obj.size = good.size_name;
|
|
|
|
|
|
arr.push(obj);
|
|
|
let cnAlphabet = good.cn_alphabet || '';
|
|
|
|
|
|
arr.push({
|
|
|
href: getProductUrlBySkc(good.product_id, good.goods_id, cnAlphabet),
|
|
|
thumb: helpers.image(good.goods_image, 60, 60),
|
|
|
name: good.product_name,
|
|
|
color: good.color_name,
|
|
|
size: good.size_name
|
|
|
});
|
|
|
});
|
|
|
|
|
|
return arr;
|
...
|
...
|
@@ -77,57 +81,60 @@ const getReturnsList = co(function*(uid, page, limit) { |
|
|
page = Number.parseInt(page, 10) || 1;
|
|
|
limit = Number.parseInt(limit, 10) || 10;
|
|
|
|
|
|
const obj = {
|
|
|
let obj = {
|
|
|
orders: [],
|
|
|
pager: {}
|
|
|
};
|
|
|
let response = yield api.post('', {
|
|
|
method: 'app.refund.getList',
|
|
|
data: { uid: uid, page: page, limit: limit }
|
|
|
uid: uid,
|
|
|
page: page,
|
|
|
limit: limit
|
|
|
});
|
|
|
let repData = response.data;
|
|
|
|
|
|
|
|
|
// 处理数据
|
|
|
if (response.code === 200 && repData && repData.list.length) {
|
|
|
obj.pager = pager(repData.total, {
|
|
|
page: page,
|
|
|
limit: limit
|
|
|
});
|
|
|
obj.pager = Object.assign({
|
|
|
count: repData.total,
|
|
|
curPage: page,
|
|
|
totalPages: repData.total_page || 1
|
|
|
}, pager(repData.total_page, {page: page}));
|
|
|
|
|
|
repData.list.forEach(item => {
|
|
|
const t = {};
|
|
|
|
|
|
t.returnId = item.id;
|
|
|
t.orderNum = item.order_code;
|
|
|
t.orderTime = item.oreder_create_time.replace('-', '/');
|
|
|
t.returnTime = item.create_time;
|
|
|
t.returnStatus = item.status_name;
|
|
|
|
|
|
let t = {
|
|
|
returnId: item.id,
|
|
|
orderNum: item.order_code,
|
|
|
orderTime: _.replace(item.oreder_create_time, '-', '/'),
|
|
|
returnTime: item.create_time,
|
|
|
returnStatus: item.status_name
|
|
|
};
|
|
|
|
|
|
const canCancel = item.canCancel === TRUE;
|
|
|
let isChange, uri;
|
|
|
let canCancel = item.canCancel === TRUE;
|
|
|
let isChange, uri = '', cancelUri = '';
|
|
|
|
|
|
switch (item.refund_type) {
|
|
|
case REFUND:
|
|
|
isChange = false;
|
|
|
if (canCancel) {
|
|
|
uri = REFUND_URI;
|
|
|
}
|
|
|
cancelUri = CANCEL_REFUND_URI;
|
|
|
break;
|
|
|
case EXCHANGE:
|
|
|
isChange = true;
|
|
|
if (canCancel) {
|
|
|
uri = EXCHANGE_URI;
|
|
|
}
|
|
|
cancelUri = CANCEL_EXCHANGE_URI;
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
t.isChange = isChange;
|
|
|
t.canCancelUrl = helpers.urlFormat(uri);
|
|
|
t.moreHref = helpers.urlFormat(uri, { id: item.id });
|
|
|
t.goods = getGoodsData(item.goods);
|
|
|
Object.assign(t, {
|
|
|
isChange: isChange,
|
|
|
canCancel: canCancel,
|
|
|
canCancelUrl: cancelUri,
|
|
|
moreHref: helpers.urlFormat(uri, { id: item.id }),
|
|
|
goods: getGoodsData(item.goods)
|
|
|
});
|
|
|
|
|
|
obj.orders.push(t);
|
|
|
});
|
...
|
...
|
|