returns.js
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* 个人中心 退换货
* @author chenxuan <xuan.chen@yoho.cn>
*/
'use strict';
const path = require('path');
const Promise = require('bluebird');
// 使用 product中的分页逻辑
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;
const helpers = global.yoho.helpers;
// 常量
const REFUND = 1; // 退货
const EXCHANGE = 2; // 换货
const TRUE = 'Y';
const RETURNS_EMPTY = '您没有退/换货订单';
const REFUND_URI = '/home/returns/refundDetail';
const EXCHANGE_URI = '/home/returns/exchangeDetail';
// 处理订单商品的数据
function getGoodsData(goods) {
const arr = [];
goods.forEach(good => {
const obj = {};
const cnAlphabet = good.cn_alphabet || '';
obj.href = helpers.getUrlBySkc(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);
});
return arr;
}
/**
* 退换货列表页数据
* @param {string} uid 用户 uid
* @param {Number} page 当前页数
* @param {Number} limit 每页最大条数
* @return {Object} Promise
*/
exports.getReturnsList = co(function*(uid, page, limit) {
page = Number.parseInt(page, 10) || 1;
limit = Number.parseInt(limit, 10) || 10;
const obj = {
orders: [],
pager: {}
};
let response = yield api.post('', {
method: 'app.refund.getList',
data: { 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
});
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;
const canCancel = item.canCancel === TRUE;
let isChange, uri;
switch (item.refund_type) {
case REFUND:
isChange = false;
if (canCancel) {
uri = REFUND_URI;
}
break;
case EXCHANGE:
isChange = true;
if (canCancel) {
uri = EXCHANGE_URI;
}
break;
default:
}
t.isChange = isChange;
t.canCancelUrl = helpers.urlFormat(uri);
t.moreHref = helpers.urlFormat(uri, { id: item.id });
t.goods = getGoodsData(item.goods);
obj.orders.push(t);
});
} else {
obj.empty = RETURNS_EMPTY;
}
return obj;
});
exports.getRefund = (orderCode, uid) =>{
};