瀏覽代碼

销售订单保存时优化运费计算逻辑

liyuan 7 月之前
父節點
當前提交
a4209c3364

+ 14 - 18
blade-service/blade-sales-part/src/main/java/org/springblade/salesPart/order/service/impl/OrderServiceImpl.java

@@ -1,19 +1,3 @@
-/*
- *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
- *
- *  Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions are met:
- *
- *  Redistributions of source code must retain the above copyright notice,
- *  this list of conditions and the following disclaimer.
- *  Redistributions in binary form must reproduce the above copyright
- *  notice, this list of conditions and the following disclaimer in the
- *  documentation and/or other materials provided with the distribution.
- *  Neither the name of the dreamlu.net developer nor the names of its
- *  contributors may be used to endorse or promote products derived from
- *  this software without specific prior written permission.
- *  Author: Chill 庄骞 (smallchill@163.com)
- */
 package org.springblade.salesPart.order.service.impl;
 
 import com.alibaba.fastjson.JSON;
@@ -34,6 +18,7 @@ import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
 import okhttp3.*;
 import org.springblade.client.entity.Message;
 import org.springblade.client.feign.IMessageClient;
+import org.springblade.common.enums.CommonEnum;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.secure.BladeUser;
@@ -4987,7 +4972,18 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
 				order.setSalesAmount(totalMoney);
 				order.setTotalMoney(totalMoney);
 				if (!"JF".equals(order.getBsType()) &&  !Objects.equals(1, order.getBillType())) {
-					if (order.getGoodsTotalNum().compareTo(new BigDecimal(1)) == 0) {//只有一条轮胎加5元运费
+					BigDecimal one = new BigDecimal(CommonEnum.ONE.info);
+					String freight = sysClient.getParamService("freight");
+					BigDecimal freightAmount = ObjectUtils.isNotNull(freight) ? new BigDecimal(freight) : BigDecimal.ZERO;
+					BigDecimal goodsTotalNum = order.getGoodsTotalNum();
+					if (StringUtils.isNotBlank(order.getSrcOrdNo()) && !Objects.equals(order.getSrcOrdNo(), order.getOrdNo())) {
+						// srcorderno != orderno 时代表是小程序单, 小程单则加上拆分出去订单的数量
+						BigDecimal orderItemSum = orderMapper.selectGoodsNumBySrcOrderNo(order.getSrcOrdNo(), order.getId());
+						goodsTotalNum = goodsTotalNum.add(orderItemSum);
+					}
+					order.setTotalMoney(goodsTotalNum.compareTo(one) == 0 ? totalMoney.add(freightAmount): totalMoney);
+					order.setFreight(goodsTotalNum.compareTo(one) == 0 ? freightAmount : BigDecimal.ZERO);
+/*					if (order.getGoodsTotalNum().compareTo(new BigDecimal(1)) == 0) {//只有一条轮胎加5元运费
 						String freight = sysClient.getParamService("freight");
 						if (ObjectUtils.isNotNull(freight)) {
 							try {
@@ -5000,7 +4996,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, PjOrder> implemen
 						}
 					} else {
 						order.setFreight(new BigDecimal(0));
-					}
+					}*/
 					//毛利
 					order.setGrossProfit(order.getOrderItemsList().stream().map(PjOrderItems::getGrossProfit).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
 					//成本