From cc9ce86cc24c413c9cbd303b8bb4fd9f5ec5a30f Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Fri, 28 Jul 2023 10:04:53 +0800 Subject: [PATCH] 赠送积分更新状态 --- src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 114 insertions(+), 5 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java index 7d869e2..07484b5 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java +++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java @@ -13,10 +13,7 @@ import cc.mrbird.febs.mall.entity.*; import cc.mrbird.febs.mall.mapper.*; import cc.mrbird.febs.mall.service.*; -import cc.mrbird.febs.mall.vo.ApiLeaderListVo; -import cc.mrbird.febs.mall.vo.OrderDetailVo; -import cc.mrbird.febs.mall.vo.OrderListVo; -import cc.mrbird.febs.mall.vo.OrderRefundVo; +import cc.mrbird.febs.mall.vo.*; import cc.mrbird.febs.pay.model.BrandWCPayRequestData; import cc.mrbird.febs.pay.model.OrderStateDto; import cc.mrbird.febs.pay.service.IPayService; @@ -84,6 +81,7 @@ private final MallElectronicFenceMapper mallElectronicFenceMapper; private final MallMemberWalletMapper mallMemberWalletMapper; private final MallRollPerkMapper mallRollPerkMapper; + private final MallMoneyFlowMapper mallMoneyFlowMapper; @Override @Transactional(rollbackFor = Exception.class) @@ -111,7 +109,7 @@ orderInfo.setStatus(OrderStatusEnum.WAIT_PAY.getValue()); orderInfo.setRemark(addOrderDto.getRemark()); orderInfo.setOrderType(addOrderDto.getOrderType()); - orderInfo.setDeliveryType(2); + orderInfo.setDeliveryType(addOrderDto.getDeliveryType()); if (CollUtil.isEmpty(addOrderDto.getItems())) { throw new FebsException("参数错误"); } @@ -389,6 +387,7 @@ throw new FebsException("兑换券已使用"); } mallRollPerk.setState(2); + mallRollPerk.setUpdateTime(DateUtil.date()); mallRollPerkMapper.updateById(mallRollPerk); payResultStr = orderInfo.getOrderNo(); @@ -400,7 +399,114 @@ mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.ROLL_PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.PRIZE_SCORE.getValue()); break; + /** + * 余额加微信 + */ + case "2,1": + MallMemberWallet mallMemberWalletThree = mallMemberWalletMapper.selectWalletByMemberId(member.getId()); + BigDecimal balanceThree = mallMemberWalletThree.getBalance(); + BigDecimal amountThree = orderInfo.getAmount(); + +// int reduceThree = memberWalletService.reduce(balanceThree, member.getId(), "balance"); +// if (reduceThree == 2) { +// throw new FebsException("余额不足"); +// } +// mallMoneyFlowService.addMoneyFlow(member.getId(), balanceThree.negate(), MoneyFlowTypeEnum.PAY.getValue(), +// orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue(),"余额支付",2); + + //实际支付余额 + BigDecimal amountActualThree = amountThree.subtract(balanceThree).setScale(2, BigDecimal.ROUND_DOWN); + orderInfo.setAmount(amountActualThree); + + BrandWCPayRequestData brandWCPayRequestDataThree = null; + try { + brandWCPayRequestDataThree = iXcxPayService.startPayment(orderInfo); + } catch (Exception e) { + throw new FebsException("支付失败"); + } + wxResultStr = JSONUtil.toJsonStr(brandWCPayRequestDataThree); + payResultStr = brandWCPayRequestDataThree.getPrepay_id(); + orderInfo.setPayMethod("余额加微信"); + amountActualMsg = amountThree.toString(); + break; + /** + * 积分加余额 + */ + case "3,2": + /** + * 获取用户的当前积分 + */ + MallMemberWallet mallMemberWalletNOne = mallMemberWalletMapper.selectWalletByMemberId(member.getId()); + BigDecimal scoreOne = mallMemberWalletNOne.getScore(); + BigDecimal amountOne = orderInfo.getAmount(); + //积分兑换比例 + DataDictionaryCustom scoreChangeOneDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( + DataDictionaryEnum.SCORE_CHANGE.getType(), + DataDictionaryEnum.SCORE_CHANGE.getCode() + ); + BigDecimal scoreChangeOne = StrUtil.isEmpty(scoreChangeOneDic.getValue()) ? new BigDecimal("1") : new BigDecimal(scoreChangeOneDic.getValue()); + int reduceOne = memberWalletService.reduce(scoreOne, member.getId(), "score"); + if (reduceOne == 2) { + throw new FebsException("积分余额不足"); + } + BigDecimal scoreToAmountOne = scoreOne.divide(scoreChangeOne, 2, BigDecimal.ROUND_DOWN); + //实际支付余额 + BigDecimal amountActualOne = amountOne.subtract(scoreToAmountOne).setScale(2, BigDecimal.ROUND_DOWN); + int balanceOne = memberWalletService.reduce(amountActualOne, member.getId(), "balance"); + if (balanceOne == 2) { + throw new FebsException("余额不足"); + } + orderInfo.setPayOrderNo(orderInfo.getOrderNo()); + orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue()); + orderInfo.setPayTime(new Date()); + orderInfo.setPayResult("1"); + orderInfo.setDeliveryState(OrderDeliveryStateEnum.DELIVERY_WAIT.getValue()); + mallMoneyFlowService.addMoneyFlow(member.getId(), amountActualOne.negate(), MoneyFlowTypeEnum.PAY.getValue(), + orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue(),"余额支付",2); + amountActualMsg = amountActualOne.toString(); + + orderInfo.setPayMethod("积分加余额"); + mallMoneyFlowService.addMoneyFlow(member.getId(), scoreOne.negate(), + MoneyFlowTypeEnum.SCORE_PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue(),"积分支付",2); + break; + /** + * 积分加微信 + */ + case "3,1": + MallMemberWallet mallMemberWalletNTwo = mallMemberWalletMapper.selectWalletByMemberId(member.getId()); + BigDecimal scoreTwo = mallMemberWalletNTwo.getScore(); + BigDecimal amountTwo = orderInfo.getAmount(); + //积分兑换比例 + DataDictionaryCustom scoreChangeTwoDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( + DataDictionaryEnum.SCORE_CHANGE.getType(), + DataDictionaryEnum.SCORE_CHANGE.getCode() + ); + BigDecimal scoreChangeTwo = StrUtil.isEmpty(scoreChangeTwoDic.getValue()) ? new BigDecimal("1") : new BigDecimal(scoreChangeTwoDic.getValue()); + int reduceTwo = memberWalletService.reduce(scoreTwo, member.getId(), "score"); + if (reduceTwo == 2) { + throw new FebsException("积分余额不足"); + } + mallMoneyFlowService.addMoneyFlow(member.getId(), scoreTwo.negate(), + MoneyFlowTypeEnum.SCORE_PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue(),"积分支付",2); + + BigDecimal scoreToAmountTwo = scoreTwo.divide(scoreChangeTwo, 2, BigDecimal.ROUND_DOWN); + //实际支付余额 + BigDecimal amountActualTwo = amountTwo.subtract(scoreToAmountTwo).setScale(2, BigDecimal.ROUND_DOWN); + orderInfo.setAmount(amountActualTwo); + + BrandWCPayRequestData brandWCPayRequestDataTwo = null; + try { + brandWCPayRequestDataTwo = iXcxPayService.startPayment(orderInfo); + } catch (Exception e) { + throw new FebsException("支付失败"); + } + wxResultStr = JSONUtil.toJsonStr(brandWCPayRequestDataTwo); + payResultStr = brandWCPayRequestDataTwo.getPrepay_id(); + orderInfo.setPayMethod("积分加微信"); + amountActualMsg = amountActualTwo.toString(); + break; default: + throw new FebsException("请选择正确的支付方式"); } if(ObjectUtil.isNotEmpty(payOrderDto.getUseTime())){ @@ -508,6 +614,9 @@ long remainTime = DateUtil.between(new Date(), endTime, DateUnit.SECOND, false); orderDetailVo.setRemainTime(remainTime); } + String orderNo = orderInfo.getOrderNo(); + List<MoneyFlowVo> moneyFlowVos = mallMoneyFlowMapper.selectMoneyFlowByOrderNo(orderNo,orderInfo.getMemberId()); + orderDetailVo.setMoneyFlowVos(moneyFlowVos); return orderDetailVo; } -- Gitblit v1.9.1