| | |
| | | @GlobalTransactional(rollbackFor = Exception.class) |
| | | public AjaxResult chargingOrderCallback(Integer paymentType, String out_trade_no, String transaction_id, String attach) { |
| | | TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, out_trade_no)); |
| | | // if(chargingOrder.getRechargePaymentStatus() == 2){ |
| | | // return AjaxResult.success(); |
| | | // } |
| | | if(chargingOrder.getRechargePaymentStatus() == 2){ |
| | | return AjaxResult.success(); |
| | | } |
| | | chargingOrder.setRechargePaymentStatus(2); |
| | | chargingOrder.setRechargeSerialNumber(transaction_id); |
| | | chargingOrder.setStatus(2); |
| | |
| | | public ChargingDetails getChargingDetails(Integer id) { |
| | | Long userId = tokenService.getLoginUserApplet().getUserId(); |
| | | TChargingOrder one = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getAppUserId, userId).eq(TChargingOrder::getChargingGunId, id) |
| | | .eq(TChargingOrder::getRechargePaymentStatus, 2).eq(TChargingOrder::getDelFlag, 0).orderByDesc(TChargingOrder::getEndTime).last(" limit 0, 1")); |
| | | .eq(TChargingOrder::getRechargePaymentStatus, 2).eq(TChargingOrder::getDelFlag, 0).orderByDesc(TChargingOrder::getStartTime).last(" limit 0, 1")); |
| | | if(null == one){ |
| | | return null; |
| | | } |
| | |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | continue; |
| | | }else{ |
| | | log.error(code1 + ":-------------------远程停止充电请求成功-------------------"); |
| | | stop_status = true; |
| | | break; |
| | | } |
| | | break; |
| | | } |
| | | if(stop_status){ |
| | | chargingOrder.setStatus(5); |
| | |
| | | editUserTag(chargingOrder); |
| | | //用户推荐奖励 |
| | | referralReward(chargingOrder); |
| | | //计算费用,处理退款 |
| | | endCharge(chargingOrder); |
| | | // 将枪状态重置为空闲 |
| | | chargingGun.setStatus(2); |
| | | chargingGunClient.updateChargingGunById(chargingGun); |
| | |
| | | } |
| | | log.error(code1 + ":停机失败:订单号:{},失败原因:{}", order.getCode(), failure_cause); |
| | | }else{ |
| | | order.setEndTime(LocalDateTime.now()); |
| | | order.setStatus(5); |
| | | order.setEndMode(1); |
| | | this.updateById(order); |
| | | //计算用户标签 |
| | | editUserTag(order); |
| | | //用户推荐奖励 |
| | | referralReward(order); |
| | | //计算费用,处理退款 |
| | | endCharge(order); |
| | | // 将枪状态重置为空闲 |
| | | chargingGun.setStatus(2); |
| | | chargingGunClient.updateChargingGunById(chargingGun); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 手动结束后的费用计算和退款逻辑 |
| | | */ |
| | | @GlobalTransactional(rollbackFor = Exception.class) |
| | | public void endCharge(TChargingOrder chargingOrder){ |
| | | //如果使用优惠券需要判断优惠券是否满足使用条件 |
| | | //根据实际的充电金额计算退款金额 退回费用=(原金额/总金额)*(总金额-实际充电金额) |
| | | //退款金额=优惠券金额+剩余充电金额 |
| | | List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.list(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>().eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrder.getId())); |
| | | BigDecimal periodElectricPrice_total = BigDecimal.ZERO; |
| | | BigDecimal periodServicePrice_total = BigDecimal.ZERO; |
| | | BigDecimal total = BigDecimal.ZERO; |
| | | for (TChargingOrderAccountingStrategy chargingOrderAccountingStrategy : list) { |
| | | BigDecimal periodElectricPrice = chargingOrderAccountingStrategy.getPeriodElectricPrice(); |
| | | BigDecimal periodServicePrice = chargingOrderAccountingStrategy.getPeriodOriginalServicePrice(); |
| | | periodElectricPrice_total = periodElectricPrice_total.add(periodElectricPrice); |
| | | periodServicePrice_total = periodServicePrice_total.add(periodServicePrice); |
| | | total = total.add(periodElectricPrice).add(periodServicePrice); |
| | | } |
| | | //原金额 |
| | | BigDecimal rechargeAmount = chargingOrder.getRechargeAmount(); |
| | | BigDecimal vipDiscountAmount = chargingOrder.getVipDiscountAmount(); |
| | | //总金额(充值金额+会员折扣金额) |
| | | BigDecimal decimal = rechargeAmount.add(vipDiscountAmount); |
| | | //退款金额(已经计算了折扣优惠部分) |
| | | BigDecimal refundAmount = rechargeAmount.divide(decimal, new MathContext(4, RoundingMode.HALF_EVEN)).multiply(decimal.subtract(total)); |
| | | BigDecimal orderAmount = BigDecimal.valueOf(total.doubleValue()); |
| | | BigDecimal payAmount = BigDecimal.valueOf(total.doubleValue()); |
| | | //折扣金额 |
| | | BigDecimal discountAmount = BigDecimal.ZERO; |
| | | if(null != chargingOrder.getVipDiscount()){ |
| | | //服务费折扣 |
| | | discountAmount = periodServicePrice_total.multiply((new BigDecimal(10).subtract(chargingOrder.getVipDiscount())).divide(new BigDecimal(10))); |
| | | |
| | | TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData(); |
| | | if(null != appUser.getVipId()){ |
| | | //判断会员是否还有充电优惠次数 |
| | | GetAppUserVipDetail getAppUserVipDetail = new GetAppUserVipDetail(); |
| | | getAppUserVipDetail.setAppUserId(chargingOrder.getAppUserId()); |
| | | getAppUserVipDetail.setVipId(appUser.getVipId()); |
| | | TAppUserVipDetail data = appUserVipDetailClient.getAppUserVipDetail(getAppUserVipDetail).getData(); |
| | | if(null != data && data.getChargeNum() > 0){ |
| | | data.setChargeNum(data.getChargeNum() - 1); |
| | | appUserVipDetailClient.updateAppUserVipDetail(data); |
| | | } |
| | | |
| | | TVip vip = vipClient.getInfo1(appUser.getVipId()).getData(); |
| | | BigDecimal maximumDeduction = vip.getMaximumDeduction(); |
| | | //普通会员有最高优惠限制 |
| | | if(vip.getType() == 1 && discountAmount.compareTo(maximumDeduction) > 0){ |
| | | discountAmount = maximumDeduction; |
| | | } |
| | | } |
| | | payAmount = payAmount.subtract(discountAmount); |
| | | } |
| | | |
| | | if(chargingOrder.getEndMode() == 2){ |
| | | chargingOrder.setEndMode(refundAmount.compareTo(BigDecimal.ZERO) > 0 ? 2 : 3); |
| | | } |
| | | chargingOrder.setStatus(5); |
| | | chargingOrder.setOrderAmount(orderAmount); |
| | | chargingOrder.setVipDiscountAmount(discountAmount); |
| | | |
| | | //计算优惠券 |
| | | if(null != chargingOrder.getAppCouponId()){ |
| | | //判断实际充电金额是否满足优惠券使用条件,如果不满足则不适用优惠券。 |
| | | TAppCoupon appCoupon = appCouponClient.getAppCouponById(chargingOrder.getAppCouponId()).getData(); |
| | | String couponJson = appCoupon.getCouponJson(); |
| | | TCoupon tCoupon = JSON.parseObject(couponJson, TCoupon.class); |
| | | Integer preferentialMode = tCoupon.getPreferentialMode(); |
| | | if(1 == preferentialMode){ |
| | | //满减 |
| | | if(payAmount.compareTo(tCoupon.getMeetTheConditions()) >= 0){ |
| | | refundAmount = refundAmount.add(tCoupon.getDiscountAmount()); |
| | | chargingOrder.setCouponDiscountAmount(tCoupon.getDiscountAmount()); |
| | | payAmount = payAmount.subtract(tCoupon.getDiscountAmount()); |
| | | }else{ |
| | | chargingOrder.setAppCouponId(null); |
| | | chargingOrder.setCouponDiscountAmount(BigDecimal.ZERO); |
| | | appCouponClient.refund(chargingOrder.getAppCouponId().toString()); |
| | | } |
| | | } |
| | | if(2 == preferentialMode){ |
| | | //抵扣 |
| | | if(payAmount.compareTo(tCoupon.getMeetTheConditions()) >= 0){ |
| | | //折扣金额 |
| | | BigDecimal divide = payAmount.multiply(new BigDecimal(10).subtract(tCoupon.getDiscount())).divide(new BigDecimal(10)); |
| | | divide = divide.compareTo(tCoupon.getMaximumDiscountAmount()) > 0 ? tCoupon.getMaximumDiscountAmount() : divide; |
| | | refundAmount = refundAmount.add(divide); |
| | | chargingOrder.setCouponDiscountAmount(divide); |
| | | payAmount = payAmount.subtract(divide); |
| | | }else{ |
| | | chargingOrder.setAppCouponId(null); |
| | | chargingOrder.setCouponDiscountAmount(BigDecimal.ZERO); |
| | | appCouponClient.refund(chargingOrder.getAppCouponId().toString()); |
| | | } |
| | | } |
| | | } |
| | | chargingOrder.setPaymentAmount(payAmount); |
| | | this.updateById(chargingOrder); |
| | | |
| | | //添加积分 |
| | | TIntegralRule integralRule = integralRuleClient.getSet().getData(); |
| | | if(null != integralRule){ |
| | | TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData(); |
| | | Integer num1 = JSON.parseObject(integralRule.getChargeCredit()).getInteger("num1"); |
| | | Integer integral = payAmount.multiply(new BigDecimal(num1)).intValue(); |
| | | if(null != appUser.getVipId()){ |
| | | TVip vip = vipClient.getInfo1(appUser.getVipId()).getData(); |
| | | Integer doubleIntegration = vip.getDoubleIntegration(); |
| | | //双倍积分 |
| | | if(1 == doubleIntegration){ |
| | | integral *= 2; |
| | | } |
| | | } |
| | | |
| | | TAppUserIntegralChange appUserIntegralChange = new TAppUserIntegralChange(); |
| | | appUserIntegralChange.setAppUserId(appUser.getId()); |
| | | appUserIntegralChange.setChangeType(2); |
| | | appUserIntegralChange.setHistoricalIntegral(appUser.getPoints()); |
| | | appUser.setPoints(appUser.getPoints() + integral); |
| | | appUserIntegralChange.setCurrentIntegral(appUser.getPoints()); |
| | | appUserIntegralChange.setCreateTime(LocalDateTime.now()); |
| | | appUserIntegralChange.setOrderCode(chargingOrder.getCode()); |
| | | appUserClient.updateAppUser(appUser); |
| | | appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange); |
| | | } |
| | | |
| | | |
| | | //开始构建退款费用 |
| | | if(refundAmount.compareTo(BigDecimal.ZERO) > 0){ |
| | | Integer rechargePaymentType = chargingOrder.getRechargePaymentType(); |
| | | //构建退款明细 |
| | | TChargingOrderRefund chargingOrderRefund = new TChargingOrderRefund(); |
| | | chargingOrderRefund.setChargingOrderId(chargingOrder.getId()); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | chargingOrderRefund.setRefundCode("CDF" + sdf.format(new Date()) + (Double.valueOf(Math.random() * 1000).intValue())); |
| | | chargingOrderRefund.setRefundAmount(refundAmount); |
| | | chargingOrderRefund.setRefundStatus(1); |
| | | chargingOrderRefund.setPayType(rechargePaymentType); |
| | | chargingOrderRefund.setRefundStatus(1); |
| | | chargingOrderRefund.setCode(chargingOrder.getCode()); |
| | | chargingOrderRefund.setRefundTitle("充电完成退款"); |
| | | chargingOrderRefund.setRefundContent("充电完成退款"); |
| | | chargingOrderRefund.setRefundReason("充电完成退款"); |
| | | chargingOrderRefund.setRefundRemark("充电完成退款"); |
| | | chargingOrderRefund.setRefundTotalAmount(refundAmount); |
| | | chargingOrderRefund.setPayAmount(rechargeAmount); |
| | | if(1 == rechargePaymentType){ |
| | | WxPaymentRefundModel model = new WxPaymentRefundModel(); |
| | | model.setOut_trade_no(chargingOrder.getCode()); |
| | | model.setOut_refund_no(chargingOrderRefund.getRefundCode()); |
| | | model.setReason("充电完成退款"); |
| | | model.setNotify_url("/payment/wx/refund/notify"); |
| | | WxPaymentRefundModel.RefundAmount amount = new WxPaymentRefundModel.RefundAmount(); |
| | | amount.setRefund(refundAmount.multiply(new BigDecimal(100)).intValue()); |
| | | amount.setTotal(rechargeAmount.multiply(new BigDecimal(100)).intValue()); |
| | | amount.setCurrency("CNY"); |
| | | model.setAmount(amount); |
| | | R<String> orderR = wxPaymentClient.refundOrderR(model); |
| | | if(200 == orderR.getCode()){ |
| | | chargingOrderRefundService.save(chargingOrderRefund); |
| | | } |
| | | } |
| | | if(2 == rechargePaymentType){ |
| | | RefundReq dto = new RefundReq(); |
| | | dto.setOutTradeNo(chargingOrder.getCode()); |
| | | dto.setOutRequestNo(chargingOrderRefund.getCode()); |
| | | dto.setRefundAmount(rechargeAmount.toString()); |
| | | dto.setRefundReason("充电完成退款"); |
| | | RefundResp resp = aliPaymentClient.refund(dto).getData(); |
| | | if(null != resp){ |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-DDTHH:mm:ss+TIMEZONE"); |
| | | AjaxResult success = chargingOrderStartupFailureWxRefund(resp.getOutTradeNo(), resp.getTradeNo(), "SUCCESS", sdf1.format(new Date())); |
| | | if(success.isSuccess()){ |
| | | chargingOrderRefundService.save(chargingOrderRefund); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | if(chargingOrderAccountingStrategy.getAccountingStrategyDetailId().equals(strategyDetail.getId())){ |
| | | //已充电总度数 |
| | | BigDecimal charging_degree = query.getCharging_degree(); |
| | | BigDecimal electrovalenc = strategyDetail.getElectrovalence().multiply(charging_degree); |
| | | BigDecimal originalServicePrice = strategyDetail.getServiceCharge().multiply(charging_degree); |
| | | BigDecimal chargingCapacity = chargingOrderAccountingStrategy.getChargingCapacity(); |
| | | //计算本阶段充电度数 |
| | | BigDecimal subtract = charging_degree.subtract(chargingCapacity); |
| | | //计算本阶段费用 |
| | | BigDecimal electrovalenc = strategyDetail.getElectrovalence().multiply(subtract); |
| | | BigDecimal originalServicePrice = strategyDetail.getServiceCharge().multiply(subtract); |
| | | BigDecimal serviceCharge = originalServicePrice; |
| | | //计算优惠金额 |
| | | if(null != chargingOrder.getVipDiscount()){ |
| | | serviceCharge = serviceCharge.multiply(chargingOrder.getVipDiscount().divide(new BigDecimal(10))); |
| | | } |
| | | //将本阶段的费用增加到总费用中 |
| | | electrovalenc = electrovalenc.add(chargingOrderAccountingStrategy.getPeriodElectricPrice()); |
| | | originalServicePrice = originalServicePrice.add(chargingOrderAccountingStrategy.getPeriodOriginalServicePrice()); |
| | | serviceCharge = serviceCharge.add(chargingOrderAccountingStrategy.getPeriodServicePrice()); |
| | | chargingOrderAccountingStrategy.setChargingCapacity(charging_degree); |
| | | chargingOrderAccountingStrategy.setPeriodElectricPrice(electrovalenc); |
| | | chargingOrderAccountingStrategy.setPeriodServicePrice(serviceCharge); |
| | |
| | | @GlobalTransactional(rollbackFor = Exception.class) |
| | | public void endCharge(String orderCode, Integer endMode) { |
| | | TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, orderCode)); |
| | | Integer status = chargingOrder.getStatus(); |
| | | if(status == 4 || status == 5){ |
| | | return; |
| | | } |
| | | chargingOrder.setStatus(5); |
| | | chargingOrder.setEndMode(endMode); |
| | | chargingOrder.setEndTime(LocalDateTime.now()); |
| | | this.updateById(chargingOrder); |
| | | // 将枪状态重置为空闲 |
| | | TChargingGun chargingGun = chargingGunClient.getChargingGunById(chargingOrder.getChargingGunId()).getData(); |
| | | chargingGun.setStatus(2); |
| | | chargingGunClient.updateChargingGunById(chargingGun); |
| | | |
| | | //计算用户标签 |
| | | editUserTag(chargingOrder); |
| | | //用户推荐奖励 |
| | | referralReward(chargingOrder); |
| | | //计算费用,处理退款 |
| | | endCharge(chargingOrder); |
| | | } |
| | | |
| | | /** |
| | |
| | | public void excelEndCharge(String orderCode) { |
| | | endCharge(orderCode, 0); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 停止充电返回账单后计算费用 |
| | | * @param vo |
| | | */ |
| | | @Override |
| | | @GlobalTransactional(rollbackFor = Exception.class) |
| | | public void endChargeBillingCharge(TransactionRecordMessageVO vo) { |
| | | TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, vo.getTransaction_serial_number())); |
| | | Integer status = chargingOrder.getStatus(); |
| | | if(status == 4 || status == 5){ |
| | | return; |
| | | } |
| | | |
| | | //计算用户标签 |
| | | editUserTag(chargingOrder); |
| | | //用户推荐奖励 |
| | | referralReward(chargingOrder); |
| | | |
| | | //如果使用优惠券需要判断优惠券是否满足使用条件 |
| | | //根据实际的充电金额计算退款金额 退回费用=(原金额/总金额)*(总金额-实际充电金额) |
| | | //退款金额=优惠券金额+剩余充电金额 |
| | | List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.list(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>().eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrder.getId())); |
| | | BigDecimal periodElectricPrice_total = BigDecimal.ZERO; |
| | | BigDecimal periodServicePrice_total = BigDecimal.ZERO; |
| | | BigDecimal total = BigDecimal.ZERO; |
| | | for (TChargingOrderAccountingStrategy chargingOrderAccountingStrategy : list) { |
| | | BigDecimal periodElectricPrice = chargingOrderAccountingStrategy.getPeriodElectricPrice(); |
| | | BigDecimal periodServicePrice = chargingOrderAccountingStrategy.getPeriodOriginalServicePrice(); |
| | | periodElectricPrice_total = periodElectricPrice_total.add(periodElectricPrice); |
| | | periodServicePrice_total = periodServicePrice_total.add(periodServicePrice); |
| | | total = total.add(periodElectricPrice).add(periodServicePrice); |
| | | } |
| | | //原金额 |
| | | BigDecimal rechargeAmount = chargingOrder.getRechargeAmount(); |
| | | BigDecimal vipDiscountAmount = chargingOrder.getVipDiscountAmount(); |
| | | //总金额(充值金额+会员折扣金额) |
| | | BigDecimal decimal = rechargeAmount.add(vipDiscountAmount); |
| | | //退款金额(已经计算了折扣优惠部分) |
| | | BigDecimal refundAmount = rechargeAmount.divide(decimal, new MathContext(4, RoundingMode.HALF_EVEN)).multiply(decimal.subtract(total)); |
| | | BigDecimal orderAmount = BigDecimal.valueOf(total.doubleValue()); |
| | | BigDecimal payAmount = BigDecimal.valueOf(total.doubleValue()); |
| | | //折扣金额 |
| | | BigDecimal discountAmount = BigDecimal.ZERO; |
| | | if(null != chargingOrder.getVipDiscount()){ |
| | | //服务费折扣 |
| | | discountAmount = periodServicePrice_total.multiply((new BigDecimal(10).subtract(chargingOrder.getVipDiscount())).divide(new BigDecimal(10))); |
| | | |
| | | TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData(); |
| | | if(null != appUser.getVipId()){ |
| | | //判断会员是否还有充电优惠次数 |
| | | GetAppUserVipDetail getAppUserVipDetail = new GetAppUserVipDetail(); |
| | | getAppUserVipDetail.setAppUserId(chargingOrder.getAppUserId()); |
| | | getAppUserVipDetail.setVipId(appUser.getVipId()); |
| | | TAppUserVipDetail data = appUserVipDetailClient.getAppUserVipDetail(getAppUserVipDetail).getData(); |
| | | if(null != data && data.getChargeNum() > 0){ |
| | | data.setChargeNum(data.getChargeNum() - 1); |
| | | appUserVipDetailClient.updateAppUserVipDetail(data); |
| | | } |
| | | |
| | | TVip vip = vipClient.getInfo1(appUser.getVipId()).getData(); |
| | | BigDecimal maximumDeduction = vip.getMaximumDeduction(); |
| | | //普通会员有最高优惠限制 |
| | | if(vip.getType() == 1 && discountAmount.compareTo(maximumDeduction) > 0){ |
| | | discountAmount = maximumDeduction; |
| | | } |
| | | } |
| | | payAmount = payAmount.subtract(discountAmount); |
| | | } |
| | | |
| | | if(chargingOrder.getEndMode() == 2){ |
| | | chargingOrder.setEndMode(refundAmount.compareTo(BigDecimal.ZERO) > 0 ? 2 : 3); |
| | | } |
| | | chargingOrder.setEndTime(LocalDateTime.now()); |
| | | chargingOrder.setStatus(5); |
| | | chargingOrder.setOrderAmount(orderAmount); |
| | | chargingOrder.setVipDiscountAmount(discountAmount); |
| | | chargingOrder.setServiceCharge(periodServicePrice_total); |
| | | chargingOrder.setElectrovalence(periodElectricPrice_total); |
| | | |
| | | //计算优惠券 |
| | | if(null != chargingOrder.getAppCouponId()){ |
| | | //判断实际充电金额是否满足优惠券使用条件,如果不满足则不适用优惠券。 |
| | | TAppCoupon appCoupon = appCouponClient.getAppCouponById(chargingOrder.getAppCouponId()).getData(); |
| | | String couponJson = appCoupon.getCouponJson(); |
| | | TCoupon tCoupon = JSON.parseObject(couponJson, TCoupon.class); |
| | | Integer preferentialMode = tCoupon.getPreferentialMode(); |
| | | if(1 == preferentialMode){ |
| | | //满减 |
| | | if(payAmount.compareTo(tCoupon.getMeetTheConditions()) >= 0){ |
| | | refundAmount = refundAmount.add(tCoupon.getDiscountAmount()); |
| | | chargingOrder.setCouponDiscountAmount(tCoupon.getDiscountAmount()); |
| | | payAmount = payAmount.subtract(tCoupon.getDiscountAmount()); |
| | | }else{ |
| | | chargingOrder.setAppCouponId(null); |
| | | chargingOrder.setCouponDiscountAmount(BigDecimal.ZERO); |
| | | appCouponClient.refund(chargingOrder.getAppCouponId().toString()); |
| | | } |
| | | } |
| | | if(2 == preferentialMode){ |
| | | //抵扣 |
| | | if(payAmount.compareTo(tCoupon.getMeetTheConditions()) >= 0){ |
| | | //折扣金额 |
| | | BigDecimal divide = payAmount.multiply(new BigDecimal(10).subtract(tCoupon.getDiscount())).divide(new BigDecimal(10)); |
| | | divide = divide.compareTo(tCoupon.getMaximumDiscountAmount()) > 0 ? tCoupon.getMaximumDiscountAmount() : divide; |
| | | refundAmount = refundAmount.add(divide); |
| | | chargingOrder.setCouponDiscountAmount(divide); |
| | | payAmount = payAmount.subtract(divide); |
| | | }else{ |
| | | chargingOrder.setAppCouponId(null); |
| | | chargingOrder.setCouponDiscountAmount(BigDecimal.ZERO); |
| | | appCouponClient.refund(chargingOrder.getAppCouponId().toString()); |
| | | } |
| | | } |
| | | } |
| | | chargingOrder.setPaymentAmount(payAmount); |
| | | this.updateById(chargingOrder); |
| | | |
| | | // 将枪状态重置为空闲 |
| | | TChargingGun chargingGun = chargingGunClient.getChargingGunById(chargingOrder.getChargingGunId()).getData(); |
| | | chargingGun.setStatus(2); |
| | | chargingGunClient.updateChargingGunById(chargingGun); |
| | | |
| | | //添加积分 |
| | | TIntegralRule integralRule = integralRuleClient.getSet().getData(); |
| | | if(null != integralRule){ |
| | | TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData(); |
| | | Integer num1 = JSON.parseObject(integralRule.getChargeCredit()).getInteger("num1"); |
| | | Integer integral = payAmount.multiply(new BigDecimal(num1)).intValue(); |
| | | if(null != appUser.getVipId()){ |
| | | TVip vip = vipClient.getInfo1(appUser.getVipId()).getData(); |
| | | Integer doubleIntegration = vip.getDoubleIntegration(); |
| | | //双倍积分 |
| | | if(1 == doubleIntegration){ |
| | | integral *= 2; |
| | | } |
| | | } |
| | | |
| | | TAppUserIntegralChange appUserIntegralChange = new TAppUserIntegralChange(); |
| | | appUserIntegralChange.setAppUserId(appUser.getId()); |
| | | appUserIntegralChange.setChangeType(2); |
| | | appUserIntegralChange.setHistoricalIntegral(appUser.getPoints()); |
| | | appUser.setPoints(appUser.getPoints() + integral); |
| | | appUserIntegralChange.setCurrentIntegral(appUser.getPoints()); |
| | | appUserIntegralChange.setCreateTime(LocalDateTime.now()); |
| | | appUserIntegralChange.setOrderCode(chargingOrder.getCode()); |
| | | appUserClient.updateAppUser(appUser); |
| | | appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange); |
| | | } |
| | | |
| | | |
| | | //开始构建退款费用 |
| | | if(refundAmount.compareTo(BigDecimal.ZERO) > 0){ |
| | | Integer rechargePaymentType = chargingOrder.getRechargePaymentType(); |
| | | //构建退款明细 |
| | | TChargingOrderRefund chargingOrderRefund = new TChargingOrderRefund(); |
| | | chargingOrderRefund.setChargingOrderId(chargingOrder.getId()); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | chargingOrderRefund.setRefundCode("CDF" + sdf.format(new Date()) + (Double.valueOf(Math.random() * 1000).intValue())); |
| | | chargingOrderRefund.setRefundAmount(refundAmount); |
| | | chargingOrderRefund.setRefundStatus(1); |
| | | chargingOrderRefund.setPayType(rechargePaymentType); |
| | | chargingOrderRefund.setRefundStatus(1); |
| | | chargingOrderRefund.setCode(chargingOrder.getCode()); |
| | | chargingOrderRefund.setRefundTitle("充电完成退款"); |
| | | chargingOrderRefund.setRefundContent("充电完成退款"); |
| | | chargingOrderRefund.setRefundReason("充电完成退款"); |
| | | chargingOrderRefund.setRefundRemark("充电完成退款"); |
| | | chargingOrderRefund.setRefundTotalAmount(refundAmount); |
| | | chargingOrderRefund.setPayAmount(rechargeAmount); |
| | | if(1 == rechargePaymentType){ |
| | | WxPaymentRefundModel model = new WxPaymentRefundModel(); |
| | | model.setOut_trade_no(chargingOrder.getCode()); |
| | | model.setOut_refund_no(chargingOrderRefund.getRefundCode()); |
| | | model.setReason("充电完成退款"); |
| | | model.setNotify_url("/payment/wx/refund/notify"); |
| | | WxPaymentRefundModel.RefundAmount amount = new WxPaymentRefundModel.RefundAmount(); |
| | | amount.setRefund(refundAmount.multiply(new BigDecimal(100)).intValue()); |
| | | amount.setTotal(rechargeAmount.multiply(new BigDecimal(100)).intValue()); |
| | | amount.setCurrency("CNY"); |
| | | model.setAmount(amount); |
| | | R<String> orderR = wxPaymentClient.refundOrderR(model); |
| | | if(200 == orderR.getCode()){ |
| | | chargingOrderRefundService.save(chargingOrderRefund); |
| | | } |
| | | } |
| | | if(2 == rechargePaymentType){ |
| | | RefundReq dto = new RefundReq(); |
| | | dto.setOutTradeNo(chargingOrder.getCode()); |
| | | dto.setOutRequestNo(chargingOrderRefund.getCode()); |
| | | dto.setRefundAmount(rechargeAmount.toString()); |
| | | dto.setRefundReason("充电完成退款"); |
| | | RefundResp resp = aliPaymentClient.refund(dto).getData(); |
| | | if(null != resp){ |
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-DDTHH:mm:ss+TIMEZONE"); |
| | | AjaxResult success = chargingOrderStartupFailureWxRefund(resp.getOutTradeNo(), resp.getTradeNo(), "SUCCESS", sdf1.format(new Date())); |
| | | if(success.isSuccess()){ |
| | | chargingOrderRefundService.save(chargingOrderRefund); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getByDate(List<Long> chargingOrderIds) { |
| | | return this.baseMapper.getByDate(chargingOrderIds); |