|
|
@@ -8,7 +8,6 @@ import cn.hutool.core.io.IoUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.URLUtil;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
-
|
|
|
import com.kym.common.config.WxFapiaoConfig;
|
|
|
import com.kym.common.config.WxPayConfig;
|
|
|
import com.kym.common.constant.ResponseEnum;
|
|
|
@@ -317,18 +316,24 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
DateTime dt = DateUtil.parse(transaction.getSuccessTime());
|
|
|
LocalDateTime successTime = LocalDateTimeUtil.of(dt);
|
|
|
|
|
|
+
|
|
|
// 钱包流水
|
|
|
var walletDetail = walletDetailService.getWalletDetailByOrderNo(transaction.getOutTradeNo(), WalletDetail.TYPE_充值);
|
|
|
if (walletDetail != null) {
|
|
|
+
|
|
|
+ // 更新余额
|
|
|
+ var account = accountService.getAccountByUserId(walletDetail.getUserId());
|
|
|
+ accountService.lambdaUpdate().setSql("balance = (balance+%d)".formatted(transaction.getAmount().getTotal()))
|
|
|
+ .eq(Account::getUserId, walletDetail.getUserId()).update();
|
|
|
+
|
|
|
walletDetail.setStatus(WalletDetail.STATUS_已确认); //已确认
|
|
|
walletDetail.setCurrency(transaction.getAmount().getCurrency());
|
|
|
walletDetail.setAmount(transaction.getAmount().getTotal());
|
|
|
+ walletDetail.setBeforeBalance(account.getBalance());
|
|
|
+ walletDetail.setAfterBalance(account.getBalance() + walletDetail.getAmount());
|
|
|
walletDetail.setTransactionTime(successTime);
|
|
|
walletDetailService.updateById(walletDetail);
|
|
|
|
|
|
- // 更新余额
|
|
|
- accountService.lambdaUpdate().setSql("balance = (balance+%d)".formatted(transaction.getAmount().getTotal()))
|
|
|
- .eq(Account::getUserId, walletDetail.getUserId()).update();
|
|
|
|
|
|
// 异步处理充值服务费打折权益活动相关逻辑
|
|
|
activityService.handleRechargeActivity(walletDetail.getUserId(), transaction.getAmount().getTotal());
|
|
|
@@ -355,7 +360,6 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
// 如果存在进行中的订单,则向en+更新用户余额
|
|
|
var chargingOrder = chargeOrderService.getChargingOrderByUserId(walletDetail.getUserId());
|
|
|
if (chargingOrder != null) {
|
|
|
- var account = accountService.getAccountByUserId(walletDetail.getUserId());
|
|
|
// TODO: 2023-11-30 快充这里考虑过充的金额要提高
|
|
|
var res = enPlusService.updateBalanceByQueryEquipChargeStatus(chargingOrder.getStartChargeSeq(), account.getBalance() - 50);
|
|
|
LOGGER.info("用户:{}充电过程中充值,已更新en+充电金额,en+返回数据:{}", account.getUserId(), res);
|
|
|
@@ -588,6 +592,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
|
|
|
if (RefundLog.STATUS_退款成功.equals(refundNotification.getRefundStatus().name())) {
|
|
|
// 冻结金额扣减此次(退款金额+优惠金额),优惠金额字段减去申请退款时的优惠金额
|
|
|
+ var account = accountService.getAccountByUserId(refundLog.getUserId());
|
|
|
accountService.lambdaUpdate().setSql("frozen_amount = (frozen_amount - (%d + %d)) , discount_amount = (discount_amount - %d)"
|
|
|
.formatted(refundNotification.getAmount().getRefund().intValue(), refundLog.getDiscountAmount(), refundLog.getDiscountAmount()))
|
|
|
.eq(Account::getUserId, refundLog.getUserId()).update();
|
|
|
@@ -599,6 +604,8 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
.set(WalletDetail::getTransactionId, refundNotification.getTransactionId())
|
|
|
.set(WalletDetail::getTransactionTime, successTime)
|
|
|
.set(WalletDetail::getAmount, refundNotification.getAmount().getRefund().intValue())
|
|
|
+ .set(WalletDetail::getBeforeBalance, account.getBalance())
|
|
|
+ .set(WalletDetail::getAfterBalance, account.getBalance() - refundNotification.getAmount().getRefund().intValue())
|
|
|
.set(WalletDetail::getTransactionTime, successTime)
|
|
|
.eq(WalletDetail::getId, walletDetail.getId()).update();
|
|
|
LOGGER.info("微信退款回调{}:业务处理结束", notifyRes[2]);
|