2023-12-11 14:21:21 +00:00
|
|
|
import request2 from '@/sheep/request2';
|
|
|
|
|
|
|
|
const OrderApi = {
|
|
|
|
// 计算订单信息
|
|
|
|
settlementOrder: (data) => {
|
|
|
|
const data2 = {
|
|
|
|
...data,
|
2023-12-12 14:23:33 +00:00
|
|
|
};
|
2023-12-11 14:21:21 +00:00
|
|
|
// 移除多余字段
|
|
|
|
if (!(data.couponId > 0)) {
|
2023-12-12 14:23:33 +00:00
|
|
|
delete data2.couponId;
|
2023-12-11 14:21:21 +00:00
|
|
|
}
|
|
|
|
if (!(data.addressId > 0)) {
|
2023-12-12 14:23:33 +00:00
|
|
|
delete data2.addressId;
|
2023-12-11 14:21:21 +00:00
|
|
|
}
|
|
|
|
// 解决 SpringMVC 接受 List<Item> 参数的问题
|
2023-12-12 14:23:33 +00:00
|
|
|
delete data2.items;
|
2023-12-11 14:21:21 +00:00
|
|
|
for (let i = 0; i < data.items.length; i++) {
|
|
|
|
data2[encodeURIComponent('items[' + i + '' + '].skuId')] = data.items[i].skuId + '';
|
|
|
|
data2[encodeURIComponent('items[' + i + '' + '].count')] = data.items[i].count + '';
|
|
|
|
if (data.items[i].cartId) {
|
|
|
|
data2[encodeURIComponent('items[' + i + '' + '].cartId')] = data.items[i].cartId + '';
|
|
|
|
}
|
|
|
|
}
|
2023-12-12 14:23:33 +00:00
|
|
|
const queryString = Object.keys(data2)
|
|
|
|
.map((key) => key + '=' + data2[key])
|
|
|
|
.join('&');
|
2023-12-11 14:21:21 +00:00
|
|
|
return request2({
|
|
|
|
url: `trade/order/settlement?${queryString}`,
|
2023-12-12 14:23:33 +00:00
|
|
|
method: 'GET',
|
|
|
|
});
|
2023-12-11 14:21:21 +00:00
|
|
|
},
|
|
|
|
// 创建订单
|
|
|
|
createOrder: (data) => {
|
|
|
|
return request2({
|
|
|
|
url: `trade/order/create`,
|
|
|
|
method: 'POST',
|
2023-12-12 14:23:33 +00:00
|
|
|
data,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
// 获得订单
|
|
|
|
getOrder: (id) => {
|
|
|
|
return request2({
|
|
|
|
url: `trade/order/get-detail`,
|
|
|
|
method: 'GET',
|
|
|
|
params: {
|
|
|
|
id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2023-12-11 14:21:21 +00:00
|
|
|
};
|
|
|
|
|
2023-12-12 14:23:33 +00:00
|
|
|
export default OrderApi;
|