...
|
...
|
@@ -10,7 +10,7 @@ const moment = require('moment'); |
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
const pager = require('./pager').handlePagerData;
|
|
|
const orderApi = require('./order-api');
|
|
|
const orderApi = require('./orders-api');
|
|
|
const ChannelConfig = require('./ChannelConfig');
|
|
|
|
|
|
const ORDER_TYPE = {
|
...
|
...
|
@@ -93,6 +93,7 @@ const _getOrderStatus = (isCancel, status, payType, payStatus) => { |
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
};
|
|
|
|
...
|
...
|
@@ -124,11 +125,11 @@ const _getOperateInfo = (attribute, isCancel, status, |
|
|
// 申请退货
|
|
|
let refundUrl = helpers.urlFormat('/home/returns/refundrequest', {orderCode: orderCode});
|
|
|
|
|
|
let operation = {};
|
|
|
let operation = [];
|
|
|
|
|
|
// 晒单评价
|
|
|
if (status >= 6 && isCancel === 'N' && payStatus === 'Y') {
|
|
|
Object.assign(operation, {
|
|
|
operation.push({
|
|
|
name: '晒单评价',
|
|
|
comment: true,
|
|
|
href: commentUrl
|
...
|
...
|
@@ -137,7 +138,7 @@ const _getOperateInfo = (attribute, isCancel, status, |
|
|
|
|
|
// 再次购买
|
|
|
if (isCancel === 'Y' && useLimitCode !== 'Y') {
|
|
|
Object.assign(operation, {
|
|
|
operation.push({
|
|
|
name: '再次购买',
|
|
|
reBuy: true
|
|
|
});
|
...
|
...
|
@@ -145,20 +146,20 @@ const _getOperateInfo = (attribute, isCancel, status, |
|
|
|
|
|
// 立即付款
|
|
|
if (payStatus === 'N' && paymentType !== 2 && isCancel === 'N') {
|
|
|
Object.assign(operation, {
|
|
|
operation.push({
|
|
|
payNow: true,
|
|
|
href: payUrl
|
|
|
});
|
|
|
}
|
|
|
|
|
|
Object.assign(operation, {
|
|
|
operation.push({
|
|
|
name: '查看订单',
|
|
|
href: orderDetailUrl
|
|
|
});
|
|
|
|
|
|
// 查看订单,虚拟订单查看二维码
|
|
|
if (attribute === 3 && payStatus === 'Y') {
|
|
|
Object.assign(operation, {
|
|
|
operation.push({
|
|
|
href: ticketUrl,
|
|
|
name: '查看二维码'
|
|
|
});
|
...
|
...
|
@@ -166,7 +167,7 @@ const _getOperateInfo = (attribute, isCancel, status, |
|
|
|
|
|
// 取消订单
|
|
|
if (status < 3 && isCancel === 'N' && orderType !== 5 && payStatus === 'N') {
|
|
|
Object.assign(operation, {
|
|
|
operation.push({
|
|
|
href: cancelOrderUrl,
|
|
|
name: '取消订单',
|
|
|
cancelOrder: true
|
...
|
...
|
@@ -175,7 +176,7 @@ const _getOperateInfo = (attribute, isCancel, status, |
|
|
|
|
|
// 确认收货
|
|
|
if (status >= 4 && status < 6 && refundStatus === 0 && attribute !== 3 && isCancel === 'N') {
|
|
|
Object.assign(operation, {
|
|
|
operation.push({
|
|
|
href: confirmOrderUrl,
|
|
|
name: '确认收货',
|
|
|
confirmReceived: true
|
...
|
...
|
@@ -187,7 +188,7 @@ const _getOperateInfo = (attribute, isCancel, status, |
|
|
let orderExchangeLimitTime = ChannelConfig.exchangeDay;
|
|
|
|
|
|
if (status >= 6 && time < 86400 * orderExchangeLimitTime && attribute !== 3 && isCancel === 'N') {
|
|
|
Object.assign(operation, {
|
|
|
operation.push({
|
|
|
href: exchangeUrl,
|
|
|
name: '申请换货',
|
|
|
optDis: opRefundStatus
|
...
|
...
|
@@ -198,7 +199,7 @@ const _getOperateInfo = (attribute, isCancel, status, |
|
|
let orderRefundLimitTime = ChannelConfig.refundDay;
|
|
|
|
|
|
if (status >= 6 && time < 86400 * orderRefundLimitTime && attribute !== 3 && isCancel === 'N') {
|
|
|
Object.assign(operation, {
|
|
|
operation.push({
|
|
|
href: refundUrl,
|
|
|
name: '申请退货',
|
|
|
optDis: opRefundStatus
|
...
|
...
|
@@ -207,9 +208,9 @@ const _getOperateInfo = (attribute, isCancel, status, |
|
|
|
|
|
// 预售商品提示app操作
|
|
|
if (attribute === 9) {
|
|
|
operation = {
|
|
|
operation = [{
|
|
|
name: '定金预售商品只能在APP端操作'
|
|
|
};
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
return operation;
|
...
|
...
|
@@ -290,7 +291,7 @@ const _getExpressInfo = (orderCode, uid, paymetType, createTime, isDetail) => { |
|
|
if (isDetail) {
|
|
|
result.logistics.push('');
|
|
|
} else {
|
|
|
result.logistics.push(moment.unix(createTime).format('YYYY-M-D H:m:s') + ' 您的订单已提交,等待付款');
|
|
|
result.logistics.push(moment.unix(createTime).format('YYYY.MM.DD HH:mm:ss') + ' 您的订单已提交,等待付款');
|
|
|
}
|
|
|
}
|
|
|
if (paymetType === 2) {
|
...
|
...
|
@@ -301,7 +302,7 @@ const _getExpressInfo = (orderCode, uid, paymetType, createTime, isDetail) => { |
|
|
'您的订单已提交,等待审核'
|
|
|
]);
|
|
|
} else {
|
|
|
result.logistics.push(moment.unix(createTime).format('YYYY-M-D H:m:s') + ' 您的订单已提交,等待审核');
|
|
|
result.logistics.push(moment.unix(createTime).format('YYYY.MM.DD HH:mm:ss') + ' 您的订单已提交,等待审核');
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -321,12 +322,15 @@ const _getExpressInfo = (orderCode, uid, paymetType, createTime, isDetail) => { |
|
|
|
|
|
result.logistics = [];
|
|
|
expressDetail.forEach((value) => {
|
|
|
let pos = value.accept_address.indexOf(' ') / 3;
|
|
|
let pos = value.accept_address.indexOf(' ');
|
|
|
|
|
|
pos = pos === -1 ? 0 : pos;
|
|
|
|
|
|
let city = value.accept_address.substr(0, pos);
|
|
|
let exInfo = value.accept_address.substr(pos);
|
|
|
|
|
|
if (isDetail) {
|
|
|
result.logistics = result.logistics.concat([value.acceptTime, city, exInfo]);
|
|
|
result.logistics.push([value.acceptTime, city, exInfo]);
|
|
|
} else {
|
|
|
result.logistics.push(value.acceptTime + city + exInfo);
|
|
|
}
|
...
|
...
|
@@ -355,17 +359,24 @@ const _getOrders = (uid, page, limit, type, isPage)=> { |
|
|
if (_.isEmpty(_.get(orderInfo, 'order_list', []))) {
|
|
|
return {
|
|
|
empty: ORDER_EMPTY_DESC[type] || '',
|
|
|
list:[]
|
|
|
list: []
|
|
|
};
|
|
|
}
|
|
|
|
|
|
let result = {};
|
|
|
|
|
|
const handleOrder = co(function * (order) {
|
|
|
order.payment_type = +order.payment_type;
|
|
|
|
|
|
let newOrder = {};
|
|
|
|
|
|
newOrder.orderNum = order.order_code; // 订单标识
|
|
|
newOrder.orderTime = moment.unix(_.get(order, 'create_time')).format('YYYY-M-D H:m:s');
|
|
|
newOrder.orderTime = moment.unix(_.get(order, 'create_time')).format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
|
|
if (order.is_cancel === 'Y' || order.status === 6) {
|
|
|
newOrder.canDelete = true; // 删除订单
|
|
|
}
|
|
|
|
|
|
let statusInfo = _getOrderStatus(order.is_cancel, order.status, order.payment_type, order.payment_status);
|
|
|
|
|
|
// 订单状态
|
...
|
...
|
@@ -432,6 +443,8 @@ const _getOrders = (uid, page, limit, type, isPage)=> { |
|
|
opRefundStatus, order.use_limit_code
|
|
|
);
|
|
|
|
|
|
console.log(newOrder.operation);
|
|
|
|
|
|
return newOrder;
|
|
|
});
|
|
|
|
...
|
...
|
@@ -512,7 +525,7 @@ const index = (uid, page, limit, type) => { |
|
|
|
|
|
result[result.name] = result.list;
|
|
|
|
|
|
result.pager = pager(result.list.pager.total, {page, limit, type});
|
|
|
result.pager = pager(_.get(result, 'list.pager.total', 0), {page, limit, type});
|
|
|
|
|
|
return Object.assign(result, {
|
|
|
tabs: _getTabs(type)
|
...
|
...
|
@@ -520,7 +533,362 @@ const index = (uid, page, limit, type) => { |
|
|
})();
|
|
|
};
|
|
|
|
|
|
const reBuy = (uid, orderId) => {
|
|
|
return co(function * () {
|
|
|
let newOrder = yield orderApi.reBuy(uid, orderId);
|
|
|
|
|
|
if (newOrder.code !== 200) {
|
|
|
return {
|
|
|
code: 400,
|
|
|
message: '商品加入购物车失败'
|
|
|
};
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
code: 200,
|
|
|
message: '商品已重新加入购物车',
|
|
|
data: newOrder.data
|
|
|
};
|
|
|
})();
|
|
|
};
|
|
|
|
|
|
const del = co(function * (uid, gender, channel, orderId) {
|
|
|
let orderInfo = yield orderApi.del(uid, gender, channel, orderId);
|
|
|
|
|
|
if (!_.has(orderInfo, 'code')) {
|
|
|
return {
|
|
|
code: 400,
|
|
|
message: '删除失败'
|
|
|
};
|
|
|
}
|
|
|
|
|
|
return orderInfo;
|
|
|
});
|
|
|
|
|
|
const _getVirtualPro = (isCancel, status, createTime) => {
|
|
|
let process = {
|
|
|
middleStatus: [
|
|
|
{
|
|
|
name: '1. 提交订单',
|
|
|
date: moment.unix(createTime).format('YYYY.MM.DD HH:mm:ss')
|
|
|
},
|
|
|
{
|
|
|
name: '2. 已发货'
|
|
|
},
|
|
|
{
|
|
|
name: '3. 交易完成'
|
|
|
}
|
|
|
]
|
|
|
};
|
|
|
|
|
|
if (isCancel === 'N') {
|
|
|
if (status === 0) {
|
|
|
process.percent = '30%';
|
|
|
process.middleStatus[0].cur = true;
|
|
|
} else if (status > 0 && status < 6) {
|
|
|
process.percent = '80%';
|
|
|
process.middleStatus[1].cur = true;
|
|
|
} else if (status === 6) {
|
|
|
process.percent = '100%';
|
|
|
process.middleStatus[3].cur = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return process;
|
|
|
};
|
|
|
|
|
|
const _getNormalPro = (isCancel, status, createTime) => {
|
|
|
let process = {
|
|
|
middleStatus: [
|
|
|
{
|
|
|
name: '1. 提交订单',
|
|
|
date: moment.unix(createTime).format('YYYY.MM.DD HH:mm:ss')
|
|
|
},
|
|
|
{
|
|
|
name: '2. 商品出库'
|
|
|
},
|
|
|
{
|
|
|
name: '3. 等待收货'
|
|
|
},
|
|
|
{
|
|
|
name: '4. 交易完成'
|
|
|
}
|
|
|
]
|
|
|
};
|
|
|
|
|
|
if (isCancel === 'N') {
|
|
|
if (status === 0) {
|
|
|
process.percent = '25%';
|
|
|
process.middleStatus[0].cur = true;
|
|
|
} else if (status > 0 && status < 4) {
|
|
|
process.percent = '50%';
|
|
|
process.middleStatus[1].cur = true;
|
|
|
} else if (status >= 4 && status < 6) {
|
|
|
process.percent = '75%';
|
|
|
process.middleStatus[2].cur = true;
|
|
|
} else if (status === 6) {
|
|
|
process.percent = '100%';
|
|
|
process.middleStatus[3].cur = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return process;
|
|
|
};
|
|
|
|
|
|
const _getOrderDetailOp = (orderId, payment, status,
|
|
|
isCancel, paymentStatus, paymentType,
|
|
|
orderType, attribute, refundStatus) => {
|
|
|
let operation = {};
|
|
|
|
|
|
//立刻付款
|
|
|
if (paymentType === 1 && paymentStatus === 'N' && isCancel === 'N' && payment !== 19) {
|
|
|
Object.assign(operation, {
|
|
|
goPay: helpers.urlFormat('/shopping/pay', {ordercode: orderId})
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//取消订单
|
|
|
if (status < 3 && isCancel === 'N' && paymentStatus === 'N' && orderType !== 5) {
|
|
|
Object.assign(operation, {
|
|
|
cancelOrder: true
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//订单已支付
|
|
|
if (paymentType === 1 && paymentStatus === 'Y' && status < 6) {
|
|
|
Object.assign(operation, {
|
|
|
paid: true
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//确认收货
|
|
|
if (status >= 4 && status < 6 && refundStatus === 0 && attribute !== 3 && isCancel === 'N') {
|
|
|
Object.assign(operation, {
|
|
|
shipped: true
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//订单已取消
|
|
|
if (isCancel === 'Y') {
|
|
|
Object.assign(operation, {
|
|
|
cancel: true
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//虚拟查看二维码
|
|
|
if (attribute === 3) {
|
|
|
Object.assign(operation, {
|
|
|
checkQrCode: helpers.urlFormat('/home/orders/ticket', {orderCode: orderId})
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return operation;
|
|
|
};
|
|
|
|
|
|
const _getPackageInfo = (cartInfo) => {
|
|
|
// 是否拆单
|
|
|
if (cartInfo.is_multi_package !== 'Y') {
|
|
|
return [];
|
|
|
}
|
|
|
|
|
|
return _.get(cartInfo, 'package_list', []).map((pack, i) => {
|
|
|
let newPack = {};
|
|
|
|
|
|
newPack.title = (pack.supplier_id === 0) ? `包裹${i}:总仓发货` : `包裹${i}:异地调拨`;
|
|
|
|
|
|
newPack.goodlist = _.get(pack, 'goods_list', []).map((good) => {
|
|
|
let tagInfo = ChannelConfig.orderTagArr[good.goods_type] || '';
|
|
|
|
|
|
return {
|
|
|
src: helpers.image(good.goods_images, 90, 90),
|
|
|
goodsType: tagInfo.name || '',
|
|
|
classname: tagInfo.classname || '',
|
|
|
link: 'javascritp:void(0)'
|
|
|
};
|
|
|
});
|
|
|
|
|
|
newPack.fee = pack.shopping_cost === '0.00' ? '' : pack.shopping_cost;
|
|
|
newPack.orign = pack.shopping_orig_cost;
|
|
|
newPack.count = pack.shopping_cut_cost;
|
|
|
|
|
|
return newPack;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const _getOrder = co(function * (uid, orderId) {
|
|
|
let orderInfo = yield orderApi.getOrderDetail(uid, orderId);
|
|
|
let detail = {};
|
|
|
|
|
|
if (orderInfo.code === 400) {
|
|
|
return orderInfo;
|
|
|
}
|
|
|
|
|
|
if (orderInfo.data) {
|
|
|
let orderDetail = orderInfo.data;
|
|
|
|
|
|
detail.orderNum = orderDetail.order_code;
|
|
|
|
|
|
// 订单状态
|
|
|
let statusInfo = _getOrderStatus(
|
|
|
orderDetail.is_cancel, +orderDetail.status,
|
|
|
orderDetail.payment_type, orderDetail.payment_status
|
|
|
);
|
|
|
|
|
|
detail.statusStr = statusInfo.statusStr;
|
|
|
|
|
|
// 订单是否已完成
|
|
|
detail.complete = +orderDetail.status === 6;
|
|
|
|
|
|
detail.progress = statusInfo.cancel ? false : (function() {
|
|
|
//未取消订单,进度
|
|
|
if (orderDetail.attribute === 3) {
|
|
|
return _getVirtualPro(orderDetail.is_cancel, +orderDetail.status, orderDetail.create_time);
|
|
|
} else {
|
|
|
return _getNormalPro(orderDetail.is_cancel, +orderDetail.status, orderDetail.create_time);
|
|
|
}
|
|
|
}());
|
|
|
|
|
|
// 物流信息
|
|
|
detail.traceOrder = {};
|
|
|
detail.traceOrder.orderDate = moment.unix(orderDetail.create_time).format('YYYY.MM.DD HH:mm:ss');
|
|
|
let expressInfo = yield _getExpressInfo(orderId, uid, +orderDetail.payment_type, orderDetail.create_time, true);
|
|
|
|
|
|
detail.traceOrder.logistics = expressInfo.logistics;
|
|
|
|
|
|
if (_.get(expressInfo, 'logistics[0]')) {
|
|
|
detail.hastrace = true;
|
|
|
} else {
|
|
|
detail.hastrace = false;
|
|
|
}
|
|
|
|
|
|
detail.traceOrder.logisticsCompany = expressInfo.logisticsCompany;
|
|
|
detail.traceOrder.courierNumbe = expressInfo.courierNumbe;
|
|
|
|
|
|
//虚拟商品
|
|
|
if (orderDetail.attribute === 3) {
|
|
|
detail.virtualGoods = true;
|
|
|
detail.virtualPayMode = {
|
|
|
payMode: ChannelConfig.payType[orderDetail.payment_type],
|
|
|
phone: _.fill(orderDetail.mobile.split(''), '*', 3, 4).join('')
|
|
|
};
|
|
|
} else {
|
|
|
detail.virtualGoods = false;
|
|
|
detail.noramlPayMode = {
|
|
|
payMode: ChannelConfig.payType[orderDetail.payment_type],
|
|
|
payWay: orderDetail.payment_name,
|
|
|
deliverTime: orderDetail.delivery_time || ''
|
|
|
};
|
|
|
|
|
|
//配送信息
|
|
|
detail.orderInfo = {
|
|
|
receiver: orderDetail.user_name,
|
|
|
address: orderDetail.area + orderDetail.address,
|
|
|
phone: _.fill(orderDetail.mobile.split(''), '*', 3, 4).join('') +
|
|
|
(orderDetail.phone ? ',' + _.fill(orderDetail.phone.split(''), '*', 3, 5).join('') : '')
|
|
|
};
|
|
|
|
|
|
detail.editInfo = {
|
|
|
userName: orderDetail.user_name,
|
|
|
address: orderDetail.address,
|
|
|
areaCode: orderDetail.area_code,
|
|
|
mobile: orderDetail.mobile,
|
|
|
phoneNum: _.nth(_.split(orderDetail.phone), 0) || '',
|
|
|
phoneCode: _.nth(_.split(orderDetail.phone), 1) || ''
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// 商品信息
|
|
|
if (orderDetail.order_goods) {
|
|
|
detail.goods = _.get(orderDetail, 'order_goods', []).map((good) => {
|
|
|
return {
|
|
|
url: helpers.getUrlBySkc(good.product_id, good.goods_id, good.cn_alphabet),
|
|
|
img: helpers.image(good.goods_image, 60, 60),
|
|
|
name: good.product_name,
|
|
|
color: good.factory_color_name,
|
|
|
size: good.size_name,
|
|
|
price: good.goods_price,
|
|
|
coin: good.yoho_give_coin,
|
|
|
num: good.buy_number,
|
|
|
sum: good.goods_amount,
|
|
|
sku: good.product_sku,
|
|
|
[_getGoodsTag(good.attribute, good.goods_type)]: true
|
|
|
};
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//详情页-订单付费详情
|
|
|
if (orderDetail.promotion_formulas) {
|
|
|
detail.orderBalance = _.get(orderDetail, 'promotion_formulas', []).map((promotion) => {
|
|
|
return {
|
|
|
promotion: promotion.promotion,
|
|
|
account: promotion.promotion_amount
|
|
|
};
|
|
|
});
|
|
|
|
|
|
detail.orderBalance.push({
|
|
|
promotion: '实际应支付',
|
|
|
account: orderDetail.amount
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//发票
|
|
|
if (orderDetail.invoice) {
|
|
|
detail.invoiceMode = true;
|
|
|
detail.invoiceType = _.get(orderDetail, 'invoice.type') === 2 ? '电子发票' : '纸质发票';
|
|
|
detail.showInvoice = _.get(orderDetail, 'invoice.showInvoice');
|
|
|
detail.pdfUrl = detail.showInvoice ? _.get(orderDetail, 'invoice.pdfUrl') : '';
|
|
|
detail.title = _.get(orderDetail, 'invoice.title') || '';
|
|
|
detail.contentValue = _.get(orderDetail, 'invoice.contentValue') || '个人';
|
|
|
}
|
|
|
|
|
|
detail.totalYoho = orderDetail.yoho_give_coin;
|
|
|
detail.yohoCoinUrl = helpers.urlFormat('/help/detail', {id: 105}); // 有货币介绍
|
|
|
detail.remark = orderDetail.remark;
|
|
|
detail.operation = _getOrderDetailOp(orderDetail.order_cde, orderDetail.payment, +orderDetail.status,
|
|
|
orderDetail.is_cancel, orderDetail.payment_status, orderDetail.payment_type,
|
|
|
orderDetail.order_type, orderDetail.attribute, orderDetail.refund_status);
|
|
|
|
|
|
detail.package = _getPackageInfo(orderDetail);
|
|
|
|
|
|
//判断是否可以修改地址
|
|
|
if (orderDetail.can_update_delivery_address === 'Y') {
|
|
|
detail.changeable = true;
|
|
|
}
|
|
|
|
|
|
return detail;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
const updateDeliveryAddress = orderApi.updateDeliveryAddress;
|
|
|
|
|
|
const confirm = orderApi.confirmUserOrder;
|
|
|
|
|
|
const cancel = orderApi.cancelUserOrder;
|
|
|
|
|
|
const detail = co(function * (uid, orderId) {
|
|
|
let apiData = yield Promise.props({
|
|
|
detailData: _getOrder(uid, orderId),
|
|
|
reason: orderApi.closeReasons()
|
|
|
});
|
|
|
|
|
|
if (apiData.detailData.code === 400) {
|
|
|
return {};
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
detail: apiData.detailData,
|
|
|
package: apiData.detailData.package,
|
|
|
cancelReason: _.get(apiData.reason, 'data', [])
|
|
|
};
|
|
|
});
|
|
|
|
|
|
module.exports = {
|
|
|
index,
|
|
|
ORDER_TYPE
|
|
|
ORDER_TYPE,
|
|
|
reBuy,
|
|
|
del,
|
|
|
updateDeliveryAddress,
|
|
|
confirm,
|
|
|
cancel,
|
|
|
detail
|
|
|
}; |
...
|
...
|
|