| | |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.order.mapper.ShoppingCartMapper; |
| | | import com.ruoyi.order.model.Order; |
| | | import com.ruoyi.order.model.OrderBalancePayment; |
| | | import com.ruoyi.order.model.OrderGood; |
| | | import com.ruoyi.order.model.ShoppingCart; |
| | | import com.ruoyi.order.service.CommissionService; |
| | | import com.ruoyi.order.service.OrderGoodService; |
| | | import com.ruoyi.order.service.OrderService; |
| | | import com.ruoyi.order.service.ShoppingCartService; |
| | | import com.ruoyi.order.service.*; |
| | | import com.ruoyi.order.vo.*; |
| | | import com.ruoyi.other.api.domain.*; |
| | | import com.ruoyi.other.api.feignClient.*; |
| | |
| | | |
| | | |
| | | |
| | | |
| | | @Resource |
| | | private PointSettingClient pointSettingClient; |
| | | |
| | | @Resource |
| | | private OrderBalancePaymentService orderBalancePaymentService; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取购物车列表 |
| | | * @param type |
| | |
| | | GoodsArea goodsArea = goodsAreaClient.getGoodsArea(area).getData(); |
| | | if(null == goodsArea){ |
| | | //没有地区价格,则使用会员价格 |
| | | GoodsVip goodsVip = goodsVipClient.getGoodsVip(appUser.getVipId()).getData(); |
| | | GoodsVip goodsVip = goodsVipClient.getGoodsVip(goodsId, appUser.getVipId()).getData(); |
| | | if(null == goodsVip){ |
| | | //没有配置价格,直接使用原始基础价格 |
| | | return null; |
| | |
| | | confirmOrderVo.setResidualPoint(appUser.getLavePoint().intValue()); |
| | | //获取默认收货地址 |
| | | UserAddress userAddress = userAddressClient.getDefaultUserAddress(userid).getData(); |
| | | userAddress.setIdStr(userAddress.getId().toString()); |
| | | confirmOrderVo.setUserAddress(userAddress); |
| | | if(null != userAddress){ |
| | | userAddress.setIdStr(userAddress.getId().toString()); |
| | | confirmOrderVo.setUserAddress(userAddress); |
| | | } |
| | | confirmOrderVo.setPaymentType(confirmOrder.getPaymentType()); |
| | | //获取用户优惠券,用户全部优惠券,不能使用的需要标识出来置灰展示 |
| | | PaymentUserCoupon paymentUserCoupon = new PaymentUserCoupon(); |
| | |
| | | //获取快递策略 |
| | | SystemConfig systemConfig = systemConfigClient.getSystemConfig(3).getData(); |
| | | JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); |
| | | confirmOrderVo.setExpressFee(jsonObject.getBigDecimal("expressFee")); |
| | | List<Integer> vip = jsonObject.getJSONArray("vip").toList(Integer.class); |
| | | confirmOrderVo.setExpressFee(jsonObject.getBigDecimal("freight")); |
| | | List<String> vip = Arrays.asList(jsonObject.getString("freeVip").split(",")); |
| | | //包邮条件(所有会员或者满足条件的会员) |
| | | if(vip.get(0) == -1 || vip.contains(appUser.getVipId())){ |
| | | if(vip.get(0).equals("0") || vip.contains(appUser.getVipId().toString())){ |
| | | if(confirmOrder.getPaymentType() == 1){ |
| | | //现金支付,支付金额满足包邮条件 |
| | | BigDecimal cash = jsonObject.getBigDecimal("cash"); |
| | | BigDecimal cash = jsonObject.getBigDecimal("freeFreight"); |
| | | if(confirmOrderVo.getPayMoney().compareTo(cash) >= 0){ |
| | | confirmOrderVo.setExpressFee(BigDecimal.ZERO); |
| | | } |
| | | }else{ |
| | | //积分支付,支付积分是否满足包邮条件 |
| | | Integer point = jsonObject.getInteger("point"); |
| | | Integer point = jsonObject.getInteger("freeIntegral"); |
| | | if(confirmOrderVo.getOrderPoint().compareTo(point) >= 0){ |
| | | confirmOrderVo.setExpressFee(BigDecimal.ZERO); |
| | | } |
| | |
| | | SystemConfig systemConfig = systemConfigClient.getSystemConfig(3).getData(); |
| | | JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); |
| | | //快递费 |
| | | expressFee = jsonObject.getBigDecimal("expressFee"); |
| | | List<Integer> vip = jsonObject.getJSONArray("vip").toList(Integer.class); |
| | | expressFee = jsonObject.getBigDecimal("freight"); |
| | | List<String> vip = Arrays.asList(jsonObject.getString("freeVip").split(",")); |
| | | //包邮条件(所有会员或者满足条件的会员) |
| | | if(vip.get(0) == -1 || vip.contains(appUser.getVipId())){ |
| | | if(vip.get(0).equals("0") || vip.contains(appUser.getVipId().toString())){ |
| | | if(shoppingCartPayment.getPaymentType() != 3){ |
| | | //现金支付,支付金额满足包邮条件 |
| | | BigDecimal cash = jsonObject.getBigDecimal("cash"); |
| | | BigDecimal cash = jsonObject.getBigDecimal("freeFreight"); |
| | | if(paymentMoney.compareTo(cash) >= 0){ |
| | | expressFee = BigDecimal.ZERO; |
| | | } |
| | | }else{ |
| | | //积分支付,支付积分是否满足包邮条件 |
| | | Integer point = jsonObject.getInteger("point"); |
| | | Integer point = jsonObject.getInteger("freeIntegral"); |
| | | if(orderPoint.compareTo(point) >= 0){ |
| | | expressFee = BigDecimal.ZERO; |
| | | } |
| | |
| | | |
| | | } |
| | | //账户余额 |
| | | BigDecimal redPacketAmount = BigDecimal.ZERO; |
| | | BigDecimal distributionAmount = BigDecimal.ZERO; |
| | | if(2 == shoppingCartPayment.getPaymentType()){ |
| | | BigDecimal totalRedPacketAmount = appUser.getTotalRedPacketAmount(); |
| | | BigDecimal totalDistributionAmount = appUser.getTotalDistributionAmount(); |
| | | BigDecimal balance = appUser.getBalance(); |
| | | //红包金额满足支付 |
| | | if(paymentMoney.compareTo(totalRedPacketAmount) <= 0){ |
| | | totalRedPacketAmount = totalRedPacketAmount.subtract(paymentMoney); |
| | | balance = balance.subtract(paymentMoney); |
| | | appUser.setTotalRedPacketAmount(totalRedPacketAmount); |
| | | appUser.setBalance(balance); |
| | | redPacketAmount = paymentMoney; |
| | | }else{ |
| | | paymentMoney = paymentMoney.subtract(totalRedPacketAmount); |
| | | redPacketAmount = totalRedPacketAmount; |
| | | totalRedPacketAmount = BigDecimal.ZERO; |
| | | if(paymentMoney.compareTo(totalDistributionAmount) <= 0){ |
| | | totalDistributionAmount = totalDistributionAmount.subtract(paymentMoney); |
| | |
| | | appUser.setTotalRedPacketAmount(totalRedPacketAmount); |
| | | appUser.setTotalDistributionAmount(totalDistributionAmount); |
| | | appUser.setBalance(balance); |
| | | distributionAmount = paymentMoney; |
| | | }else{ |
| | | paymentMoney = paymentMoney.subtract(totalDistributionAmount); |
| | | totalDistributionAmount = BigDecimal.ZERO; |
| | |
| | | appUser.setTotalRedPacketAmount(totalRedPacketAmount); |
| | | appUser.setTotalDistributionAmount(totalDistributionAmount); |
| | | appUser.setBalance(balance); |
| | | distributionAmount = totalDistributionAmount; |
| | | } |
| | | } |
| | | //构建积分流水记录 |
| | | if(earnPoint > 0){ |
| | | PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); |
| | | int earnPoint1 = earnPoint; |
| | | if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){ |
| | | earnPoint1 = earnPoint1 * (100 - pointSetting.getBuyPoint()); |
| | | } |
| | | appUser.setShopPoint(appUser.getShopPoint() + earnPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() + earnPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() + earnPoint1); |
| | | appUser.setTotalPoint(appUser.getTotalPoint() + earnPoint); |
| | | |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(1); |
| | | userPoint.setHistoricalPoint(appUser.getLavePoint() - earnPoint); |
| | | userPoint.setHistoricalPoint(appUser.getLavePoint() - earnPoint1); |
| | | userPoint.setVariablePoint(earnPoint); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | |
| | | //积分支付 |
| | | if(3 == shoppingCartPayment.getPaymentType()){ |
| | | Integer lavePoint = appUser.getLavePoint(); |
| | | appUser.setLavePoint(lavePoint - orderPoint); |
| | | PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); |
| | | int earnPoint1 = earnPoint; |
| | | //计算可用积分比例 |
| | | if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){ |
| | | earnPoint1 = earnPoint1 * (100 - pointSetting.getBuyPoint()); |
| | | } |
| | | appUser.setLavePoint(appUser.getLavePoint() - orderPoint); |
| | | appUser.setShopPoint(appUser.getShopPoint() + earnPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() + earnPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() + earnPoint1); |
| | | appUser.setTotalPoint(appUser.getTotalPoint() + earnPoint); |
| | | appUser.setShopAmount(appUser.getShopAmount().add(paymentMoney).setScale(2, RoundingMode.HALF_EVEN)); |
| | | appUser.setLastShopTime(LocalDateTime.now()); |
| | | appUserClient.editAppUserById(appUser); |
| | | //检查消费积分满足后升级会员 |
| | |
| | | |
| | | //构建积分流水记录 |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(4); |
| | | userPoint.setType(1); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(orderPoint); |
| | | Integer point = appUser.getLavePoint() - lavePoint; |
| | | userPoint.setVariablePoint(point >= 0 ? point : point * -1); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(appUser.getId()); |
| | | userPoint.setObjectId(order.getId()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | if(earnPoint > 0){ |
| | | userPoint = new UserPoint(); |
| | | userPoint.setType(1); |
| | | userPoint.setHistoricalPoint(appUser.getLavePoint() - earnPoint); |
| | | userPoint.setVariablePoint(earnPoint); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(appUser.getId()); |
| | | userPoint.setObjectId(order.getId()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | } |
| | | //如果有运费,需要先扣除账户积分,再进行支付。支付成功后修改订单状态,未支付成功则回退积分,删除的订单 |
| | | if(expressFee.compareTo(BigDecimal.ZERO) > 0){ |
| | | if(shoppingCartPayment.getFreightPaymentType() == 1){ |
| | |
| | | balance = balance.subtract(expressFee); |
| | | appUser.setTotalRedPacketAmount(totalRedPacketAmount); |
| | | appUser.setBalance(balance); |
| | | redPacketAmount = expressFee; |
| | | }else{ |
| | | expressFee = expressFee.subtract(totalRedPacketAmount); |
| | | redPacketAmount = totalRedPacketAmount; |
| | | totalRedPacketAmount = BigDecimal.ZERO; |
| | | if(expressFee.compareTo(totalDistributionAmount) <= 0){ |
| | | totalDistributionAmount = totalDistributionAmount.subtract(expressFee); |
| | |
| | | appUser.setTotalRedPacketAmount(totalRedPacketAmount); |
| | | appUser.setTotalDistributionAmount(totalDistributionAmount); |
| | | appUser.setBalance(balance); |
| | | distributionAmount = expressFee; |
| | | }else{ |
| | | expressFee = expressFee.subtract(totalDistributionAmount); |
| | | totalDistributionAmount = BigDecimal.ZERO; |
| | |
| | | appUser.setTotalRedPacketAmount(totalRedPacketAmount); |
| | | appUser.setTotalDistributionAmount(totalDistributionAmount); |
| | | appUser.setBalance(balance); |
| | | distributionAmount = totalDistributionAmount; |
| | | } |
| | | } |
| | | |
| | |
| | | this.removeBatchByIds(ids); |
| | | } |
| | | } |
| | | //添加账户余额支付明细 |
| | | if(redPacketAmount.compareTo(BigDecimal.ZERO) > 0 || distributionAmount.compareTo(BigDecimal.ZERO) > 0){ |
| | | OrderBalancePayment orderBalancePayment = new OrderBalancePayment(); |
| | | orderBalancePayment.setOrderId(order.getId()); |
| | | orderBalancePayment.setRedPacketAmount(redPacketAmount); |
| | | orderBalancePayment.setDistributionAmount(distributionAmount); |
| | | orderBalancePaymentService.save(orderBalancePayment); |
| | | } |
| | | return R.ok(order.getId().toString()); |
| | | } |
| | | |