fix配置pad端菜品bug

This commit is contained in:
谭凯凯 2024-11-28 11:30:57 +08:00 committed by Tankaikai
parent 78a9e5b8ad
commit 15d2e28921
4 changed files with 66 additions and 1 deletions

View File

@ -98,6 +98,9 @@ public class TbCreditBuyer {
@TableField(value = "(select shop_name from tb_shop_info where id = tb_credit_buyer.shop_id)", select = false, insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
private String shopName;
/**
* 剩余挂账额度
*/
public BigDecimal getRemainingAmount() {
return NumberUtil.sub(creditAmount, NumberUtil.null2Zero(owedAmount));
}

View File

@ -26,4 +26,12 @@ public interface TbCreditBuyerOrderService extends IService<TbCreditBuyerOrder>
*/
boolean save(String creditBuyerId, Long orderId);
/**
* 挂账人退款
* @param creditBuyerId 挂账人id
* @param orderId 订单id
* @return
*/
boolean refund(String creditBuyerId, Long orderId);
}

View File

@ -148,6 +148,7 @@ public class TbCreditBuyerOrderServiceImpl extends ServiceImpl<TbCreditBuyerOrde
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean save(String creditBuyerId, Long orderId) {
if (StrUtil.isBlank(creditBuyerId)) {
throw new BadRequestException("挂账人id不能为空");
@ -237,4 +238,55 @@ public class TbCreditBuyerOrderServiceImpl extends ServiceImpl<TbCreditBuyerOrde
}
return super.saveOrUpdate(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean refund(String creditBuyerId, Long orderId) {
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())) {
baseMapper.deleteById(dto.getId());
return true;
}
// 2.部分还款/已还款删除挂账订单+红冲还款记录并把已还款金额退回余额或挂账额度
if ("partial".equals(dto.getStatus()) || "paid".equals(dto.getStatus())) {
// 已还款金额
BigDecimal paidAmount = dto.getPaidAmount();
// 已还款金额进行红冲
TbCreditPaymentRecord record = new TbCreditPaymentRecord();
record.setCreditBuyerId(creditBuyerId);
record.setOrderId(orderId);
record.setRepaymentAmount(NumberUtil.sub(BigDecimal.ZERO, paidAmount));
record.setPaymentMethod("余额支付");
record.setPaymentTime(new Date());
record.setRemark(StrUtil.format("挂账订单:{}退款,已还款金额退回余额或挂账额度", orderInfo.getOrderNo()));
record.setCreateTime(new Date());
tbCreditPaymentRecordMapper.insert(record);
// 删除挂账订单恢复挂账额度
baseMapper.deleteById(dto.getId());
// 退回余额
creditBuyer.setAccountBalance(NumberUtil.add(creditBuyer.getAccountBalance(), paidAmount));
tbCreditBuyerService.updateById(creditBuyer);
return true;
}
return false;
}
}

View File

@ -284,6 +284,7 @@ public class TbShopTableBookingServiceImpl extends ServiceImpl<TbShopTableBookin
public void batchTimeout() {
baseMapper.update(Wrappers.<TbShopTableBooking>lambdaUpdate()
.set(TbShopTableBooking::getStatus, 999)
.set(TbShopTableBooking::getUpdateTime, new Date())
.eq(TbShopTableBooking::getStatus, 20)
.last("and TIMESTAMPDIFF(MINUTE, NOW(), booking_time) >= timeout_minute"));
}
@ -293,6 +294,7 @@ public class TbShopTableBookingServiceImpl extends ServiceImpl<TbShopTableBookin
// 15分钟后自动取消
baseMapper.update(Wrappers.<TbShopTableBooking>lambdaUpdate()
.set(TbShopTableBooking::getStatus, -1)
.set(TbShopTableBooking::getUpdateTime, new Date())
.eq(TbShopTableBooking::getStatus, 999)
.last("and TIMESTAMPDIFF(MINUTE, NOW(), booking_time) >= timeout_minute+15"));
}