| | |
| | | |
| | | if(2 == shoppingCartPayment.getPaymentType()){ |
| | | BigDecimal balance = appUser.getBalance(); |
| | | if(balance.compareTo(paymentMoney.add(expressFee)) < 0){ |
| | | if(balance.compareTo(paymentMoney) < 0){ |
| | | return R.fail("账户余额不足"); |
| | | } |
| | | } |
| | | //判断运费支付是否足够 |
| | | if(2 == shoppingCartPayment.getFreightPaymentType() && expressFee.compareTo(BigDecimal.ZERO) > 0){ |
| | | BigDecimal balance = appUser.getBalance(); |
| | | if(balance.compareTo(expressFee) < 0){ |
| | | return R.fail("账户余额不足"); |
| | | } |
| | | } |
| | | |
| | | orderService.save(order); |
| | | //构建订单明细数据 |
| | | for (MyShoppingCartVo myShoppingCartVo : goodsList) { |
| | |
| | | userPoint.setObjectId(order.getId()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | } |
| | | //修改订支付状态 |
| | | order.setPayStatus(2); |
| | | orderService.updateById(order); |
| | | //删除购物车数据 |
| | | this.removeBatchByIds(ids); |
| | | //如果有运费,需要先扣除账户积分,再进行支付。支付成功后修改订单状态,未支付成功则回退积分,删除的订单 |
| | | if(expressFee.compareTo(BigDecimal.ZERO) > 0){ |
| | | if(shoppingCartPayment.getFreightPaymentType() == 1){ |
| | | //调起微信支付 |
| | | } |
| | | if(shoppingCartPayment.getFreightPaymentType() == 2){ |
| | | BigDecimal totalRedPacketAmount = appUser.getTotalRedPacketAmount(); |
| | | BigDecimal totalDistributionAmount = appUser.getTotalDistributionAmount(); |
| | | BigDecimal balance = appUser.getBalance(); |
| | | if(expressFee.compareTo(totalRedPacketAmount) <= 0){ |
| | | totalRedPacketAmount = totalRedPacketAmount.subtract(expressFee); |
| | | balance = balance.subtract(expressFee); |
| | | appUser.setTotalRedPacketAmount(totalRedPacketAmount); |
| | | appUser.setBalance(balance); |
| | | }else{ |
| | | expressFee = expressFee.subtract(totalRedPacketAmount); |
| | | totalRedPacketAmount = BigDecimal.ZERO; |
| | | if(expressFee.compareTo(totalDistributionAmount) <= 0){ |
| | | totalDistributionAmount = totalDistributionAmount.subtract(expressFee); |
| | | balance = balance.subtract(expressFee); |
| | | appUser.setTotalRedPacketAmount(totalRedPacketAmount); |
| | | appUser.setTotalDistributionAmount(totalDistributionAmount); |
| | | appUser.setBalance(balance); |
| | | }else{ |
| | | expressFee = expressFee.subtract(totalDistributionAmount); |
| | | totalDistributionAmount = BigDecimal.ZERO; |
| | | balance = balance.subtract(expressFee); |
| | | appUser.setTotalRedPacketAmount(totalRedPacketAmount); |
| | | appUser.setTotalDistributionAmount(totalDistributionAmount); |
| | | appUser.setBalance(balance); |
| | | } |
| | | } |
| | | |
| | | appUserClient.editAppUserById(appUser); |
| | | //构建余额明细变动记录 |
| | | BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord(); |
| | | balanceChangeRecord.setAppUserId(appUser.getId()); |
| | | balanceChangeRecord.setOrderId(order.getId()); |
| | | balanceChangeRecord.setChangeType(5); |
| | | balanceChangeRecord.setBeforeAmount(balance.add(paymentMoney)); |
| | | balanceChangeRecord.setChangeAmount(paymentMoney); |
| | | balanceChangeRecord.setAfterAmount(balance); |
| | | balanceChangeRecord.setDelFlag(0); |
| | | balanceChangeRecord.setCreateTime(LocalDateTime.now()); |
| | | balanceChangeRecordClient.saveBalanceChangeRecord(balanceChangeRecord); |
| | | //修改订支付状态 |
| | | order.setPayStatus(2); |
| | | orderService.updateById(order); |
| | | //删除购物车数据 |
| | | this.removeBatchByIds(ids); |
| | | } |
| | | }else{ |
| | | //修改订支付状态 |
| | | order.setPayStatus(2); |
| | | orderService.updateById(order); |
| | | //删除购物车数据 |
| | | this.removeBatchByIds(ids); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |