支付相关先注释
parent
cea51a8433
commit
713f047aa1
|
|
@ -37,6 +37,11 @@ import com.njzscloud.supervisory.expense.contant.Scope;
|
||||||
import com.njzscloud.supervisory.expense.pojo.entity.ExpenseItemsConfigEntity;
|
import com.njzscloud.supervisory.expense.pojo.entity.ExpenseItemsConfigEntity;
|
||||||
import com.njzscloud.supervisory.expense.service.ExpenseItemsConfigService;
|
import com.njzscloud.supervisory.expense.service.ExpenseItemsConfigService;
|
||||||
import com.njzscloud.supervisory.goods.contant.MoneyStrategy;
|
import com.njzscloud.supervisory.goods.contant.MoneyStrategy;
|
||||||
|
import com.njzscloud.supervisory.money.contant.MoneyChangeCategory;
|
||||||
|
import com.njzscloud.supervisory.money.pojo.entity.MoneyAccountEntity;
|
||||||
|
import com.njzscloud.supervisory.money.pojo.entity.MoneyChangeDetailEntity;
|
||||||
|
import com.njzscloud.supervisory.money.service.MoneyAccountService;
|
||||||
|
import com.njzscloud.supervisory.money.service.MoneyChangeDetailService;
|
||||||
import com.njzscloud.supervisory.order.contant.*;
|
import com.njzscloud.supervisory.order.contant.*;
|
||||||
import com.njzscloud.supervisory.order.mapper.OrderInfoMapper;
|
import com.njzscloud.supervisory.order.mapper.OrderInfoMapper;
|
||||||
import com.njzscloud.supervisory.order.pojo.entity.*;
|
import com.njzscloud.supervisory.order.pojo.entity.*;
|
||||||
|
|
@ -84,6 +89,8 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||||
private final AppProperties appProperties;
|
private final AppProperties appProperties;
|
||||||
private final StationManageService stationManageService;
|
private final StationManageService stationManageService;
|
||||||
private final CloudVoiceboxService cloudVoiceboxService;
|
private final CloudVoiceboxService cloudVoiceboxService;
|
||||||
|
private final MoneyAccountService moneyAccountService;
|
||||||
|
private final MoneyChangeDetailService moneyChangeDetailService;
|
||||||
|
|
||||||
private static void stopTuqiangTrack(String gpsId) {
|
private static void stopTuqiangTrack(String gpsId) {
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
|
|
@ -637,7 +644,7 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||||
Assert.isNull(orderInfo.getDriverId(), () -> Exceptions.clierr("当前订单已分配司机,无需重复分配"));
|
Assert.isNull(orderInfo.getDriverId(), () -> Exceptions.clierr("当前订单已分配司机,无需重复分配"));
|
||||||
Assert.isTrue(orderInfo.getOrderStatus() == OrderStatus.DaiPaiDan, () -> Exceptions.clierr("当前订单状态,无法分配司机"));
|
Assert.isTrue(orderInfo.getOrderStatus() == OrderStatus.DaiPaiDan, () -> Exceptions.clierr("当前订单状态,无法分配司机"));
|
||||||
// 查询订单及相关支付上下文
|
// 查询订单及相关支付上下文
|
||||||
PaymentContextResult ctx = paymentContext(orderInfo.getId());
|
/*PaymentContextResult ctx = paymentContext(orderInfo.getId());
|
||||||
if (PaymentWay.COMPANY.getVal().equals(orderInfo.getPaymentCategory()) &&
|
if (PaymentWay.COMPANY.getVal().equals(orderInfo.getPaymentCategory()) &&
|
||||||
SettlementWay.BALANCE.getVal().equals(ctx.getSettlementWay())) {
|
SettlementWay.BALANCE.getVal().equals(ctx.getSettlementWay())) {
|
||||||
// 当该笔订单支付方式为公司支付,并且支付方式为余额支付时,需在分配之前查询当前清运公司余额是否充足,
|
// 当该笔订单支付方式为公司支付,并且支付方式为余额支付时,需在分配之前查询当前清运公司余额是否充足,
|
||||||
|
|
@ -646,7 +653,7 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||||
// 已经是负数,禁止再次支付
|
// 已经是负数,禁止再次支付
|
||||||
throw Exceptions.clierr("公司账户余额不足");
|
throw Exceptions.clierr("公司账户余额不足");
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
baseMapper.busyDriver(driverId, Boolean.TRUE);
|
baseMapper.busyDriver(driverId, Boolean.TRUE);
|
||||||
|
|
||||||
this.updateById(new OrderInfoEntity()
|
this.updateById(new OrderInfoEntity()
|
||||||
|
|
@ -716,6 +723,10 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||||
Assert.isTrue(orderInfo.getOrderStatus() == OrderStatus.YiJieDan, () -> Exceptions.clierr("当前订单状态,无法开始运输"));
|
Assert.isTrue(orderInfo.getOrderStatus() == OrderStatus.YiJieDan, () -> Exceptions.clierr("当前订单状态,无法开始运输"));
|
||||||
Assert.isTrue(orderInfo.getAuditStatus() == AuditStatus.TongGuo, () -> Exceptions.clierr("当前订单未审核完成,无法开始运输"));
|
Assert.isTrue(orderInfo.getAuditStatus() == AuditStatus.TongGuo, () -> Exceptions.clierr("当前订单未审核完成,无法开始运输"));
|
||||||
Long orderInfoId = orderInfo.getId();
|
Long orderInfoId = orderInfo.getId();
|
||||||
|
|
||||||
|
// 判断支付方式,如果为公司支付,在此处直接扣减
|
||||||
|
// handleCompanyPay(orderInfo);
|
||||||
|
|
||||||
this.updateById(new OrderInfoEntity()
|
this.updateById(new OrderInfoEntity()
|
||||||
.setId(orderInfoId)
|
.setId(orderInfoId)
|
||||||
.setCargoPhoto(startTransportOrderParam.getCargoPhoto())
|
.setCargoPhoto(startTransportOrderParam.getCargoPhoto())
|
||||||
|
|
@ -742,6 +753,54 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handleCompanyPay(OrderInfoEntity orderInfo) {
|
||||||
|
PaymentContextResult ctx = paymentContext(orderInfo.getId());
|
||||||
|
if (PaymentWay.COMPANY.getVal().equals(orderInfo.getPaymentCategory())) {
|
||||||
|
// 验证资金账户信息
|
||||||
|
if (ctx.getCompanyAccountId() == null) {
|
||||||
|
throw Exceptions.clierr("公司资金账户不存在");
|
||||||
|
}
|
||||||
|
// 根据结算方式判断是否需要检查余额
|
||||||
|
if (SettlementWay.BALANCE.getVal().equals(ctx.getSettlementWay())) {
|
||||||
|
// 余额结算:允许本次支付后余额为负数,但仅限于余额首次变为负数
|
||||||
|
if (ctx.getCompanyBalance() == null) {
|
||||||
|
ctx.setCompanyBalance(BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
if (ctx.getCompanyBalance().compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
// 已经是负数,禁止再次支付
|
||||||
|
throw Exceptions.clierr("公司账户余额不足");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal oldBalance = ctx.getCompanyBalance();
|
||||||
|
BigDecimal newBalance = oldBalance.subtract(ctx.getSettleMoney());
|
||||||
|
|
||||||
|
// 更新账户余额(支持负数余额)
|
||||||
|
MoneyAccountEntity companyAccount = new MoneyAccountEntity()
|
||||||
|
.setId(ctx.getCompanyAccountId())
|
||||||
|
.setMoney(newBalance);
|
||||||
|
moneyAccountService.updateById(companyAccount);
|
||||||
|
|
||||||
|
// 记录资金变动明细
|
||||||
|
MoneyChangeDetailEntity changeDetail = new MoneyChangeDetailEntity()
|
||||||
|
.setCompanyId(ctx.getTransCompanyId())
|
||||||
|
.setOrderId(orderInfo.getId())
|
||||||
|
.setMoneyAccountId(companyAccount.getId())
|
||||||
|
.setOldMoney(oldBalance)
|
||||||
|
.setDelta(ctx.getSettleMoney().negate()) // 扣减为负数
|
||||||
|
.setNewMoney(newBalance)
|
||||||
|
.setMoneyChangeCategory(MoneyChangeCategory.DingDanKouKuan)
|
||||||
|
.setMemo("订单支付扣款,订单号:" + orderInfo.getSn() + ",结算方式:" + ctx.getSettlementWay());
|
||||||
|
|
||||||
|
moneyChangeDetailService.save(changeDetail);
|
||||||
|
|
||||||
|
log.info("公司账户扣减成功,用户ID:{},扣减金额:{},余额:{} -> {},结算方式:{}",
|
||||||
|
ctx.getCompanyUserId(), ctx.getSettleMoney(), oldBalance, newBalance, ctx.getSettlementWay());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void orderTimeOut() {
|
public void orderTimeOut() {
|
||||||
log.info("检查超时订单");
|
log.info("检查超时订单");
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,6 @@ public class PaymentController {
|
||||||
throw Exceptions.clierr("公司账户余额不足");
|
throw Exceptions.clierr("公司账户余额不足");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handleCompanyPay(ctx, ctx.getSettleMoney(), paymentParam.getOrderId());
|
|
||||||
|
|
||||||
// 3. 更新订单支付状态为已支付
|
// 3. 更新订单支付状态为已支付
|
||||||
orderInfoService.lambdaUpdate()
|
orderInfoService.lambdaUpdate()
|
||||||
|
|
@ -188,43 +187,6 @@ public class PaymentController {
|
||||||
return R.success();
|
return R.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理企业支付
|
|
||||||
*/
|
|
||||||
public void handleCompanyPay(PaymentContextResult ctx, BigDecimal amount, Long orderId) {
|
|
||||||
// 验证资金账户信息
|
|
||||||
if (ctx.getCompanyAccountId() == null) {
|
|
||||||
throw Exceptions.clierr("公司资金账户不存在");
|
|
||||||
}
|
|
||||||
BigDecimal oldBalance = ctx.getCompanyBalance();
|
|
||||||
BigDecimal newBalance = oldBalance.subtract(amount);
|
|
||||||
|
|
||||||
// 更新账户余额(支持负数余额)
|
|
||||||
MoneyAccountEntity companyAccount = new MoneyAccountEntity()
|
|
||||||
.setId(ctx.getCompanyAccountId())
|
|
||||||
.setMoney(newBalance);
|
|
||||||
moneyAccountService.updateById(companyAccount);
|
|
||||||
|
|
||||||
// 记录资金变动明细
|
|
||||||
MoneyChangeDetailEntity changeDetail = new MoneyChangeDetailEntity()
|
|
||||||
// .setUserId(ctx.getCompanyUserId())
|
|
||||||
.setCompanyId(ctx.getTransCompanyId())
|
|
||||||
.setOrderId(orderId)
|
|
||||||
.setMoneyAccountId(companyAccount.getId())
|
|
||||||
.setOldMoney(oldBalance)
|
|
||||||
.setDelta(amount.negate()) // 扣减为负数
|
|
||||||
.setNewMoney(newBalance)
|
|
||||||
.setMoneyChangeCategory(MoneyChangeCategory.DingDanKouKuan)
|
|
||||||
.setMemo("订单支付扣款,订单ID:" + orderId + ",结算方式:" + ctx.getSettlementWay());
|
|
||||||
|
|
||||||
moneyChangeDetailService.save(changeDetail);
|
|
||||||
|
|
||||||
log.info("公司账户扣减成功,用户ID:{},扣减金额:{},余额:{} -> {},结算方式:{}",
|
|
||||||
ctx.getCompanyUserId(), amount, oldBalance, newBalance, ctx.getSettlementWay());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前用户openid
|
* 获取当前用户openid
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue