|
@@ -368,7 +368,17 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
BigDecimal totalPrice = BigDecimal.ZERO;
|
|
|
|
|
|
if(goodsSellDtos != null){
|
|
|
- String goodsIdsStr = goodsSellDtos.stream().map(t -> t.getGoodsId().toString()).collect(Collectors.joining(","));
|
|
|
+ //String goodsIdsStr = goodsSellDtos.stream().map(t -> t.getGoodsId().toString()).collect(Collectors.joining(","));
|
|
|
+
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ for(GoodsSellDto goodsSellDto : goodsSellDtos){
|
|
|
+ for(int i = 0; i < goodsSellDto.getGoodsNum() ; i++){
|
|
|
+ sb.append(goodsSellDto.getGoodsId()).append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String goodsIdsStr = StringUtils.removeEnd(sb.toString(), ",");
|
|
|
+
|
|
|
List<Goods> goodsList = goodsService.findGoodsByIds(goodsIdsStr);
|
|
|
BigDecimal totalGroupPurchasePrice = goodsList.stream().map(t -> t.getGroupPurchasePrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
@@ -870,18 +880,32 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
) {
|
|
|
throw new BizException("邮寄信息必填");
|
|
|
}
|
|
|
+
|
|
|
+ List<RepairGoodsDto> repairGoodsDtos = null;
|
|
|
Date date = new Date();
|
|
|
StudentRepair studentRepair = studentRepairDao.get(repairInfo.getId());
|
|
|
studentDao.lockUser(studentRepair.getStudentId());
|
|
|
BigDecimal amount = studentRepair.getAmount();
|
|
|
String goodsJson = studentRepair.getGoodsJson();
|
|
|
if (StringUtils.isNotEmpty(goodsJson)) {
|
|
|
- List<RepairGoodsDto> repairGoodsDtos = JSONObject.parseArray(goodsJson, RepairGoodsDto.class);
|
|
|
+ repairGoodsDtos = JSONObject.parseArray(goodsJson, RepairGoodsDto.class);
|
|
|
BigDecimal reduce = repairGoodsDtos.stream().map(e -> e.getGroupPurchasePrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
amount = amount.add(reduce);
|
|
|
}
|
|
|
amount = amount.subtract(studentRepair.getExemptionAmount());
|
|
|
|
|
|
+ BigDecimal goodsPrice = BigDecimal.ZERO;
|
|
|
+ if (StringUtils.isNoneBlank(goodsJson)) {
|
|
|
+ JSONArray goods = JSON.parseArray(goodsJson);
|
|
|
+ for (Object good : goods) {
|
|
|
+ JSONObject goodObject = (JSONObject) good;
|
|
|
+ BigDecimal groupPurchasePrice = goodObject.getBigDecimal("groupPurchasePrice");
|
|
|
+ if (Objects.nonNull(groupPurchasePrice)) {
|
|
|
+ goodsPrice = goodsPrice.add(groupPurchasePrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
studentRepair.setUseBalancePayment(repairInfo.getUseBalancePayment());
|
|
|
studentRepair.setTransNo(orderNo);
|
|
@@ -914,6 +938,77 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
|
|
|
studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
studentPaymentOrder.setVersion(0);
|
|
|
+
|
|
|
+ List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<StudentPaymentOrderDetail>();
|
|
|
+ // 添加studentPaymentOrderDetail
|
|
|
+ StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
+ studentPaymentOrderDetail.setCreateTime(date);
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.REPAIR);
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(null);
|
|
|
+ studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().multiply(studentRepair.getAmount()).divide(goodsPrice.add(studentRepair.getAmount()), RoundingMode.UP));
|
|
|
+ studentPaymentOrderDetail.setUpdateTime(date);
|
|
|
+ studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+
|
|
|
+ studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+
|
|
|
+ BigDecimal totalPrice = studentPaymentOrderDetail.getPrice();
|
|
|
+ BigDecimal repairPrice = studentPaymentOrderDetail.getPrice();
|
|
|
+
|
|
|
+ if(StringUtils.isNotBlank(studentRepair.getGoodsJson()) && repairGoodsDtos != null){
|
|
|
+ String goodsIds = repairGoodsDtos.stream().map(t -> t.getId().toString()).collect(Collectors.joining(","));
|
|
|
+ List<Goods> goodsList = goodsService.findGoodsByIds(goodsIds);
|
|
|
+ Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
+ Goods goods = null;
|
|
|
+ BigDecimal totalGroupPurchasePrice = BigDecimal.ZERO;
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+
|
|
|
+ if(goods != null){
|
|
|
+ totalGroupPurchasePrice = totalGroupPurchasePrice.add(goods.getGroupPurchasePrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+
|
|
|
+ if(goods != null){
|
|
|
+ studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
+ studentPaymentOrderDetail.setCreateTime(date);
|
|
|
+ if(goods.getType() == GoodsType.INSTRUMENT){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
|
|
|
+ }else if(goods.getType() == GoodsType.ACCESSORIES){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
|
|
|
+ }else if(goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
|
|
|
+ }else{
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(goodsIdStr);
|
|
|
+
|
|
|
+ BigDecimal tempPrice = studentPaymentOrder.getExpectAmount().subtract(repairPrice).multiply(goods.getGroupPurchasePrice()).divide(totalGroupPurchasePrice, RoundingMode.UP);
|
|
|
+
|
|
|
+ if(totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0){
|
|
|
+ studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
|
|
|
+ }else{
|
|
|
+ studentPaymentOrderDetail.setPrice(tempPrice);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setUpdateTime(date);
|
|
|
+ studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+
|
|
|
+ totalPrice = totalPrice.add(studentPaymentOrderDetail.getPrice());
|
|
|
+ studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(studentPaymentOrderDetailList.size() > 0){
|
|
|
+ studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
|
|
|
+ }
|
|
|
|
|
|
BigDecimal balance = BigDecimal.ZERO;
|
|
|
if (studentRepair.getUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
|