支持挂账部分退款
This commit is contained in:
@@ -4,6 +4,7 @@ import cn.ysk.cashier.mybatis.entity.TbCreditBuyerOrder;
|
||||
import cn.ysk.cashier.mybatis.entity.TbCreditPaymentRecord;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -27,11 +28,22 @@ public interface TbCreditBuyerOrderService extends IService<TbCreditBuyerOrder>
|
||||
boolean save(String creditBuyerId, Long orderId);
|
||||
|
||||
/**
|
||||
* 挂账人退款
|
||||
* 挂账人退款(整单退款)
|
||||
* @param creditBuyerId 挂账人id
|
||||
* @param orderId 订单id
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
boolean refund(String creditBuyerId, Long orderId);
|
||||
|
||||
|
||||
/**
|
||||
* 挂账人退款(部分退款)
|
||||
* @param creditBuyerId 挂账人id
|
||||
* @param orderId 订单id
|
||||
* @param refundAmount 退款金额
|
||||
* @return
|
||||
*/
|
||||
boolean partRefund(String creditBuyerId, Long orderId, BigDecimal refundAmount);
|
||||
|
||||
}
|
||||
@@ -240,6 +240,7 @@ public class TbCreditBuyerOrderServiceImpl extends ServiceImpl<TbCreditBuyerOrde
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean refund(String creditBuyerId, Long orderId) {
|
||||
if (StrUtil.isBlank(creditBuyerId)) {
|
||||
@@ -289,4 +290,72 @@ public class TbCreditBuyerOrderServiceImpl extends ServiceImpl<TbCreditBuyerOrde
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean partRefund(String creditBuyerId, Long orderId, BigDecimal refundAmount) {
|
||||
if (StrUtil.isBlank(creditBuyerId)) {
|
||||
throw new BadRequestException("挂账人id不能为空");
|
||||
}
|
||||
TbCreditBuyer creditBuyer = tbCreditBuyerService.getById(creditBuyerId);
|
||||
if (creditBuyer == null) {
|
||||
throw new BadRequestException("挂账人不存在");
|
||||
}
|
||||
TbOrderInfo orderInfo = mpOrderInfoService.getById(orderId);
|
||||
if (orderInfo == null) {
|
||||
throw new BadRequestException("订单不存在");
|
||||
}
|
||||
|
||||
Map<String, Object> params = new HashMap<>(2);
|
||||
params.put("creditBuyerId", creditBuyerId);
|
||||
params.put("orderId", orderId);
|
||||
CreditBuyerOrderDTO dto = baseMapper.getOne(params);
|
||||
if (dto == null) {
|
||||
throw new BadRequestException("挂账订单不存在");
|
||||
}
|
||||
// 1.只挂账未还款的情况,直接返回挂账额度
|
||||
if ("unpaid".equals(dto.getStatus())) {
|
||||
// 退回额度
|
||||
creditBuyer.setCreditAmount(NumberUtil.add(creditBuyer.getCreditAmount(), refundAmount));
|
||||
tbCreditBuyerService.updateById(creditBuyer);
|
||||
return true;
|
||||
}
|
||||
// 2.部分还款/已还款,删除挂账订单+红冲还款记录,并把已还款金额退回余额或挂账额度
|
||||
if ("partial".equals(dto.getStatus()) || "paid".equals(dto.getStatus())) {
|
||||
// 已还款金额小于退款金额,需要把已还款金额退回余额
|
||||
if (NumberUtil.isLessOrEqual(dto.getPaidAmount(), refundAmount)) {
|
||||
creditBuyer.setAccountBalance(NumberUtil.add(creditBuyer.getAccountBalance(), dto.getPaidAmount()));
|
||||
// 这部分需要返回到额度
|
||||
BigDecimal subAmount = NumberUtil.sub(refundAmount, dto.getPaidAmount());
|
||||
creditBuyer.setCreditAmount(NumberUtil.add(creditBuyer.getCreditAmount(), subAmount));
|
||||
// 已还款金额进行冲红
|
||||
TbCreditPaymentRecord record = new TbCreditPaymentRecord();
|
||||
record.setCreditBuyerId(creditBuyerId);
|
||||
record.setOrderId(orderId);
|
||||
record.setRepaymentAmount(NumberUtil.sub(BigDecimal.ZERO, dto.getPaidAmount()));
|
||||
record.setPaymentMethod("挂账退款");
|
||||
record.setPaymentTime(new Date());
|
||||
record.setRemark(StrUtil.format("挂账订单:{}申请退款¥{}元,还款部分¥{}元已归还至账户余额,剩余¥{}元已归还至挂账额度。", orderInfo.getOrderNo(), refundAmount, dto.getPaidAmount(), subAmount));
|
||||
record.setCreateTime(new Date());
|
||||
tbCreditPaymentRecordMapper.insert(record);
|
||||
tbCreditBuyerService.updateById(creditBuyer);
|
||||
return true;
|
||||
}
|
||||
// 已还款金额大于退款金额,需要把已还款金额退回余额
|
||||
creditBuyer.setAccountBalance(NumberUtil.add(creditBuyer.getAccountBalance(), refundAmount));
|
||||
// 已还款金额进行冲红
|
||||
TbCreditPaymentRecord record = new TbCreditPaymentRecord();
|
||||
record.setCreditBuyerId(creditBuyerId);
|
||||
record.setOrderId(orderId);
|
||||
record.setRepaymentAmount(NumberUtil.sub(BigDecimal.ZERO, refundAmount));
|
||||
record.setPaymentMethod("挂账退款");
|
||||
record.setPaymentTime(new Date());
|
||||
record.setRemark(StrUtil.format("挂账订单:{}申请退款¥{}元,还款部分¥{}元已归还至账户余额。", orderInfo.getOrderNo(), refundAmount, refundAmount));
|
||||
record.setCreateTime(new Date());
|
||||
tbCreditPaymentRecordMapper.insert(record);
|
||||
tbCreditBuyerService.updateById(creditBuyer);
|
||||
tbCreditBuyerService.updateById(creditBuyer);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package cn.ysk.cashier.pojo.shop;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -299,6 +300,10 @@ public class TbShopInfo implements Serializable {
|
||||
@ApiModelProperty(value = "台桌预订短信")
|
||||
private String bookingSms;
|
||||
|
||||
@Transient
|
||||
@TableField(exist = false)
|
||||
private String registerCode;
|
||||
|
||||
public void copy(TbShopInfo source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
|
||||
@@ -323,6 +323,18 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
|
||||
ValidationUtil.isNull(tbShopInfo.getId(), "TbShopInfo", "id", resources.getId());
|
||||
tbShopInfo.copy(resources);
|
||||
tbShopInfo.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
if (resources.getRegisterCode() != null) {
|
||||
TbMerchantRegister tbMerchantRegister = merchantRegisterRepository.findByRegisterCode(resources.getRegisterCode());
|
||||
if (tbMerchantRegister == null) {
|
||||
throw new BadRequestException("激活码有误");
|
||||
}
|
||||
if (tbMerchantRegister.getStatus() == 1) {
|
||||
throw new BadRequestException("激活码已激活,不能重复绑定");
|
||||
}
|
||||
tbShopInfo.setExpireAt(DateUtil.addMonthsAndGetTimestamp(tbMerchantRegister.getPeriodYear()));
|
||||
//向redis中存入key
|
||||
redisUtils.set(CacheKey.ACT_CODE + resources.getAccount(), "1", tbShopInfo.getExpireAt() - Instant.now().toEpochMilli());
|
||||
}
|
||||
tbShopInfoRepository.save(tbShopInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -2890,11 +2890,12 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||
.eq(TbOrderDetail::getShopId, returnOrderDTO.getShopId())
|
||||
.eq(TbOrderDetail::getStatus, "closed")
|
||||
.eq(TbOrderDetail::getOrderId, returnOrderDTO.getOrderId())
|
||||
.in(TbOrderDetail::getId, detailIds)
|
||||
.orderByDesc(TbOrderDetail::getUserCouponId));
|
||||
|
||||
if (detailList.size() != returnOrderDTO.getOrderDetails().size()) {
|
||||
/*if (detailList.size() != returnOrderDTO.getOrderDetails().size()) {
|
||||
throw new BadRequestException("挂账退款必须全退");
|
||||
}
|
||||
}*/
|
||||
} else {
|
||||
detailList = orderDetailMapper.selectList(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getShopId, returnOrderDTO.getShopId())
|
||||
@@ -3129,7 +3130,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Object returnOrder(ReturnOrderDTO returnOrderDTO) {
|
||||
TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaQueryWrapper<TbOrderInfo>()
|
||||
.eq(TbOrderInfo::getId, returnOrderDTO.getOrderId())
|
||||
@@ -3171,7 +3172,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||
mpOrderDetailService.updateStatusByOrderIdAndIds(OrderStatusEnums.REFUNDING, OrderStatusEnums.REFUND,
|
||||
returnOrderDTO.getOrderId(), returnOrderDTO.getOrderDetails().stream().map(ReturnOrderDTO.OrderDetail::getId).collect(Collectors.toList()));
|
||||
} else if (TableConstant.OrderInfo.PayType.CREDIT_BUYER.equalsVals(payType)) {
|
||||
creditBuyerOrderService.refund(orderInfo.getCreditBuyerId(), Long.valueOf(orderInfo.getId()));
|
||||
creditBuyerOrderService.partRefund(orderInfo.getCreditBuyerId(), Long.valueOf(orderInfo.getId()), returnAmount);
|
||||
}
|
||||
orderInfo.setStatus(TableConstant.OrderInfo.Status.CLOSED.getValue());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user