|
@@ -46,6 +46,25 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
|
|
|
// 订单状态、支付状态
|
|
// 订单状态、支付状态
|
|
|
var washOrder = washOrderService.lambdaQuery().eq(WashOrder::getOrderId, orderInfo.getOrder_id()).one();
|
|
var washOrder = washOrderService.lambdaQuery().eq(WashOrder::getOrderId, orderInfo.getOrder_id()).one();
|
|
|
if (washOrder != null) {
|
|
if (washOrder != null) {
|
|
|
|
|
+ int rechargePayment;
|
|
|
|
|
+ int grantsPayment = 0;
|
|
|
|
|
+ // 扣款更新余额(优先扣减充值款,不够则扣除赠款),新增资金流水
|
|
|
|
|
+ var account = accountService.getAccountByUserId(washOrder.getUserId());
|
|
|
|
|
+ if (account.getRechargeBalance() >= orderInfo.getAmount()) {
|
|
|
|
|
+ rechargePayment = orderInfo.getAmount();
|
|
|
|
|
+ accountService.lambdaUpdate().setSql("balance = balance - {0}, recharge_balance = recharge_balance - {1}",
|
|
|
|
|
+ orderInfo.getAmount(), rechargePayment)
|
|
|
|
|
+ .eq(Account::getUserId, washOrder.getUserId()).update();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 充值款余额不足以支付订单,则扣赠款
|
|
|
|
|
+ rechargePayment = account.getRechargeBalance();
|
|
|
|
|
+ grantsPayment = orderInfo.getAmount() - account.getRechargeBalance();
|
|
|
|
|
+ accountService.lambdaUpdate()
|
|
|
|
|
+ .setSql("balance = balance - {0}, recharge_balance = 0, grants_balance = grants_balance - {1}",
|
|
|
|
|
+ orderInfo.getAmount(), grantsPayment)
|
|
|
|
|
+ .eq(Account::getUserId, washOrder.getUserId()).update();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
washOrder
|
|
washOrder
|
|
|
.setCloseType(orderInfo.getClose_type())
|
|
.setCloseType(orderInfo.getClose_type())
|
|
|
.setAmount(orderInfo.getAmount())
|
|
.setAmount(orderInfo.getAmount())
|
|
@@ -53,15 +72,12 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
|
|
|
.setDiscountMoney(orderInfo.getDiscount_money())
|
|
.setDiscountMoney(orderInfo.getDiscount_money())
|
|
|
.setDetail(JSONArray.toJSONString(orderInfo.getDetail()))
|
|
.setDetail(JSONArray.toJSONString(orderInfo.getDetail()))
|
|
|
.setEndTime(LocalDateTime.now())
|
|
.setEndTime(LocalDateTime.now())
|
|
|
|
|
+ .setRechargePayment(rechargePayment)
|
|
|
|
|
+ .setGrantsPayment(grantsPayment)
|
|
|
.setOrderStatus(WashOrder.ORDER_STATUS_成功)
|
|
.setOrderStatus(WashOrder.ORDER_STATUS_成功)
|
|
|
.setPayStatus(WashOrder.PAY_STATUS_已支付);
|
|
.setPayStatus(WashOrder.PAY_STATUS_已支付);
|
|
|
washOrderService.updateById(washOrder);
|
|
washOrderService.updateById(washOrder);
|
|
|
|
|
|
|
|
- // 扣款更新余额,新增资金流水 TODO 【存在优惠情况下校验优惠,更新优惠使用情况等】
|
|
|
|
|
- var account = accountService.getAccountByUserId(washOrder.getUserId());
|
|
|
|
|
- accountService.lambdaUpdate().setSql("balance = balance - {0}", orderInfo.getAmount())
|
|
|
|
|
- .eq(Account::getUserId, washOrder.getUserId()).update();
|
|
|
|
|
-
|
|
|
|
|
var walletDetail = new WalletDetail();
|
|
var walletDetail = new WalletDetail();
|
|
|
walletDetail.setUserId(washOrder.getUserId());
|
|
walletDetail.setUserId(washOrder.getUserId());
|
|
|
walletDetail.setType(WalletDetail.TYPE_消费);
|
|
walletDetail.setType(WalletDetail.TYPE_消费);
|
|
@@ -73,10 +89,9 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
|
|
|
walletDetail.setTransactionTime(LocalDateTime.now());
|
|
walletDetail.setTransactionTime(LocalDateTime.now());
|
|
|
walletDetail.setStatus(WalletDetail.STATUS_已确认);
|
|
walletDetail.setStatus(WalletDetail.STATUS_已确认);
|
|
|
walletDetailService.save(walletDetail);
|
|
walletDetailService.save(walletDetail);
|
|
|
- }else {
|
|
|
|
|
|
|
+ } else {
|
|
|
log.error("订单不存在,订单号:{}", orderInfo.getOrder_id());
|
|
log.error("订单不存在,订单号:{}", orderInfo.getOrder_id());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|