| | |
| | | area.setProvinceCode(appUser.getProvinceCode()); |
| | | area.setVip(appUser.getVipId()); |
| | | GoodsArea goodsArea = goodsAreaClient.getGoodsArea(area).getData(); |
| | | price.setEarnSpendingPoints(goodsArea.getEarnSpendingPoints()); |
| | | price.setSuperiorSubcommission(goodsArea.getSuperiorSubcommission()); |
| | | price.setSuperiorRebatePoints(goodsArea.getSuperiorRebatePoints()); |
| | | price.setSuperiorType(goodsArea.getSuperiorType()); |
| | | price.setSuperiorPriceType(goodsArea.getSuperiorPriceType()); |
| | | price.setServuceShopCharges(goodsArea.getServuceShopCharges()); |
| | | price.setServuceShopPoints(goodsArea.getServuceShopPoints()); |
| | | price.setTechnicianPoints(goodsArea.getTechnicianPoints()); |
| | | price.setBoundShopCharges(goodsArea.getBoundShopCharges()); |
| | | price.setBoundShopPoints(goodsArea.getBoundShopPoints()); |
| | | price.setBoundShopSuperiorsCharges(goodsArea.getBoundShopSuperiorsCharges()); |
| | | price.setBoundShopSuperiorsPoints(goodsArea.getBoundShopSuperiorsPoints()); |
| | | if(null != goodsArea){ |
| | | price.setEarnSpendingPoints(goodsArea.getEarnSpendingPoints()); |
| | | price.setSuperiorSubcommission(goodsArea.getSuperiorSubcommission()); |
| | | price.setSuperiorRebatePoints(goodsArea.getSuperiorRebatePoints()); |
| | | price.setSuperiorType(goodsArea.getSuperiorType()); |
| | | price.setSuperiorPriceType(goodsArea.getSuperiorPriceType()); |
| | | price.setServuceShopCharges(goodsArea.getServuceShopCharges()); |
| | | price.setServuceShopPoints(goodsArea.getServuceShopPoints()); |
| | | price.setTechnicianPoints(goodsArea.getTechnicianPoints()); |
| | | price.setBoundShopCharges(goodsArea.getBoundShopCharges()); |
| | | price.setBoundShopPoints(goodsArea.getBoundShopPoints()); |
| | | price.setBoundShopSuperiorsCharges(goodsArea.getBoundShopSuperiorsCharges()); |
| | | price.setBoundShopSuperiorsPoints(goodsArea.getBoundShopSuperiorsPoints()); |
| | | }else{ |
| | | GoodsVip goodsVip = goodsVipClient.getGoodsVip(goodsId, appUser.getVipId()).getData(); |
| | | price.setEarnSpendingPoints(goodsVip.getEarnSpendingPoints()); |
| | | price.setSuperiorSubcommission(goodsVip.getSuperiorSubcommission()); |
| | | price.setSuperiorRebatePoints(goodsVip.getSuperiorRebatePoints()); |
| | | price.setSuperiorType(goodsVip.getSuperiorType()); |
| | | price.setSuperiorPriceType(goodsVip.getSuperiorPriceType()); |
| | | price.setServuceShopCharges(goodsVip.getServuceShopCharges()); |
| | | price.setServuceShopPoints(goodsVip.getServuceShopPoints()); |
| | | price.setTechnicianPoints(goodsVip.getTechnicianPoints()); |
| | | price.setBoundShopCharges(goodsVip.getBoundShopCharges()); |
| | | price.setBoundShopPoints(goodsVip.getBoundShopPoints()); |
| | | price.setBoundShopSuperiorsCharges(goodsVip.getBoundShopSuperiorsCharges()); |
| | | price.setBoundShopSuperiorsPoints(goodsVip.getBoundShopSuperiorsPoints()); |
| | | } |
| | | } |
| | | }else{ |
| | | //构建价格数据 |
| | |
| | | } |
| | | |
| | | //查询当前是否有订单活动 |
| | | OrderActivityInfo orderActivityInfo = orderActivityInfoClient.getNowOrderActivityInfo(appUser.getVipId()).getData(); |
| | | List<OrderActivityInfo> orderActivityInfo = orderActivityInfoClient.getNowOrderActivityInfo(appUser.getVipId()).getData(); |
| | | //满XX才打折,只有现金才能优惠 |
| | | if(null != orderActivityInfo && confirmOrder.getPaymentType() == 1 && orderActivityInfo.getConditionAmount().compareTo(orderMoney) <= 0){ |
| | | confirmOrderVo.setActivityName(orderActivityInfo.getActivityName()); |
| | | BigDecimal multiply = orderActivityInfo.getDiscount().divide(new BigDecimal(10)).multiply(paymentMoney); |
| | | BigDecimal bigDecimal = paymentMoney.subtract(multiply).setScale(2, RoundingMode.HALF_EVEN); |
| | | activityAmount = activityAmount.add(bigDecimal); |
| | | if(null != orderActivityInfo && confirmOrder.getPaymentType() == 1){ |
| | | for (OrderActivityInfo activityInfo : orderActivityInfo) { |
| | | if(activityInfo.getConditionAmount().compareTo(paymentMoney) <= 0){ |
| | | confirmOrderVo.setActivityName(activityInfo.getActivityName()); |
| | | //优惠后的支付金额 |
| | | BigDecimal multiply = activityInfo.getDiscount().divide(new BigDecimal(10)).multiply(paymentMoney); |
| | | //优惠金额 |
| | | BigDecimal bigDecimal = paymentMoney.subtract(multiply).setScale(2, RoundingMode.HALF_EVEN); |
| | | paymentMoney = multiply; |
| | | activityAmount = activityAmount.add(bigDecimal); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
| | | confirmOrderVo.setDiscountAmount(activityAmount); |
| | | BaseSetting baseSetting = baseSettingClient.getBaseSetting(4).getData(); |
| | |
| | | } |
| | | |
| | | //查询当前是否有订单活动 |
| | | OrderActivityInfo orderActivityInfo = orderActivityInfoClient.getNowOrderActivityInfo(appUser.getVipId()).getData(); |
| | | List<OrderActivityInfo> orderActivityInfo = orderActivityInfoClient.getNowOrderActivityInfo(appUser.getVipId()).getData(); |
| | | BaseSetting baseSetting = baseSettingClient.getBaseSetting(4).getData(); |
| | | //系统活动设置(优惠券和活动能否同时使用) |
| | | boolean useSimultaneously = baseSetting.getContent().equals("1"); |
| | | Integer status = JSON.parseObject(baseSetting.getContent()).getInteger("status"); |
| | | //满XX才打折,只有现金才能优惠 |
| | | //如果使用优惠券,则需要判断是否可以和同时使用,且活动满足使用条件。 |
| | | //没有使用优惠券,只需要判断是都满足使用条件 |
| | | if((useSimultaneously || null == shoppingCartPayment.getUserCouponId()) && |
| | | null != orderActivityInfo && shoppingCartPayment.getPaymentType() != 3 && orderActivityInfo.getConditionAmount().compareTo(paymentMoney) <= 0){ |
| | | BigDecimal paymentMoney1 = orderActivityInfo.getDiscount().divide(new BigDecimal(10)).multiply(paymentMoney); |
| | | BigDecimal bigDecimal = paymentMoney.subtract(paymentMoney1).setScale(2, RoundingMode.HALF_EVEN); |
| | | discount = orderActivityInfo.getDiscount(); |
| | | paymentMoney = paymentMoney1; |
| | | activityAmount = activityAmount.add(bigDecimal); |
| | | OrderActivityInfo orderActivityInfo1 = null; |
| | | if((1 == status || null == shoppingCartPayment.getUserCouponId()) && |
| | | null != orderActivityInfo && shoppingCartPayment.getPaymentType() != 3){ |
| | | for (OrderActivityInfo activityInfo : orderActivityInfo) { |
| | | if(activityInfo.getConditionAmount().compareTo(paymentMoney) <= 0){ |
| | | BigDecimal paymentMoney1 = activityInfo.getDiscount().divide(new BigDecimal(10)).multiply(paymentMoney); |
| | | BigDecimal bigDecimal = paymentMoney.subtract(paymentMoney1).setScale(2, RoundingMode.HALF_EVEN); |
| | | discount = activityInfo.getDiscount(); |
| | | paymentMoney = paymentMoney1; |
| | | activityAmount = activityAmount.add(bigDecimal); |
| | | orderActivityInfo1 = activityInfo; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | //可获得的消费积分 |
| | |
| | | order.setCouponJson(JSON.toJSONString(couponInfoVo)); |
| | | } |
| | | if(activityAmount.compareTo(BigDecimal.ZERO) > 0){ |
| | | order.setActivityJson(JSON.toJSONString(orderActivityInfo)); |
| | | order.setActivityJson(JSON.toJSONString(orderActivityInfo1)); |
| | | } |
| | | if(null != shoppingCartPayment.getUserAddressId()){ |
| | | UserAddress address = userAddressClient.getUserAddressById(shoppingCartPayment.getUserAddressId()).getData(); |
| | |
| | | if(expressFee.compareTo(BigDecimal.ZERO) > 0){ |
| | | if(shoppingCartPayment.getFreightPaymentType() == 1){ |
| | | //调起微信支付 |
| | | UniPayResult uniPayResult = PaymentUtil.uniPay(order.getOrderNumber() + appUser.getId(), expressFee.doubleValue(), order.getOrderType() == 1 ? "购买服务商品快递费" : "购买单品商品快递费", |
| | | UniPayResult uniPayResult = PaymentUtil.uniPay("K" + order.getOrderNumber(), expressFee.doubleValue(), order.getOrderType() == 1 ? "购买服务商品快递费" : "购买单品商品快递费", |
| | | "快递费", "", "/order/shopping-cart/shoppingCartMaterialFlowPaymentCallback", appUser.getWxOpenid(), null); |
| | | if(null == uniPayResult || !"100".equals(uniPayResult.getRa_Code())){ |
| | | return R.fail(null == uniPayResult ? "支付失败" : uniPayResult.getRb_CodeMsg()); |
| | |
| | | jsonObject.put("orderId", order.getId().toString()); |
| | | //将支付数据添加到redis队列中,便于定时任务去校验是否完成支付,没有完成支付支付,15分钟后关闭订单。 |
| | | long second = LocalDateTime.now().plusMinutes(15).toEpochSecond(ZoneOffset.UTC); |
| | | redisTemplate.opsForZSet().add("MaterialFlowPayment", order.getOrderNumber() + appUser.getId(), second); |
| | | redisTemplate.opsForZSet().add("MaterialFlowPayment", "K" + order.getOrderNumber(), second); |
| | | return R.ok(jsonObject.toJSONString()); |
| | | } |
| | | } |
| | |
| | | @Override |
| | | public R shoppingCartMaterialFlowPaymentCallback(UniPayCallbackResult uniPayCallbackResult) { |
| | | String r2_orderNo = uniPayCallbackResult.getR2_OrderNo(); |
| | | r2_orderNo = r2_orderNo.substring(0, 23); |
| | | r2_orderNo = r2_orderNo.substring(1); |
| | | Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNumber, r2_orderNo)); |
| | | if(null == order || order.getPayStatus() == 2){ |
| | | return R.ok(); |
| | |
| | | //订单支付数据 |
| | | long second = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); |
| | | Set<String> orderPayment = redisTemplate.opsForZSet().range("OrderPayment", 0, second); |
| | | for (String code : orderPayment) { |
| | | Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNumber, code)); |
| | | if(null == order || order.getPayStatus() != 1){ |
| | | redisTemplate.opsForZSet().remove("OrderPayment", code); |
| | | continue; |
| | | if(orderPayment.size() > 0){ |
| | | List<Order> list = orderService.list(new LambdaQueryWrapper<Order>().in(Order::getOrderNumber, orderPayment)); |
| | | for (Order order : list) { |
| | | if(null == order || order.getPayStatus() != 1){ |
| | | redisTemplate.opsForZSet().remove("OrderPayment", order.getOrderNumber()); |
| | | continue; |
| | | } |
| | | //开始执行关闭订单操作 |
| | | CloseOrderResult closeOrderResult = PaymentUtil.closeOrder(order.getOrderNumber()); |
| | | if((null == closeOrderResult || !closeOrderResult.getRa_Status().equals("100")) && |
| | | Arrays.asList("0", "4", "101", "10080000", "10080002", "10083004", "10083005").contains(closeOrderResult.getRb_Code())){ |
| | | redisTemplate.opsForZSet().add("OrderPayment", order.getOrderNumber(), 0); |
| | | log.error("关闭订单失败:{}---->{}", order.getOrderNumber(), JSON.toJSONString(closeOrderResult)); |
| | | } |
| | | redisTemplate.opsForZSet().remove("OrderPayment", order.getOrderNumber()); |
| | | } |
| | | //开始执行关闭订单操作 |
| | | CloseOrderResult closeOrderResult = PaymentUtil.closeOrder(code); |
| | | if((null == closeOrderResult || !closeOrderResult.getRa_Status().equals("100")) && |
| | | Arrays.asList("0", "4", "101", "10080000", "10080002", "10083004", "10083005").contains(closeOrderResult.getRb_Code())){ |
| | | redisTemplate.opsForZSet().add("OrderPayment", code, 0); |
| | | log.error("关闭订单失败:{}---->{}", code, JSON.toJSONString(closeOrderResult)); |
| | | } |
| | | redisTemplate.opsForZSet().remove("OrderPayment", code); |
| | | } |
| | | |
| | | //快递支付 |
| | | Set<String> materialFlowPayment = redisTemplate.opsForZSet().range("MaterialFlowPayment", 0, second); |
| | | for (String code : materialFlowPayment) { |
| | | code = code.substring(0, 23); |
| | | Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNumber, code)); |
| | | if(null == order || order.getPayStatus() != 1){ |
| | | redisTemplate.opsForZSet().remove("MaterialFlowPayment", code); |
| | | continue; |
| | | if(materialFlowPayment.size() > 0){ |
| | | materialFlowPayment.forEach(s->s.substring(1)); |
| | | List<Order> list = orderService.list(new LambdaQueryWrapper<Order>().in(Order::getOrderNumber, materialFlowPayment)); |
| | | for (Order order : list) { |
| | | if(null == order || order.getPayStatus() != 1){ |
| | | redisTemplate.opsForZSet().remove("MaterialFlowPayment", order.getOrderNumber()); |
| | | continue; |
| | | } |
| | | //开始执行关闭订单操作 |
| | | CloseOrderResult closeOrderResult = PaymentUtil.closeOrder("K" + order.getOrderNumber()); |
| | | if((null == closeOrderResult || !closeOrderResult.getRa_Status().equals("100")) && |
| | | Arrays.asList("0", "4", "101", "10080000", "10080002", "10083004", "10083005").contains(closeOrderResult.getRb_Code())){ |
| | | redisTemplate.opsForZSet().add("MaterialFlowPayment", order.getOrderNumber(), 0); |
| | | log.error("关闭订单失败:{}---->{}", order.getOrderNumber(), JSON.toJSONString(closeOrderResult)); |
| | | } |
| | | redisTemplate.opsForZSet().remove("MaterialFlowPayment", order.getOrderNumber()); |
| | | } |
| | | //开始执行关闭订单操作 |
| | | CloseOrderResult closeOrderResult = PaymentUtil.closeOrder(code); |
| | | if((null == closeOrderResult || !closeOrderResult.getRa_Status().equals("100")) && |
| | | Arrays.asList("0", "4", "101", "10080000", "10080002", "10083004", "10083005").contains(closeOrderResult.getRb_Code())){ |
| | | redisTemplate.opsForZSet().add("MaterialFlowPayment", code, 0); |
| | | log.error("关闭订单失败:{}---->{}", code, JSON.toJSONString(closeOrderResult)); |
| | | } |
| | | redisTemplate.opsForZSet().remove("MaterialFlowPayment", code); |
| | | } |
| | | } |
| | | } |