挂账接口
This commit is contained in:
@@ -2,6 +2,7 @@ package com.czg.controller.admin;
|
||||
|
||||
import com.czg.log.annotation.OperationLog;
|
||||
import com.czg.order.dto.CreditBuyerDTO;
|
||||
import com.czg.order.entity.CreditBuyer;
|
||||
import com.czg.order.param.CreditBuyerQueryParam;
|
||||
import com.czg.order.param.CreditBuyerRepaymentParam;
|
||||
import com.czg.order.service.CreditBuyerService;
|
||||
@@ -43,10 +44,9 @@ public class CreditBuyerController {
|
||||
@GetMapping("{id}")
|
||||
@OperationLog("挂账人-详情")
|
||||
//@SaAdminCheckPermission("creditBuyer:info")
|
||||
public CzgResult<CreditBuyerDTO> getCreditBuyerById(@PathVariable("id") String id) {
|
||||
public CzgResult<CreditBuyer> getCreditBuyerById(@PathVariable("id") String id) {
|
||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||
CreditBuyerDTO data = creditBuyerService.getCreditBuyerById(id);
|
||||
return CzgResult.success(data);
|
||||
return CzgResult.success(creditBuyerService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +55,7 @@ public class CreditBuyerController {
|
||||
@PostMapping
|
||||
@OperationLog("挂账人-新增")
|
||||
//@SaAdminCheckPermission("creditBuyer:add")
|
||||
public CzgResult<Void> addCreditBuyer(@RequestBody CreditBuyerDTO dto) {
|
||||
public CzgResult<Void> addCreditBuyer(@RequestBody CreditBuyer dto) {
|
||||
creditBuyerService.addCreditBuyer(dto);
|
||||
return CzgResult.success();
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class CreditBuyerController {
|
||||
@PutMapping
|
||||
@OperationLog("挂账人-修改")
|
||||
//@SaAdminCheckPermission("creditBuyer:update")
|
||||
public CzgResult<Void> updateCreditBuyer(@RequestBody CreditBuyerDTO dto) {
|
||||
public CzgResult<Void> updateCreditBuyer(@RequestBody CreditBuyer dto) {
|
||||
creditBuyerService.updateCreditBuyer(dto);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@@ -76,4 +76,14 @@ public class CreditBuyer implements Serializable {
|
||||
* 删除标志 0-正常 1-删除
|
||||
*/
|
||||
private Integer isDel;
|
||||
/**
|
||||
* 还款提醒日 最大28
|
||||
*/
|
||||
private Integer expireRemindDay;
|
||||
/**
|
||||
* 还款提醒 提醒多久以前的数据 暂定单位 月
|
||||
*/
|
||||
private Integer expireRemind;
|
||||
|
||||
|
||||
}
|
||||
@@ -36,10 +36,18 @@ public class CreditBuyerOrder implements Serializable {
|
||||
* 挂账人编码
|
||||
*/
|
||||
private String creditBuyerId;
|
||||
/**
|
||||
* 订单金额
|
||||
*/
|
||||
private BigDecimal orderAmount;
|
||||
/**
|
||||
* 已付金额
|
||||
*/
|
||||
private BigDecimal paidAmount;
|
||||
/**
|
||||
* 退款金额
|
||||
*/
|
||||
private BigDecimal refundAmount;
|
||||
/**
|
||||
* 状态 unpaid-未付款 partial-部分支付 paid-已付款
|
||||
*/
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.czg.order.service;
|
||||
import com.czg.order.dto.CreditBuyerOrderDTO;
|
||||
import com.czg.order.entity.CreditBuyerOrder;
|
||||
import com.czg.order.entity.CreditPaymentRecord;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.param.CreditBuyerOrderQueryParam;
|
||||
import com.czg.order.vo.CreditBuyerOrderSummaryVo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
@@ -46,17 +47,7 @@ public interface CreditBuyerOrderService extends IService<CreditBuyerOrder> {
|
||||
* @param creditBuyerId 挂账人id
|
||||
* @param orderId 订单id
|
||||
*/
|
||||
boolean save(String creditBuyerId, Long orderId);
|
||||
|
||||
/**
|
||||
* 挂账人退款(整单退款)
|
||||
*
|
||||
* @param creditBuyerId 挂账人id
|
||||
* @param orderId 订单id
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
boolean refund(String creditBuyerId, Long orderId);
|
||||
boolean save(OrderInfo orderInfo, String creditBuyerId, Long orderId);
|
||||
|
||||
|
||||
/**
|
||||
@@ -67,6 +58,6 @@ public interface CreditBuyerOrderService extends IService<CreditBuyerOrder> {
|
||||
* @param refundAmount 退款金额
|
||||
* @return
|
||||
*/
|
||||
boolean partRefund(String creditBuyerId, Long orderId, BigDecimal refundAmount);
|
||||
boolean partRefund(String creditBuyerId, Long orderId, String orderNo, BigDecimal refundAmount);
|
||||
|
||||
}
|
||||
@@ -17,11 +17,10 @@ import com.mybatisflex.core.service.IService;
|
||||
public interface CreditBuyerService extends IService<CreditBuyer> {
|
||||
Page<CreditBuyerDTO> getCreditBuyerPage(CreditBuyerQueryParam param);
|
||||
|
||||
CreditBuyerDTO getCreditBuyerById(String id);
|
||||
|
||||
void addCreditBuyer(CreditBuyerDTO dto);
|
||||
void addCreditBuyer(CreditBuyer dto);
|
||||
|
||||
void updateCreditBuyer(CreditBuyerDTO dto);
|
||||
void updateCreditBuyer(CreditBuyer dto);
|
||||
|
||||
void deleteCreditBuyer(String id);
|
||||
|
||||
|
||||
@@ -25,14 +25,14 @@ public class CreditBuyerRepaymentVo implements Serializable {
|
||||
* 还款金额
|
||||
*/
|
||||
private BigDecimal repaymentAmount;
|
||||
/**
|
||||
* 支付欠款
|
||||
*/
|
||||
private BigDecimal payAmount;
|
||||
/**
|
||||
* 转存金额
|
||||
*/
|
||||
private BigDecimal rechargeAmount;
|
||||
// /**
|
||||
// * 支付欠款
|
||||
// */
|
||||
// private BigDecimal payAmount;
|
||||
// /**
|
||||
// * 转存金额
|
||||
// */
|
||||
// private BigDecimal rechargeAmount;
|
||||
/**
|
||||
* 还款反馈消息
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,6 @@ import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.constants.SystemConstants;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.order.dto.CreditBuyerDTO;
|
||||
import com.czg.order.dto.CreditBuyerOrderDTO;
|
||||
import com.czg.order.entity.CreditBuyer;
|
||||
import com.czg.order.entity.CreditBuyerOrder;
|
||||
@@ -20,7 +19,6 @@ import com.czg.order.vo.CreditBuyerOrderSummaryVo;
|
||||
import com.czg.service.order.mapper.CreditBuyerMapper;
|
||||
import com.czg.service.order.mapper.CreditBuyerOrderMapper;
|
||||
import com.czg.service.order.mapper.CreditPaymentRecordMapper;
|
||||
import com.czg.service.market.mapper.OrderInfoMapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
@@ -53,8 +51,6 @@ public class CreditBuyerOrderServiceImpl extends ServiceImpl<CreditBuyerOrderMap
|
||||
@Resource
|
||||
@Lazy
|
||||
private CreditBuyerService creditBuyerService;
|
||||
@Resource
|
||||
private OrderInfoMapper orderInfoMapper;
|
||||
|
||||
@Override
|
||||
public Page<CreditBuyerOrderDTO> getCreditBuyerOrderPage(CreditBuyerOrderQueryParam param) {
|
||||
@@ -140,11 +136,11 @@ public class CreditBuyerOrderServiceImpl extends ServiceImpl<CreditBuyerOrderMap
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean save(String creditBuyerId, Long orderId) {
|
||||
public boolean save(OrderInfo orderInfo, String creditBuyerId, Long orderId) {
|
||||
if (StrUtil.isBlank(creditBuyerId)) {
|
||||
throw new CzgException("挂账人id不能为空");
|
||||
}
|
||||
CreditBuyerDTO creditBuyer = creditBuyerService.getCreditBuyerById(creditBuyerId);
|
||||
CreditBuyer creditBuyer = creditBuyerService.getById(creditBuyerId);
|
||||
if (creditBuyer == null) {
|
||||
throw new CzgException("挂账人不存在");
|
||||
}
|
||||
@@ -156,84 +152,47 @@ public class CreditBuyerOrderServiceImpl extends ServiceImpl<CreditBuyerOrderMap
|
||||
if (status != null && status == SystemConstants.OneZero.ZERO) {
|
||||
throw new CzgException("挂账人已被停用");
|
||||
}
|
||||
OrderInfo orderInfo = orderInfoMapper.selectOneById(orderId);
|
||||
if (orderInfo == null) {
|
||||
throw new CzgException("订单不存在");
|
||||
}
|
||||
// 账户余额
|
||||
BigDecimal accountBalance = creditBuyer.getAccountBalance();
|
||||
// 如果有余额的话,从余额里面扣除,没有余额的话,从信用额度里面扣除,余额和信用额度都为0,则不允许挂账,余额+信用额度刚好够支付这笔订单的话需要同时减余额减信用额度
|
||||
if (NumberUtil.isGreaterOrEqual(accountBalance, orderInfo.getOrderAmount())) {
|
||||
// 减余额
|
||||
creditBuyer.setAccountBalance(NumberUtil.sub(accountBalance, orderInfo.getOrderAmount()));
|
||||
CreditBuyer dbRecord = BeanUtil.copyProperties(creditBuyer, CreditBuyer.class);
|
||||
creditBuyerMapper.update(dbRecord);
|
||||
// 记录还款记录
|
||||
CreditPaymentRecord record = new CreditPaymentRecord();
|
||||
record.setCreditBuyerId(creditBuyerId);
|
||||
record.setOrderId(orderId);
|
||||
record.setRepaymentAmount(orderInfo.getOrderAmount());
|
||||
record.setPaymentMethod("余额支付");
|
||||
record.setPaymentTime(LocalDateTime.now());
|
||||
record.setRemark("挂账时余额充足,直接从余额扣除");
|
||||
creditPaymentRecordMapper.insert(record);
|
||||
CreditBuyerOrder entity = new CreditBuyerOrder();
|
||||
entity.setCreditBuyerId(creditBuyerId);
|
||||
entity.setOrderId(orderId);
|
||||
boolean greater = NumberUtil.isGreater(orderInfo.getOrderAmount(), accountBalance);
|
||||
if (greater) {
|
||||
throw new CzgException(StrUtil.format("剩余可挂账金额{} ,不足{}元", accountBalance, orderInfo.getOrderAmount()));
|
||||
}
|
||||
// 减余额
|
||||
creditBuyer.setAccountBalance(NumberUtil.sub(accountBalance, orderInfo.getOrderAmount()));
|
||||
CreditBuyer upCreditBuyer = new CreditBuyer();
|
||||
upCreditBuyer.setId(creditBuyerId);
|
||||
upCreditBuyer.setAccountBalance(creditBuyer.getAccountBalance());
|
||||
creditBuyerMapper.update(upCreditBuyer);
|
||||
|
||||
CreditBuyerOrder entity = new CreditBuyerOrder();
|
||||
entity.setCreditBuyerId(creditBuyerId);
|
||||
entity.setOrderId(orderId);
|
||||
entity.setOrderAmount(orderInfo.getOrderAmount());
|
||||
//减去订单金额 余额仍大于挂账额度 则全额付款
|
||||
if (NumberUtil.isGreaterOrEqual(creditBuyer.getAccountBalance(), creditBuyer.getCreditAmount())) {
|
||||
entity.setPaidAmount(orderInfo.getOrderAmount());
|
||||
entity.setStatus("paid");
|
||||
entity.setLastPaymentTime(LocalDateTime.now());
|
||||
entity.setLastPaymentMethod(record.getPaymentMethod());
|
||||
entity.setRemark(record.getRemark());
|
||||
return super.save(entity);
|
||||
} else {
|
||||
if(NumberUtil.isGreater(accountBalance, creditBuyer.getCreditAmount())){
|
||||
entity.setStatus("partial");
|
||||
entity.setPaidAmount(NumberUtil.sub(accountBalance, creditBuyer.getCreditAmount()));
|
||||
}else {
|
||||
entity.setStatus("unpaid");
|
||||
entity.setPaidAmount(BigDecimal.ZERO);
|
||||
}
|
||||
}
|
||||
CreditBuyerOrder entity = null;
|
||||
if (NumberUtil.isGreater(accountBalance, BigDecimal.ZERO)) {
|
||||
// 减余额
|
||||
creditBuyer.setAccountBalance(BigDecimal.ZERO);
|
||||
CreditBuyer dbRecord = BeanUtil.copyProperties(creditBuyer, CreditBuyer.class);
|
||||
creditBuyerMapper.update(dbRecord);
|
||||
// 记录还款记录
|
||||
CreditPaymentRecord record = new CreditPaymentRecord();
|
||||
record.setCreditBuyerId(creditBuyerId);
|
||||
record.setOrderId(orderId);
|
||||
record.setRepaymentAmount(accountBalance);
|
||||
record.setPaymentMethod("余额支付");
|
||||
record.setPaymentTime(LocalDateTime.now());
|
||||
record.setRemark("挂账时余额不足,先扣除现有余额,其他的从挂账额度中扣除");
|
||||
creditPaymentRecordMapper.insert(record);
|
||||
entity = new CreditBuyerOrder();
|
||||
entity.setCreditBuyerId(creditBuyerId);
|
||||
entity.setOrderId(orderId);
|
||||
entity.setPaidAmount(accountBalance);
|
||||
entity.setStatus("partial");
|
||||
entity.setLastPaymentTime(LocalDateTime.now());
|
||||
entity.setLastPaymentMethod(record.getPaymentMethod());
|
||||
entity.setRemark(record.getRemark());
|
||||
//super.save(entity);
|
||||
orderInfo.setPayAmount(NumberUtil.sub(orderInfo.getOrderAmount(), accountBalance));
|
||||
}
|
||||
// 剩余挂账额度
|
||||
BigDecimal remainingAmount = creditBuyer.getRemainingAmount();
|
||||
// 验证挂账金额是否大于剩余额度
|
||||
boolean greater = NumberUtil.isGreater(orderInfo.getOrderAmount(), remainingAmount);
|
||||
if (greater) {
|
||||
throw new CzgException(StrUtil.format("{}:¥{}不能大于剩余挂账额度({})", "挂账金额", orderInfo.getOrderAmount(), remainingAmount));
|
||||
}
|
||||
if (entity == null) {
|
||||
entity = new CreditBuyerOrder();
|
||||
entity.setStatus("unpaid");
|
||||
entity.setPaidAmount(BigDecimal.ZERO);
|
||||
entity.setCreditBuyerId(creditBuyerId);
|
||||
entity.setOrderId(orderId);
|
||||
}
|
||||
return super.saveOrUpdate(entity);
|
||||
entity.setRefundAmount(BigDecimal.ZERO);
|
||||
entity.setLastPaymentTime(LocalDateTime.now());
|
||||
return save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean refund(String creditBuyerId, Long orderId) {
|
||||
public boolean partRefund(String creditBuyerId, Long orderId, String orderNo, BigDecimal refundAmount) {
|
||||
if (StrUtil.isBlank(creditBuyerId)) {
|
||||
throw new CzgException("挂账人id不能为空");
|
||||
}
|
||||
@@ -241,66 +200,12 @@ public class CreditBuyerOrderServiceImpl extends ServiceImpl<CreditBuyerOrderMap
|
||||
if (creditBuyer == null) {
|
||||
throw new CzgException("挂账人不存在");
|
||||
}
|
||||
OrderInfo orderInfo = orderInfoMapper.selectOneById(orderId);
|
||||
if (orderInfo == null) {
|
||||
throw new CzgException("订单不存在");
|
||||
}
|
||||
|
||||
CreditBuyerOrderQueryParam param = new CreditBuyerOrderQueryParam();
|
||||
param.setCreditBuyerId(creditBuyerId);
|
||||
param.setOrderId(Convert.toStr(orderId));
|
||||
CreditBuyerOrderDTO dto = super.mapper.getOne(param);
|
||||
if (dto == null) {
|
||||
throw new CzgException("挂账订单不存在");
|
||||
}
|
||||
// 1.只挂账未还款的情况,直接删除挂账订单
|
||||
if ("unpaid".equals(dto.getStatus())) {
|
||||
super.mapper.deleteById(dto.getId());
|
||||
return true;
|
||||
}
|
||||
// 2.部分还款/已还款,删除挂账订单+红冲还款记录,并把已还款金额退回余额或挂账额度
|
||||
if ("partial".equals(dto.getStatus()) || "paid".equals(dto.getStatus())) {
|
||||
// 已还款金额
|
||||
BigDecimal paidAmount = dto.getPaidAmount();
|
||||
// 已还款金额进行红冲
|
||||
CreditPaymentRecord record = new CreditPaymentRecord();
|
||||
record.setCreditBuyerId(creditBuyerId);
|
||||
record.setOrderId(orderId);
|
||||
record.setRepaymentAmount(NumberUtil.sub(BigDecimal.ZERO, paidAmount));
|
||||
record.setPaymentMethod("挂账退款");
|
||||
record.setPaymentTime(LocalDateTime.now());
|
||||
record.setRemark(StrUtil.format("挂账订单:{}申请退款,已归还挂账额度或账户余额", orderInfo.getOrderNo()));
|
||||
creditPaymentRecordMapper.insert(record);
|
||||
// 删除挂账订单,恢复挂账额度
|
||||
super.mapper.deleteById(dto.getId());
|
||||
// 退回余额
|
||||
creditBuyer.setAccountBalance(NumberUtil.add(creditBuyer.getAccountBalance(), paidAmount));
|
||||
creditBuyerService.updateById(creditBuyer);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean partRefund(String creditBuyerId, Long orderId, BigDecimal refundAmount) {
|
||||
if (StrUtil.isBlank(creditBuyerId)) {
|
||||
throw new CzgException("挂账人id不能为空");
|
||||
}
|
||||
CreditBuyerDTO creditBuyer = creditBuyerService.getCreditBuyerById(creditBuyerId);
|
||||
if (creditBuyer == null) {
|
||||
throw new CzgException("挂账人不存在");
|
||||
}
|
||||
OrderInfo orderInfo = orderInfoMapper.selectOneById(orderId);
|
||||
if (orderInfo == null) {
|
||||
throw new CzgException("订单不存在");
|
||||
}
|
||||
|
||||
CreditBuyerOrderQueryParam param = new CreditBuyerOrderQueryParam();
|
||||
param.setCreditBuyerId(creditBuyerId);
|
||||
param.setOrderId(Convert.toStr(orderId));
|
||||
CreditBuyerOrderDTO dto = mapper.getOne(param);
|
||||
if (dto == null) {
|
||||
CreditBuyerOrder creditBuyerOrder = getOne(query().eq(CreditBuyerOrder::getCreditBuyerId, creditBuyerId).eq(CreditBuyerOrder::getOrderId, orderId));
|
||||
if (creditBuyerOrder == null) {
|
||||
throw new CzgException("挂账订单不存在");
|
||||
}
|
||||
// 已还款金额进行红冲
|
||||
@@ -310,10 +215,10 @@ public class CreditBuyerOrderServiceImpl extends ServiceImpl<CreditBuyerOrderMap
|
||||
record.setRepaymentAmount(NumberUtil.sub(BigDecimal.ZERO, refundAmount));
|
||||
record.setPaymentMethod("挂账退款");
|
||||
record.setPaymentTime(LocalDateTime.now());
|
||||
record.setRemark(StrUtil.format("挂账订单:{},申请退款¥{}元,已恢复挂账额度。", orderInfo.getOrderNo(), refundAmount));
|
||||
record.setRemark(StrUtil.format("挂账订单:{},申请退款¥{}元,已恢复挂账额度。", orderNo, refundAmount));
|
||||
creditPaymentRecordMapper.insert(record);
|
||||
dto = mapper.getOne(param);
|
||||
BigDecimal sub = NumberUtil.sub(refundAmount, dto.getUnpaidAmount());
|
||||
//退款金额减去 待支付金额
|
||||
BigDecimal sub = NumberUtil.sub(refundAmount, NumberUtil.sub(creditBuyerOrder.getOrderAmount(), creditBuyerOrder.getPaidAmount()));
|
||||
if (NumberUtil.isGreater(sub, BigDecimal.ZERO)) {
|
||||
CreditPaymentRecord flow = new CreditPaymentRecord();
|
||||
flow.setCreditBuyerId(creditBuyerId);
|
||||
@@ -321,16 +226,24 @@ public class CreditBuyerOrderServiceImpl extends ServiceImpl<CreditBuyerOrderMap
|
||||
flow.setRepaymentAmount(sub);
|
||||
flow.setPaymentMethod("转储余额");
|
||||
flow.setPaymentTime(LocalDateTime.now());
|
||||
flow.setRemark(StrUtil.format("挂账订单:{},申请退款¥{}元,由于此挂账订单已提前还款,溢出部分¥{}元将转储至账户余额。", orderInfo.getOrderNo(), refundAmount, sub));
|
||||
flow.setRemark(StrUtil.format("挂账订单:{},申请退款¥{}元,由于此挂账订单已提前还款,溢出部分¥{}元将转储至账户余额。", orderNo, refundAmount, sub));
|
||||
creditPaymentRecordMapper.insert(flow);
|
||||
UpdateChain.of(CreditBuyerOrder.class)
|
||||
.set(CreditBuyerOrder::getPaidAmount, NumberUtil.sub(dto.getPaidAmount(), sub))
|
||||
.eq(CreditBuyerOrder::getId, dto.getId())
|
||||
.set(CreditBuyerOrder::getPaidAmount, NumberUtil.sub(creditBuyerOrder.getPaidAmount(), sub))
|
||||
.set(CreditBuyerOrder::getRefundAmount, NumberUtil.add(creditBuyerOrder.getRefundAmount(), sub))
|
||||
.eq(CreditBuyerOrder::getId, creditBuyerOrder.getId())
|
||||
.update();
|
||||
// 退回余额
|
||||
creditBuyer.setAccountBalance(NumberUtil.add(creditBuyer.getAccountBalance(), sub));
|
||||
CreditBuyer entity = BeanUtil.copyProperties(dto, CreditBuyer.class);
|
||||
CreditBuyer entity = new CreditBuyer();
|
||||
entity.setId(creditBuyer.getId());
|
||||
entity.setAccountBalance(creditBuyer.getAccountBalance());
|
||||
creditBuyerService.updateById(entity);
|
||||
} else {
|
||||
UpdateChain.of(CreditBuyerOrder.class)
|
||||
.set(CreditBuyerOrder::getRefundAmount, NumberUtil.add(creditBuyerOrder.getRefundAmount(), sub))
|
||||
.eq(CreditBuyerOrder::getId, creditBuyerOrder.getId())
|
||||
.update();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class CreditBuyerServiceImpl extends ServiceImpl<CreditBuyerMapper, Credi
|
||||
return PageUtil.convert(pageInfo);
|
||||
}
|
||||
|
||||
private void commonVerify(CreditBuyerDTO dto) {
|
||||
private void commonVerify(CreditBuyer dto) {
|
||||
try {
|
||||
Assert.notNull(dto.getShopId(), "{}({})不能为空", "店铺id", "shopId");
|
||||
Assert.notNull(dto.getStatus(), "{}({})不能为空", "状态", "status");
|
||||
@@ -83,21 +83,9 @@ public class CreditBuyerServiceImpl extends ServiceImpl<CreditBuyerMapper, Credi
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreditBuyerDTO getCreditBuyerById(String id) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
CreditBuyerQueryParam param = new CreditBuyerQueryParam();
|
||||
param.setId(id);
|
||||
param.setShopId(shopId);
|
||||
List<CreditBuyerDTO> list = super.mapper.findCreditBuyerList(param);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return null;
|
||||
}
|
||||
return list.getFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCreditBuyer(CreditBuyerDTO dto) {
|
||||
public void addCreditBuyer(CreditBuyer dto) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
dto.setShopId(shopId);
|
||||
commonVerify(dto);
|
||||
@@ -109,13 +97,13 @@ public class CreditBuyerServiceImpl extends ServiceImpl<CreditBuyerMapper, Credi
|
||||
if (!ArrayUtil.contains(new String[]{"total", "order"}, dto.getRepaymentMethod())) {
|
||||
throw new CzgException(StrUtil.format("{}({})不合法", "还款方式", "repaymentMethod"));
|
||||
}
|
||||
dto.setAccountBalance(BigDecimal.ZERO);
|
||||
dto.setAccountBalance(dto.getCreditAmount());
|
||||
CreditBuyer entity = BeanUtil.copyProperties(dto, CreditBuyer.class);
|
||||
super.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCreditBuyer(CreditBuyerDTO dto) {
|
||||
public void updateCreditBuyer(CreditBuyer dto) {
|
||||
try {
|
||||
Assert.notEmpty(dto.getId(), "{}不能为空", "id");
|
||||
} catch (IllegalArgumentException e) {
|
||||
@@ -128,18 +116,27 @@ public class CreditBuyerServiceImpl extends ServiceImpl<CreditBuyerMapper, Credi
|
||||
if (entity == null) {
|
||||
throw new CzgException("挂账人不存在");
|
||||
}
|
||||
CreditBuyerDTO record = getCreditBuyerById(dto.getId());
|
||||
// 验证挂账额度是否小于已挂账金额
|
||||
boolean less = NumberUtil.isLess(dto.getCreditAmount(), NumberUtil.nullToZero(record.getOwedAmount()));
|
||||
if (less) {
|
||||
throw new CzgException(StrUtil.format("{}({})不能小于已挂账金额({})", "挂账额度", "creditAmount", record.getOwedAmount()));
|
||||
//余额减去挂账金额 100 60 挂账40 修改后 如果是 80
|
||||
BigDecimal sub = NumberUtil.sub(dto.getCreditAmount(), entity.getCreditAmount());
|
||||
//修改后的余额
|
||||
BigDecimal balance = NumberUtil.add(entity.getAccountBalance(), sub);
|
||||
if (NumberUtil.isLess(balance, BigDecimal.ZERO)) {
|
||||
throw new CzgException("挂账额度不能小于已挂账金额");
|
||||
}
|
||||
BeanUtil.copyProperties(dto, entity, CopyOptions.create().setIgnoreNullValue(false).setIgnoreProperties("repaymentMethod", "accountBalance"));
|
||||
super.updateById(entity);
|
||||
entity.setAccountBalance(balance);
|
||||
updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCreditBuyer(String id) {
|
||||
CreditBuyer entity = getById(id);
|
||||
if (entity == null) {
|
||||
throw new CzgException("挂账人不存在");
|
||||
}
|
||||
if (NumberUtil.isLess(entity.getAccountBalance(), entity.getCreditAmount())) {
|
||||
throw new CzgException("删除失败,有未还款挂账金额。");
|
||||
}
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
UpdateChain.of(CreditBuyer.class)
|
||||
.set(CreditBuyer::getIsDel, SystemConstants.OneZero.ONE)
|
||||
@@ -160,7 +157,7 @@ public class CreditBuyerServiceImpl extends ServiceImpl<CreditBuyerMapper, Credi
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new CzgException(e.getMessage());
|
||||
}
|
||||
CreditBuyerDTO dto = getCreditBuyerById(param.getId());
|
||||
CreditBuyer dto = getById(param.getId());
|
||||
if (dto == null) {
|
||||
throw new CzgException("挂账人不存在");
|
||||
}
|
||||
@@ -174,44 +171,28 @@ public class CreditBuyerServiceImpl extends ServiceImpl<CreditBuyerMapper, Credi
|
||||
if (NumberUtil.isLess(repaymentAmount, BigDecimal.ZERO)) {
|
||||
throw new CzgException("还款金额不能小于0");
|
||||
}
|
||||
BigDecimal initRepaymentAmount = NumberUtil.add(repaymentAmount, BigDecimal.ZERO);
|
||||
// 已挂账金额
|
||||
BigDecimal owedAmount = dto.getOwedAmount();
|
||||
if (NumberUtil.equals(owedAmount, BigDecimal.ZERO)) {
|
||||
dto.setAccountBalance(NumberUtil.add(dto.getAccountBalance(), repaymentAmount));
|
||||
CreditBuyer entity = BeanUtil.copyProperties(dto, CreditBuyer.class);
|
||||
super.updateById(entity);
|
||||
CreditPaymentRecord record = new CreditPaymentRecord();
|
||||
record.setCreditBuyerId(param.getId());
|
||||
record.setRepaymentAmount(repaymentAmount);
|
||||
record.setPaymentMethod(param.getPaymentMethod());
|
||||
record.setPaymentTime(LocalDateTime.now());
|
||||
record.setRemark(param.getRemark());
|
||||
creditPaymentRecordMapper.insert(record);
|
||||
|
||||
CreditBuyer upEntity = new CreditBuyer();
|
||||
upEntity.setId(param.getId());
|
||||
upEntity.setAccountBalance(NumberUtil.add(dto.getAccountBalance(), repaymentAmount));
|
||||
super.updateById(upEntity);
|
||||
|
||||
CreditPaymentRecord record2 = new CreditPaymentRecord();
|
||||
record2.setCreditBuyerId(param.getId());
|
||||
record2.setRepaymentAmount(repaymentAmount);
|
||||
record2.setPaymentMethod(param.getPaymentMethod());
|
||||
record2.setPaymentTime(LocalDateTime.now());
|
||||
record2.setRemark(param.getRemark());
|
||||
creditPaymentRecordMapper.insert(record2);
|
||||
if (NumberUtil.isGreaterOrEqual(dto.getAccountBalance(), dto.getCreditAmount())) {
|
||||
CreditBuyerRepaymentVo result = new CreditBuyerRepaymentVo();
|
||||
result.setRepaymentCount(0);
|
||||
result.setRepaymentAmount(repaymentAmount);
|
||||
result.setRepaymentMsg(StrUtil.format("账单无需还款,{}元已转储至余额。", repaymentAmount));
|
||||
result.setRepaymentMsg("账单无需还款,已转储至余额。");
|
||||
return result;
|
||||
}
|
||||
// 转存余额
|
||||
BigDecimal rechargeAmount = BigDecimal.ZERO;
|
||||
if (NumberUtil.isGreater(repaymentAmount, owedAmount)) {
|
||||
rechargeAmount = NumberUtil.sub(repaymentAmount, owedAmount);
|
||||
dto.setAccountBalance(NumberUtil.add(dto.getAccountBalance(), rechargeAmount));
|
||||
CreditBuyer entity = BeanUtil.copyProperties(dto, CreditBuyer.class);
|
||||
super.updateById(entity);
|
||||
CreditPaymentRecord record = new CreditPaymentRecord();
|
||||
record.setCreditBuyerId(param.getId());
|
||||
record.setRepaymentAmount(rechargeAmount);
|
||||
record.setPaymentMethod(param.getPaymentMethod());
|
||||
record.setPaymentTime(LocalDateTime.now());
|
||||
record.setRemark(param.getRemark());
|
||||
creditPaymentRecordMapper.insert(record);
|
||||
}
|
||||
|
||||
// 校验完毕,可以批量还款
|
||||
|
||||
CreditBuyerOrderQueryParam where = new CreditBuyerOrderQueryParam();
|
||||
where.setCreditBuyerId(param.getId());
|
||||
where.setStatusList(List.of("unpaid", "partial"));
|
||||
@@ -271,12 +252,9 @@ public class CreditBuyerServiceImpl extends ServiceImpl<CreditBuyerMapper, Credi
|
||||
}
|
||||
}
|
||||
CreditBuyerRepaymentVo result = new CreditBuyerRepaymentVo();
|
||||
BigDecimal payAmount = NumberUtil.sub(initRepaymentAmount, repaymentAmount);
|
||||
result.setRepaymentCount(repaymentCount);
|
||||
result.setRepaymentAmount(initRepaymentAmount);
|
||||
result.setPayAmount(payAmount);
|
||||
result.setRechargeAmount(rechargeAmount);
|
||||
result.setRepaymentMsg(StrUtil.format("共计还款{}笔,还款金额:{}元,支付欠款:{}元,转存余额:{}元,当前余额:{}元。", repaymentCount, initRepaymentAmount, payAmount, rechargeAmount, dto.getAccountBalance()));
|
||||
result.setRepaymentMsg(StrUtil.format("共计还款{}笔,还款金额:{}元,当前余额:{}元。",
|
||||
repaymentCount, NumberUtil.sub(param.getRepaymentAmount(), repaymentAmount), upEntity.getAccountBalance()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ public class OrderPayServiceImpl implements OrderPayService {
|
||||
orderInfoCustomService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
|
||||
LocalDateTime.now(), null, PayEnums.CREDIT_PAY);
|
||||
//挂账后续逻辑
|
||||
buyerOrderService.save(payParam.getCreditBuyerId().toString(), orderInfo.getId());
|
||||
buyerOrderService.save(orderInfo, payParam.getCreditBuyerId().toString(), orderInfo.getId());
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@@ -498,7 +498,7 @@ public class OrderPayServiceImpl implements OrderPayService {
|
||||
shopUserService.updateMoney(shopUserMoneyEditDTO);
|
||||
} else if (orderInfo.getPayType().equals(PayEnums.CREDIT_PAY.getValue())) {
|
||||
AssertUtil.isNull(orderInfo.getCreditBuyerId(), "挂账单退款失败,未查询到挂账人");
|
||||
buyerOrderService.partRefund(orderInfo.getCreditBuyerId().toString(), orderInfo.getId(), param.getRefundAmount());
|
||||
buyerOrderService.partRefund(orderInfo.getCreditBuyerId().toString(), orderInfo.getId(), orderInfo.getOrderNo(), param.getRefundAmount());
|
||||
} else if (!orderInfo.getPayType().equals(PayEnums.CASH_PAY.getValue())) {
|
||||
//退款 param.getRefundAmount()
|
||||
if (orderInfo.getPayOrderId() == null) {
|
||||
|
||||
Reference in New Issue
Block a user