fix: 退款修改
This commit is contained in:
parent
a635c1b9e3
commit
8dd9421197
|
|
@ -0,0 +1,16 @@
|
|||
package cn.ysk.cashier.dto;
|
||||
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivateOutRecord;
|
||||
import cn.ysk.cashier.vo.OrderInfoUserCouponVo;
|
||||
import cn.ysk.cashier.vo.TbUserCouponVo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class OrderInfoCouponInfoDTO {
|
||||
private List<TbActivateOutRecord> outRecordList;
|
||||
private Collection<OrderInfoUserCouponVo> fullReductionCoupon;
|
||||
private Collection<OrderInfoUserCouponVo> productCoupon;
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ import cn.ysk.cashier.cons.RedisConstant;
|
|||
import cn.ysk.cashier.cons.TableConstant;
|
||||
import cn.ysk.cashier.cons.rabbit.RabbitConstants;
|
||||
import cn.ysk.cashier.dto.CouponDto;
|
||||
import cn.ysk.cashier.dto.OrderInfoCouponInfoDTO;
|
||||
import cn.ysk.cashier.dto.order.OrderCartInfoDTO;
|
||||
import cn.ysk.cashier.dto.order.OrderCouponInfoDTO;
|
||||
import cn.ysk.cashier.dto.order.OrderPriceDTO;
|
||||
|
|
@ -47,6 +48,7 @@ import cn.ysk.cashier.service.order.TbOrderInfoService;
|
|||
import cn.ysk.cashier.service.shop.TbShopTableService;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
import cn.ysk.cashier.vo.ActivateInInfoVO;
|
||||
import cn.ysk.cashier.vo.OrderInfoUserCouponVo;
|
||||
import cn.ysk.cashier.vo.PendingCountVO;
|
||||
import cn.ysk.cashier.vo.TbUserCouponVo;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
|
@ -1511,18 +1513,30 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
}
|
||||
}
|
||||
|
||||
private void returnCoupon(TbOrderInfo orderInfo) {
|
||||
private void returnCoupon(TbOrderInfo orderInfo, boolean resetInfo) {
|
||||
// 返还优惠券
|
||||
if (StrUtil.isNotBlank(orderInfo.getCouponInfoList())) {
|
||||
OrderCouponInfoDTO couponInfoDTO = JSONObject.parseObject(orderInfo.getCouponInfoList(), OrderCouponInfoDTO.class);
|
||||
OrderInfoCouponInfoDTO couponInfoDTO = JSONObject.parseObject(orderInfo.getCouponInfoList(), OrderInfoCouponInfoDTO.class);
|
||||
ArrayList<Integer> couponIds = new ArrayList<>();
|
||||
couponInfoDTO.getProductCoupon().forEach(item -> {
|
||||
if (item.getReturnNum() >= item.getFinalUseNum()) {
|
||||
couponIds.add(item.getId());
|
||||
}
|
||||
});
|
||||
// 券返还
|
||||
if (!couponInfoDTO.getOutRecordList().isEmpty()) {
|
||||
ArrayList<TbActivateOutRecord> finalReturnList = new ArrayList<>();
|
||||
couponInfoDTO.getOutRecordList().forEach(item -> {
|
||||
item.setRefNum(item.getUseNum());
|
||||
if (!couponIds.contains(item.getGiveId())) {
|
||||
item.setRefNum(item.getUseNum());
|
||||
finalReturnList.add(item);
|
||||
}
|
||||
});
|
||||
shopCouponService.refund(couponInfoDTO.getOutRecordList());
|
||||
couponInfoDTO.setOutRecordList(new ArrayList<>());
|
||||
orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfoDTO));
|
||||
shopCouponService.refund(finalReturnList);
|
||||
if (resetInfo) {
|
||||
couponInfoDTO.setOutRecordList(new ArrayList<>());
|
||||
orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfoDTO));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2091,7 +2105,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
|
||||
private BigDecimal calcDiscountAndUpdateInfo(PayDTO payDTO, TbOrderInfo orderInfo) {
|
||||
// 返还上次使用的券
|
||||
returnCoupon(orderInfo);
|
||||
returnCoupon(orderInfo, true);
|
||||
|
||||
|
||||
Set<String> productIdSet = new HashSet<>();
|
||||
List<TbCashierCart> cashierCarts = mpCashierCartService.selectByOrderIdAndState(orderInfo.getId());
|
||||
|
|
@ -2133,11 +2148,21 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
consumeCoupon(couponInfo.getOutRecordList(), payDTO.getVipUserId(), orderInfo);
|
||||
|
||||
couponInfo.setProductCouponMap(BeanUtil.copyProperties(couponInfo.getProductCouponMap(), HashMap.class));
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("outRecordList", couponInfo.getOutRecordList());
|
||||
map.put("fullReductionCoupon", couponInfo.getFullReductionCouponMap().values());
|
||||
map.put("productCoupon", couponInfo.getProductCouponMap().values());
|
||||
orderInfo.setCouponInfoList(JSONObject.toJSONString(map));
|
||||
OrderInfoCouponInfoDTO infoDTO = new OrderInfoCouponInfoDTO();
|
||||
infoDTO.setOutRecordList(couponInfo.getOutRecordList());
|
||||
|
||||
ArrayList<OrderInfoUserCouponVo> productArr = new ArrayList<>();
|
||||
couponInfo.getProductCouponMap().values().forEach(item -> {
|
||||
BeanUtil.copyProperties(item, OrderInfoUserCouponVo.class);
|
||||
});
|
||||
infoDTO.setProductCoupon(productArr);
|
||||
|
||||
ArrayList<OrderInfoUserCouponVo> fullArr = new ArrayList<>();
|
||||
couponInfo.getFullReductionCouponMap().values().forEach(item -> {
|
||||
BeanUtil.copyProperties(item, OrderInfoUserCouponVo.class);
|
||||
});
|
||||
infoDTO.setFullReductionCoupon(fullArr);
|
||||
orderInfo.setCouponInfoList(JSONObject.toJSONString(infoDTO));
|
||||
// orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfo));
|
||||
|
||||
// 修改订单detail
|
||||
|
|
@ -2697,6 +2722,11 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
}
|
||||
|
||||
private HashMap<String, Object> updateReturnOrderInfo(ReturnOrderDTO returnOrderDTO, TbOrderInfo oldOrderInfo, boolean isOnline) {
|
||||
String couponInfoList = oldOrderInfo.getCouponInfoList();
|
||||
OrderInfoCouponInfoDTO couponInfoDTO = null;
|
||||
if (StrUtil.isNotBlank(couponInfoList)) {
|
||||
couponInfoDTO = JSONObject.parseObject(couponInfoList, OrderInfoCouponInfoDTO.class);
|
||||
}
|
||||
ArrayList<Integer> detailIds = new ArrayList<>();
|
||||
HashMap<String, BigDecimal> returnNumMap = new HashMap<>();
|
||||
returnOrderDTO.getOrderDetails().forEach(item -> {
|
||||
|
|
@ -2753,6 +2783,13 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
shopCouponService.refund(CollUtil.newArrayList(outRecord));
|
||||
currentDetailAMount = returnNum.multiply(orderDetail.getPrice())
|
||||
.add(returnPackFee);
|
||||
// 移除使用的券
|
||||
couponInfoDTO.getProductCoupon().forEach(item -> {
|
||||
if (Objects.equals(item.getId(), outRecord.getGiveId())) {
|
||||
item.setReturnNum(item.getReturnNum() + outRecord.getRefNum());
|
||||
}
|
||||
});
|
||||
|
||||
// 使用了满减或积分,获取普通付款商品计算退款比例,退部分现金
|
||||
}else if (oldOrderInfo.getFullCouponDiscountAmount().compareTo(BigDecimal.ZERO) > 0 || oldOrderInfo.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0){
|
||||
hasNormalReturn = true;
|
||||
|
|
@ -2792,6 +2829,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
throw new BadRequestException("退款金额必须大于0");
|
||||
}
|
||||
|
||||
oldOrderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfoDTO));
|
||||
|
||||
// 保存剩余未退款的订单详情
|
||||
if (!remainOrderDetailList.isEmpty()) {
|
||||
mpOrderDetailService.saveBatch(remainOrderDetailList);
|
||||
|
|
@ -2923,9 +2962,23 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
returnOrderDTO.getOrderId(), returnOrderDTO.getOrderDetails().stream().map(ReturnOrderDTO.OrderDetail::getId).collect(Collectors.toList()));
|
||||
}
|
||||
orderInfo.setStatus(TableConstant.OrderInfo.Status.CLOSED.getValue());
|
||||
|
||||
// 订单金额全退,退优惠券以及积分
|
||||
if (orderInfo.getPayAmount().compareTo(orderInfo.getRefundAmount()) <= 0) {
|
||||
returnCoupon(orderInfo);
|
||||
String couponInfoList = orderInfo.getCouponInfoList();
|
||||
if (StrUtil.isNotBlank(couponInfoList)) {
|
||||
OrderInfoCouponInfoDTO orderInfoCouponInfoDTO = JSONObject.parseObject(couponInfoList, OrderInfoCouponInfoDTO.class);
|
||||
int remainNum = 0;
|
||||
for (OrderInfoUserCouponVo item : orderInfoCouponInfoDTO.getProductCoupon()) {
|
||||
if (item.getFinalUseNum() > item.getReturnNum()) {
|
||||
remainNum = remainNum + (item.getFinalUseNum() - item.getReturnNum());
|
||||
}
|
||||
}
|
||||
|
||||
if (remainNum == 0) {
|
||||
returnCoupon(orderInfo, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
orderInfoMapper.updateById(orderInfo);
|
||||
// 打印退款小票
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package cn.ysk.cashier.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class OrderInfoUserCouponVo extends TbUserCouponVo{
|
||||
private int returnNum = 0;
|
||||
}
|
||||
Loading…
Reference in New Issue