|
@@ -1,5 +1,6 @@
|
|
|
package com.caimei365.order.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.caimei365.order.components.ProductService;
|
|
|
import com.caimei365.order.mapper.BaseMapper;
|
|
|
import com.caimei365.order.mapper.OrderClubMapper;
|
|
@@ -19,15 +20,15 @@ import com.github.pagehelper.PageInfo;
|
|
|
import com.google.common.util.concurrent.AtomicDouble;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Description
|
|
@@ -104,6 +105,103 @@ public class OrderClubServiceImpl implements OrderClubService {
|
|
|
return ResponseJson.success(pageInfo);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 机构订单详情
|
|
|
+ *
|
|
|
+ * @param userId 用户Id
|
|
|
+ * @param orderId 订单Id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<Map<String, Object>> getOrderDetail(Integer userId, Integer orderId) {
|
|
|
+ OrderPo orderPo = orderClubMapper.getMainOrderByOrderId(orderId);
|
|
|
+ if (null == orderPo) {
|
|
|
+ return ResponseJson.error("该订单不存在!", null);
|
|
|
+ }
|
|
|
+ if (!userId.equals(orderPo.getUserId())) {
|
|
|
+ return ResponseJson.error("无权限查看此订单!", null);
|
|
|
+ }
|
|
|
+ OrderVo order = new OrderVo();
|
|
|
+ // OrderPo -> OrderVo
|
|
|
+ BeanUtils.copyProperties(orderPo, order);
|
|
|
+ order.setOrderMark("#" + order.getOrderId() + "#");
|
|
|
+ // 设置订单状态
|
|
|
+ setOrderStatus(order);
|
|
|
+ // 设置子订单数据
|
|
|
+ getShopOrderData(order);
|
|
|
+ // 子订单列表
|
|
|
+ List<ShopOrderVo> shopOrderList = order.getShopOrderList();
|
|
|
+ AtomicDouble expensesOfTaxation = new AtomicDouble(0d);
|
|
|
+ shopOrderList.forEach(shopOrder -> {
|
|
|
+ List<OrderProductVo> orderProductList = shopOrder.getOrderProductList();
|
|
|
+ orderProductList.forEach(orderProduct -> {
|
|
|
+ // 是否充值商品
|
|
|
+ boolean recharge = productService.isRechargeProduct(orderProduct.getProductId());
|
|
|
+ if (recharge) {
|
|
|
+ order.setRechargeGoods(true);
|
|
|
+ }
|
|
|
+ // 总税费
|
|
|
+ expensesOfTaxation.set(MathUtil.add(expensesOfTaxation.get(), orderProduct.getTotalAddedValueTax()).doubleValue());
|
|
|
+ //已发货数量
|
|
|
+ orderProduct.setShipmentsNum(orderProduct.getNum() + orderProduct.getPresentNum() - orderProduct.getNotOutStore());
|
|
|
+ //已退货数量
|
|
|
+ Integer returnedNum = orderClubMapper.countReturnedNum(orderProduct.getShopOrderId(), orderProduct.getProductId());
|
|
|
+ returnedNum = null != returnedNum ? returnedNum : 0;
|
|
|
+ orderProduct.setReturnedNum(returnedNum);
|
|
|
+ //已取消发货数量
|
|
|
+ Integer actualCancelNum = orderClubMapper.countActualCancelNum(orderProduct.getShopOrderId(), orderProduct.getProductId());
|
|
|
+ actualCancelNum = null != actualCancelNum ? actualCancelNum : 0;
|
|
|
+ orderProduct.setActualCancelNum(actualCancelNum);
|
|
|
+ //判断商品价格是否含税
|
|
|
+ boolean taxFlag = (1 == orderProduct.getIncludedTax() || (0 == orderProduct.getIncludedTax() && (1 == orderProduct.getInvoiceType() || 2 == orderProduct.getInvoiceType())));
|
|
|
+ if (taxFlag) {
|
|
|
+ orderProduct.setIncludedTaxFlag(2);
|
|
|
+ } else if (orderProduct.getIncludedTax() != null && 0 == orderProduct.getIncludedTax() && 3 == orderProduct.getInvoiceType()) {
|
|
|
+ orderProduct.setIncludedTaxFlag(1);
|
|
|
+ } else {
|
|
|
+ orderProduct.setIncludedTaxFlag(3);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ order.setExpensesOfTaxation(expensesOfTaxation.get());
|
|
|
+
|
|
|
+ // 发票信息
|
|
|
+ InvoiceVo invoice = baseMapper.getUserInvoice(userId);
|
|
|
+ // 可用余额
|
|
|
+ Double availableMoney = baseMapper.getAbleUserMoney(userId);
|
|
|
+ // 付款金额
|
|
|
+ List<DiscernReceiptVo> discernReceiptList = getDiscernReceiptAndSetOrder(order);
|
|
|
+ // 退款记录
|
|
|
+ List<ReturnedPurchaseVo> returnedPurchaseList = orderClubMapper.getReturnedPurchaseList(order.getOrderId());
|
|
|
+ if (!returnedPurchaseList.isEmpty()) {
|
|
|
+ AtomicDouble returnedPurchaseFee = new AtomicDouble(0d);
|
|
|
+ returnedPurchaseList.forEach(returnedPurchase -> {
|
|
|
+ returnedPurchaseFee.set(MathUtil.add(returnedPurchaseFee.get(), returnedPurchase.getRefundFee()).doubleValue());
|
|
|
+ });
|
|
|
+ //退款总金额
|
|
|
+ order.setReturnedPurchaseFee(returnedPurchaseFee.get());
|
|
|
+ }
|
|
|
+ //售后条款
|
|
|
+ ClauseVo clause = null;
|
|
|
+ // 非二手
|
|
|
+ if (0 == order.getSecondHandOrderFlag()) {
|
|
|
+ Integer clauseId = order.getClauseId() == null ? 1 : order.getClauseId();
|
|
|
+ clause = orderClubMapper.getClauseById(clauseId);
|
|
|
+ }
|
|
|
+ // 收货地址
|
|
|
+ OrderUserinfoVo userInfo = orderClubMapper.getOrderUserinfo(orderId);
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("order", order);
|
|
|
+ map.put("shopOrderList", shopOrderList);
|
|
|
+ map.put("orderInvoice", invoice);
|
|
|
+ map.put("ableUserMoney", availableMoney);
|
|
|
+ map.put("userInfo", userInfo);
|
|
|
+ map.put("discernReceiptList", discernReceiptList);
|
|
|
+ map.put("returnedPurchaseList", returnedPurchaseList);
|
|
|
+ map.put("clause", clause);
|
|
|
+ return ResponseJson.success(map);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 设置订单状态
|
|
|
*/
|
|
@@ -142,7 +240,8 @@ public class OrderClubServiceImpl implements OrderClubService {
|
|
|
shopOrder.setShopPromotion(shopPromotion);
|
|
|
}
|
|
|
List<OrderProductVo> orderProductList = orderClubMapper.getShopOrderProduct(shopOrder.getShopOrderId());
|
|
|
- for (OrderProductVo orderProduct : orderProductList) {
|
|
|
+ orderProductList.forEach(orderProduct -> {
|
|
|
+ // 不含税可开票商品,单价/折后单价在原基础上加上税费
|
|
|
boolean taxFlag = (0 == orderProduct.getIncludedTax() && (1 == orderProduct.getInvoiceType() || 2 == orderProduct.getInvoiceType()));
|
|
|
if (taxFlag) {
|
|
|
orderProduct.setPrice(MathUtil.add(orderProduct.getPrice(), orderProduct.getAddedValueTax()).doubleValue());
|
|
@@ -159,7 +258,7 @@ public class OrderClubServiceImpl implements OrderClubService {
|
|
|
orderProduct.setProductPromotion(promotions);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
shopOrder.setOrderProductList(orderProductList);
|
|
|
shopOrder.setShopLogo(ImageUtil.getImageUrl("shopLogo", shopOrder.getShopLogo(), domain));
|
|
|
});
|
|
@@ -457,7 +556,6 @@ public class OrderClubServiceImpl implements OrderClubService {
|
|
|
public ResponseJson<Void> receiveGoods(Integer orderId) {
|
|
|
OrderPo order = orderClubMapper.getMainOrderByOrderId(orderId);
|
|
|
if (null == order) {
|
|
|
- // 非已关闭订单
|
|
|
return ResponseJson.error("订单不存在!", null);
|
|
|
}
|
|
|
if (33 == order.getStatus() && 3 == order.getPayStatus()) {
|
|
@@ -507,4 +605,58 @@ public class OrderClubServiceImpl implements OrderClubService {
|
|
|
List<SearchHistoryVo> historyList = orderClubMapper.getOrderSearchHistory(userId);
|
|
|
return ResponseJson.success(historyList);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据用户Id删除订单搜索历史记录
|
|
|
+ *
|
|
|
+ * @param userId 用户Id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<Void> deleteOrderSearchHistory(Integer userId) {
|
|
|
+ orderClubMapper.deleteOrderSearchHistory(userId);
|
|
|
+ return ResponseJson.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 物流详情
|
|
|
+ *
|
|
|
+ * @param orderId 订单Id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<List<LogisticsBatchVo>> getOrderLogistics(Integer orderId) {
|
|
|
+ OrderPo order = orderClubMapper.getMainOrderByOrderId(orderId);
|
|
|
+ if (null == order) {
|
|
|
+ return ResponseJson.error("订单不存在!", null);
|
|
|
+ }
|
|
|
+ // 获取物流批次列表
|
|
|
+ List<LogisticsBatchVo> batchList = orderClubMapper.getLogisticsBatchList(orderId);
|
|
|
+ batchList.forEach(batch -> {
|
|
|
+ // 根据物流批次获取子订单
|
|
|
+ List<String> shopOrderIds = orderClubMapper.getBatchShopOrderIds(orderId, batch.getId());
|
|
|
+ List<ShopOrderVo> shopOrderList = orderClubMapper.getShopOrderList(shopOrderIds);
|
|
|
+ shopOrderList.forEach(shopOrder -> {
|
|
|
+ shopOrder.setShopLogo(ImageUtil.getImageUrl("shopLogo", shopOrder.getShopLogo(), domain));
|
|
|
+ // 获取发货物流记录
|
|
|
+ List<LogisticsRecordVo> logisticsRecordList = orderClubMapper.getLogisticsRecord(shopOrder.getShopOrderId(), batch.getId());
|
|
|
+ shopOrder.setLogisticsRecordList(logisticsRecordList);
|
|
|
+ });
|
|
|
+ // 获取物流信息
|
|
|
+ List<LogisticsInformationVo> logisticsInfoList = orderClubMapper.getLogisticsInfoList(batch.getId());
|
|
|
+ logisticsInfoList.forEach(logisticsInfo -> {
|
|
|
+ List<LogisticsRouterVo> routers = JSONArray.parseArray(logisticsInfo.getInfo(), LogisticsRouterVo.class);
|
|
|
+ if (!CollectionUtils.isEmpty(routers)) {
|
|
|
+ routers.forEach(router -> {
|
|
|
+ if (StringUtils.isEmpty(router.getDesc())) {
|
|
|
+ router.setDesc(router.getContext());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ logisticsInfo.setRouterList(routers);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ batch.setLogisticsInformationList(logisticsInfoList);
|
|
|
+ batch.setShopOrderList(shopOrderList);
|
|
|
+ });
|
|
|
+
|
|
|
+ return ResponseJson.success(batchList);
|
|
|
+ }
|
|
|
}
|