订单支持多次退款
This commit is contained in:
parent
8fe78a48fd
commit
5ce67b4014
|
|
@ -0,0 +1,15 @@
|
||||||
|
package cn.ysk.cashier.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum OrderStatusEnums {
|
||||||
|
REFUNDING("refunding"),
|
||||||
|
REFUND("refund"),
|
||||||
|
CLOSED("closed");
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
OrderStatusEnums(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
package cn.ysk.cashier.mybatis.service;
|
package cn.ysk.cashier.mybatis.service;
|
||||||
|
|
||||||
|
import cn.ysk.cashier.dto.shoptable.ReturnOrderDTO;
|
||||||
|
import cn.ysk.cashier.enums.OrderStatusEnums;
|
||||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (TbShopPermission)表服务接口
|
* (TbShopPermission)表服务接口
|
||||||
*
|
*
|
||||||
|
|
@ -11,5 +15,14 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
*/
|
*/
|
||||||
public interface MpOrderDetailService extends IService<TbOrderDetail> {
|
public interface MpOrderDetailService extends IService<TbOrderDetail> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据orderId和id修改detail状态
|
||||||
|
* @param oldOrderStatusEnums 原始订单状态
|
||||||
|
* @param orderStatusEnums 状态
|
||||||
|
* @param orderId 订单id
|
||||||
|
* @param orderDetails detailIds
|
||||||
|
* @return 影响数量
|
||||||
|
*/
|
||||||
|
boolean updateStatusByOrderIdAndIds(OrderStatusEnums oldOrderStatusEnums, OrderStatusEnums orderStatusEnums, Integer orderId, List<Integer> orderDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,16 @@
|
||||||
package cn.ysk.cashier.mybatis.service.impl;
|
package cn.ysk.cashier.mybatis.service.impl;
|
||||||
|
|
||||||
|
import cn.ysk.cashier.dto.shoptable.ReturnOrderDTO;
|
||||||
|
import cn.ysk.cashier.enums.OrderStatusEnums;
|
||||||
import cn.ysk.cashier.mybatis.mapper.TbOrderDetailMapper;
|
import cn.ysk.cashier.mybatis.mapper.TbOrderDetailMapper;
|
||||||
import cn.ysk.cashier.mybatis.service.MpOrderDetailService;
|
import cn.ysk.cashier.mybatis.service.MpOrderDetailService;
|
||||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (TbShopPermission)表服务实现类
|
* (TbShopPermission)表服务实现类
|
||||||
*
|
*
|
||||||
|
|
@ -14,6 +19,16 @@ import org.springframework.stereotype.Service;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class MpOrderDetailServiceImpl extends ServiceImpl<TbOrderDetailMapper, TbOrderDetail> implements MpOrderDetailService {
|
public class MpOrderDetailServiceImpl extends ServiceImpl<TbOrderDetailMapper, TbOrderDetail> implements MpOrderDetailService {
|
||||||
|
@Override
|
||||||
|
public boolean updateStatusByOrderIdAndIds(OrderStatusEnums oldOrderStatusEnums, OrderStatusEnums orderStatusEnums, Integer orderId, List<Integer> orderDetails) {
|
||||||
|
LambdaUpdateWrapper<TbOrderDetail> wrapper = new LambdaUpdateWrapper<TbOrderDetail>()
|
||||||
|
.eq(TbOrderDetail::getOrderId, orderId)
|
||||||
|
.in(TbOrderDetail::getId, orderDetails)
|
||||||
|
.set(TbOrderDetail::getStatus, orderStatusEnums.getValue());
|
||||||
|
if (oldOrderStatusEnums != null) {
|
||||||
|
wrapper.eq(TbOrderDetail::getStatus, oldOrderStatusEnums.getValue());
|
||||||
|
}
|
||||||
|
return update(wrapper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ public class TbFreeDineServiceImpl implements TbFreeDineService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StrUtil.isNotBlank(freeDineConfig.getUseType())) {
|
if (StrUtil.isNotBlank(freeDineConfig.getUseType())) {
|
||||||
freeDineConfig.setUseTypeList(JSONObject.parseArray(freeDineConfig.getUseType()).toJavaList(String.class));
|
freeDineConfig.setUseTypeList(JSONObject.parseArray(freeDineConfig.getUseType()).toJavaList(String.class ));
|
||||||
}
|
}
|
||||||
return freeDineConfig;
|
return freeDineConfig;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
private final TbProducSkutMapper producSkutMapper;
|
private final TbProducSkutMapper producSkutMapper;
|
||||||
private final RabbitTemplate rabbitTemplate;
|
private final RabbitTemplate rabbitTemplate;
|
||||||
private final TbShopInfoRepository shopInfoRepository;
|
private final TbShopInfoRepository shopInfoRepository;
|
||||||
private final TbShopOpenIdMapper shopOpenIdMapper;
|
|
||||||
private final WxMsgUtils wxMsgUtils;
|
private final WxMsgUtils wxMsgUtils;
|
||||||
private final TbShopPayTypeRepository payTypeRepository;
|
private final TbShopPayTypeRepository payTypeRepository;
|
||||||
private final MpShopTableMapper mpShopTableMapper;
|
private final MpShopTableMapper mpShopTableMapper;
|
||||||
|
|
@ -97,8 +96,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
private final MpShopTableService mpShopTableService;
|
private final MpShopTableService mpShopTableService;
|
||||||
private final MpShopUnitMapper mpShopUnitMapper;
|
private final MpShopUnitMapper mpShopUnitMapper;
|
||||||
private final MpProductStockDetailMapper mpProductStockDetailMapper;
|
private final MpProductStockDetailMapper mpProductStockDetailMapper;
|
||||||
@Value("${thirdPay.payType}")
|
|
||||||
private String thirdPayType;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1999,18 +1996,36 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
.eq(TbOrderDetail::getStatus, "closed")
|
.eq(TbOrderDetail::getStatus, "closed")
|
||||||
.eq(TbOrderDetail::getOrderId, returnOrderDTO.getOrderId())
|
.eq(TbOrderDetail::getOrderId, returnOrderDTO.getOrderId())
|
||||||
.in(TbOrderDetail::getId, detailIds));
|
.in(TbOrderDetail::getId, detailIds));
|
||||||
if (detailIds.size() != returnOrderDTO.getOrderDetails().size()) {
|
if (detailList.size() != returnOrderDTO.getOrderDetails().size()) {
|
||||||
throw new BadRequestException("订单明细数量不一致");
|
throw new BadRequestException("订单明细数量不一致");
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal returnAmount = BigDecimal.ZERO;
|
BigDecimal returnAmount = BigDecimal.ZERO;
|
||||||
BigDecimal packAMount = BigDecimal.ZERO;
|
BigDecimal packAMount = BigDecimal.ZERO;
|
||||||
BigDecimal saleAmount = BigDecimal.ZERO;
|
BigDecimal saleAmount = BigDecimal.ZERO;
|
||||||
|
ArrayList<TbOrderDetail> remainOrderDetailList = new ArrayList<>();
|
||||||
List<TbOrderDetail> returnDetail = new ArrayList<>();
|
|
||||||
|
|
||||||
for (TbOrderDetail orderDetail : detailList) {
|
for (TbOrderDetail orderDetail : detailList) {
|
||||||
Integer returnNum = returnNumMap.get(orderDetail.getId().toString());
|
Integer returnNum = returnNumMap.get(orderDetail.getId().toString());
|
||||||
|
int remainNum = orderDetail.getNum() - returnNum;
|
||||||
|
if (remainNum < 0) {
|
||||||
|
throw new BadRequestException("{}最多可退数量为: {}", orderDetail.getProductName(), orderDetail.getNum());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将未退款的剩余订单详情重新生成记录
|
||||||
|
BigDecimal packFee = orderDetail.getPackAmount().divide(BigDecimal.valueOf(orderDetail.getNum()), RoundingMode.HALF_UP);
|
||||||
|
if (remainNum > 0) {
|
||||||
|
// 单个打包费
|
||||||
|
BigDecimal remainPackFee = packFee.multiply(BigDecimal.valueOf(remainNum));
|
||||||
|
TbOrderDetail remainOrderDetail = BeanUtil.copyProperties(orderDetail, TbOrderDetail.class);
|
||||||
|
remainOrderDetail.setNum(remainNum);
|
||||||
|
remainOrderDetail.setPriceAmount(BigDecimal.valueOf(remainNum).multiply(orderDetail.getPrice())
|
||||||
|
.add(remainPackFee));
|
||||||
|
remainOrderDetail.setPackAmount(remainPackFee);
|
||||||
|
remainOrderDetail.setReturnNum("0");
|
||||||
|
remainOrderDetail.setId(null);
|
||||||
|
remainOrderDetailList.add(remainOrderDetail);
|
||||||
|
}
|
||||||
|
|
||||||
returnAmount = returnAmount.add(orderDetail.getPriceAmount()
|
returnAmount = returnAmount.add(orderDetail.getPriceAmount()
|
||||||
.divide(new BigDecimal(orderDetail.getNum()), 2, RoundingMode.DOWN)
|
.divide(new BigDecimal(orderDetail.getNum()), 2, RoundingMode.DOWN)
|
||||||
.multiply(BigDecimal.valueOf(returnNum)));
|
.multiply(BigDecimal.valueOf(returnNum)));
|
||||||
|
|
@ -2019,10 +2034,20 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
.divide(new BigDecimal(orderDetail.getNum()), 2, RoundingMode.DOWN)
|
.divide(new BigDecimal(orderDetail.getNum()), 2, RoundingMode.DOWN)
|
||||||
.multiply(BigDecimal.valueOf(returnNum)));
|
.multiply(BigDecimal.valueOf(returnNum)));
|
||||||
|
|
||||||
|
BigDecimal returnPackFee = packFee.multiply(BigDecimal.valueOf(returnNum));
|
||||||
|
orderDetail.setNum(returnNum);
|
||||||
|
orderDetail.setPriceAmount(BigDecimal.valueOf(returnNum).multiply(orderDetail.getPrice())
|
||||||
|
.add(returnPackFee));
|
||||||
|
orderDetail.setPackAmount(returnPackFee);
|
||||||
orderDetail.setRefundNumber(returnNum);
|
orderDetail.setRefundNumber(returnNum);
|
||||||
orderDetail.setStatus("refunding");
|
orderDetail.setStatus("refunding");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保存剩余未退款的订单详情
|
||||||
|
if (!remainOrderDetailList.isEmpty()) {
|
||||||
|
mpOrderDetailService.saveBatch(remainOrderDetailList);
|
||||||
|
}
|
||||||
|
|
||||||
String orderNo = generateOrderNumber(isOnline ? "OLRO" : "RO");
|
String orderNo = generateOrderNumber(isOnline ? "OLRO" : "RO");
|
||||||
TbOrderInfo returnOrder = BeanUtil.copyProperties(oldOrderInfo, TbOrderInfo.class);
|
TbOrderInfo returnOrder = BeanUtil.copyProperties(oldOrderInfo, TbOrderInfo.class);
|
||||||
returnOrder.setId(null);
|
returnOrder.setId(null);
|
||||||
|
|
@ -2039,7 +2064,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
orderInfoMapper.insert(returnOrder);
|
orderInfoMapper.insert(returnOrder);
|
||||||
|
|
||||||
updateStockAndRecord(detailList);
|
updateStockAndRecord(detailList);
|
||||||
|
mpOrderDetailService.updateBatchById(detailList);
|
||||||
return returnOrder;
|
return returnOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2084,9 +2109,11 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
public Object returnOrder(ReturnOrderDTO returnOrderDTO) {
|
public Object returnOrder(ReturnOrderDTO returnOrderDTO) {
|
||||||
TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaQueryWrapper<TbOrderInfo>()
|
TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaQueryWrapper<TbOrderInfo>()
|
||||||
.eq(TbOrderInfo::getId, returnOrderDTO.getOrderId())
|
.eq(TbOrderInfo::getId, returnOrderDTO.getOrderId())
|
||||||
.eq(TbOrderInfo::getStatus, "closed"));
|
.in(TbOrderInfo::getStatus, OrderStatusEnums.REFUND.getValue(), OrderStatusEnums.CLOSED.getValue())
|
||||||
|
// .eq(TbOrderInfo::getStatus, "closed")
|
||||||
|
);
|
||||||
if (orderInfo == null) {
|
if (orderInfo == null) {
|
||||||
throw new BadRequestException("订单非完单状态");
|
throw new BadRequestException("订单不处于可退款状态");
|
||||||
}
|
}
|
||||||
|
|
||||||
TbShopInfo shopInfo = mpShopInfoMapper.selectById(orderInfo.getShopId());
|
TbShopInfo shopInfo = mpShopInfoMapper.selectById(orderInfo.getShopId());
|
||||||
|
|
@ -2112,8 +2139,12 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
} else if ("deposit".equals(payType)) {
|
} else if ("deposit".equals(payType)) {
|
||||||
orderInfoService.depositReturn(Integer.valueOf(orderInfo.getUserId()), Integer.valueOf(orderInfo.getShopId()), returnOrderInfo.getRefundAmount());
|
orderInfoService.depositReturn(Integer.valueOf(orderInfo.getUserId()), Integer.valueOf(orderInfo.getShopId()), returnOrderInfo.getRefundAmount());
|
||||||
orderInfo.setStatus("refund");
|
orderInfo.setStatus("refund");
|
||||||
|
mpOrderDetailService.updateStatusByOrderIdAndIds(OrderStatusEnums.REFUNDING, OrderStatusEnums.REFUND,
|
||||||
|
returnOrderDTO.getOrderId(), returnOrderDTO.getOrderDetails().stream().map(ReturnOrderDTO.OrderDetail::getId).collect(Collectors.toList()));
|
||||||
} else if ("cash".equals(payType)) {
|
} else if ("cash".equals(payType)) {
|
||||||
orderInfo.setStatus("refund");
|
orderInfo.setStatus("refund");
|
||||||
|
mpOrderDetailService.updateStatusByOrderIdAndIds(OrderStatusEnums.REFUNDING, OrderStatusEnums.REFUND,
|
||||||
|
returnOrderDTO.getOrderId(), returnOrderDTO.getOrderDetails().stream().map(ReturnOrderDTO.OrderDetail::getId).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
orderInfoMapper.updateById(orderInfo);
|
orderInfoMapper.updateById(orderInfo);
|
||||||
// 打印退款小票
|
// 打印退款小票
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue