|
@@ -27,6 +27,7 @@ import com.kxmall.order.domain.KxStoreOrderProduct;
|
|
|
import com.kxmall.order.domain.bo.DeliveryRequestBo;
|
|
|
import com.kxmall.order.domain.bo.OrderRequestBo;
|
|
|
import com.kxmall.order.domain.bo.OrderRequestProductBo;
|
|
|
+import com.kxmall.order.domain.bo.OrderPriceBo;
|
|
|
import com.kxmall.order.domain.vo.KxStoreOrderProductVo;
|
|
|
import com.kxmall.order.domain.vo.KxStoreOrderVo;
|
|
|
import com.kxmall.order.mapper.KxStoreOrderMapper;
|
|
@@ -318,6 +319,64 @@ public class KxAppOrderService implements IKxAppOrderService {
|
|
|
result.setMsg("不予配送");
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OrderPriceBo calculateOrderPrice(OrderRequestBo orderRequestBo) {
|
|
|
+ OrderPriceBo orderPriceBo = new OrderPriceBo();
|
|
|
+
|
|
|
+ // 1. 计算商品总价
|
|
|
+ BigDecimal productTotalPrice = BigDecimal.ZERO;
|
|
|
+ BigDecimal productOriginalPrice = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ for (OrderRequestProductBo product : orderRequestBo.getProductList()) {
|
|
|
+ BigDecimal price = ObjectUtils.isEmpty(product.getVipPrice()) ? product.getPrice() : product.getVipPrice();
|
|
|
+ BigDecimal itemTotal = price.multiply(BigDecimal.valueOf(product.getCartNum()));
|
|
|
+ productTotalPrice = productTotalPrice.add(itemTotal);
|
|
|
+
|
|
|
+ // 原价计算(如果需要显示优惠信息)
|
|
|
+ BigDecimal originalPrice = product.getPrice().multiply(BigDecimal.valueOf(product.getCartNum()));
|
|
|
+ productOriginalPrice = productOriginalPrice.add(originalPrice);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 计算配送费
|
|
|
+ BigDecimal freightPrice = BigDecimal.ZERO;
|
|
|
+ if (orderRequestBo.getShippingType() == 1) {
|
|
|
+ DeliveryRequestBo deliveryResult = getFreightMoney(orderRequestBo);
|
|
|
+ freightPrice = deliveryResult.getTotalPrice().compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : deliveryResult.getTotalPrice();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 获取加急费用
|
|
|
+ BigDecimal urgentFee = orderRequestBo.getUrgentFee() != null ? orderRequestBo.getUrgentFee() : BigDecimal.ZERO;
|
|
|
+
|
|
|
+ // 4. 计算优惠券抵扣
|
|
|
+ BigDecimal couponPrice = BigDecimal.ZERO;
|
|
|
+ if (orderRequestBo.getCoupon() != null) {
|
|
|
+ couponPrice = orderRequestBo.getCoupon().getCouponPrice();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 计算最终价格 = 商品总价 - 优惠券 + 配送费 + 加急费用
|
|
|
+ BigDecimal actualPrice = productTotalPrice.subtract(couponPrice).add(freightPrice).add(urgentFee);
|
|
|
+
|
|
|
+ // 确保最终价格不为负数
|
|
|
+ if (actualPrice.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ actualPrice = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 组装返回结果
|
|
|
+ orderPriceBo.setProductTotalPrice(productTotalPrice);
|
|
|
+ orderPriceBo.setProductOriginalTotalPrice(productOriginalPrice);
|
|
|
+ orderPriceBo.setFreightPrice(freightPrice);
|
|
|
+ orderPriceBo.setUrgentFee(urgentFee);
|
|
|
+ orderPriceBo.setCouponPrice(couponPrice);
|
|
|
+ orderPriceBo.setActualPrice(actualPrice);
|
|
|
+
|
|
|
+ if (orderRequestBo.getCoupon() != null) {
|
|
|
+ orderPriceBo.setCouponId(orderRequestBo.getCoupon().getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ return orderPriceBo;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String refund(String orderId, Long userId, String reason) {
|