From 0cbc17f0c1db20613670b113b4f48a6ddcb52631 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Fri, 28 Jul 2023 16:21:21 +0800
Subject: [PATCH] 赠送积分更新状态
---
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java | 175 +++++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 135 insertions(+), 40 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 7656e4d..f9861df 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("参数错误");
}
@@ -145,35 +143,8 @@
if(1 != goodsResult){
throw new FebsException(mallGoods.getGoodsName() + "库存不足");
}
- BigDecimal amount = BigDecimal.ZERO;
- BigDecimal itemPrice = BigDecimal.ZERO;
- /**
- *
- */
- Integer isNormal = mallGoods.getIsNormal();
- if(GoodsTypeEnum.SCORE_CHANGE.getValue() == isNormal){
- //普通用户使用原价购买
- amount = sku.getOriginalPrice().multiply(BigDecimal.valueOf(item.getCnt()));
- itemPrice = sku.getOriginalPrice();
- }else if(GoodsTypeEnum.BUY_SCORE.getValue() == isNormal){
- //普通用户使用原价购买
- amount = sku.getLevelOnePrice().multiply(BigDecimal.valueOf(item.getCnt()));
- itemPrice = sku.getLevelOnePrice();
- }else if(GoodsTypeEnum.NORMAL_GOODS.getValue() == isNormal){
- //普通用户使用原价购买
- amount = sku.getLevelTwoPrice().multiply(BigDecimal.valueOf(item.getCnt()));
- itemPrice = sku.getLevelTwoPrice();
- }else if(GoodsTypeEnum.CLASS_ROLL.getValue() == isNormal){
- //普通用户使用原价购买
- amount = sku.getLevelThreePrice().multiply(BigDecimal.valueOf(item.getCnt()));
- itemPrice = sku.getLevelThreePrice();
- }else if(GoodsTypeEnum.HOUSE_ROLL.getValue() == isNormal){
- //普通用户使用原价购买
- amount = sku.getLevelThreePrice().multiply(BigDecimal.valueOf(item.getCnt()));
- itemPrice = sku.getLevelThreePrice();
- }else{
- throw new FebsException("当前商品无法购买!");
- }
+ BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt()));
+ BigDecimal itemPrice = sku.getPresentPrice();
orderItem.setAmount(amount);
orderItem.setCnt(item.getCnt());
orderItem.setOrderId(orderInfo.getId());
@@ -322,6 +293,7 @@
String payResultStr = "";
String wxResultStr = "";
+ String amountActualMsg = "0";
switch (payOrderDto.getType()) {
case "1":
BrandWCPayRequestData brandWCPayRequestData = null;
@@ -333,6 +305,7 @@
wxResultStr = JSONUtil.toJsonStr(brandWCPayRequestData);
payResultStr = brandWCPayRequestData.getPrepay_id();
orderInfo.setPayMethod("微信支付");
+ amountActualMsg = orderInfo.getAmount().toString();
break;
case "2":
payResultStr = balancePay(orderInfo, payOrderDto.getTradePwd(), "balance");
@@ -346,6 +319,8 @@
mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(),
orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue(),"余额支付",2);
+
+ amountActualMsg = orderInfo.getAmount().toString();
break;
case "3":
/**
@@ -395,6 +370,7 @@
if(amountActual.compareTo(BigDecimal.ZERO) > 0){
mallMoneyFlowService.addMoneyFlow(member.getId(), amountActual.negate(), MoneyFlowTypeEnum.PAY.getValue(),
orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue(),"余额支付",2);
+ amountActualMsg = amountActual.toString();
}
if(scoreActual.compareTo(BigDecimal.ZERO) > 0){
mallMoneyFlowService.addMoneyFlow(member.getId(), scoreActual.negate(),
@@ -410,28 +386,144 @@
if(stateRoll == 2){
throw new FebsException("兑换券已使用");
}
-
+ mallRollPerk.setState(2);
+ mallRollPerk.setUpdateTime(DateUtil.date());
+ mallRollPerkMapper.updateById(mallRollPerk);
payResultStr = orderInfo.getOrderNo();
- orderInfo.setPayOrderNo(orderInfo.getOrderNo());
+ orderInfo.setPayOrderNo(payOrderDto.getRollId().toString());
orderInfo.setPayMethod("兑换券支付");
- orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue());
orderInfo.setPayTime(new Date());
orderInfo.setPayResult("1");
mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.ROLL_PAY.getValue(),
orderInfo.getOrderNo(), FlowTypeEnum.PRIZE_SCORE.getValue());
break;
- default:
+ /**
+ * 余额加微信
+ */
+ 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("余额加微信");
+ orderInfo.setAmount(amountThree);
+ 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())){
+ orderInfo.setUseTime(DateUtil.parseDate(payOrderDto.getUseTime()));
}
//订单支付成功产生一个提货码
String takeCode = ShareCodeUtil.toSerialCode(orderInfo.getId());
orderInfo.setTakeCode(takeCode);
this.baseMapper.updateById(orderInfo);
-
-
+ StringBuffer stringBuffer = new StringBuffer();
+ stringBuffer.append(orderInfo.getId().toString());
+ stringBuffer.append("@");
+ stringBuffer.append(amountActualMsg);
+ agentProducer.sendOrderGetMsg(stringBuffer.toString());
+ agentProducer.sendRollSendMsg(orderInfo.getId());
// OrderStateDto orderStateDto = new OrderStateDto();
// orderStateDto.setOrderNo(orderInfo.getOrderNo());
@@ -523,6 +615,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