|
|
@@ -566,12 +566,13 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
}
|
|
|
} else if (type.equals(2)) {
|
|
|
order = baseMapper.selectLiveOrderByOrderId(String.valueOf(orderId));
|
|
|
- if (!order.getStatus().equals(OrderInfoEnum.STATUS_0.getValue())) {
|
|
|
+ // LiveOrder 待支付状态为1,FsStoreOrder 待支付为0,兼容两种
|
|
|
+ if (!order.getStatus().equals(OrderInfoEnum.STATUS_0.getValue()) && !order.getStatus().equals(1)) {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
return "";
|
|
|
}
|
|
|
}
|
|
|
- if (order.getStatus() != 1) {
|
|
|
+ if (order.getStatus() != 1 && !order.getStatus().equals(OrderInfoEnum.STATUS_0.getValue())) {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
return "";
|
|
|
}
|
|
|
@@ -684,6 +685,160 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 统一支付创建逻辑,按 wxPayment 的实现方式:创建支付单后走 PaymentHandler.createLiveOrder
|
|
|
+ * @param order 直播订单
|
|
|
+ * @param user 用户
|
|
|
+ * @param payTypeCode 支付类型码 alipay/weixin
|
|
|
+ * @param tradeType 汇付交易类型 T_MINIAPP/T_JSAPI/A_NATIVE(仅汇付使用)
|
|
|
+ * @param openId 公众号mpOpenId或小程序maOpenId,支付宝可传null
|
|
|
+ */
|
|
|
+ private R doCreateLivePayment(LiveOrder order, FsUser user, String payTypeCode,
|
|
|
+ String tradeType, String openId) {
|
|
|
+ String json = configService.selectConfigByKey("store.pay");
|
|
|
+ FsPayConfig fsPayConfig = JSON.parseObject(json, FsPayConfig.class);
|
|
|
+ String payCode = SnowflakeUtils.nextId();
|
|
|
+ if (StringUtils.isEmpty(payCode)) {
|
|
|
+ return R.error("订单生成失败,请重试");
|
|
|
+ }
|
|
|
+ LiveOrderPayment storePayment = new LiveOrderPayment();
|
|
|
+ storePayment.setStatus(0);
|
|
|
+ storePayment.setPayMode(fsPayConfig.getType());
|
|
|
+ storePayment.setBusinessCode(order.getOrderCode());
|
|
|
+ storePayment.setPayCode(payCode);
|
|
|
+ storePayment.setPayMoney(order.getPayMoney());
|
|
|
+ storePayment.setCreateTime(new Date());
|
|
|
+ storePayment.setPayTypeCode(payTypeCode);
|
|
|
+ storePayment.setBusinessType(5);
|
|
|
+ storePayment.setRemark("直播商品订单支付");
|
|
|
+ if (openId != null) {
|
|
|
+ storePayment.setOpenId(openId);
|
|
|
+ }
|
|
|
+ storePayment.setUserId(user.getUserId());
|
|
|
+ storePayment.setBusinessId(order.getOrderId().toString());
|
|
|
+ if (liveOrderPaymentMapper.insertLiveOrderPayment(storePayment) > 0) {
|
|
|
+ LiveOrder newOrder = new LiveOrder();
|
|
|
+ newOrder.setOrderId(order.getOrderId());
|
|
|
+ newOrder.setPayPrice(order.getPayMoney());
|
|
|
+ baseMapper.updateLiveOrder(newOrder);
|
|
|
+ PayProcessContext processContext = new PayProcessContext();
|
|
|
+ processContext.setOrderId(order.getOrderId());
|
|
|
+ processContext.setPayType("alipay".equals(payTypeCode) ? 3 : 1);
|
|
|
+ processContext.setPaymentId(storePayment.getPaymentId());
|
|
|
+ processContext.setPayCode(storePayment.getPayCode());
|
|
|
+ processContext.setFsPayConfig(fsPayConfig);
|
|
|
+ processContext.setUserId(Long.valueOf(order.getUserId()));
|
|
|
+ processContext.setGoodsInfo("直播商品订单支付");
|
|
|
+ processContext.setOrderPrefix("live-");
|
|
|
+ processContext.setTradeType(tradeType);
|
|
|
+ processContext.setOpenId(openId);
|
|
|
+ PaymentHandler payment = PaymentHandlerHolder.findBest(fsPayConfig.getType());
|
|
|
+ if (ObjectUtil.isNull(payment)) {
|
|
|
+ throw new CustomException("支付方式不存在");
|
|
|
+ }
|
|
|
+ R process = payment.createLiveOrder(processContext);
|
|
|
+ if ("200".equals(String.valueOf(process.get("code")))) {
|
|
|
+ redisCache.setCacheObject("isPaying:" + order.getOrderId(), order.getOrderId().toString(), 1, TimeUnit.MINUTES);
|
|
|
+ return process;
|
|
|
+ }
|
|
|
+ return process;
|
|
|
+ } else {
|
|
|
+ return R.error("支付记录创建失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
|
|
|
+ public R aliPayment(FsUserLiveOrderPayUParam param) {
|
|
|
+ LiveOrder order = baseMapper.selectLiveOrderByOrderId(String.valueOf(param.getOrderId()));
|
|
|
+ if (order == null) {
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ if (order.getStatus() != 1) {
|
|
|
+ return R.error("非法操作");
|
|
|
+ }
|
|
|
+ FsUser user = userMapper.selectFsUserByUserId(param.getUserId());
|
|
|
+ if (user == null) {
|
|
|
+ return R.error("用户不存在");
|
|
|
+ }
|
|
|
+ if (order.getPayMoney().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ payConfirm(2, param.getOrderId(), null, null, null, null);
|
|
|
+ return R.ok().put("isPay", 1);
|
|
|
+ }
|
|
|
+ return doCreateLivePayment(order, user, "alipay", "A_NATIVE", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
|
|
|
+ public R H5WxPayment(FsUserLiveOrderPayUParam param) {
|
|
|
+ LiveOrder order = baseMapper.selectLiveOrderByOrderId(String.valueOf(param.getOrderId()));
|
|
|
+ if (order == null) {
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ if (order.getStatus() != 1) {
|
|
|
+ return R.error("非法操作");
|
|
|
+ }
|
|
|
+ String orderIdCache = redisCache.getCacheObject("isPaying:" + order.getOrderId());
|
|
|
+ if (StringUtils.isNotEmpty(orderIdCache) && orderIdCache.equals(order.getOrderId().toString())) {
|
|
|
+ return R.error("正在支付中...");
|
|
|
+ }
|
|
|
+ FsUser user = userMapper.selectFsUserByUserId(param.getUserId());
|
|
|
+ if (user == null || StringUtils.isEmpty(user.getMpOpenId())) {
|
|
|
+ return R.error(401, "用户OPENID不存在");
|
|
|
+ }
|
|
|
+ if (order.getPayMoney().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ payConfirm(2, param.getOrderId(), null, null, null, null);
|
|
|
+ return R.ok().put("isPay", 1);
|
|
|
+ }
|
|
|
+ return doCreateLivePayment(order, user, "weixin", "T_JSAPI", user.getMpOpenId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
|
|
|
+ public R appWxPayment(FsUserLiveOrderPayUParam param) {
|
|
|
+ LiveOrder order = baseMapper.selectLiveOrderByOrderId(String.valueOf(param.getOrderId()));
|
|
|
+ if (order == null) {
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ if (order.getStatus() != 1) {
|
|
|
+ return R.error("非法操作");
|
|
|
+ }
|
|
|
+ String orderIdCache = redisCache.getCacheObject("isPaying:" + order.getOrderId());
|
|
|
+ if (StringUtils.isNotEmpty(orderIdCache) && orderIdCache.equals(order.getOrderId().toString())) {
|
|
|
+ return R.error("正在支付中...");
|
|
|
+ }
|
|
|
+ FsUser user = userMapper.selectFsUserByUserId(param.getUserId());
|
|
|
+ if (user == null || StringUtils.isEmpty(user.getMaOpenId())) {
|
|
|
+ return R.error(401, "用户OPENID不存在");
|
|
|
+ }
|
|
|
+ if (order.getPayMoney().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ payConfirm(2, param.getOrderId(), null, null, null, null);
|
|
|
+ return R.ok().put("isPay", 1);
|
|
|
+ }
|
|
|
+ return doCreateLivePayment(order, user, "weixin", "T_MINIAPP", user.getMaOpenId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
|
|
|
+ public R H5AliPayment(FsUserLiveOrderPayUParam param) {
|
|
|
+ LiveOrder order = baseMapper.selectLiveOrderByOrderId(String.valueOf(param.getOrderId()));
|
|
|
+ if (order == null) {
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+ if (order.getStatus() != 1) {
|
|
|
+ return R.error("非法操作");
|
|
|
+ }
|
|
|
+ FsUser user = userMapper.selectFsUserByUserId(param.getUserId());
|
|
|
+ if (user == null) {
|
|
|
+ return R.error("用户不存在");
|
|
|
+ }
|
|
|
+ if (order.getPayMoney().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ payConfirm(2, param.getOrderId(), null, null, null, null);
|
|
|
+ return R.ok().put("isPay", 1);
|
|
|
+ }
|
|
|
+ return doCreateLivePayment(order, user, "alipay", "A_NATIVE", null);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public int tuiOrder(Long orderId) {
|
|
|
LiveOrder liveOrder = new LiveOrder();
|