|
@@ -11,6 +11,7 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -497,96 +498,45 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
|
|
|
}
|
|
|
}
|
|
|
Map<String, BigDecimal> sellAmount = new HashMap<>();
|
|
|
- //乐器销售,声部更改
|
|
|
- if (order.getType().equals(OrderTypeEnum.GOODS_SELL) || order.getType().equals(OrderTypeEnum.SUBJECT_CHANGE)) {
|
|
|
+ //乐器销售,声部更改,乐器置换
|
|
|
+ if (order.getType().equals(OrderTypeEnum.GOODS_SELL) || order.getType().equals(OrderTypeEnum.SUBJECT_CHANGE) || order.getType().equals(OrderTypeEnum.REPLACEMENT)) {
|
|
|
sellAmount.put("actualAmount", order.getActualAmount().subtract(cloudIncome));
|
|
|
sellAmount.put("balance", order.getBalancePaymentAmount() == null ? BigDecimal.ZERO : order.getBalancePaymentAmount().subtract(cloudBalanceIncome));
|
|
|
return sellAmount;
|
|
|
}
|
|
|
- //乐器置换
|
|
|
- if (order.getType().equals(OrderTypeEnum.REPLACEMENT)) {
|
|
|
- sellAmount.put("actualAmount", order.getActualAmount().subtract(cloudIncome));
|
|
|
- sellAmount.put("balance", order.getBalancePaymentAmount() == null ? BigDecimal.ZERO : order.getBalancePaymentAmount().subtract(cloudBalanceIncome));
|
|
|
- return sellAmount;
|
|
|
+ //乐团报名,乐器维修
|
|
|
+ if (order.getType().equals(OrderTypeEnum.APPLY) || order.getType().equals(OrderTypeEnum.REPAIR)) {
|
|
|
+ return this.calcSellAmount(order,cloudBalanceIncome, cloudIncome);
|
|
|
}
|
|
|
+ sellAmount.put("actualAmount", BigDecimal.ZERO);
|
|
|
+ sellAmount.put("balance", BigDecimal.ZERO);
|
|
|
+ return sellAmount;
|
|
|
+ }
|
|
|
|
|
|
- //乐器维修
|
|
|
- if (order.getType().equals(OrderTypeEnum.REPAIR)) {
|
|
|
- /*StudentRepair repairInfo = studentRepairDao.getRepairInfo(Integer.parseInt(order.getMusicGroupId()));
|
|
|
-
|
|
|
- if (StringUtils.isBlank(repairInfo.getGoodsJson())) {
|
|
|
- sellAmount.put("actualAmount", BigDecimal.ZERO);
|
|
|
- sellAmount.put("balance", BigDecimal.ZERO);
|
|
|
- return sellAmount;
|
|
|
- }
|
|
|
- List<Goods> goodies = JSONObject.parseArray(repairInfo.getGoodsJson(), Goods.class);
|
|
|
- List<Integer> goodsIds = goodies.stream().map(Goods::getId).collect(Collectors.toList());
|
|
|
- if (goodsIds.size() <= 0) {
|
|
|
- sellAmount.put("actualAmount", BigDecimal.ZERO);
|
|
|
- sellAmount.put("balance", BigDecimal.ZERO);
|
|
|
- return sellAmount;
|
|
|
- }
|
|
|
-
|
|
|
- BigDecimal totalAmount = order.getExpectAmount().add(repairInfo.getExemptionAmount());
|
|
|
- if (totalAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
- sellAmount.put("actualAmount", BigDecimal.ZERO);
|
|
|
- sellAmount.put("balance", BigDecimal.ZERO);
|
|
|
- return sellAmount;
|
|
|
- }
|
|
|
-
|
|
|
- BigDecimal goodsTotalPrice = BigDecimal.ZERO;
|
|
|
- goodies = goodsDao.getGoodies(goodsIds);
|
|
|
- int i = 1;
|
|
|
- for (Integer goodsId : goodsIds) {
|
|
|
- for (Goods goods : goodies) {
|
|
|
- if (goods.getId().equals(goodsId)) {
|
|
|
- goodsTotalPrice = goodsTotalPrice.add(goods.getDiscountPrice());
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- BigDecimal balance = order.getBalancePaymentAmount() == null ? BigDecimal.ZERO : order.getBalancePaymentAmount();
|
|
|
+ public Map<String, BigDecimal> calcSellAmount(StudentPaymentOrder order,BigDecimal cloudBalanceIncome,BigDecimal cloudIncome) {
|
|
|
+ List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailDao.getOrderDetail(order.getId());
|
|
|
+ //总余额支付
|
|
|
+ BigDecimal totalBalance = order.getBalancePaymentAmount() != null ? order.getBalancePaymentAmount() : BigDecimal.ZERO;
|
|
|
+ //总价格
|
|
|
+ BigDecimal totalPrice = order.getExpectAmount();
|
|
|
+ //商品总付款
|
|
|
+ BigDecimal detailTotalPrice = orderDetails.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ //商品销售占的余额
|
|
|
+ BigDecimal detailTotalBalance = detailTotalPrice.multiply(totalBalance).divide(totalPrice, 2, BigDecimal.ROUND_DOWN);
|
|
|
|
|
|
- BigDecimal goodsTotalBalance = goodsTotalPrice.multiply(balance).divide(totalAmount, 2, BigDecimal.ROUND_DOWN);
|
|
|
- BigDecimal goodsTotalActualAmount = goodsTotalPrice.multiply(order.getActualAmount()).divide(totalAmount, 2, BigDecimal.ROUND_DOWN);
|
|
|
- sellAmount.put("actualAmount", goodsTotalActualAmount.subtract(cloudIncome));
|
|
|
- sellAmount.put("balance", goodsTotalBalance.subtract(cloudBalanceIncome));*/
|
|
|
-
|
|
|
- sellAmount.put("actualAmount", order.getActualAmount().subtract(cloudIncome));
|
|
|
- sellAmount.put("balance", order.getBalancePaymentAmount() == null ? BigDecimal.ZERO : order.getBalancePaymentAmount().subtract(cloudBalanceIncome));
|
|
|
- return sellAmount;
|
|
|
+ if(detailTotalBalance.subtract(cloudBalanceIncome).compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ detailTotalBalance = cloudBalanceIncome;
|
|
|
}
|
|
|
|
|
|
- //乐团报名
|
|
|
- if (order.getType().equals(OrderTypeEnum.APPLY)) {
|
|
|
- List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailDao.getOrderDetail(order.getId());
|
|
|
- //总余额支付
|
|
|
- BigDecimal totalBalance = order.getBalancePaymentAmount() != null ? order.getBalancePaymentAmount() : BigDecimal.ZERO;
|
|
|
- //总价格
|
|
|
- BigDecimal totalPrice = order.getExpectAmount();
|
|
|
- //商品总付款
|
|
|
- BigDecimal detailTotalPrice = orderDetails.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- //商品销售占的余额
|
|
|
- BigDecimal detailTotalBalance = detailTotalPrice.multiply(totalBalance).divide(totalPrice, 2, BigDecimal.ROUND_DOWN);
|
|
|
-
|
|
|
- if(detailTotalBalance.subtract(cloudBalanceIncome).compareTo(BigDecimal.ZERO) < 0) {
|
|
|
- detailTotalBalance = cloudBalanceIncome;
|
|
|
- }
|
|
|
-
|
|
|
- BigDecimal actualAmount = detailTotalPrice.multiply(order.getActualAmount()).divide(totalPrice, 2, BigDecimal.ROUND_DOWN);
|
|
|
-
|
|
|
- if(actualAmount.subtract(cloudIncome).compareTo(BigDecimal.ZERO) < 0){
|
|
|
- actualAmount = cloudIncome;
|
|
|
- }
|
|
|
-
|
|
|
- //返回销售收入
|
|
|
- sellAmount.put("actualAmount", actualAmount.subtract(cloudIncome));
|
|
|
- sellAmount.put("balance", detailTotalBalance.subtract(cloudBalanceIncome));
|
|
|
- return sellAmount;
|
|
|
- }
|
|
|
+ BigDecimal actualAmount = detailTotalPrice.multiply(order.getActualAmount()).divide(totalPrice, 2, BigDecimal.ROUND_DOWN);
|
|
|
|
|
|
- sellAmount.put("actualAmount", BigDecimal.ZERO);
|
|
|
- sellAmount.put("balance", BigDecimal.ZERO);
|
|
|
+ if(actualAmount.subtract(cloudIncome).compareTo(BigDecimal.ZERO) < 0){
|
|
|
+ actualAmount = cloudIncome;
|
|
|
+ }
|
|
|
+ Map<String, BigDecimal> sellAmount = new HashMap<>(2);
|
|
|
+ //返回销售收入
|
|
|
+ sellAmount.put("actualAmount", actualAmount.subtract(cloudIncome));
|
|
|
+ sellAmount.put("balance", detailTotalBalance.subtract(cloudBalanceIncome));
|
|
|
return sellAmount;
|
|
|
}
|
|
|
|